aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-09-19 16:19:25 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-09-19 16:19:25 +0200
commit55df757e98329e8e09afffe274ce2ceab269f8b3 (patch)
tree738b3a5b1c46e3b1b04184cfd9aeb32eb21af48a /odb
parent6c01cad9cbfb6e69121d106226b2c50026f86fa9 (diff)
Make processing top-level action, like validation and generation
Diffstat (limited to 'odb')
-rw-r--r--odb/context.cxx36
-rw-r--r--odb/context.hxx6
-rw-r--r--odb/generator.cxx54
-rw-r--r--odb/generator.hxx8
-rw-r--r--odb/makefile5
-rw-r--r--odb/plugin.cxx25
-rw-r--r--odb/processor.cxx34
-rw-r--r--odb/processor.hxx27
-rw-r--r--odb/relational/processor.cxx (renamed from odb/relational/type-processor.cxx)6
-rw-r--r--odb/relational/processor.hxx (renamed from odb/relational/type-processor.hxx)10
-rw-r--r--odb/validator.cxx79
-rw-r--r--odb/validator.hxx4
12 files changed, 212 insertions, 82 deletions
diff --git a/odb/context.cxx b/odb/context.cxx
index e679a55..7919e39 100644
--- a/odb/context.cxx
+++ b/odb/context.cxx
@@ -9,6 +9,10 @@
#include <odb/context.hxx>
#include <odb/common.hxx>
+#include <odb/relational/mysql/context.hxx>
+#include <odb/relational/pgsql/context.hxx>
+#include <odb/relational/sqlite/context.hxx>
+
using namespace std;
namespace
@@ -93,6 +97,38 @@ namespace
};
}
+auto_ptr<context>
+create_context (ostream& os, semantics::unit& unit, options const& ops)
+{
+ auto_ptr<context> r;
+
+ switch (ops.database ())
+ {
+ case database::mysql:
+ {
+ r.reset (new relational::mysql::context (os, unit, ops));
+ break;
+ }
+ case database::pgsql:
+ {
+ r.reset (new relational::pgsql::context (os, unit, ops));
+ break;
+ }
+ case database::sqlite:
+ {
+ r.reset (new relational::sqlite::context (os, unit, ops));
+ break;
+ }
+ case database::tracer:
+ {
+ r.reset (new context (os, unit, ops));
+ break;
+ }
+ }
+
+ return r;
+}
+
context::
~context ()
{
diff --git a/odb/context.hxx b/odb/context.hxx
index 1e6ccae..8f77645 100644
--- a/odb/context.hxx
+++ b/odb/context.hxx
@@ -13,6 +13,7 @@
#include <stack>
#include <vector>
#include <string>
+#include <memory> // std::auto_ptr
#include <ostream>
#include <cstddef> // std::size_t
#include <iostream>
@@ -686,6 +687,11 @@ private:
operator= (context const&);
};
+// Create concrete database context.
+//
+std::auto_ptr<context>
+create_context (std::ostream&, semantics::unit&, options const&);
+
// Checks if scope Y names any of X.
//
template <typename X, typename Y>
diff --git a/odb/generator.cxx b/odb/generator.cxx
index 0064b5c..50abbe9 100644
--- a/odb/generator.cxx
+++ b/odb/generator.cxx
@@ -21,11 +21,6 @@
#include <odb/generate.hxx>
#include <odb/tracer/generate.hxx>
#include <odb/relational/generate.hxx>
-#include <odb/relational/type-processor.hxx>
-
-#include <odb/relational/mysql/context.hxx>
-#include <odb/relational/pgsql/context.hxx>
-#include <odb/relational/sqlite/context.hxx>
using namespace std;
using namespace cutl;
@@ -93,56 +88,11 @@ namespace
}
}
-generator::
-generator ()
-{
-}
-
-static auto_ptr<context>
-create_context (ostream& os, semantics::unit& unit, options const& ops)
-{
- auto_ptr<context> r;
-
- switch (ops.database ())
- {
- case database::mysql:
- {
- r.reset (new relational::mysql::context (os, unit, ops));
- break;
- }
- case database::pgsql:
- {
- r.reset (new relational::pgsql::context (os, unit, ops));
- break;
- }
- case database::sqlite:
- {
- r.reset (new relational::sqlite::context (os, unit, ops));
- break;
- }
- case database::tracer:
- {
- r.reset (new context (os, unit, ops));
- break;
- }
- }
-
- return r;
-}
-
void generator::
generate (options const& ops, semantics::unit& unit, path const& p)
{
try
{
- // Process types.
- //
- if (ops.database () != database::tracer)
- {
- auto_ptr<context> ctx (create_context (cerr, unit, ops));
- relational::process_types ();
- }
-
// Output files.
//
path file (p.leaf ());
@@ -439,13 +389,13 @@ generate (options const& ops, semantics::unit& unit, path const& p)
auto_rm.cancel ();
}
- catch (const generation_failed&)
+ catch (generation_failed const&)
{
// Code generation failed. Diagnostics has already been issued.
//
throw failed ();
}
- catch (const re::format& e)
+ catch (re::format const& e)
{
cerr << "error: invalid regex: '" << e.regex () << "': " <<
e.description () << endl;
diff --git a/odb/generator.hxx b/odb/generator.hxx
index 0a64ad2..418e576 100644
--- a/odb/generator.hxx
+++ b/odb/generator.hxx
@@ -12,18 +12,16 @@
class generator
{
public:
- generator ();
-
class failed {};
void
generate (options const&, semantics::unit&, semantics::path const&);
+ generator () {}
+
private:
generator (generator const&);
-
- generator&
- operator= (generator const&);
+ generator& operator= (generator const&);
};
#endif // ODB_GENERATOR_HXX
diff --git a/odb/makefile b/odb/makefile
index 493eca7..97617d0 100644
--- a/odb/makefile
+++ b/odb/makefile
@@ -20,6 +20,7 @@ include.cxx \
header.cxx \
inline.cxx \
validator.cxx \
+processor.cxx \
generator.cxx \
parser.cxx \
plugin.cxx \
@@ -37,11 +38,11 @@ tracer/source.cxx
cxx_ptun += \
relational/common.cxx \
relational/context.cxx \
+relational/processor.cxx \
relational/header.cxx \
relational/inline.cxx \
relational/source.cxx \
-relational/schema.cxx \
-relational/type-processor.cxx
+relational/schema.cxx
# Relational/MySQL
#
diff --git a/odb/plugin.cxx b/odb/plugin.cxx
index 5364425..aba5e78 100644
--- a/odb/plugin.cxx
+++ b/odb/plugin.cxx
@@ -21,6 +21,7 @@
#include <odb/profile.hxx>
#include <odb/version.hxx>
#include <odb/validator.hxx>
+#include <odb/processor.hxx>
#include <odb/generator.hxx>
#include <odb/semantics/unit.hxx>
@@ -109,13 +110,23 @@ gate_callback (void*, void*)
parser p (*options_, loc_pragmas_, decl_pragmas_);
auto_ptr<unit> u (p.parse (global_namespace, file_));
+ // Validate.
//
- //
- validator v;
- if (!v.validate (*options_, *u, file_))
- r = 1;
+ {
+ validator v;
+ if (!v.validate (*options_, *u, file_))
+ r = 1;
+ }
+ // Process.
//
+ if (r == 0)
+ {
+ processor p;
+ p.process (*options_, *u, file_);
+ }
+
+ // Generate.
//
if (r == 0)
{
@@ -129,6 +140,12 @@ gate_callback (void*, void*)
//
r = 1;
}
+ catch (processor::failed const&)
+ {
+ // Diagnostics has aready been issued.
+ //
+ r = 1;
+ }
catch (generator::failed const&)
{
// Diagnostics has aready been issued.
diff --git a/odb/processor.cxx b/odb/processor.cxx
new file mode 100644
index 0000000..601b6c1
--- /dev/null
+++ b/odb/processor.cxx
@@ -0,0 +1,34 @@
+// file : odb/processor.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#include <iostream>
+
+#include <odb/context.hxx>
+#include <odb/processor.hxx>
+
+#include <odb/relational/processor.hxx>
+
+using namespace std;
+
+void processor::
+process (options const& ops, semantics::unit& unit, semantics::path const&)
+{
+ try
+ {
+ // Process types.
+ //
+ if (ops.database () != database::tracer)
+ {
+ auto_ptr<context> ctx (create_context (cerr, unit, ops));
+ relational::process ();
+ }
+ }
+ catch (generation_failed const&)
+ {
+ // Processing failed. Diagnostics has already been issued.
+ //
+ throw failed ();
+ }
+}
diff --git a/odb/processor.hxx b/odb/processor.hxx
new file mode 100644
index 0000000..4903108
--- /dev/null
+++ b/odb/processor.hxx
@@ -0,0 +1,27 @@
+// file : odb/processor.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_PROCESSOR_HXX
+#define ODB_PROCESSOR_HXX
+
+#include <odb/options.hxx>
+#include <odb/semantics/unit.hxx>
+
+class processor
+{
+public:
+ class failed {};
+
+ void
+ process (options const&, semantics::unit&, semantics::path const&);
+
+ processor () {}
+
+private:
+ processor (processor const&);
+ processor& operator= (processor const&);
+};
+
+#endif // ODB_PROCESSOR_HXX
diff --git a/odb/relational/type-processor.cxx b/odb/relational/processor.cxx
index c6e8d41..cc3c695 100644
--- a/odb/relational/type-processor.cxx
+++ b/odb/relational/processor.cxx
@@ -1,4 +1,4 @@
-// file : odb/relational/type-processor.cxx
+// file : odb/relational/processor.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
@@ -13,7 +13,7 @@
#include <odb/common.hxx>
#include <odb/relational/context.hxx>
-#include <odb/relational/type-processor.hxx>
+#include <odb/relational/processor.hxx>
using namespace std;
@@ -2208,7 +2208,7 @@ namespace relational
}
void
- process_types ()
+ process ()
{
context ctx;
diff --git a/odb/relational/type-processor.hxx b/odb/relational/processor.hxx
index 00cb2c5..6ef2913 100644
--- a/odb/relational/type-processor.hxx
+++ b/odb/relational/processor.hxx
@@ -1,17 +1,17 @@
-// file : odb/relational/type-processor.hxx
+// file : odb/relational/processor.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_RELATIONAL_TYPE_PROCESSOR_HXX
-#define ODB_RELATIONAL_TYPE_PROCESSOR_HXX
+#ifndef ODB_RELATIONAL_PROCESSOR_HXX
+#define ODB_RELATIONAL_PROCESSOR_HXX
namespace relational
{
// Issues diagnostics and throws generation_failed in case of an error.
//
void
- process_types ();
+ process ();
}
-#endif // ODB_RELATIONAL_TYPE_PROCESSOR_HXX
+#endif // ODB_RELATIONAL_PROCESSOR_HXX
diff --git a/odb/validator.cxx b/odb/validator.cxx
index 201caf1..7fb6a68 100644
--- a/odb/validator.cxx
+++ b/odb/validator.cxx
@@ -8,6 +8,7 @@
#include <iostream>
#include <odb/traversal.hxx>
+#include <odb/common.hxx>
#include <odb/context.hxx>
#include <odb/validator.hxx>
@@ -165,6 +166,64 @@ namespace
traversal::inherits inherits_;
};
+ struct view_data_member: object_members_base
+ {
+ view_data_member (bool& valid)
+ : object_members_base (false, false, true), valid_ (valid), dm_ (0)
+ {
+ }
+
+ virtual void
+ traverse_simple (semantics::data_member& m)
+ {
+ if (context::object_pointer (m.type ()))
+ {
+ semantics::data_member& dm (dm_ != 0 ? *dm_ : m);
+
+ cerr << dm.file () << ":" << dm.line () << ":" << dm.column () << ":"
+ << " error: view data member '" << member_prefix_ << m.name ()
+ << "' is an object pointer" << endl;
+
+ cerr << dm.file () << ":" << dm.line () << ":" << dm.column () << ":"
+ << ": info: views cannot contain object pointers" << endl;
+
+ valid_ = false;
+ }
+ }
+
+ virtual void
+ traverse_container (semantics::data_member& m, semantics::type&)
+ {
+ semantics::data_member& dm (dm_ != 0 ? *dm_ : m);
+
+ cerr << dm.file () << ":" << dm.line () << ":" << dm.column () << ":"
+ << " error: view data member '" << member_prefix_ << m.name ()
+ << "' is a container" << endl;
+
+ cerr << dm.file () << ":" << dm.line () << ":" << dm.column () << ":"
+ << ": info: views cannot contain containers" << endl;
+
+ valid_ = false;
+ }
+
+ virtual void
+ traverse_composite (semantics::data_member* m, semantics::class_& c)
+ {
+ semantics::data_member* old_dm (dm_);
+
+ if (dm_ == 0)
+ dm_ = m;
+
+ object_members_base::traverse_composite (m, c);
+
+ dm_ = old_dm;
+ }
+
+ private:
+ bool& valid_;
+ semantics::data_member* dm_; // Direct view data member.
+ };
+
//
//
struct value_type: traversal::type
@@ -195,9 +254,11 @@ namespace
options_ (ops),
unit_ (unit),
vt_ (vt),
- member_ (valid)
+ member_ (valid),
+ view_member_ (valid)
{
*this >> names_ >> member_;
+ view_names_ >> view_member_;
}
virtual void
@@ -439,6 +500,8 @@ namespace
valid_ = false;
}
+
+ //names (c, view_names_);
}
virtual void
@@ -514,14 +577,17 @@ namespace
data_member member_;
traversal::names names_;
+
+ view_data_member view_member_;
+ traversal::names view_names_;
};
}
bool validator::
-validate (options const& ops,
- semantics::unit& u,
- semantics::path const&)
+validate (options const& ops, semantics::unit& u, semantics::path const&)
{
+ auto_ptr<context> ctx (create_context (cerr, u, ops));
+
bool valid (true);
traversal::unit unit;
@@ -546,8 +612,3 @@ validate (options const& ops,
return valid;
}
-
-validator::
-validator ()
-{
-}
diff --git a/odb/validator.hxx b/odb/validator.hxx
index 1c41260..efb01d3 100644
--- a/odb/validator.hxx
+++ b/odb/validator.hxx
@@ -12,11 +12,11 @@
class validator
{
public:
- validator ();
-
bool
validate (options const&, semantics::unit&, semantics::path const&);
+ validator () {}
+
private:
validator (validator const&);
validator& operator= (validator const&);