From fa1fa57d5fe1cb901520f03e7f802a156aae1034 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Mar 2011 12:07:10 +0200 Subject: Move the rest of generators to new ctor-less context --- odb/include.cxx | 252 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 132 insertions(+), 120 deletions(-) (limited to 'odb/include.cxx') diff --git a/odb/include.cxx b/odb/include.cxx index a26bfc4..1edaded 100644 --- a/odb/include.cxx +++ b/odb/include.cxx @@ -11,7 +11,9 @@ #include #include -#include +#include +#include +#include #include @@ -20,7 +22,7 @@ using semantics::path; namespace { - struct include + struct include_directive { enum type { quote, bracket }; @@ -28,13 +30,13 @@ namespace path path_; }; - typedef std::map includes; + typedef std::map includes; typedef std::map include_map; // Map of files to the lines which contain include directives // that we are interested in. // - typedef std::map include_lines; + typedef std::map include_lines; typedef std::map file_map; // Set of include directives sorted in the preference order. @@ -42,7 +44,7 @@ namespace struct include_comparator { bool - operator() (include const* x, include const* y) const + operator() (include_directive const* x, include_directive const* y) const { // Prefer <> over "". // @@ -56,13 +58,15 @@ namespace } }; - typedef std::multiset include_set; + typedef + std::multiset + include_set; struct class_: traversal::class_, context { - class_ (context& c, include_map& map) - : context (c), map_ (map) + class_ (include_map& map) + : map_ (map) { } @@ -98,7 +102,7 @@ namespace f.normalize (); if (map_.find (f) == map_.end ()) - map_[f][lm] = include (); + map_[f][lm] = include_directive (); } } } @@ -197,7 +201,7 @@ namespace private: bool - parse_line (string const& l, include& inc) + parse_line (string const& l, include_directive& inc) { enum state { @@ -294,12 +298,12 @@ namespace if (c == '"') { path_end = '"'; - inc.type_ = include::quote; + inc.type_ = include_directive::quote; } else if (c == '<') { path_end = '>'; - inc.type_ = include::bracket; + inc.type_ = include_directive::bracket; } else return false; @@ -353,152 +357,160 @@ namespace }; } -void -generate_include (context& ctx) +namespace include { - include_map imap; - - traversal::unit unit; - traversal::defines unit_defines; - traversal::namespace_ ns; - class_ c (ctx, imap); - - unit >> unit_defines >> ns; - unit_defines >> c; - - traversal::defines ns_defines; + void + generate () + { + context ctx; + include_map imap; - ns >> ns_defines >> ns; - ns_defines >> c; + traversal::unit unit; + traversal::defines unit_defines; + traversal::namespace_ ns; + class_ c (imap); - unit.dispatch (ctx.unit); + unit >> unit_defines >> ns; + unit_defines >> c; - // Add all the known include locations for each file in the map. - // - for (size_t i (0); i < line_table->used; ++i) - { - line_map const* m (line_table->maps + i); + traversal::defines ns_defines; - if (MAIN_FILE_P (m) || m->reason != LC_ENTER) - continue; + ns >> ns_defines >> ns; + ns_defines >> c; - line_map const* i (INCLUDED_FROM (line_table, m)); + unit.dispatch (ctx.unit); - path f (m->to_file); - f.complete (); - f.normalize (); + // Add all the known include locations for each file in the map. + // + for (size_t i (0); i < line_table->used; ++i) + { + line_map const* m (line_table->maps + i); - include_map::iterator it (imap.find (f)); + if (MAIN_FILE_P (m) || m->reason != LC_ENTER) + continue; - if (it != imap.end ()) - it->second[i] = include (); - } + line_map const* i (INCLUDED_FROM (line_table, m)); - // - // - file_map fmap; + path f (m->to_file); + f.complete (); + f.normalize (); - for (include_map::iterator i (imap.begin ()), e (imap.end ()); i != e; ++i) - { - /* - cerr << endl - << i->first << " included from" << endl; + include_map::iterator it (imap.find (f)); - for (includes::iterator j (i->second.begin ()); j != i->second.end (); ++j) - { - line_map const* lm (j->first); - cerr << '\t' << lm->to_file << ":" << LAST_SOURCE_LINE (lm) << endl; + if (it != imap.end ()) + it->second[i] = include_directive (); } - */ - // First see if there is an include from the main file. If so, then - // it is preferred over all others. Use the first one if there are - // several. // - line_map const* main_lm (0); - include* main_inc (0); + // + file_map fmap; - for (includes::iterator j (i->second.begin ()); j != i->second.end (); ++j) + for (include_map::iterator i (imap.begin ()), e (imap.end ()); i != e; ++i) { - line_map const* lm (j->first); + /* + cerr << endl + << i->first << " included from" << endl; - if (MAIN_FILE_P (lm)) + for (includes::iterator j (i->second.begin ()); + j != i->second.end (); ++j) + { + line_map const* lm (j->first); + cerr << '\t' << lm->to_file << ":" << LAST_SOURCE_LINE (lm) << endl; + } + */ + + // First see if there is an include from the main file. If so, then + // it is preferred over all others. Use the first one if there are + // several. + // + line_map const* main_lm (0); + include_directive* main_inc (0); + + for (includes::iterator j (i->second.begin ()); + j != i->second.end (); ++j) { - if (main_lm == 0 || LAST_SOURCE_LINE (main_lm) > LAST_SOURCE_LINE (lm)) + line_map const* lm (j->first); + + if (MAIN_FILE_P (lm)) { - main_lm = lm; - main_inc = &j->second; + if (main_lm == 0 || + LAST_SOURCE_LINE (main_lm) > LAST_SOURCE_LINE (lm)) + { + main_lm = lm; + main_inc = &j->second; + } } } - } - if (main_lm != 0) - { - path f (main_lm->to_file); - f.complete (); - f.normalize (); + if (main_lm != 0) + { + path f (main_lm->to_file); + f.complete (); + f.normalize (); - fmap[f][LAST_SOURCE_LINE (main_lm)] = main_inc; - continue; - } + fmap[f][LAST_SOURCE_LINE (main_lm)] = main_inc; + continue; + } - // Otherwise, add all entries. - // - for (includes::iterator j (i->second.begin ()); j != i->second.end (); ++j) - { - line_map const* lm (j->first); + // Otherwise, add all entries. + // + for (includes::iterator j (i->second.begin ()); + j != i->second.end (); ++j) + { + line_map const* lm (j->first); - path f (lm->to_file); - f.complete (); - f.normalize (); + path f (lm->to_file); + f.complete (); + f.normalize (); - fmap[f][LAST_SOURCE_LINE (lm)] = &j->second; + fmap[f][LAST_SOURCE_LINE (lm)] = &j->second; + } } - } - - // - // - include_parser ip; - for (file_map::iterator i (fmap.begin ()), e (fmap.end ()); i != e; ++i) - { - ip.parse_file (i->first, i->second); - } - - // Finally, output the include directives. - // - for (include_map::const_iterator i (imap.begin ()), e (imap.end ()); - i != e; ++i) - { - includes const& is (i->second); - include const* inc (0); + // + // + include_parser ip; - if (is.size () == 1) + for (file_map::iterator i (fmap.begin ()), e (fmap.end ()); i != e; ++i) { - inc = &is.begin ()->second; + ip.parse_file (i->first, i->second); } - else + + // Finally, output the include directives. + // + for (include_map::const_iterator i (imap.begin ()), e (imap.end ()); + i != e; ++i) { - include_set set; + includes const& is (i->second); + include_directive const* inc (0); - for (includes::const_iterator j (i->second.begin ()); - j != i->second.end (); ++j) + if (is.size () == 1) { - if (!j->second.path_.empty ()) - set.insert (&j->second); + inc = &is.begin ()->second; } + else + { + include_set set; - assert (set.size () > 0); - inc = *set.rbegin (); - } + for (includes::const_iterator j (i->second.begin ()); + j != i->second.end (); ++j) + { + if (!j->second.path_.empty ()) + set.insert (&j->second); + } - path f (inc->path_.base ()); - f += ctx.options.odb_file_suffix (); - f += ctx.options.hxx_suffix (); + assert (set.size () > 0); + inc = *set.rbegin (); + } + + path f (inc->path_.base ()); + f += ctx.options.odb_file_suffix (); + f += ctx.options.hxx_suffix (); - ctx.os << "#include " << - (inc->type_ == include::quote ? '"' : '<') << f << - (inc->type_ == include::quote ? '"' : '>') << endl - << endl; + ctx.os << "#include " << + (inc->type_ == include_directive::quote ? '"' : '<') << f << + (inc->type_ == include_directive::quote ? '"' : '>') << endl + << endl; + } } } -- cgit v1.1