aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-10 12:07:10 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-21 15:40:00 +0200
commitfa1fa57d5fe1cb901520f03e7f802a156aae1034 (patch)
treeb97d57e4a1262add1ff57f76bdbbf9b4b1495e0f
parentb0f28bd39db1732db794c6ba1f02d244bce0641c (diff)
Move the rest of generators to new ctor-less context
-rw-r--r--odb/context.hxx8
-rw-r--r--odb/generate.hxx27
-rw-r--r--odb/generator.cxx12
-rw-r--r--odb/header.cxx108
-rw-r--r--odb/header.hxx14
-rw-r--r--odb/include.cxx252
-rw-r--r--odb/include.hxx14
-rw-r--r--odb/inline.cxx55
-rw-r--r--odb/inline.hxx14
-rw-r--r--odb/relational/type-processor.cxx34
-rw-r--r--odb/tracer/header.cxx1
-rw-r--r--odb/tracer/inline.cxx1
-rw-r--r--odb/tracer/source.cxx1
13 files changed, 271 insertions, 270 deletions
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<func> (key) (*this);
+ return c.get<func> (key) ();
else
return c.get<X> (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 <boris@codesynthesis.com>
+// 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 <odb/context.hxx>
#include <odb/generator.hxx>
-#include <odb/include.hxx>
-#include <odb/header.hxx>
-#include <odb/inline.hxx>
-
+#include <odb/generate.hxx>
#include <odb/tracer/generate.hxx>
-
#include <odb/relational/generate.hxx>
#include <odb/relational/type-processor.hxx>
@@ -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 <odb/common.hxx>
-#include <odb/header.hxx>
+#include <odb/context.hxx>
+#include <odb/generate.hxx>
+
+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 <memory>" << endl
- << "#include <cstddef>" << endl // std::size_t
- << endl;
-
- ctx.os << "#include <odb/core.hxx>" << endl
- << "#include <odb/traits.hxx>" << endl
- << "#include <odb/pointer-traits.hxx>" << 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<bool> ("tr1-pointer-used"))
- {
- ctx.os << "#include <odb/tr1/pointer-traits.hxx>" << endl;
- }
- else if (ctx.unit.count ("boost-pointer-used") &&
- ctx.unit.get<bool> ("boost-pointer-used"))
+ void
+ generate ()
{
- ctx.os << "#ifdef BOOST_TR1_MEMORY_HPP_INCLUDED" << endl
- << "# include <odb/tr1/pointer-traits.hxx>" << endl
- << "#endif" << endl;
- }
-
- ctx.os << "#include <odb/container-traits.hxx>" << endl;
+ context ctx;
+ ostream& os (ctx.os);
+
+ os << "#include <memory>" << endl
+ << "#include <cstddef>" << endl // std::size_t
+ << endl;
+
+ os << "#include <odb/core.hxx>" << endl
+ << "#include <odb/traits.hxx>" << endl
+ << "#include <odb/pointer-traits.hxx>" << 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<bool> ("tr1-pointer-used"))
+ {
+ os << "#include <odb/tr1/pointer-traits.hxx>" << endl;
+ }
+ else if (ctx.unit.count ("boost-pointer-used") &&
+ ctx.unit.get<bool> ("boost-pointer-used"))
+ {
+ os << "#ifdef BOOST_TR1_MEMORY_HPP_INCLUDED" << endl
+ << "# include <odb/tr1/pointer-traits.hxx>" << endl
+ << "#endif" << endl;
+ }
- if (ctx.options.generate_query ())
- ctx.os << "#include <odb/result.hxx>" << endl;
+ os << "#include <odb/container-traits.hxx>" << endl;
- ctx.os << endl;
+ if (ctx.options.generate_query ())
+ os << "#include <odb/result.hxx>" << 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 <boris@codesynthesis.com>
-// 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 <odb/context.hxx>
-
-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 <cassert>
#include <fstream>
-#include <odb/include.hxx>
+#include <odb/common.hxx>
+#include <odb/context.hxx>
+#include <odb/generate.hxx>
#include <iostream>
@@ -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<line_map const*, include> includes;
+ typedef std::map<line_map const*, include_directive> includes;
typedef std::map<path, includes> include_map;
// Map of files to the lines which contain include directives
// that we are interested in.
//
- typedef std::map<size_t, include*> include_lines;
+ typedef std::map<size_t, include_directive*> include_lines;
typedef std::map<path, include_lines> 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 const*, include_comparator> include_set;
+ typedef
+ std::multiset<include_directive const*, include_comparator>
+ 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 <boris@codesynthesis.com>
-// 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 <odb/context.hxx>
-
-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 <odb/common.hxx>
-#include <odb/inline.hxx>
+#include <odb/context.hxx>
+#include <odb/generate.hxx>
+
+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 <boris@codesynthesis.com>
-// 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 <odb/context.hxx>
-
-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<string> ("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<string> ("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 <odb/common.hxx>
+#include <odb/context.hxx>
#include <odb/tracer/generate.hxx>
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 <odb/common.hxx>
+#include <odb/context.hxx>
#include <odb/tracer/generate.hxx>
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 <odb/common.hxx>
+#include <odb/context.hxx>
#include <odb/tracer/generate.hxx>
using namespace std;