diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-28 17:51:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-28 17:51:23 +0200 |
commit | 7dff3249f7ef6f8675e0c0fcbe3109d50f4c1b1d (patch) | |
tree | 8596735f193cc4a377e97cf63af1a0a6c40d5bbf /odb/semantics/elements.hxx | |
parent | c6a2b0f125c70f521daf820d014ff07b4fe8af3b (diff) |
Add support for literal names (template-id, derived type declarator)
Diffstat (limited to 'odb/semantics/elements.hxx')
-rw-r--r-- | odb/semantics/elements.hxx | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/odb/semantics/elements.hxx b/odb/semantics/elements.hxx index 2e8908e..dfc5840 100644 --- a/odb/semantics/elements.hxx +++ b/odb/semantics/elements.hxx @@ -66,6 +66,7 @@ namespace semantics // class node; class edge; + class unit; // // @@ -142,8 +143,33 @@ namespace semantics // node (); + protected: + typedef semantics::unit unit_type; + + unit_type const& + unit () const + { + return *unit_; + } + + unit_type& + unit () + { + return *unit_; + } + + private: + friend class semantics::unit; + + void + unit (unit_type& u) + { + unit_ = &u; + } + private: tree tree_node_; + unit_type* unit_; path file_; size_t line_; @@ -269,34 +295,68 @@ namespace semantics public: typedef semantics::scope scope_type; + // Return true if this type is unnamed and no literal name, such as + // template-id or derived type declarator, can be used instead. + // bool anonymous () const { - return defined_ == 0 && named_.empty (); + if (defined_ != 0 || !named_.empty ()) + return false; + + return anonymous_ (); } + // Return true if the node itself or any of the scopes up to the + // global scope is anonymous. For a named class nested in an unnamed + // class, anonymous() will return false and fq_anonymous() will + // return true. + // bool fq_anonymous () const; - // If hint is 0, use the defines edge. + // As above but use the hint to select the first outer scope. If + // hint is 0, use the defines edge. // bool fq_anonymous (names* hint) const; + // Return the node's unqualifed name. If the node has a name, then + // return it, preferring the defines edge. Otherwise, return a + // literal name, e.g., template-id or a derived type declarator. + // Finally, if the type is anonymous, return <anonymous> string. + // string name () const { - return named ().name (); + if (defined_ != 0) + return defined_->name (); + + if (!named_.empty ()) + return named_[0]->name (); + + return name_ (); } + // Return the node's fully-qualifed name. + // virtual string fq_name () const; - // If hint is 0, use the defines edge. + // As above but use the hint to select the first outer scope. If hint + // is 0, use the defines edge. // virtual string fq_name (names* hint) const; + // Return true if the type is named. + // + bool + named_p () const + { + return defined_ != 0 || !named_.empty (); + } + scope_type& scope () const { @@ -331,6 +391,13 @@ namespace semantics using node::add_edge_right; private: + bool + anonymous_ () const; + + string + name_ () const; + + private: defines* defined_; names_list named_; }; |