From cc3979f34a886ae4c89d4e3e86a5b0db1669585f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Nov 2012 11:46:03 +0200 Subject: Move some of the preprocessing from relational to common --- odb/relational/processor.cxx | 1067 ++---------------------------------------- 1 file changed, 37 insertions(+), 1030 deletions(-) (limited to 'odb/relational') diff --git a/odb/relational/processor.cxx b/odb/relational/processor.cxx index 4213602..88e86fc 100644 --- a/odb/relational/processor.cxx +++ b/odb/relational/processor.cxx @@ -23,14 +23,6 @@ namespace relational { // Indirect (dynamic) context values. // - static semantics::type* - id_tree_type () - { - context& c (context::current ()); - semantics::data_member& id (*context::id_member (*c.top_object)); - return &id.type (); - } - static string id_column_type () { @@ -41,79 +33,6 @@ namespace relational struct data_member: traversal::data_member, context { - data_member () - { - // Find the odb namespace. - // - tree odb = lookup_qualified_name ( - global_namespace, get_identifier ("odb"), false, false); - - if (odb == error_mark_node) - { - os << unit.file () << ": error: unable to resolve odb namespace" - << endl; - - throw operation_failed (); - } - - // Find wrapper traits. - // - wrapper_traits_ = lookup_qualified_name ( - odb, get_identifier ("wrapper_traits"), true, false); - - if (wrapper_traits_ == error_mark_node || - !DECL_CLASS_TEMPLATE_P (wrapper_traits_)) - { - os << unit.file () << ": error: unable to resolve wrapper_traits " - << "in the odb namespace" << endl; - - throw operation_failed (); - } - - // Find pointer traits. - // - pointer_traits_ = lookup_qualified_name ( - odb, get_identifier ("pointer_traits"), true, false); - - if (pointer_traits_ == error_mark_node || - !DECL_CLASS_TEMPLATE_P (pointer_traits_)) - { - os << unit.file () << ": error: unable to resolve pointer_traits " - << "in the odb namespace" << endl; - - throw operation_failed (); - } - - // Find the access class. - // - tree access = lookup_qualified_name ( - odb, get_identifier ("access"), true, false); - - if (access == error_mark_node) - { - os << unit.file () << ": error: unable to resolve access class" - << "in the odb namespace" << endl; - - throw operation_failed (); - } - - access = TREE_TYPE (access); - - // Find container_traits. - // - container_traits_ = lookup_qualified_name ( - access, get_identifier ("container_traits"), true, false); - - if (container_traits_ == error_mark_node || - !DECL_CLASS_TEMPLATE_P (container_traits_)) - { - os << unit.file () << ": error: unable to resolve container_traits " - << "in the odb namespace" << endl; - - throw operation_failed (); - } - } - virtual void traverse (semantics::data_member& m) { @@ -123,31 +42,10 @@ namespace relational semantics::names* hint; semantics::type& t (utype (m, hint)); - // Handle wrappers. - // - semantics::type* wt (0), *qwt (0); + semantics::type* wt; semantics::names* whint (0); - if (process_wrapper (t)) - { - qwt = t.get ("wrapper-type"); - whint = t.get ("wrapper-hint"); - wt = &utype (*qwt, whint); - } - - // If the type is const and the member is not id, version, or - // inverse, then mark it as readonly. In case of a wrapper, - // both the wrapper type and the wrapped type must be const. - // To see why, consider these possibilities: - // - // auto_ptr - can modify by setting a new pointer - // const auto_ptr - can modify by changing the pointed-to value - // - if (const_type (m.type ()) && - !(id (m) || version (m) || m.count ("inverse"))) - { - if (qwt == 0 || const_type (*qwt)) - m.set ("readonly", true); - } + if ((wt = wrapper (t, whint))) + wt = &utype (*wt, whint); // Determine the member kind. // @@ -175,7 +73,7 @@ namespace relational id_type = type; } - if (semantics::class_* c = process_object_pointer (m, t)) + if (semantics::class_* c = object_pointer (t)) { // This is an object pointer. The column type is the pointed-to // object id type. @@ -185,20 +83,17 @@ namespace relational semantics::names* idhint; semantics::type& idt (utype (id, idhint)); - semantics::type* wt (0); - semantics::names* whint (0); - if (process_wrapper (idt)) - { - whint = idt.get ("wrapper-hint"); - wt = &utype (*idt.get ("wrapper-type"), whint); - } - // The id type can be a composite value type. // if (composite_wrapper (idt)) kind = composite; else { + semantics::type* wt; + semantics::names* whint (0); + if ((wt = wrapper (idt, whint))) + wt = &utype (*wt, whint); + if (type.empty () && id.count ("id-type")) type = id.get ("id-type"); @@ -284,10 +179,11 @@ namespace relational // If not a simple value, see if this is a container. // - if (kind == unknown && - (process_container (m, t) || - (wt != 0 && process_container (m, *wt)))) + if (kind == unknown && context::container (m)) + { + process_container (m, (wt != 0 ? *wt : t)); kind = container; + } // If it is none of the above then we have an error. // @@ -296,7 +192,7 @@ namespace relational os << m.file () << ":" << m.line () << ":" << m.column () << ":" << " error: unable to map C++ type '" << t.fq_name (hint) << "' used in data member '" << m.name () << "' to a " - << "database type" << endl; + << db.name () << " database type" << endl; os << m.file () << ":" << m.line () << ":" << m.column () << ":" << " info: use '#pragma db type' to specify the database type" @@ -360,17 +256,12 @@ namespace relational string const& prefix, bool obj_ptr) { - semantics::type* wt (0); - semantics::names* wh (0); - if (process_wrapper (t)) - { - wt = t.get ("wrapper-type"); - wh = t.get ("wrapper-hint"); - } - if (composite_wrapper (t)) return; + semantics::names* wh (0); + semantics::type* wt (wrapper (t, wh)); + string type; semantics::type& ct (utype (m)); @@ -386,7 +277,7 @@ namespace relational type = ct.get (prefix + "-type"); semantics::class_* c; - if (obj_ptr && (c = process_object_pointer (m, t, prefix))) + if (obj_ptr && (c = object_pointer (t))) { // This is an object pointer. The column type is the pointed-to // object id type. @@ -396,19 +287,16 @@ namespace relational semantics::names* idhint; semantics::type& idt (utype (id, idhint)); - semantics::type* wt (0); - semantics::names* whint (0); - if (process_wrapper (idt)) - { - whint = idt.get ("wrapper-hint"); - wt = &utype (*idt.get ("wrapper-type"), whint); - } - // Nothing to do if this is a composite value type. // if (composite_wrapper (idt)) return; + semantics::type* wt (0); + semantics::names* whint (0); + if ((wt = wrapper (idt, whint))) + wt = &utype (*wt, whint); + if (type.empty () && id.count ("id-type")) type = id.get ("id-type"); @@ -468,7 +356,8 @@ namespace relational os << m.file () << ":" << m.line () << ":" << m.column () << ":" << " error: unable to map C++ type '" << fq_type << "' used in " - << "data member '" << m.name () << "' to a database type" << endl; + << "data member '" << m.name () << "' to a " << db.name () + << " database type" << endl; os << m.file () << ":" << m.line () << ":" << m.column () << ":" << " info: use '#pragma db " << prefix << "_type' to specify the " @@ -477,264 +366,32 @@ namespace relational throw operation_failed (); } - bool + void process_container (semantics::data_member& m, semantics::type& t) { - // The overall idea is as follows: try to instantiate the container - // traits class template. If we are successeful, then this is a - // container type and we can extract the various information from - // the instantiation. Otherwise, this is not a container. - // - - container_kind_type ck; - semantics::type* vt (0); + container_kind_type ck (t.get ("container-kind")); + semantics::type* vt (t.get ("value-tree-type")); semantics::type* it (0); semantics::type* kt (0); - semantics::names* vh (0); + semantics::names* vh (t.get ("value-tree-hint")); semantics::names* ih (0); semantics::names* kh (0); - if (t.count ("container-kind")) + if (ck == ck_ordered) { - ck = t.get ("container-kind"); - vt = t.get ("value-tree-type"); - vh = t.get ("value-tree-hint"); - - if (ck == ck_ordered) - { - it = t.get ("index-tree-type"); - ih = t.get ("index-tree-hint"); - } - - if (ck == ck_map || ck == ck_multimap) - { - kt = t.get ("key-tree-type"); - kh = t.get ("key-tree-hint"); - } + it = t.get ("index-tree-type"); + ih = t.get ("index-tree-hint"); } - else - { - tree inst (instantiate_template (container_traits_, t.tree_node ())); - - if (inst == 0) - return false; - - // @@ This points to the primary template, not the specialization. - // - tree decl (TYPE_NAME (inst)); - - string f (DECL_SOURCE_FILE (decl)); - size_t l (DECL_SOURCE_LINE (decl)); - size_t c (DECL_SOURCE_COLUMN (decl)); - - // Determine the container kind. - // - try - { - tree kind ( - lookup_qualified_name ( - inst, get_identifier ("kind"), false, false)); - - if (kind == error_mark_node || TREE_CODE (kind) != VAR_DECL) - throw operation_failed (); - - - // Instantiate this decalaration so that we can get its value. - // - if (DECL_TEMPLATE_INSTANTIATION (kind) && - !DECL_TEMPLATE_INSTANTIATED (kind) && - !DECL_EXPLICIT_INSTANTIATION (kind)) - instantiate_decl (kind, false, false); - - tree init (DECL_INITIAL (kind)); - - if (init == error_mark_node || TREE_CODE (init) != INTEGER_CST) - throw operation_failed (); - - unsigned long long e; - - { - HOST_WIDE_INT hwl (TREE_INT_CST_LOW (init)); - HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (init)); - - unsigned long long l (hwl); - unsigned long long h (hwh); - unsigned short width (HOST_BITS_PER_WIDE_INT); - - e = (h << width) + l; - } - - ck = static_cast (e); - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "container_traits specialization does not define the " - << "container kind constant" << endl; - - throw; - } - - t.set ("container-kind", ck); - - // Mark id column as not null. - // - t.set ("id-not-null", true); - - // Get the value type. - // - try - { - tree decl ( - lookup_qualified_name ( - inst, get_identifier ("value_type"), true, false)); - - if (decl == error_mark_node || TREE_CODE (decl) != TYPE_DECL) - throw operation_failed (); - tree type (TYPE_MAIN_VARIANT (TREE_TYPE (decl))); - vt = &dynamic_cast (*unit.find (type)); - - // Find the hint. - // - for (tree ot (DECL_ORIGINAL_TYPE (decl)); - ot != 0; - ot = decl ? DECL_ORIGINAL_TYPE (decl) : 0) - { - if ((vh = unit.find_hint (ot))) - break; - - decl = TYPE_NAME (ot); - } - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "container_traits specialization does not define the " - << "value_type type" << endl; - - throw; - } - - t.set ("value-tree-type", vt); - t.set ("value-tree-hint", vh); - - // If we have a set container, automatically mark the value - // column as not null. If we already have an explicit null for - // this column, issue an error. - // - if (ck == ck_set) - { - if (t.count ("value-null")) - { - os << t.file () << ":" << t.line () << ":" << t.column () << ":" - << " error: set container cannot contain null values" << endl; - - throw operation_failed (); - } - else - t.set ("value-not-null", true); - } - - // Issue a warning if we are relaxing null-ness in the - // container type. - // - if (t.count ("value-null") && vt->count ("not-null")) - { - os << t.file () << ":" << t.line () << ":" << t.column () << ":" - << " warning: container value declared null while its type " - << "is declared not null" << endl; - } - - // Get the index type for ordered containers. - // - if (ck == ck_ordered) - { - try - { - tree decl ( - lookup_qualified_name ( - inst, get_identifier ("index_type"), true, false)); - - if (decl == error_mark_node || TREE_CODE (decl) != TYPE_DECL) - throw operation_failed (); - - tree type (TYPE_MAIN_VARIANT (TREE_TYPE (decl))); - it = &dynamic_cast (*unit.find (type)); - - // Find the hint. - // - for (tree ot (DECL_ORIGINAL_TYPE (decl)); - ot != 0; - ot = decl ? DECL_ORIGINAL_TYPE (decl) : 0) - { - if ((ih = unit.find_hint (ot))) - break; - - decl = TYPE_NAME (ot); - } - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "container_traits specialization does not define the " - << "index_type type" << endl; - - throw; - } - - t.set ("index-tree-type", it); - t.set ("index-tree-hint", ih); - t.set ("index-not-null", true); - } - - // Get the key type for maps. - // - if (ck == ck_map || ck == ck_multimap) - { - try - { - tree decl ( - lookup_qualified_name ( - inst, get_identifier ("key_type"), true, false)); - - if (decl == error_mark_node || TREE_CODE (decl) != TYPE_DECL) - throw operation_failed (); - - tree type (TYPE_MAIN_VARIANT (TREE_TYPE (decl))); - kt = &dynamic_cast (*unit.find (type)); - - // Find the hint. - // - for (tree ot (DECL_ORIGINAL_TYPE (decl)); - ot != 0; - ot = decl ? DECL_ORIGINAL_TYPE (decl) : 0) - { - if ((kh = unit.find_hint (ot))) - break; - - decl = TYPE_NAME (ot); - } - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "container_traits specialization does not define the " - << "key_type type" << endl; - - throw; - } - - t.set ("key-tree-type", kt); - t.set ("key-tree-hint", kh); - t.set ("key-not-null", true); - } + if (ck == ck_map || ck == ck_multimap) + { + kt = t.get ("key-tree-type"); + kh = t.get ("key-tree-hint"); } // Process member data. // - m.set ("id-tree-type", &id_tree_type); m.set ("id-column-type", &id_column_type); process_container_value (*vt, vh, m, "value", true); @@ -744,562 +401,7 @@ namespace relational if (kt != 0) process_container_value (*kt, kh, m, "key", false); - - // If this is an inverse side of a bidirectional object relationship - // and it is an ordered container, mark it as unordred since there is - // no concept of order in this construct. - // - if (ck == ck_ordered && m.count ("value-inverse")) - m.set ("unordered", true); - - // Issue an error if we have a null column in a set container. - // This can only happen if the value is declared as null in - // the member. - // - if (ck == ck_set && m.count ("value-null")) - { - os << m.file () << ":" << m.line () << ":" << m.column () << ":" - << " error: set container cannot contain null values" << endl; - - throw operation_failed (); - } - - // Issue a warning if we are relaxing null-ness in the member. - // - if (m.count ("value-null") && - (t.count ("value-not-null") || vt->count ("not-null"))) - { - os << m.file () << ":" << m.line () << ":" << m.column () << ":" - << " warning: container value declared null while the container " - << "type or value type declares it as not null" << endl; - } - - return true; } - - semantics::class_* - process_object_pointer (semantics::data_member& m, - semantics::type& t, - string const& kp = string ()) - { - // The overall idea is as follows: try to instantiate the pointer - // traits class template. If we are successeful, then get the - // element type and see if it is an object. - // - using semantics::class_; - using semantics::data_member; - - class_* c (0); - - if (t.count ("element-type")) - c = t.get ("element-type"); - else - { - tree inst (instantiate_template (pointer_traits_, t.tree_node ())); - - if (inst == 0) - return 0; - - // @@ This points to the primary template, not the specialization. - // - tree decl (TYPE_NAME (inst)); - - string fl (DECL_SOURCE_FILE (decl)); - size_t ln (DECL_SOURCE_LINE (decl)); - size_t cl (DECL_SOURCE_COLUMN (decl)); - - // Get the element type. - // - tree tn (0); - try - { - tree decl ( - lookup_qualified_name ( - inst, get_identifier ("element_type"), true, false)); - - if (decl == error_mark_node || TREE_CODE (decl) != TYPE_DECL) - throw operation_failed (); - - tn = TYPE_MAIN_VARIANT (TREE_TYPE (decl)); - - // Check if the pointer is a TR1 template instantiation. - // - if (tree ti = TYPE_TEMPLATE_INFO (t.tree_node ())) - { - decl = TI_TEMPLATE (ti); // DECL_TEMPLATE - - // Get to the most general template declaration. - // - while (DECL_TEMPLATE_INFO (decl)) - decl = DECL_TI_TEMPLATE (decl); - - bool& tr1 (features.tr1_pointer); - bool& boost (features.boost_pointer); - - string n (decl_as_string (decl, TFF_PLAIN_IDENTIFIER)); - - // In case of a boost TR1 implementation, we cannot distinguish - // between the boost:: and std::tr1:: usage since the latter is - // just a using-declaration for the former. - // - tr1 = tr1 - || n.compare (0, 8, "std::tr1") == 0 - || n.compare (0, 10, "::std::tr1") == 0; - - boost = boost - || n.compare (0, 17, "boost::shared_ptr") == 0 - || n.compare (0, 19, "::boost::shared_ptr") == 0; - } - } - catch (operation_failed const&) - { - os << fl << ":" << ln << ":" << cl << ": error: pointer_traits " - << "specialization does not define the 'element_type' type" - << endl; - throw; - } - - c = dynamic_cast (unit.find (tn)); - - if (c == 0 || !object (*c)) - return 0; - - t.set ("element-type", c); - - // Determine the pointer kind. - // - try - { - tree kind ( - lookup_qualified_name ( - inst, get_identifier ("kind"), false, false)); - - if (kind == error_mark_node || TREE_CODE (kind) != VAR_DECL) - throw operation_failed (); - - // Instantiate this decalaration so that we can get its value. - // - if (DECL_TEMPLATE_INSTANTIATION (kind) && - !DECL_TEMPLATE_INSTANTIATED (kind) && - !DECL_EXPLICIT_INSTANTIATION (kind)) - instantiate_decl (kind, false, false); - - tree init (DECL_INITIAL (kind)); - - if (init == error_mark_node || TREE_CODE (init) != INTEGER_CST) - throw operation_failed (); - - unsigned long long e; - - { - HOST_WIDE_INT hwl (TREE_INT_CST_LOW (init)); - HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (init)); - - unsigned long long l (hwl); - unsigned long long h (hwh); - unsigned short width (HOST_BITS_PER_WIDE_INT); - - e = (h << width) + l; - } - - pointer_kind_type pk = static_cast (e); - t.set ("pointer-kind", pk); - } - catch (operation_failed const&) - { - os << fl << ":" << ln << ":" << cl << ": error: pointer_traits " - << "specialization does not define the 'kind' constant" << endl; - throw; - } - - // Get the lazy flag. - // - try - { - tree lazy ( - lookup_qualified_name ( - inst, get_identifier ("lazy"), false, false)); - - if (lazy == error_mark_node || TREE_CODE (lazy) != VAR_DECL) - throw operation_failed (); - - // Instantiate this decalaration so that we can get its value. - // - if (DECL_TEMPLATE_INSTANTIATION (lazy) && - !DECL_TEMPLATE_INSTANTIATED (lazy) && - !DECL_EXPLICIT_INSTANTIATION (lazy)) - instantiate_decl (lazy, false, false); - - tree init (DECL_INITIAL (lazy)); - - if (init == error_mark_node || TREE_CODE (init) != INTEGER_CST) - throw operation_failed (); - - unsigned long long e; - - { - HOST_WIDE_INT hwl (TREE_INT_CST_LOW (init)); - HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (init)); - - unsigned long long l (hwl); - unsigned long long h (hwh); - unsigned short width (HOST_BITS_PER_WIDE_INT); - - e = (h << width) + l; - } - - t.set ("pointer-lazy", static_cast (e)); - } - catch (operation_failed const&) - { - os << fl << ":" << ln << ":" << cl << ": error: pointer_traits " - << "specialization does not define the 'kind' constant" << endl; - throw; - } - } - - // Make sure the pointed-to class is complete. - // - if (!c->complete ()) - { - os << m.file () << ":" << m.line () << ":" << m.column () << ": " - << "error: pointed-to class '" << class_fq_name (*c) << "' " - << "is incomplete" << endl; - - os << c->file () << ":" << c->line () << ":" << c->column () << ": " - << "info: class '" << class_name (*c) << "' is declared here" - << endl; - - os << c->file () << ":" << c->line () << ":" << c->column () << ": " - << "info: consider including its definition with the " - << "--odb-epilogue option" << endl; - - throw operation_failed (); - } - - // Make sure the pointed-to class is not reuse-abstract. - // - if (abstract (*c) && !polymorphic (*c)) - { - os << m.file () << ":" << m.line () << ":" << m.column () << ": " - << "error: pointed-to class '" << class_fq_name (*c) << "' " - << "is abstract" << endl; - - os << c->file () << ":" << c->line () << ":" << c->column () << ": " - << "info: class '" << class_name (*c) << "' is defined here" - << endl; - - throw operation_failed (); - } - - // Make sure the pointed-to class has object id. - // - if (id_member (*c) == 0) - { - os << m.file () << ":" << m.line () << ":" << m.column () << ": " - << "error: pointed-to class '" << class_fq_name (*c) << "' " - << "has no object id" << endl; - - os << c->file () << ":" << c->line () << ":" << c->column () << ": " - << "info: class '" << class_name (*c) << "' is defined here" - << endl; - - throw operation_failed (); - } - - // See if this is the inverse side of a bidirectional relationship. - // If so, then resolve the member and cache it in the context. - // - if (m.count ("inverse")) - { - string name (m.get ("inverse")); - location_t loc (m.get ("inverse-location")); - - try - { - data_member& im ( - c->lookup (name, class_::include_hidden)); - - // @@ Would be good to check that the other end is actually - // an object pointer, is not marked as transient or inverse, - // and points to the correct object. But the other class may - // not have been processed yet. - // - m.remove ("inverse"); - m.set (kp + (kp.empty () ? "": "-") + "inverse", &im); - } - catch (semantics::unresolved const& e) - { - if (e.type_mismatch) - error (loc) << "name '" << name << "' in '#pragma db " << - "inverse' does not refer to a data member" << endl; - else - error (loc) << "unable to resolve data member '" << name << - "' specified with '#pragma db inverse'" << endl; - - throw operation_failed (); - } - catch (semantics::ambiguous const& e) - { - error (loc) << "data member name '" << name << "' specified " << - "with '#pragma db inverse' is ambiguous" << endl; - - info (e.first.named ().location ()) << "could resolve to this " << - "data member" << endl; - - info (e.second.named ().location ()) << "or could resolve to " << - "this data member" << endl; - - throw operation_failed (); - } - } - - return c; - } - - bool - process_wrapper (semantics::type& t) - { - if (t.count ("wrapper")) - return t.get ("wrapper"); - - // Check this type with wrapper_traits. - // - tree inst (instantiate_template (wrapper_traits_, t.tree_node ())); - - if (inst == 0) - { - t.set ("wrapper", false); - return false; - } - - // @@ This points to the primary template, not the specialization. - // - tree decl (TYPE_NAME (inst)); - - string f (DECL_SOURCE_FILE (decl)); - size_t l (DECL_SOURCE_LINE (decl)); - size_t c (DECL_SOURCE_COLUMN (decl)); - - // Get the wrapped type. - // - try - { - tree decl ( - lookup_qualified_name ( - inst, get_identifier ("wrapped_type"), true, false)); - - if (decl == error_mark_node || TREE_CODE (decl) != TYPE_DECL) - throw operation_failed (); - - // The wrapped_type alias is a typedef in an instantiation - // that we just instantiated dynamically. As a result there - // is no semantic graph edges corresponding to this typedef - // since we haven't parsed it yet. So to get the tree node - // that can actually be resolved to the graph node, we use - // the source type of this typedef. - // - tree type (DECL_ORIGINAL_TYPE (decl)); - - semantics::type& wt ( - dynamic_cast (*unit.find (type))); - - // Find the hint. - // - semantics::names* wh (0); - - for (tree ot (DECL_ORIGINAL_TYPE (decl)); - ot != 0; - ot = decl ? DECL_ORIGINAL_TYPE (decl) : 0) - { - if ((wh = unit.find_hint (ot))) - break; - - decl = TYPE_NAME (ot); - } - - t.set ("wrapper-type", &wt); - t.set ("wrapper-hint", wh); - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "wrapper_traits specialization does not define the " - << "wrapped_type type" << endl; - throw; - } - - // Get the null_handler flag. - // - bool null_handler (false); - - try - { - tree nh ( - lookup_qualified_name ( - inst, get_identifier ("null_handler"), false, false)); - - if (nh == error_mark_node || TREE_CODE (nh) != VAR_DECL) - throw operation_failed (); - - // Instantiate this decalaration so that we can get its value. - // - if (DECL_TEMPLATE_INSTANTIATION (nh) && - !DECL_TEMPLATE_INSTANTIATED (nh) && - !DECL_EXPLICIT_INSTANTIATION (nh)) - instantiate_decl (nh, false, false); - - tree init (DECL_INITIAL (nh)); - - if (init == error_mark_node || TREE_CODE (init) != INTEGER_CST) - throw operation_failed (); - - unsigned long long e; - - { - HOST_WIDE_INT hwl (TREE_INT_CST_LOW (init)); - HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (init)); - - unsigned long long l (hwl); - unsigned long long h (hwh); - unsigned short width (HOST_BITS_PER_WIDE_INT); - - e = (h << width) + l; - } - - null_handler = static_cast (e); - t.set ("wrapper-null-handler", null_handler); - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "wrapper_traits specialization does not define the " - << "null_handler constant" << endl; - throw; - } - - // Get the null_default flag. - // - if (null_handler) - { - try - { - tree nh ( - lookup_qualified_name ( - inst, get_identifier ("null_default"), false, false)); - - if (nh == error_mark_node || TREE_CODE (nh) != VAR_DECL) - throw operation_failed (); - - // Instantiate this decalaration so that we can get its value. - // - if (DECL_TEMPLATE_INSTANTIATION (nh) && - !DECL_TEMPLATE_INSTANTIATED (nh) && - !DECL_EXPLICIT_INSTANTIATION (nh)) - instantiate_decl (nh, false, false); - - tree init (DECL_INITIAL (nh)); - - if (init == error_mark_node || TREE_CODE (init) != INTEGER_CST) - throw operation_failed (); - - unsigned long long e; - - { - HOST_WIDE_INT hwl (TREE_INT_CST_LOW (init)); - HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (init)); - - unsigned long long l (hwl); - unsigned long long h (hwh); - unsigned short width (HOST_BITS_PER_WIDE_INT); - - e = (h << width) + l; - } - - t.set ("wrapper-null-default", static_cast (e)); - } - catch (operation_failed const&) - { - os << f << ":" << l << ":" << c << ": error: " - << "wrapper_traits specialization does not define the " - << "null_default constant" << endl; - throw; - } - } - - // Check if the wrapper is a TR1 template instantiation. - // - if (tree ti = TYPE_TEMPLATE_INFO (t.tree_node ())) - { - tree decl (TI_TEMPLATE (ti)); // DECL_TEMPLATE - - // Get to the most general template declaration. - // - while (DECL_TEMPLATE_INFO (decl)) - decl = DECL_TI_TEMPLATE (decl); - - bool& tr1 (features.tr1_pointer); - bool& boost (features.boost_pointer); - - string n (decl_as_string (decl, TFF_PLAIN_IDENTIFIER)); - - // In case of a boost TR1 implementation, we cannot distinguish - // between the boost:: and std::tr1:: usage since the latter is - // just a using-declaration for the former. - // - tr1 = tr1 - || n.compare (0, 8, "std::tr1") == 0 - || n.compare (0, 10, "::std::tr1") == 0; - - boost = boost - || n.compare (0, 17, "boost::shared_ptr") == 0 - || n.compare (0, 19, "::boost::shared_ptr") == 0; - } - - t.set ("wrapper", true); - return true; - } - - tree - instantiate_template (tree t, tree arg) - { - tree args (make_tree_vec (1)); - TREE_VEC_ELT (args, 0) = arg; - - // This step should succeed regardles of whether there is a - // specialization for this type. - // - tree inst ( - lookup_template_class (t, args, 0, 0, 0, tf_warning_or_error)); - - if (inst == error_mark_node) - { - // Diagnostics has already been issued by lookup_template_class. - // - throw operation_failed (); - } - - inst = TYPE_MAIN_VARIANT (inst); - - // The instantiation may already be complete if it matches a - // (complete) specialization or was used before. - // - if (!COMPLETE_TYPE_P (inst)) - inst = instantiate_class_template (inst); - - // If we cannot instantiate this type, assume there is no suitable - // specialization for it. - // - if (inst == error_mark_node || !COMPLETE_TYPE_P (inst)) - return 0; - - return inst; - } - - private: - tree wrapper_traits_; - tree pointer_traits_; - tree container_traits_; }; // @@ -2151,19 +1253,10 @@ namespace relational throw operation_failed (); } - // Resolve referenced objects from tree nodes to semantic graph - // nodes. + // Process join conditions. // - view_alias_map& amap (c.set ("alias-map", view_alias_map ())); - view_object_map& omap (c.set ("object-map", view_object_map ())); - - size_t& obj_count (c.set ("object-count", size_t (0))); - size_t& tbl_count (c.set ("table-count", size_t (0))); - if (has_o) { - using semantics::class_; - view_objects& objs (c.get ("objects")); for (view_objects::iterator i (objs.begin ()); i != objs.end (); ++i) @@ -2181,94 +1274,8 @@ namespace relational throw operation_failed (); } - tbl_count++; continue; } - else - obj_count++; - - tree n (TYPE_MAIN_VARIANT (i->obj_node)); - - if (TREE_CODE (n) != RECORD_TYPE) - { - error (i->loc) - << "name '" << i->obj_name << "' in db pragma object does " - << "not name a class" << endl; - - throw operation_failed (); - } - - class_& o (dynamic_cast (*unit.find (n))); - - if (!object (o)) - { - error (i->loc) - << "name '" << i->obj_name << "' in db pragma object does " - << "not name a persistent class" << endl; - - info (o.file (), o.line (), o.column ()) - << "class '" << i->obj_name << "' is defined here" << endl; - - throw operation_failed (); - } - - i->obj = &o; - - if (i->alias.empty ()) - { - if (!omap.insert (view_object_map::value_type (&o, &*i)).second) - { - error (i->loc) << "persistent class '" << i->obj_name << - "' is used in the view more than once" << endl; - - error (omap[&o]->loc) << "previously used here" << endl; - - info (i->loc) << "use the alias clause to assign it a " << - "different name" << endl; - - throw operation_failed (); - } - - // Also add the bases of a polymorphic object. - // - class_* poly_root (polymorphic (o)); - - if (poly_root != 0 && poly_root != &o) - { - for (class_* b (&polymorphic_base (o));; - b = &polymorphic_base (*b)) - { - if (!omap.insert ( - view_object_map::value_type (b, &*i)).second) - { - error (i->loc) << "base class '" << class_name (*b) << - "' is used in the view more than once" << endl; - - error (omap[b]->loc) << "previously used here" << endl; - - info (i->loc) << "use the alias clause to assign it a " << - "different name" << endl; - - throw operation_failed (); - } - - if (b == poly_root) - break; - } - } - } - else - { - if (!amap.insert ( - view_alias_map::value_type (i->alias, &*i)).second) - { - error (i->loc) - << "alias '" << i->alias << "' is used in the view more " - << "than once" << endl; - - throw operation_failed (); - } - } // If we have to generate the query and there was no JOIN // condition specified by the user, try to come up with one -- cgit v1.1