From 73edd8b28ac415b6fdb7d8c7f8728dc7f8de75d0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 29 Nov 2010 09:27:29 +0200 Subject: Make container pragmas also work on types in addition to members --- odb/context.cxx | 38 ++++++++++++++++++++++++++++++++++++-- odb/context.hxx | 17 +++++++++++++++-- odb/mysql/header.cxx | 2 +- odb/mysql/schema.cxx | 2 +- odb/mysql/source.cxx | 2 +- odb/pragma.cxx | 39 +++++++++++++++++++++++++++++++-------- 6 files changed, 85 insertions(+), 15 deletions(-) diff --git a/odb/context.cxx b/odb/context.cxx index 5585ab1..5c16e68 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -120,6 +120,30 @@ context:: { } +bool context:: +comp_value_ (semantics::class_& c) +{ + bool r (true); + + //@@ This is bad. Did I add new value pragmas and forgot to + // account for them here? + // + r = r && c.count ("value"); + r = r && !c.count ("table"); + r = r && !c.count ("type"); + r = r && !c.count ("value-type"); + r = r && !c.count ("index-type"); + r = r && !c.count ("key-type"); + r = r && !c.count ("value-column"); + r = r && !c.count ("index-column"); + r = r && !c.count ("key-column"); + r = r && !c.count ("id-column"); + r = r && !c.count ("unordered"); + + c.set ("composite-value", r); + return r; +} + string context:: table_name (semantics::class_& t) const { @@ -147,14 +171,24 @@ table_name (semantics::data_member& m, table_prefix const& p) const string context:: column_name (semantics::data_member& m) const { - return m.count ("column") ? m.get ("column") : public_name_db (m); + if (m.count ("column")) + return m.get ("column"); + else if (m.type ().count ("column")) + return m.type ().get ("column"); + else + return public_name_db (m); } string context:: column_name (semantics::data_member& m, string const& p, string const& d) const { string key (p + "-column"); - return m.count (key) ? m.get (key) : d; + if (m.count (key)) + return m.get (key); + else if (m.type ().count (key)) + return m.type ().get (key); + else + return d; } string context:: diff --git a/odb/context.hxx b/odb/context.hxx index dde1d72..bc8a8bf 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -55,7 +55,10 @@ public: static bool comp_value (semantics::class_& c) { - return c.count ("value") && !c.count ("type"); + if (c.count ("composite-value")) + return c.get ("composite-value"); + else + return comp_value_ (c); } // Return the class object if this type is a composite value type @@ -65,7 +68,7 @@ public: comp_value (semantics::type& t) { semantics::class_* c (dynamic_cast (&t)); - return c != 0 && t.count ("value") && !t.count ("type") ? c : 0; + return c != 0 && comp_value (*c) ? c : 0; } static bool @@ -97,6 +100,12 @@ public: : 0; } + static bool + unordered (semantics::data_member& m) + { + return m.count ("unordered") || m.type ().count ("unordered"); + } + // Database names and types. // public: @@ -215,6 +224,10 @@ public: static bool has_a (semantics::type&, unsigned short flags); +private: + static bool + comp_value_ (semantics::class_&); + protected: struct data; typedef cutl::shared_ptr data_ptr; diff --git a/odb/mysql/header.cxx b/odb/mysql/header.cxx index 1b995a9..83ab5a7 100644 --- a/odb/mysql/header.cxx +++ b/odb/mysql/header.cxx @@ -251,7 +251,7 @@ namespace mysql { case ck_ordered: { - if (!m.count ("unordered")) + if (!unordered (m)) { it = &container_it (t); ordered = true; diff --git a/odb/mysql/schema.cxx b/odb/mysql/schema.cxx index cb89c4b..e02dde6 100644 --- a/odb/mysql/schema.cxx +++ b/odb/mysql/schema.cxx @@ -94,7 +94,7 @@ namespace mysql // index (simple value) // string index_name; - bool ordered (ck == ck_ordered && !m.count ("unordered")); + bool ordered (ck == ck_ordered && !unordered (m)); if (ordered) { index_name = column_name (m, "index", "index"); diff --git a/odb/mysql/source.cxx b/odb/mysql/source.cxx index 0b182ae..60b1296 100644 --- a/odb/mysql/source.cxx +++ b/odb/mysql/source.cxx @@ -1239,7 +1239,7 @@ namespace mysql { case ck_ordered: { - if (!m.count ("unordered")) + if (!unordered (m)) { it = &container_it (t); ordered = true; diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 9970376..002a25c 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -117,12 +117,7 @@ check_decl_type (tree d, string const& name, string const& p, location_t l) p == "id" || p == "auto" || p == "column" || - p == "value_column" || - p == "index_column" || - p == "key_column" || - p == "id_column" || p == "inverse" || - p == "unordered" || p == "transient") { if (tc != FIELD_DECL) @@ -144,11 +139,12 @@ check_decl_type (tree d, string const& name, string const& p, location_t l) } else if (p == "table") { - // Table can be used for both members (container) and types. + // Table can be used for both members (container) and types (container + // or object). // - if (tc != FIELD_DECL && tc != RECORD_TYPE) + if (tc != FIELD_DECL && !TYPE_P (d)) { - error_at (l, "name %qs in db pragma %qs does not refer to a class " + error_at (l, "name %qs in db pragma %qs does not refer to a type " "or data member", name.c_str (), pc); return false; } @@ -176,6 +172,33 @@ check_decl_type (tree d, string const& name, string const& p, location_t l) return false; } } + else if (p == "value_column" || + p == "index_column" || + p == "key_column" || + p == "id_column") + { + // Container columns can be used for both members (container) and + // types (container). + // + if (tc != FIELD_DECL && !TYPE_P (d)) + { + error_at (l, "name %qs in db pragma %qs does not refer to a type " + "or data member", name.c_str (), pc); + return false; + } + } + else if (p == "unordered") + { + // Unordered can be used for both members (container) and + // types (container). + // + if (tc != FIELD_DECL && !TYPE_P (d)) + { + error_at (l, "name %qs in db pragma %qs does not refer to a type " + "or data member", name.c_str (), pc); + return false; + } + } else { error ("unknown db pragma %qs", pc); -- cgit v1.1