From 526f66e63f23afb40cc01550ca1a3a3592a84254 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Jul 2012 11:12:11 +0200 Subject: Use cxx_lexer interface instead of pragma_lex() directly This will allow us to use different kinds of cxx_lexer implementations in the future. --- odb/relational/processor.cxx | 33 +++++++++++----------- odb/relational/source.cxx | 65 +++++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 47 deletions(-) (limited to 'odb/relational') diff --git a/odb/relational/processor.cxx b/odb/relational/processor.cxx index 8e0c693..5cb5f35 100644 --- a/odb/relational/processor.cxx +++ b/odb/relational/processor.cxx @@ -1276,8 +1276,9 @@ namespace relational lex_.start (i->value); - string t; - cpp_ttype tt (lex_.next (t)); + string tl; + tree tn; + cpp_ttype tt (lex_.next (tl, &tn)); string name; tree decl (0); @@ -1287,7 +1288,7 @@ namespace relational // if (tt == CPP_NAME) { - view_alias_map::iterator j (amap_.find (t)); + view_alias_map::iterator j (amap_.find (tl)); if (j != amap_.end ()) { @@ -1295,7 +1296,7 @@ namespace relational // Skip '::'. // - if (lex_.next (t) != CPP_SCOPE) + if (lex_.next (tl, &tn) != CPP_SCOPE) { error (i->loc) << "member name expected after an alias in db pragma " @@ -1303,11 +1304,11 @@ namespace relational throw operation_failed (); } - tt = lex_.next (t); + tt = lex_.next (tl, &tn); cpp_ttype ptt; // Not used. decl = lookup::resolve_scoped_name ( - t, tt, ptt, lex_, vo->obj->tree_node (), name, false); + lex_, tt, tl, tn, ptt, vo->obj->tree_node (), name, false); } } @@ -1322,7 +1323,7 @@ namespace relational tree type; cpp_ttype ptt; // Not used. decl = lookup::resolve_scoped_name ( - t, tt, ptt, lex_, i->scope, name, false, &type); + lex_, tt, tl, tn, ptt, i->scope, name, false, &type); type = TYPE_MAIN_VARIANT (type); @@ -1388,18 +1389,18 @@ namespace relational // Finally, resolve nested members if any. // - for (; tt == CPP_DOT; tt = lex_.next (t)) + for (; tt == CPP_DOT; tt = lex_.next (tl, &tn)) { - lex_.next (t); // Get CPP_NAME. + lex_.next (tl, &tn); // Get CPP_NAME. tree type (TYPE_MAIN_VARIANT (TREE_TYPE (decl))); decl = lookup_qualified_name ( - type, get_identifier (t.c_str ()), false, false); + type, get_identifier (tl.c_str ()), false, false); if (decl == error_mark_node || TREE_CODE (decl) != FIELD_DECL) { - error (i->loc) << "name '" << t << "' in db pragma column " + error (i->loc) << "name '" << tl << "' in db pragma column " << "does not refer to a data member" << endl; throw operation_failed (); } @@ -2257,8 +2258,7 @@ namespace relational tt != CPP_EOF; tt = lexer.next (t)) { - cxx_token ct; - ct.type = tt; + cxx_token ct (lexer.location (), tt); ct.literal = t; i->cond.push_back (ct); } @@ -2746,15 +2746,16 @@ namespace relational { try { - string t; + string tl; + tree tn; cpp_ttype tt, ptt; nested_lexer.start (qn); - tt = nested_lexer.next (t); + tt = nested_lexer.next (tl, &tn); string name; return lookup::resolve_scoped_name ( - t, tt, ptt, nested_lexer, scope, name, is_type); + nested_lexer, tt, tl, tn, ptt, scope, name, is_type); } catch (cxx_lexer::invalid_input const&) { diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index e97cdfe..ee7ac21 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -3308,14 +3308,15 @@ namespace relational } static string - translate_name_trailer (string& t, + translate_name_trailer (cxx_lexer& l, cpp_ttype& tt, - cpp_ttype& ptt, - cxx_tokens_lexer& lex) + string& tl, + tree& tn, + cpp_ttype& ptt) { string r; - for (; tt != CPP_EOF; ptt = tt, tt = lex.next (t)) + for (; tt != CPP_EOF; ptt = tt, tt = l.next (tl, &tn)) { bool done (false); @@ -3339,7 +3340,7 @@ namespace relational if (ptt == CPP_NAME || ptt == CPP_KEYWORD) r += ' '; - r += t; + r += tl; } else done = true; @@ -3356,10 +3357,11 @@ namespace relational } static class_::expression - translate_name (string& t, + translate_name (cxx_lexer& l, cpp_ttype& tt, + string& tl, + tree& tn, cpp_ttype& ptt, - cxx_tokens_lexer& lex, tree scope, location_t loc, string const& prag, @@ -3390,7 +3392,7 @@ namespace relational // if (tt == CPP_NAME) { - view_alias_map::const_iterator i (amap.find (t)); + view_alias_map::const_iterator i (amap.find (tl)); if (i != amap.end ()) { @@ -3406,7 +3408,7 @@ namespace relational // Skip '::'. // ptt = tt; - tt = lex.next (t); + tt = l.next (tl, &tn); if (tt != CPP_SCOPE) { @@ -3417,10 +3419,10 @@ namespace relational } ptt = tt; - tt = lex.next (t); + tt = l.next (tl, &tn); decl = lookup::resolve_scoped_name ( - t, tt, ptt, lex, vo->obj->tree_node (), name, false); + l, tt, tl, tn, ptt, vo->obj->tree_node (), name, false); } } @@ -3434,7 +3436,7 @@ namespace relational // tree type; decl = lookup::resolve_scoped_name ( - t, tt, ptt, lex, scope, name, false, &type); + l, tt, tl, tn, ptt, scope, name, false, &type); type = TYPE_MAIN_VARIANT (type); @@ -3446,7 +3448,7 @@ namespace relational // is some other valid name. // return expression ( - name + translate_name_trailer (t, tt, ptt, lex)); + name + translate_name_trailer (l, tt, tl, tn, ptt)); } vo = i->second; @@ -3471,7 +3473,7 @@ namespace relational } else return expression ( - name + translate_name_trailer (t, tt, ptt, lex)); + name + translate_name_trailer (l, tt, tl, tn, ptt)); } expression e (vo); @@ -3491,7 +3493,7 @@ namespace relational // Finally, resolve nested members if any. // - for (; tt == CPP_DOT; ptt = tt, tt = lex.next (t)) + for (; tt == CPP_DOT; ptt = tt, tt = l.next (tl, &tn)) { // Check if this member is actually of a composite value type. // This is to handle expressions like "object::member.is_null ()" @@ -3503,7 +3505,7 @@ namespace relational break; ptt = tt; - tt = lex.next (t); + tt = l.next (tl, &tn); if (tt != CPP_NAME) { @@ -3515,12 +3517,12 @@ namespace relational tree type (TYPE_MAIN_VARIANT (TREE_TYPE (decl))); decl = lookup_qualified_name ( - type, get_identifier (t.c_str ()), false, false); + type, get_identifier (tl.c_str ()), false, false); if (decl == error_mark_node || TREE_CODE (decl) != FIELD_DECL) { error (loc) - << "name '" << t << "' in db pragma " << prag << " does not " + << "name '" << tl << "' in db pragma " << prag << " does not " << "refer to a data member" << endl; throw operation_failed (); } @@ -3557,7 +3559,7 @@ namespace relational // loop. // if (tt == CPP_DOT) - r += translate_name_trailer (t, tt, ptt, lex); + r += translate_name_trailer (l, tt, tl, tn, ptt); return expression (r); } @@ -3570,7 +3572,7 @@ namespace relational } else return expression ( - name + translate_name_trailer (t, tt, ptt, lex)); + name + translate_name_trailer (l, tt, tl, tn, ptt)); } catch (lookup::unable_to_resolve const& e) { @@ -3582,7 +3584,7 @@ namespace relational } else return expression ( - name + translate_name_trailer (t, tt, ptt, lex)); + name + translate_name_trailer (l, tt, tl, tn, ptt)); } } @@ -3610,11 +3612,12 @@ namespace relational view_alias_map const& amap (c.get ("alias-map")); view_object_map const& omap (c.get ("object-map")); - cxx_tokens_lexer lex; - lex.start (ts); + cxx_tokens_lexer l; + l.start (ts); - string t; - for (cpp_ttype tt (lex.next (t)), ptt (CPP_EOF); tt != CPP_EOF;) + tree tn; + string tl; + for (cpp_ttype tt (l.next (tl, &tn)), ptt (CPP_EOF); tt != CPP_EOF;) { // Try to format the expression to resemble the style of the // generated code. @@ -3726,7 +3729,7 @@ namespace relational ptt == CPP_NUMBER) add_space (r); - r += strlit (t); + r += strlit (tl); break; } case CPP_NUMBER: @@ -3737,7 +3740,7 @@ namespace relational ptt == CPP_NUMBER) add_space (r); - r += t; + r += tl; break; } case CPP_SCOPE: @@ -3759,7 +3762,7 @@ namespace relational // expression e ( translate_name ( - t, tt, ptt, lex, + l, tt, tl, tn, ptt, scope, loc, prag, r.empty () && placeholder == 0, amap, omap)); @@ -3779,7 +3782,7 @@ namespace relational // Get the next token and see if it is ')'. // ptt = tt; - tt = lex.next (t); + tt = l.next (tl, &tn); if (tt == CPP_CLOSE_PAREN) { @@ -3811,7 +3814,7 @@ namespace relational ptt == CPP_NUMBER) add_space (r); - r += t; + r += tl; } else { @@ -3831,7 +3834,7 @@ namespace relational // ptt = tt; - tt = lex.next (t); + tt = l.next (tl, &tn); } return e; -- cgit v1.1