From ebe76d1f33c45476adc0ad86fad25f32662bd7f4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Jul 2015 17:37:10 +0200 Subject: Fix member name conflicts in query support --- odb/common-query.cxx | 66 +++++++++++++++++++++++++++++++--------------------- odb/common-query.hxx | 11 +++++---- 2 files changed, 47 insertions(+), 30 deletions(-) (limited to 'odb') diff --git a/odb/common-query.cxx b/odb/common-query.cxx index ade621a..22407fc 100644 --- a/odb/common-query.cxx +++ b/odb/common-query.cxx @@ -11,6 +11,19 @@ using namespace std; // query_utils // +string query_utils:: +depth_suffix (size_t d) +{ + if (d != 0) + { + ostringstream os; + os << d; + return '_' + os.str (); + } + + return string (); +} + // Collect nested (composite) types as generated by query_columns. // struct query_nested_types: object_columns_base, virtual context @@ -31,8 +44,9 @@ struct query_nested_types: object_columns_base, virtual context if (m != 0) { string name (prefix_ + public_name (*m)); - name += in_ptr_ ? "_column_class_" : "_class_"; - name += query_columns::depth_suffix (depth_); + name += in_ptr_ ? "_column_class" : "_class"; + name += query_utils::depth_suffix (depth_); + name += '_'; types.push_back (name); depth_++; @@ -174,10 +188,13 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) if (nl_) os << endl; - os << "struct " << public_name (*m) << "_tag" + os << "struct " << public_name (*m) << "_tag" << + query_utils::depth_suffix (depth_) << "{"; + depth_++; object_columns_base::traverse_composite (m, c); + depth_--; os << "};"; @@ -207,7 +224,7 @@ generate (string const& name) query_alias_traits:: query_alias_traits (semantics::class_& c, bool decl) - : decl_ (decl) + : decl_ (decl), depth_ (0) { scope_ = "access::"; scope_ += (object (c) ? "object_traits_impl" : "view_traits_impl"); @@ -234,9 +251,12 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) } string old_scope (scope_); - scope_ += "::" + public_name (*m) + "_tag"; + scope_ += "::" + public_name (*m) + "_tag" + + query_utils::depth_suffix (depth_); + depth_++; object_columns_base::traverse_composite (m, c); + depth_--; scope_ = old_scope; } @@ -319,7 +339,7 @@ generate_def (string const&, semantics::class_&, string const&) query_columns_base:: query_columns_base (semantics::class_& c, bool decl, bool inst) - : decl_ (decl), inst_ (inst) + : decl_ (decl), inst_ (inst), depth_ (0) { string const& n (class_fq_name (c)); @@ -355,18 +375,21 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) return; string name (public_name (*m)); + string dsuffix (query_utils::depth_suffix (depth_)); if (decl_) { os << "// " << name << endl << "//" << endl - << "struct " << name << "_base_" + << "struct " << name << "_base" << dsuffix << '_' << "{"; string old_scope (scope_); - scope_ += "::" + name + "_tag"; + scope_ += "::" + name + "_tag" + dsuffix; + depth_++; object_columns_base::traverse_composite (m, c); + depth_--; scope_ = old_scope; @@ -375,9 +398,11 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) else { string old_scope (scope_); - scope_ += "::" + name + "_base_"; + scope_ += "::" + name + "_base" + dsuffix + '_'; + depth_++; object_columns_base::traverse_composite (m, c); + depth_--; scope_ = old_scope; } @@ -480,19 +505,6 @@ query_columns (bool decl, bool ptr, semantics::class_& c) { } -string query_columns:: -depth_suffix (size_t d) -{ - if (d != 0) - { - ostringstream os; - os << d; - return os.str () + '_'; - } - - return string (); -} - void query_columns:: traverse_object (semantics::class_& c) { @@ -516,7 +528,7 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) // the class and member names. // string name (public_name (*m)); - string suffix (in_ptr_ ? "_column_class_" : "_class_"); + string suffix (in_ptr_ ? "_column_class" : "_class"); // Add depth to the nested composite to avoid potential name conflicts // in situations like these: @@ -525,7 +537,9 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) // struct outer { inner value; }; // struct object { outer value; } // - suffix += depth_suffix (depth_); + string dsuffix (query_utils::depth_suffix (depth_)); + suffix += dsuffix; + suffix += '_'; depth_++; @@ -551,7 +565,7 @@ traverse_composite (semantics::data_member* m, semantics::class_& c) // data for the pointer members. // if (!ptr_ && !poly_ref_ && has_a (c, test_pointer)) - os << ": " << name << "_base_"; + os << ": " << name << "_base" << dsuffix << '_'; os << "{"; @@ -717,7 +731,7 @@ traverse_pointer (semantics::data_member& m, semantics::class_& c) os << "struct " << name << "_type_: " << name << "_pointer_type_, " << - name << "_column_class_" << depth_suffix (depth_) + name << "_column_class" << query_utils::depth_suffix (depth_) << '_' << "{"; if (!const_.empty ()) diff --git a/odb/common-query.hxx b/odb/common-query.hxx index 7404bc0..3bd2560 100644 --- a/odb/common-query.hxx +++ b/odb/common-query.hxx @@ -20,6 +20,9 @@ struct query_utils: virtual context string const& type, // Object fq-type. string const& alias, // Table alias. semantics::class_&); // Traverse for nested structs. + + static string + depth_suffix (size_t); }; // Generate query tags for pointers in this object. @@ -28,7 +31,7 @@ struct query_tags: object_columns_base, virtual context { typedef query_tags base; - query_tags (): nl_ (false) {} + query_tags (): nl_ (false), depth_ (0) {} virtual void traverse (semantics::class_&); @@ -47,6 +50,7 @@ struct query_tags: object_columns_base, virtual context private: bool nl_; + size_t depth_; }; // Generate alias_traits specializations for pointers in this objects. @@ -81,6 +85,7 @@ struct query_alias_traits: object_columns_base, virtual context protected: bool decl_; string scope_; + size_t depth_; }; // Generate query columns in the query_columns_base class. @@ -111,6 +116,7 @@ protected: bool inst_; string const_; // Const prefix or empty. string scope_; + size_t depth_; }; // Generate query columns in the query_columns or pointer_query_columns @@ -143,9 +149,6 @@ struct query_columns: object_columns_base, virtual context virtual void traverse_pointer (semantics::data_member&, semantics::class_&); - static string - depth_suffix (size_t); - protected: bool decl_; bool ptr_; -- cgit v1.1