From b9fe963646367f2da21ba1053bc086bd17b09967 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 24 Apr 2011 11:27:14 +0200 Subject: Implement id_type value type pragma --- odb/context.cxx | 1 + odb/pragma.cxx | 20 ++++++++++++++++++++ odb/relational/type-processor.cxx | 33 ++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 15 deletions(-) (limited to 'odb') diff --git a/odb/context.cxx b/odb/context.cxx index 2d64885..8a85dcd 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -190,6 +190,7 @@ comp_value_ (semantics::class_& c) r = r && c.count ("value"); r = r && !c.count ("table"); r = r && !c.count ("type"); + r = r && !c.count ("id-type"); r = r && !c.count ("value-type"); r = r && !c.count ("index-type"); r = r && !c.count ("key-type"); diff --git a/odb/pragma.cxx b/odb/pragma.cxx index c09c683..8cfc3fa 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -158,6 +158,17 @@ check_decl_type (tree d, string const& name, string const& p, location_t l) return false; } } + else if (p == "id_type") + { + // Id type can only be used for types. + // + if (!TYPE_P (d)) + { + error_at (l, "name %qs in db pragma %qs does not refer to a type", + name.c_str (), pc); + return false; + } + } else if (p == "type" || p == "value_type" || p == "index_type" || @@ -421,11 +432,13 @@ handle_pragma (cpp_reader* reader, tt = pragma_lex (&t); } else if (p == "type" || + p == "id_type" || p == "value_type" || p == "index_type" || p == "key_type") { // type ("") + // id_type ("") // value_type ("") // index_type ("") // key_type ("") @@ -812,6 +825,12 @@ handle_pragma_db_type (cpp_reader* reader) } extern "C" void +handle_pragma_db_id_type (cpp_reader* reader) +{ + handle_pragma_qualifier (reader, "id_type"); +} + +extern "C" void handle_pragma_db_vtype (cpp_reader* reader) { handle_pragma_qualifier (reader, "value_type"); @@ -873,6 +892,7 @@ register_odb_pragmas (void*, void*) c_register_pragma_with_expansion ("db", "key_column", handle_pragma_db_kcolumn); c_register_pragma_with_expansion ("db", "id_column", handle_pragma_db_idcolumn); c_register_pragma_with_expansion ("db", "type", handle_pragma_db_type); + c_register_pragma_with_expansion ("db", "id_type", handle_pragma_db_id_type); c_register_pragma_with_expansion ("db", "value_type", handle_pragma_db_vtype); c_register_pragma_with_expansion ("db", "index_type", handle_pragma_db_itype); c_register_pragma_with_expansion ("db", "key_type", handle_pragma_db_ktype); diff --git a/odb/relational/type-processor.cxx b/odb/relational/type-processor.cxx index 97f4d85..511ac9e 100644 --- a/odb/relational/type-processor.cxx +++ b/odb/relational/type-processor.cxx @@ -31,7 +31,7 @@ namespace relational { context& c (context::current ()); semantics::data_member& id (context::id_member (*c.object)); - return id.get ("ref-column-type"); + return id.get ("column-type"); } struct data_member: traversal::data_member, context @@ -113,9 +113,6 @@ namespace relational if (m.count ("type")) type = m.get ("type"); - if (type.empty () && t.count ("type")) - type = t.get ("type"); - if (semantics::class_* c = process_object_pointer (m, t)) { // This is an object pointer. The column type is the pointed-to @@ -127,6 +124,9 @@ namespace relational if (type.empty () && id.count ("type")) type = id.get ("type"); + if (type.empty () && idt.count ("id-type")) + type = idt.get ("id-type"); + if (type.empty () && idt.count ("type")) type = idt.get ("type"); @@ -139,20 +139,18 @@ namespace relational } else { - string orig (type); - type = database_type (t, orig, m, ctf_none); + if (type.empty () && m.count ("id") && t.count ("id-type")) + type = t.get ("id-type"); + + if (type.empty () && t.count ("type")) + type = t.get ("type"); - if (m.count ("id")) - ref_type = database_type (t, orig, m, ctf_none); + type = database_type (t, type, m, ctf_none); } if (!type.empty ()) { m.set ("column-type", type); - - if (!ref_type.empty ()) - m.set ("ref-column-type", ref_type); - return; } @@ -199,9 +197,6 @@ namespace relational if (type.empty () && ct.count (prefix + "-type")) type = ct.get (prefix + "-type"); - if (type.empty () && t.count ("type")) - type = t.get ("type"); - semantics::class_* c; if (obj_ptr && (c = process_object_pointer (m, t, prefix))) { @@ -214,6 +209,9 @@ namespace relational if (type.empty () && id.count ("type")) type = id.get ("type"); + if (type.empty () && idt.count ("id-type")) + type = idt.get ("id-type"); + if (type.empty () && idt.count ("type")) type = idt.get ("type"); @@ -225,7 +223,12 @@ namespace relational type = database_type (idt, type, id, f); } else + { + if (type.empty () && t.count ("type")) + type = t.get ("type"); + type = database_type (t, type, m, ctf_none); + } if (!type.empty ()) { -- cgit v1.1