From eacf52a9a4f3832274fdefc909ab23c13413e128 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Aug 2012 11:46:00 +0200 Subject: Add support for member accessors/modifiers New pragmas: get, set, access. New test: common/access. --- odb/context.hxx | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'odb/context.hxx') diff --git a/odb/context.hxx b/odb/context.hxx index f201596..5d8c339 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -217,6 +217,27 @@ struct column_expr: std::vector location_t loc; }; +// +// +struct member_access +{ + member_access (location_t l): loc (l), by_value (false) {} + + // Return true of we have the (?) placeholder. + // + bool + placeholder () const; + + std::string + translate (std::string const& obj, + std::string const& val = std::string ()) const; + + location_t loc; // If zero, then this is a synthesized expression. + cxx_tokens expr; + bool by_value; // True if accessor returns by value. False doesn't + // necessarily mean that it is by reference. +}; + class context { public: @@ -260,11 +281,14 @@ public: static semantics::type& utype (semantics::data_member&, semantics::names*& hint); + // For arrays this function returns true if the (innermost) element + // type is const. + // static bool const_type (semantics::type&); static semantics::type& - member_type (semantics::data_member& m, string const& key_prefix); + member_type (semantics::data_member&, string const& key_prefix); static semantics::type& member_utype (semantics::data_member& m, string const& key_prefix) @@ -272,6 +296,44 @@ public: return utype (member_type (m, key_prefix)); } + // Form a reference type for a member type. If make_const is true, then + // add top-level const qualifier, unless it is already there. If it is + // false, then strip it if it is already there. If var is not empty, + // then embed the variable name into the type (e.g., char (*v)[3]). + // + static string + member_ref_type (semantics::data_member& m, + bool make_const, + string const& var = "") + { + return type_ref_type (m.type (), m.belongs ().hint (), make_const, var); + } + + static string + type_ref_type (semantics::type&, + semantics::names* hint, + bool make_const, + string const& var = ""); + + // Form a value type for a member type. If make_const is true, then add + // top-level const qualifier, unless it is already there. If it is false, + // then strip it if it is already there. If var is not empty, then embed + // the variable name into the type (e.g., char v[3]). + // + static string + member_val_type (semantics::data_member& m, + bool make_const, + string const& var = "") + { + return type_val_type (m.type (), m.belongs ().hint (), make_const, var); + } + + static string + type_val_type (semantics::type&, + semantics::names* hint, + bool make_const, + string const& var = ""); + // Predicates. // public: @@ -617,7 +679,7 @@ public: // Return a string literal that can be used in C++ source code. It // includes "". // - string + static string strlit (string const&); // Counts and other information. -- cgit v1.1