diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-08-31 10:03:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-08-31 10:03:45 +0200 |
commit | c0957cfe1c73ecb6c96314e45e7d29b4199b20d6 (patch) | |
tree | 96a747f7196baa335cf83ff160527bb8333ca9e3 /odb/semantics/elements.hxx | |
parent | ed52acc5e65dd9ea2fb2d9c851c2faa61d5cb2d9 (diff) |
Add support for virtual data members
New test: common/virtual.
Diffstat (limited to 'odb/semantics/elements.hxx')
-rw-r--r-- | odb/semantics/elements.hxx | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/odb/semantics/elements.hxx b/odb/semantics/elements.hxx index c9aa00e..137fbda 100644 --- a/odb/semantics/elements.hxx +++ b/odb/semantics/elements.hxx @@ -17,6 +17,7 @@ #include <cutl/fs/path.hxx> #include <cutl/container/graph.hxx> #include <cutl/container/pointer-iterator.hxx> +#include <cutl/compiler/type-id.hxx> #include <cutl/compiler/context.hxx> #include <odb/gcc-fwd.hxx> @@ -32,6 +33,7 @@ namespace semantics using container::graph; using container::pointer_iterator; + using compiler::type_id; using compiler::context; // @@ -501,6 +503,24 @@ namespace semantics }; + // Ambiguous name lookup exception. + // + struct ambiguous + { + ambiguous (names& f, names& s): first (f), second (s) {} + names& first; + names& second; + }; + + // Unresolved name lookup exception. + // + struct unresolved + { + unresolved (string const& n, bool tm): name (n), type_mismatch (tm) {} + string name; + bool type_mismatch; // True if the name resolved but types didn't match. + }; + // // class scope: public virtual nameable @@ -555,12 +575,40 @@ namespace semantics return names_.end (); } + // Find a name in this scope. + // + public: virtual names_iterator_pair find (string const& name) const; names_iterator find (names&); + // Lookup a name of the specified type in this scope and, if not + // found, in outer scopes. + // + public: + static unsigned int const exclude_outer = 0x01; // Exclude outer scopes. + static unsigned int const include_hidden = 0x02; // Include hidden names. + + virtual names* + lookup (string const& name, + type_id const&, + unsigned int flags = 0, + bool* hidden = 0) const; + + template <typename T> + T& + lookup (string const& name, unsigned int flags = 0) const + { + bool hidden (false); + + if (names* n = lookup (name, typeid (T), flags, &hidden)) + return dynamic_cast<T&> (n->named ()); + + throw unresolved (name, hidden); + } + public: scope (path const& file, size_t line, size_t column, tree tn) : node (file, line, column, tn) @@ -757,17 +805,6 @@ namespace semantics } }; - // Virtual data member (extension to the standard C++ model). - // - class virtual_data_member: public data_member - { - public: - virtual_data_member (path const& file, size_t line, size_t column) - : node (file, line, column, 0) - { - } - }; - // Unsupported type. // class unsupported_type: public type |