From ab132de5f11e414974cdc0c4b8d85a19792b2e47 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Sep 2011 13:49:43 +0200 Subject: Use common lookup function instead of duplicating code --- odb/lookup.cxx | 10 ----- odb/pragma.cxx | 19 +++++++- odb/relational/type-processor.cxx | 94 +++++++++++---------------------------- 3 files changed, 43 insertions(+), 80 deletions(-) diff --git a/odb/lookup.cxx b/odb/lookup.cxx index 4f87203..cc02c66 100644 --- a/odb/lookup.cxx +++ b/odb/lookup.cxx @@ -114,16 +114,6 @@ namespace lookup tt = lex.next (t); } - // Get the actual type if this is a TYPE_DECL. - // - if (is_type) - { - if (TREE_CODE (scope) == TYPE_DECL) - scope = TREE_TYPE (scope); - - scope = TYPE_MAIN_VARIANT (scope); - } - return scope; } } diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 76e2968..e41792a 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -213,8 +213,23 @@ resolve_scoped_name (tree& token, cxx_pragma_lexer lex; cpp_ttype ptt; // Not used. string st (lex.start (token, type)); - return lookup::resolve_scoped_name ( - st, type, ptt, lex, current_scope (), name, is_type); + + tree decl ( + lookup::resolve_scoped_name ( + st, type, ptt, lex, current_scope (), name, is_type)); + + // Get the actual type if this is a TYPE_DECL. + // + if (is_type) + { + if (TREE_CODE (decl) == TYPE_DECL) + decl = TREE_TYPE (decl); + + if (TYPE_P (decl)) // Can be a template. + decl = TYPE_MAIN_VARIANT (decl); + } + + return decl; } catch (lookup::invalid_name const&) { diff --git a/odb/relational/type-processor.cxx b/odb/relational/type-processor.cxx index 9996196..de05735 100644 --- a/odb/relational/type-processor.cxx +++ b/odb/relational/type-processor.cxx @@ -1906,6 +1906,10 @@ namespace relational tree decl (0); // Resolved template node. string decl_name; // User-provided template name. + // Scope in which the pointer pragma was specified. + // + tree resolve_scope (c.scope ().tree_node ()); + if (c.count ("pointer")) { string const& p (c.get ("pointer")); @@ -1926,7 +1930,7 @@ namespace relational // This is not a template-id. Resolve it and see if it is a // template or a type. // - decl = resolve_name (p, c.scope (), true); + decl = resolve_name (p, resolve_scope, true); int tc (TREE_CODE (decl)); if (tc == TYPE_DECL) @@ -2003,7 +2007,7 @@ namespace relational if (!tr1) { if (decl == 0) - decl = resolve_name (decl_name, c.scope (), false); + decl = resolve_name (decl_name, resolve_scope, false); if (TREE_CODE (decl) != TEMPLATE_DECL || ! DECL_CLASS_TEMPLATE_P (decl)) @@ -2076,7 +2080,7 @@ namespace relational // if (!scoped) { - tree decl (resolve_name (t, c.scope (), false)); + tree decl (resolve_name (t, resolve_scope, false)); tree scope (CP_DECL_CONTEXT (decl)); if (scope != global_namespace) @@ -2146,82 +2150,36 @@ namespace relational string name_; }; - struct unable_to_resolve - { - unable_to_resolve (string const& n): name_ (n) {} - - string const& - name () const {return name_;} - - private: - string name_; - }; + typedef lookup::unable_to_resolve unable_to_resolve; tree - resolve_name (string const& qn, semantics::scope& ss, bool type) + resolve_name (string const& qn, tree scope, bool is_type) { - tree scope (ss.tree_node ()); - - // @@ Could use cxx_lexer to parse the name. - // - for (size_t b (0), e (qn.find (':')), size (qn.size ());; - e = qn.find (':', b)) + try { - bool last (e == string::npos); - string n (qn, b, last ? string::npos : e - b); + string t; + cpp_ttype tt, ptt; - if (n.empty ()) - { - if (b == 0) - scope = global_namespace; - else - throw invalid_name (qn); - } - else - { - tree nid (get_identifier (n.c_str ())); - scope = lookup_qualified_name (scope, nid, last && type, false); + nested_lexer.start (qn); + tt = nested_lexer.next (t); - // If this is the first component in the name, then also - // search the outer scopes. - // - if (scope == error_mark_node && b == 0 && !ss.global_scope ()) - { - semantics::scope* s (&ss); - do - { - s = &s->scope_ (); - scope = lookup_qualified_name ( - s->tree_node (), nid, last && type, false); - } while (scope == error_mark_node && !s->global_scope ()); - } - - if (scope == error_mark_node) - throw unable_to_resolve (qn); - - if (!last && TREE_CODE (scope) == TYPE_DECL) - scope = TREE_TYPE (scope); - } - - if (e == string::npos) - break; - - if (qn[++e] != ':') - throw invalid_name (qn); - - ++e; // Second ':'. - - if (e == size) - break; - - b = e; + string name; + return lookup::resolve_scoped_name ( + t, tt, ptt, nested_lexer, scope, name, is_type); + } + catch (cxx_lexer::invalid_input const&) + { + throw invalid_name (qn); + } + catch (lookup::invalid_name const&) + { + throw invalid_name (qn); } - - return scope; } private: cxx_string_lexer lexer; + cxx_string_lexer nested_lexer; data_member member_; traversal::names member_names_; -- cgit v1.1