summaryrefslogtreecommitdiff
path: root/odb/relational/validator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/relational/validator.cxx')
-rw-r--r--odb/relational/validator.cxx118
1 files changed, 118 insertions, 0 deletions
diff --git a/odb/relational/validator.cxx b/odb/relational/validator.cxx
index ec78e8f..1269406 100644
--- a/odb/relational/validator.cxx
+++ b/odb/relational/validator.cxx
@@ -2,6 +2,7 @@
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
+#include <map>
#include <iostream>
#include <odb/diagnostics.hxx>
@@ -14,6 +15,95 @@ using namespace std;
namespace relational
{
+ namespace
+ {
+ //
+ // Pass 2.
+ //
+
+ struct class2: traversal::class_, context
+ {
+ class2 (bool& valid)
+ : valid_ (valid)
+ {
+ }
+
+ virtual void
+ traverse (type& c)
+ {
+ if (object (c))
+ traverse_object (c);
+ else if (view (c))
+ traverse_view (c);
+ else if (composite (c))
+ traverse_composite (c);
+
+ // Make sure indexes are not defined for anything other than objects.
+ //
+ if (c.count ("index") && !object (c))
+ {
+ indexes& ins (c.get<indexes> ("index"));
+
+ for (indexes::iterator i (ins.begin ()); i != ins.end (); ++i)
+ {
+ error (i->loc) << "index definition on a non-persistent class"
+ << endl;
+ valid_ = false;
+ }
+ }
+ }
+
+ virtual void
+ traverse_object (type& c)
+ {
+ // Validate indexes.
+ //
+ {
+ indexes& ins (c.get<indexes> ("index"));
+
+ // Make sure index members are not transient or containers.
+ //
+ for (indexes::iterator i (ins.begin ()); i != ins.end (); ++i)
+ {
+ index& in (*i);
+
+ for (index::members_type::iterator i (in.members.begin ());
+ i != in.members.end (); ++i)
+ {
+ index::member& im (*i);
+ semantics::data_member& m (*im.path.back ());
+
+ if (transient (m))
+ {
+ error (im.loc) << "index member is transient" << endl;
+ valid_ = false;
+ }
+
+ if (container (m))
+ {
+ error (im.loc) << "index member is a container" << endl;
+ valid_ = false;
+ }
+ }
+ }
+ }
+ }
+
+ virtual void
+ traverse_view (type&)
+ {
+ }
+
+ virtual void
+ traverse_composite (type&)
+ {
+ }
+
+ public:
+ bool& valid_;
+ };
+ }
+
void validator::
validate (options const&,
features&,
@@ -95,5 +185,33 @@ namespace relational
if (!valid)
throw failed ();
+
+ if (pass == 1)
+ {
+ }
+ else
+ {
+ traversal::unit unit;
+ traversal::defines unit_defines;
+ typedefs unit_typedefs (true);
+ traversal::namespace_ ns;
+ class2 c (valid);
+
+ unit >> unit_defines >> ns;
+ unit_defines >> c;
+ unit >> unit_typedefs >> c;
+
+ traversal::defines ns_defines;
+ typedefs ns_typedefs (true);
+
+ ns >> ns_defines >> ns;
+ ns_defines >> c;
+ ns >> ns_typedefs >> c;
+
+ unit.dispatch (u);
+ }
+
+ if (!valid)
+ throw failed ();
}
}