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/context.hxx | 8 +- odb/generate.hxx | 27 ++++ odb/generator.cxx | 12 +- odb/header.cxx | 108 ++++++++-------- odb/header.hxx | 14 --- odb/include.cxx | 252 ++++++++++++++++++++------------------ odb/include.hxx | 14 --- odb/inline.cxx | 55 +++++---- odb/inline.hxx | 14 --- odb/relational/type-processor.cxx | 34 ++--- odb/tracer/header.cxx | 1 + odb/tracer/inline.cxx | 1 + odb/tracer/source.cxx | 1 + 13 files changed, 271 insertions(+), 270 deletions(-) create mode 100644 odb/generate.hxx delete mode 100644 odb/header.hxx delete mode 100644 odb/include.hxx delete mode 100644 odb/inline.hxx diff --git a/odb/context.hxx b/odb/context.hxx index 859a665..0de95c1 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -173,7 +173,7 @@ public: static size_t out_column_count (semantics::class_&); - semantics::data_member& + static semantics::data_member& id_member (semantics::class_&); // Object pointer information. @@ -321,11 +321,11 @@ private: X indirect_value (semantics::context const& c, string const& key) { - typedef X (*func) (context&); + typedef X (*func) (); std::type_info const& ti (c.type_info (key)); if (ti == typeid (func)) - return c.get (key) (*this); + return c.get (key) (); else return c.get (key); } @@ -457,8 +457,6 @@ has (Y& y) // struct namespace_: traversal::namespace_, context { - namespace_ (context& c) : context (c) {} - virtual void traverse (type&); }; diff --git a/odb/generate.hxx b/odb/generate.hxx new file mode 100644 index 0000000..87e36aa --- /dev/null +++ b/odb/generate.hxx @@ -0,0 +1,27 @@ +// file : odb/generate.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v3; see accompanying LICENSE file + +#ifndef ODB_GENERATE_HXX +#define ODB_GENERATE_HXX + +namespace include +{ + void + generate (); +} + +namespace header +{ + void + generate (); +} + +namespace inline_ +{ + void + generate (); +} + +#endif // ODB_GENERATE_HXX diff --git a/odb/generator.cxx b/odb/generator.cxx index 097a5a5..a6431ed 100644 --- a/odb/generator.cxx +++ b/odb/generator.cxx @@ -18,12 +18,8 @@ #include #include -#include -#include -#include - +#include #include - #include #include @@ -283,8 +279,8 @@ generate (options const& ops, semantics::unit& unit, path const& p) (br ? '>' : '"') << endl << endl; - generate_include (*ctx); - generate_header (*ctx); + include::generate (); + header::generate (); switch (ops.database ()) { @@ -348,7 +344,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) << "// End prologue." << endl << endl; - generate_inline (*ctx); + inline_::generate (); switch (ops.database ()) { diff --git a/odb/header.cxx b/odb/header.cxx index 458c822..140a781 100644 --- a/odb/header.cxx +++ b/odb/header.cxx @@ -4,17 +4,15 @@ // license : GNU GPL v3; see accompanying LICENSE file #include -#include +#include +#include + +using namespace std; namespace { struct data_member: traversal::data_member, context { - data_member (context& c) - : context (c) - { - } - virtual void traverse (semantics::data_member& m) { @@ -36,8 +34,7 @@ namespace struct class_: traversal::class_, context { - class_ (context& c) - : context (c), member_ (c) + class_ () { member_names_ >> member_; } @@ -77,62 +74,67 @@ namespace }; } -void -generate_header (context& ctx) +namespace header { - ctx.os << "#include " << endl - << "#include " << endl // std::size_t - << endl; - - ctx.os << "#include " << endl - << "#include " << endl - << "#include " << endl; - - // In case of a boost TR1 implementation, we cannot distinguish - // between the boost::shared_ptr and std::tr1::shared_ptr usage since - // the latter is just a using-declaration for the former. To resolve - // this we will include TR1 traits if the Boost TR1 header is included. - // - if (ctx.unit.count ("tr1-pointer-used") && - ctx.unit.get ("tr1-pointer-used")) - { - ctx.os << "#include " << endl; - } - else if (ctx.unit.count ("boost-pointer-used") && - ctx.unit.get ("boost-pointer-used")) + void + generate () { - ctx.os << "#ifdef BOOST_TR1_MEMORY_HPP_INCLUDED" << endl - << "# include " << endl - << "#endif" << endl; - } - - ctx.os << "#include " << endl; + context ctx; + ostream& os (ctx.os); + + os << "#include " << endl + << "#include " << endl // std::size_t + << endl; + + os << "#include " << endl + << "#include " << endl + << "#include " << endl; + + // In case of a boost TR1 implementation, we cannot distinguish + // between the boost::shared_ptr and std::tr1::shared_ptr usage since + // the latter is just a using-declaration for the former. To resolve + // this we will include TR1 traits if the Boost TR1 header is included. + // + if (ctx.unit.count ("tr1-pointer-used") && + ctx.unit.get ("tr1-pointer-used")) + { + os << "#include " << endl; + } + else if (ctx.unit.count ("boost-pointer-used") && + ctx.unit.get ("boost-pointer-used")) + { + os << "#ifdef BOOST_TR1_MEMORY_HPP_INCLUDED" << endl + << "# include " << endl + << "#endif" << endl; + } - if (ctx.options.generate_query ()) - ctx.os << "#include " << endl; + os << "#include " << endl; - ctx.os << endl; + if (ctx.options.generate_query ()) + os << "#include " << endl; + os << endl; - /* - traversal::unit unit; - traversal::defines unit_defines; - traversal::namespace_ ns; - class_ c (ctx); + /* + traversal::unit unit; + traversal::defines unit_defines; + traversal::namespace_ ns; + class_ c; - unit >> unit_defines >> ns; - unit_defines >> c; + unit >> unit_defines >> ns; + unit_defines >> c; - traversal::defines ns_defines; + traversal::defines ns_defines; - ns >> ns_defines >> ns; - ns_defines >> c; + ns >> ns_defines >> ns; + ns_defines >> c; - ctx.os << "namespace odb" + os << "namespace odb" << "{"; - unit.dispatch (ctx.unit); + unit.dispatch (ctx.unit); - ctx.os << "}"; - */ + os << "}"; + */ + } } diff --git a/odb/header.hxx b/odb/header.hxx deleted file mode 100644 index 36a336b..0000000 --- a/odb/header.hxx +++ /dev/null @@ -1,14 +0,0 @@ -// file : odb/header.hxx -// author : Boris Kolpackov -// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC -// license : GNU GPL v3; see accompanying LICENSE file - -#ifndef ODB_HEADER_HXX -#define ODB_HEADER_HXX - -#include - -void -generate_header (context&); - -#endif // ODB_HEADER_HXX 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; + } } } diff --git a/odb/include.hxx b/odb/include.hxx deleted file mode 100644 index f255d8b..0000000 --- a/odb/include.hxx +++ /dev/null @@ -1,14 +0,0 @@ -// file : odb/include.hxx -// author : Boris Kolpackov -// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC -// license : GNU GPL v3; see accompanying LICENSE file - -#ifndef ODB_INCLUDE_HXX -#define ODB_INCLUDE_HXX - -#include - -void -generate_include (context&); - -#endif // ODB_INCLUDE_HXX diff --git a/odb/inline.cxx b/odb/inline.cxx index f9df4ed..d62a34f 100644 --- a/odb/inline.cxx +++ b/odb/inline.cxx @@ -4,14 +4,16 @@ // license : GNU GPL v3; see accompanying LICENSE file #include -#include +#include +#include + +using namespace std; namespace { struct data_member: traversal::data_member, context { - data_member (context& c, semantics::class_& cl) - : context (c) + data_member (semantics::class_& cl) //@@ context::object { scope_ = "access::value_traits< " + cl.fq_name () + " >"; } @@ -46,11 +48,6 @@ namespace struct class_: traversal::class_, context { - class_ (context& c) - : context (c) - { - } - virtual void traverse (type& c) { @@ -63,35 +60,41 @@ namespace os << "// " << c.name () << endl << "//" << endl; - data_member member (*this, c); + data_member member (c); traversal::names member_names (member); names (c, member_names); } }; } -void -generate_inline (context& /*ctx*/) +namespace inline_ { - /* - traversal::unit unit; - traversal::defines unit_defines; - traversal::namespace_ ns; - class_ c (ctx); + void + generate () + { + /* + context ctx; + ostream& os (ctx.os); + + traversal::unit unit; + traversal::defines unit_defines; + traversal::namespace_ ns; + class_ c; - unit >> unit_defines >> ns; - unit_defines >> c; + unit >> unit_defines >> ns; + unit_defines >> c; - traversal::defines ns_defines; + traversal::defines ns_defines; - ns >> ns_defines >> ns; - ns_defines >> c; + ns >> ns_defines >> ns; + ns_defines >> c; - ctx.os << "namespace odb" - << "{"; + os << "namespace odb" + << "{"; - unit.dispatch (ctx.unit); + unit.dispatch (ctx.unit); - ctx.os << "}"; - */ + os << "}"; + */ + } } diff --git a/odb/inline.hxx b/odb/inline.hxx deleted file mode 100644 index 1613c58..0000000 --- a/odb/inline.hxx +++ /dev/null @@ -1,14 +0,0 @@ -// file : odb/inline.hxx -// author : Boris Kolpackov -// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC -// license : GNU GPL v3; see accompanying LICENSE file - -#ifndef ODB_INLINE_HXX -#define ODB_INLINE_HXX - -#include - -void -generate_inline (context&); - -#endif // ODB_INLINE_HXX diff --git a/odb/relational/type-processor.cxx b/odb/relational/type-processor.cxx index 7b5eb13..52bec34 100644 --- a/odb/relational/type-processor.cxx +++ b/odb/relational/type-processor.cxx @@ -12,26 +12,28 @@ using namespace std; -// Indirect (dynamic) context values. -// -static semantics::type* -id_tree_type (context& c) -{ - semantics::data_member& id (c.id_member (*c.object)); - return &id.type (); -} - -static string -id_column_type (context& c) -{ - semantics::data_member& id (c.id_member (*c.object)); - return id.get ("ref-column-type"); -} - namespace relational { namespace { + // Indirect (dynamic) context values. + // + static semantics::type* + id_tree_type () + { + context& c (context::current ()); + semantics::data_member& id (context::id_member (*c.object)); + return &id.type (); + } + + static string + id_column_type () + { + context& c (context::current ()); + semantics::data_member& id (context::id_member (*c.object)); + return id.get ("ref-column-type"); + } + struct data_member: traversal::data_member, context { data_member () diff --git a/odb/tracer/header.cxx b/odb/tracer/header.cxx index c8c5a43..6973fe4 100644 --- a/odb/tracer/header.cxx +++ b/odb/tracer/header.cxx @@ -4,6 +4,7 @@ // license : GNU GPL v3; see accompanying LICENSE file #include +#include #include using namespace std; diff --git a/odb/tracer/inline.cxx b/odb/tracer/inline.cxx index bf5f0f4..0abfb70 100644 --- a/odb/tracer/inline.cxx +++ b/odb/tracer/inline.cxx @@ -4,6 +4,7 @@ // license : GNU GPL v3; see accompanying LICENSE file #include +#include #include using namespace std; diff --git a/odb/tracer/source.cxx b/odb/tracer/source.cxx index 73f0a8a..5b26274 100644 --- a/odb/tracer/source.cxx +++ b/odb/tracer/source.cxx @@ -4,6 +4,7 @@ // license : GNU GPL v3; see accompanying LICENSE file #include +#include #include using namespace std; -- cgit v1.1