aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-07-20 11:12:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-07-27 10:30:15 +0200
commit526f66e63f23afb40cc01550ca1a3a3592a84254 (patch)
treef17fd648c4c1e11838b413c6de91ff61693c0480
parent0a6a2fe64508497d287aa3341e667fe313912774 (diff)
Use cxx_lexer interface instead of pragma_lex() directly
This will allow us to use different kinds of cxx_lexer implementations in the future.
-rw-r--r--odb/cxx-lexer.cxx59
-rw-r--r--odb/cxx-lexer.hxx36
-rw-r--r--odb/cxx-token.hxx10
-rw-r--r--odb/diagnostics.cxx13
-rw-r--r--odb/diagnostics.hxx10
-rw-r--r--odb/lookup.cxx25
-rw-r--r--odb/lookup.hxx16
-rw-r--r--odb/pragma.cxx598
-rw-r--r--odb/relational/processor.cxx33
-rw-r--r--odb/relational/source.cxx65
10 files changed, 474 insertions, 391 deletions
diff --git a/odb/cxx-lexer.cxx b/odb/cxx-lexer.cxx
index 9a910aa..b02b4e0 100644
--- a/odb/cxx-lexer.cxx
+++ b/odb/cxx-lexer.cxx
@@ -41,20 +41,30 @@ start (cxx_tokens const& ts)
{
tokens_ = &ts;
cur_ = ts.begin ();
+ loc_ = 0;
}
cpp_ttype cxx_tokens_lexer::
-next (std::string& token)
+next (std::string& token, tree* node)
{
if (cur_ != tokens_->end ())
{
+ loc_ = cur_->loc;
token = cur_->literal;
+ if (node != 0)
+ *node = cur_->node;
return static_cast<cpp_ttype> (cur_++->type);
}
else
return CPP_EOF;
}
+location_t cxx_tokens_lexer::
+location () const
+{
+ return loc_;
+}
+
//
// cxx_pragma_lexer
//
@@ -76,15 +86,7 @@ start (tree& token, cpp_ttype& type)
}
cpp_ttype cxx_pragma_lexer::
-next (string& token)
-{
- next (*token_);
- token = translate ();
- return *type_;
-}
-
-cpp_ttype cxx_pragma_lexer::
-next (tree& token)
+next (string& token, tree* node)
{
*type_ = pragma_lex (token_);
@@ -94,12 +96,19 @@ next (tree& token)
if (*type_ == CPP_NAME && C_IS_RESERVED_WORD (*token_))
*type_ = CPP_KEYWORD;
- if (&token != token_)
- token = *token_;
+ if (node != 0 && node != token_)
+ *node = *token_;
+ token = translate ();
return *type_;
}
+location_t cxx_pragma_lexer::
+location () const
+{
+ return input_location;
+}
+
string cxx_pragma_lexer::
translate ()
{
@@ -221,6 +230,7 @@ start (string const& data)
data_ = data;
buf_ = data;
buf_ += '\n';
+ loc_ = 0;
cpp_push_buffer (
reader_,
@@ -230,7 +240,7 @@ start (string const& data)
}
cpp_ttype cxx_string_lexer::
-next (string& token)
+next (string& token, tree* node)
{
token.clear ();
cpp_token const* t (cpp_get_token (reader_));
@@ -258,11 +268,18 @@ next (string& token)
if (C_IS_RESERVED_WORD (id))
tt = CPP_KEYWORD;
+ if (node != 0)
+ *node = id;
+
token = name;
break;
}
+ case CPP_STRING:
case CPP_NUMBER:
{
+ if (node != 0)
+ *node = 0; // Doesn't seem to be available.
+
cpp_string const& s (t->val.str);
token.assign (reinterpret_cast<char const*> (s.text), s.len);
break;
@@ -270,7 +287,11 @@ next (string& token)
default:
{
if (tt <= CPP_LAST_PUNCTUATOR)
- token += token_spelling[tt];
+ {
+ if (node != 0)
+ *node = 0;
+ token = token_spelling[tt];
+ }
else
{
cerr << "unexpected token '" << token_spelling[tt] << "' in '" <<
@@ -281,5 +302,15 @@ next (string& token)
}
}
+ // Cache the location of this token.
+ //
+ loc_ = t->src_loc;
+
return tt;
}
+
+location_t cxx_string_lexer::
+location () const
+{
+ return loc_;
+}
diff --git a/odb/cxx-lexer.hxx b/odb/cxx-lexer.hxx
index e1e9fa5..9235ecf 100644
--- a/odb/cxx-lexer.hxx
+++ b/odb/cxx-lexer.hxx
@@ -28,14 +28,20 @@ public:
struct invalid_input {};
virtual cpp_ttype
- next (std::string& token) = 0;
+ next (std::string& token, tree* node = 0) = 0;
+
+ // Location of the last returned token.
+ //
+ virtual location_t
+ location () const = 0;
public:
static char const* token_spelling[N_TTYPES + 1];
};
-// Adapter to scan a saved token sequence.
+// Adapter to scan a saved token sequence. It returns numbers in the same
+// form as they were saved in the token sequence.
//
class cxx_tokens_lexer: public cxx_lexer
{
@@ -44,16 +50,20 @@ public:
start (cxx_tokens const&);
virtual cpp_ttype
- next (std::string& token);
+ next (std::string& token, tree* node = 0);
+
+ virtual location_t
+ location () const;
private:
cxx_tokens const* tokens_;
cxx_tokens::const_iterator cur_;
+ location_t loc_;
};
// A thin wrapper around the pragma_lex() function that recognizes
-// CPP_KEYWORD.
+// CPP_KEYWORD. It returns numbers as tree nodes.
//
class cxx_pragma_lexer: public cxx_lexer
{
@@ -72,13 +82,10 @@ public:
start (tree& token, cpp_ttype& type);
virtual cpp_ttype
- next (std::string& token);
+ next (std::string& token, tree* node = 0);
- // This pragma-specific version of next() returns a token as a tree
- // node.
- //
- cpp_ttype
- next (tree& token);
+ virtual location_t
+ location () const;
private:
std::string
@@ -92,7 +99,8 @@ private:
cpp_ttype type_data_;
};
-// A thin wrapper around cpp_reader for lexing C++ code fragments.
+// A thin wrapper around cpp_reader for lexing C++ code fragments. It
+// returns numbers as string literals.
//
class cxx_string_lexer: public cxx_lexer
{
@@ -107,7 +115,10 @@ public:
start (std::string const&);
virtual cpp_ttype
- next (std::string& token);
+ next (std::string& token, tree* node = 0);
+
+ virtual location_t
+ location () const;
private:
std::string data_;
@@ -115,6 +126,7 @@ private:
line_maps line_map_;
cpp_reader* reader_;
cpp_callbacks* callbacks_;
+ location_t loc_;
};
#endif // ODB_CXX_LEXER_HXX
diff --git a/odb/cxx-token.hxx b/odb/cxx-token.hxx
index 193d122..6478fc1 100644
--- a/odb/cxx-token.hxx
+++ b/odb/cxx-token.hxx
@@ -8,10 +8,18 @@
#include <string>
#include <vector>
+#include <odb/gcc-fwd.hxx>
+
struct cxx_token
{
+ cxx_token (location_t l, unsigned int t): loc (l), type (t), node (0) {}
+
+ location_t loc; // Location of this token.
unsigned int type; // Untyped cpp_ttype.
- std::string literal; // Only used for name, string, number, etc.
+ std::string literal; // Only used for name, keyword, string, amd number.
+ tree node; // Tree node for the number. The number can be
+ // represented as either literal, tree node, or
+ // both, depending on which lexer was used.
};
typedef std::vector<cxx_token> cxx_tokens;
diff --git a/odb/diagnostics.cxx b/odb/diagnostics.cxx
index 41ddd63..bce1102 100644
--- a/odb/diagnostics.cxx
+++ b/odb/diagnostics.cxx
@@ -3,6 +3,7 @@
// license : GNU GPL v3; see accompanying LICENSE file
#include <odb/gcc.hxx>
+#include <odb/cxx-lexer.hxx>
#include <odb/diagnostics.hxx>
using namespace std;
@@ -68,21 +69,21 @@ info (location_t loc)
}
std::ostream&
-error ()
+error (cxx_lexer& l)
{
- return error (input_location);
+ return error (l.location ());
}
std::ostream&
-warn ()
+warn (cxx_lexer& l)
{
- return warn (input_location);
+ return warn (l.location ());
}
std::ostream&
-info ()
+info (cxx_lexer& l)
{
- return info (input_location);
+ return info (l.location ());
}
cutl::fs::path
diff --git a/odb/diagnostics.hxx b/odb/diagnostics.hxx
index 9e676dc..a7dd575 100644
--- a/odb/diagnostics.hxx
+++ b/odb/diagnostics.hxx
@@ -32,14 +32,18 @@ warn (location_t);
std::ostream&
info (location_t);
+//
+//
+class cxx_lexer;
+
std::ostream&
-error ();
+error (cxx_lexer&);
std::ostream&
-warn ();
+warn (cxx_lexer&);
std::ostream&
-info ();
+info (cxx_lexer&);
// location_t macro wrappers.
//
diff --git a/odb/lookup.cxx b/odb/lookup.cxx
index 1568c42..c6b40b1 100644
--- a/odb/lookup.cxx
+++ b/odb/lookup.cxx
@@ -9,14 +9,14 @@ using namespace std;
namespace lookup
{
std::string
- parse_scoped_name (std::string& t, cpp_ttype& tt, cxx_lexer& lex)
+ parse_scoped_name (cxx_lexer& l, cpp_ttype& tt, string& tl, tree& tn)
{
string name;
if (tt == CPP_SCOPE)
{
name += "::";
- tt = lex.next (t);
+ tt = l.next (tl, &tn);
}
while (true)
@@ -26,24 +26,25 @@ namespace lookup
if (tt != CPP_NAME && tt != CPP_KEYWORD)
throw invalid_name ();
- name += t;
- tt = lex.next (t);
+ name += tl;
+ tt = l.next (tl, &tn);
if (tt != CPP_SCOPE)
break;
name += "::";
- tt = lex.next (t);
+ tt = l.next (tl, &tn);
}
return name;
}
tree
- resolve_scoped_name (string& t,
+ resolve_scoped_name (cxx_lexer& l,
cpp_ttype& tt,
+ string& tl,
+ tree& tn,
cpp_ttype& ptt,
- cxx_lexer& lex,
tree scope,
string& name,
bool is_type,
@@ -59,7 +60,7 @@ namespace lookup
first = false;
ptt = tt;
- tt = lex.next (t);
+ tt = l.next (tl, &tn);
}
while (true)
@@ -72,10 +73,10 @@ namespace lookup
if (tt != CPP_NAME && tt != CPP_KEYWORD)
throw invalid_name ();
- name += t;
- id = get_identifier (t.c_str ());
+ name += tl;
+ id = get_identifier (tl.c_str ());
ptt = tt;
- tt = lex.next (t);
+ tt = l.next (tl, &tn);
bool last (tt != CPP_SCOPE);
tree decl = lookup_qualified_name (scope, id, last && is_type, false);
@@ -110,7 +111,7 @@ namespace lookup
name += "::";
ptt = tt;
- tt = lex.next (t);
+ tt = l.next (tl, &tn);
}
return scope;
diff --git a/odb/lookup.hxx b/odb/lookup.hxx
index c19f963..7df8f34 100644
--- a/odb/lookup.hxx
+++ b/odb/lookup.hxx
@@ -35,15 +35,17 @@ namespace lookup
};
std::string
- parse_scoped_name (std::string& token,
- cpp_ttype& type,
- cxx_lexer& lexer);
+ parse_scoped_name (cxx_lexer&,
+ cpp_ttype&,
+ std::string& tl, // Token literal.
+ tree& tn); // Token node.
tree
- resolve_scoped_name (std::string& token,
- cpp_ttype& type,
- cpp_ttype& previous_type,
- cxx_lexer& lexer,
+ resolve_scoped_name (cxx_lexer&,
+ cpp_ttype&,
+ std::string& tl, // Token literal.
+ tree& tn, // Token node.
+ cpp_ttype& ptt, // Previous token type.
tree start_scope,
std::string& name,
bool is_type,
diff --git a/odb/pragma.cxx b/odb/pragma.cxx
index dcfab4e..0d21f7b 100644
--- a/odb/pragma.cxx
+++ b/odb/pragma.cxx
@@ -56,8 +56,10 @@ pragma_name_set simple_value_pragmas_;
// Empty leading components means fully qualified (similar to ::foo in C++).
//
static bool
-parse_qname (tree& t,
+parse_qname (cxx_lexer& l,
cpp_ttype& tt,
+ string& tl,
+ tree& tn,
string const& p, // Pragma name for diagnostic.
qname& name,
bool* expr = 0, // If specified, detect an expression
@@ -69,41 +71,41 @@ parse_qname (tree& t,
//
if (tt == CPP_DOT)
{
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_STRING)
{
- error () << "name expected after '.' in db pragma " << p << endl;
+ error (l) << "name expected after '.' in db pragma " << p << endl;
return false;
}
- name = TREE_STRING_POINTER (t);
- tt = pragma_lex (&t);
+ name = tl;
+ tt = l.next (tl, &tn);
return true;
}
name.clear ();
- string str (TREE_STRING_POINTER (t));
+ string str (tl);
// See what comes after the string.
//
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_DOT)
{
name.append (str);
- for (; tt == CPP_DOT; tt = pragma_lex (&t))
+ for (; tt == CPP_DOT; tt = l.next (tl, &tn))
{
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_STRING)
{
- error () << "name expected after '.' in db pragma " << p << endl;
+ error (l) << "name expected after '.' in db pragma " << p << endl;
return false;
}
- name.append (TREE_STRING_POINTER (t));
+ name.append (tl);
}
return true;
@@ -150,25 +152,23 @@ parse_qname (tree& t,
return true;
}
-
static bool
-parse_expression (tree& t,
+parse_expression (cxx_lexer& l,
cpp_ttype& tt,
+ string& tl,
+ tree& tn,
cxx_tokens& ts,
string const& prag)
{
// Keep reading tokens until we see a matching ')' while keeping track
- // of their balance. Also switch to the pragma lexer so that we detect
- // C++ keywords (this is a C++ expression).
+ // of their balance.
//
size_t balance (0);
- cxx_pragma_lexer lex;
- lex.start (t, tt);
- for (; tt != CPP_EOF; tt = lex.next (t))
+ for (; tt != CPP_EOF; tt = l.next (tl, &tn))
{
bool done (false);
- cxx_token ct;
+ cxx_token ct (l.location (), tt);
switch (tt)
{
@@ -187,25 +187,25 @@ parse_expression (tree& t,
}
case CPP_STRING:
{
- ct.literal = TREE_STRING_POINTER (t);
+ ct.literal = tl;
break;
}
case CPP_NAME:
//case CPP_KEYWORD: see default:
{
- ct.literal = IDENTIFIER_POINTER (t);
+ ct.literal = tl;
break;
}
case CPP_NUMBER:
{
- switch (TREE_CODE (t))
+ switch (TREE_CODE (tn))
{
case INTEGER_CST:
{
- tree type (TREE_TYPE (t));
+ tree type (TREE_TYPE (tn));
- HOST_WIDE_INT hwl (TREE_INT_CST_LOW (t));
- HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (t));
+ HOST_WIDE_INT hwl (TREE_INT_CST_LOW (tn));
+ HOST_WIDE_INT hwh (TREE_INT_CST_HIGH (tn));
unsigned long long l (hwl);
unsigned long long h (hwh);
@@ -234,8 +234,8 @@ parse_expression (tree& t,
}
case REAL_CST:
{
- tree type (TREE_TYPE (t));
- REAL_VALUE_TYPE val (TREE_REAL_CST (t));
+ tree type (TREE_TYPE (tn));
+ REAL_VALUE_TYPE val (TREE_REAL_CST (tn));
// This is the best we can do. val cannot be INF or NaN.
//
@@ -262,8 +262,8 @@ parse_expression (tree& t,
}
default:
{
- error ()
- << "unexpected numeric constant in db pragma " << prag << endl;
+ error (l) << "unexpected numeric constant in db pragma "
+ << prag << endl;
return false;
}
}
@@ -275,7 +275,7 @@ parse_expression (tree& t,
// CPP_KEYWORD is not in the cpp_ttype enumeration.
//
if (tt == CPP_KEYWORD)
- ct.literal = IDENTIFIER_POINTER (t);
+ ct.literal = tl;
break;
}
@@ -284,7 +284,9 @@ parse_expression (tree& t,
if (done)
break;
- ct.type = tt;
+ // We don't store the tree node in ct since we converted numbers to
+ // string literals.
+ //
ts.push_back (ct);
}
@@ -293,51 +295,52 @@ parse_expression (tree& t,
static string
-parse_scoped_name (tree& token, cpp_ttype& type, string const& prag)
+parse_scoped_name (cxx_lexer& l,
+ cpp_ttype& tt,
+ string& tl,
+ tree& tn,
+ string const& prag)
{
try
{
- cxx_pragma_lexer lex;
- string st (lex.start (token, type));
- return lookup::parse_scoped_name (st, type, lex);
+ return lookup::parse_scoped_name (l, tt, tl, tn);
}
catch (lookup::invalid_name const&)
{
- error () << "invalid name in db pragma " << prag << endl;
+ error (l) << "invalid name in db pragma " << prag << endl;
return "";
}
}
static tree
-resolve_scoped_name (tree& token,
- cpp_ttype& type,
+resolve_scoped_name (cxx_lexer& l,
+ cpp_ttype& tt,
+ string& tl,
+ tree& tn,
string& name,
bool is_type,
string const& prag)
{
try
{
- 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);
+ l, tt, tl, tn, ptt, current_scope (), name, is_type);
}
catch (lookup::invalid_name const&)
{
- error () << "invalid name in db pragma " << prag << endl;
+ error (l) << "invalid name in db pragma " << prag << endl;
return 0;
}
catch (lookup::unable_to_resolve const& e)
{
if (e.last ())
- error () << "unable to resolve " << (is_type ? "type " : "") << "name "
- << "'" << e.name () << "' in db pragma " << prag << endl;
+ error (l) << "unable to resolve " << (is_type ? "type " : "") << "name "
+ << "'" << e.name () << "' in db pragma " << prag << endl;
else
- error () << "unable to resolve name '" << e.name () << "' in db pragma "
- << prag << endl;
+ error (l) << "unable to resolve name '" << e.name () << "' in db pragma "
+ << prag << endl;
return 0;
}
@@ -531,7 +534,7 @@ check_spec_decl_type (tree d,
}
else
{
- error () << "unknown db pragma " << p << endl;
+ error (l) << "unknown db pragma " << p << endl;
return false;
}
@@ -560,7 +563,7 @@ add_pragma (pragma const& prag, tree decl, bool ns)
}
static void
-handle_pragma (cpp_reader* reader,
+handle_pragma (cxx_lexer& l,
string const& p,
string const& qualifier,
any& qualifier_value,
@@ -568,13 +571,14 @@ handle_pragma (cpp_reader* reader,
string const& decl_name,
bool ns) // True if this is a position namespace pragma.
{
- tree t;
cpp_ttype tt;
+ string tl;
+ tree tn;
string name (p); // Pragma name.
any val; // Pragma value.
pragma::add_func adder (0); // Custom context adder.
- location_t loc (input_location); // Pragma location.
+ location_t loc (l.location ()); // Pragma location.
if (p == "table")
{
@@ -589,17 +593,17 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_STRING && tt != CPP_DOT)
{
- error () << "table name expected in db pragma " << p << endl;
+ error (l) << "table name expected in db pragma " << p << endl;
return;
}
@@ -613,44 +617,44 @@ handle_pragma (cpp_reader* reader,
view_object vo;
vo.kind = view_object::table;
- if (!parse_qname (t, tt, p, vo.tbl_name))
+ if (!parse_qname (l, tt, tl, tn, p, vo.tbl_name))
return; // Diagnostics has already been issued.
if (tt == CPP_EQ)
{
// We have an alias.
//
- if (pragma_lex (&t) != CPP_STRING)
+ if (l.next (tl, &tn) != CPP_STRING)
{
- error ()
- << "table alias expected after '=' in db pragma " << p << endl;
+ error (l) << "table alias expected after '=' in db pragma " << p
+ << endl;
return;
}
- vo.alias = TREE_STRING_POINTER (t);
- tt = pragma_lex (&t);
+ vo.alias = tl;
+ tt = l.next (tl, &tn);
}
if (tt == CPP_COLON)
{
// We have a condition.
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
- if (!parse_expression (t, tt, vo.cond, p))
+ if (!parse_expression (l, tt, tl, tn, vo.cond, p))
return; // Diagnostics has already been issued.
if (vo.cond.empty ())
{
- error ()
- << "join condition expected after ':' in db pragma " << p << endl;
+ error (l) << "join condition expected after ':' in db pragma " << p
+ << endl;
return;
}
}
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
@@ -668,7 +672,7 @@ handle_pragma (cpp_reader* reader,
name = "objects";
adder = &accumulate<view_object>;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "session")
{
@@ -681,29 +685,28 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_OPEN_PAREN)
{
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
- string s;
- if (tt != CPP_NAME ||
- ((s = IDENTIFIER_POINTER (t)) != "true" && s != "false"))
+ if (tt != CPP_KEYWORD || (tl != "true" && tl != "false"))
{
- error () << "true or false expected in db pragma " << p << endl;
+ error (l) << "true or false expected in db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ val = (tl == "true");
+
+ tt = l.next (tl, &tn);
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- val = (s == "true");
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
}
else if (p == "schema")
@@ -718,32 +721,32 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_STRING && tt != CPP_DOT)
{
- error () << "table name expected in db pragma " << p << endl;
+ error (l) << "table name expected in db pragma " << p << endl;
return;
}
qname s;
- if (!parse_qname (t, tt, p, s))
+ if (!parse_qname (l, tt, tl, tn, p, s))
return; // Diagnostics has already been issued.
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
val = s;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "pointer")
{
@@ -755,9 +758,9 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
@@ -765,9 +768,9 @@ handle_pragma (cpp_reader* reader,
size_t pb (0);
bool punc (false);
- for (tt = pragma_lex (&t);
+ for (tt = l.next (tl, &tn);
tt != CPP_EOF && (tt != CPP_CLOSE_PAREN || pb != 0);
- tt = pragma_lex (&t))
+ tt = l.next (tl, &tn))
{
if (punc && tt > CPP_LAST_PUNCTUATOR)
cp.name += ' ';
@@ -799,19 +802,25 @@ handle_pragma (cpp_reader* reader,
break;
}
case CPP_NAME:
+ // case CPP_KEYWORD: // see default:
{
- cp.name += IDENTIFIER_POINTER (t);
+ cp.name += tl;
punc = true;
break;
}
default:
{
- if (tt <= CPP_LAST_PUNCTUATOR)
+ if (tt == CPP_KEYWORD)
+ {
+ cp.name += tl;
+ punc = true;
+ }
+ else if (tt <= CPP_LAST_PUNCTUATOR)
cp.name += cxx_lexer::token_spelling[tt];
else
{
- error () << "unexpected token '" << cxx_lexer::token_spelling[tt]
- << "' in db pragma " << p << endl;
+ error (l) << "unexpected token '" << cxx_lexer::token_spelling[tt]
+ << "' in db pragma " << p << endl;
return;
}
break;
@@ -821,13 +830,13 @@ handle_pragma (cpp_reader* reader,
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
if (cp.name.empty ())
{
- error () << "expected pointer name in db pragma " << p << endl;
+ error (l) << "expected pointer name in db pragma " << p << endl;
return;
}
@@ -835,7 +844,7 @@ handle_pragma (cpp_reader* reader,
cp.loc = loc;
val = cp;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "abstract")
{
@@ -847,7 +856,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "optimistic")
{
@@ -859,7 +868,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "polymorphic")
{
@@ -871,7 +880,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "callback")
{
@@ -883,29 +892,29 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_NAME)
{
- error () << "member function name expected in db pragma " << p << endl;
+ error (l) << "member function name expected in db pragma " << p << endl;
return;
}
- val = string (IDENTIFIER_POINTER (t));
+ val = tl;
- if (pragma_lex (&t) != CPP_CLOSE_PAREN)
+ if (l.next (tl, &tn) != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "query")
{
@@ -919,13 +928,13 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
view_query vq;
@@ -935,8 +944,8 @@ handle_pragma (cpp_reader* reader,
if (tt == CPP_STRING)
{
s = true;
- str = TREE_STRING_POINTER (t);
- tt = pragma_lex (&t);
+ str = tl;
+ tt = l.next (tl, &tn);
}
if (tt == CPP_CLOSE_PAREN)
@@ -957,25 +966,24 @@ handle_pragma (cpp_reader* reader,
//
if (s)
{
- vq.expr.push_back (cxx_token ());
- vq.expr.back ().type = CPP_STRING;
+ vq.expr.push_back (cxx_token (0, CPP_STRING));
vq.expr.back ().literal = str;
}
- if (!parse_expression (t, tt, vq.expr, p))
+ if (!parse_expression (l, tt, tl, tn, vq.expr, p))
return; // Diagnostics has already been issued.
}
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
vq.scope = current_scope ();
vq.loc = loc;
val = vq;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "object")
{
@@ -987,23 +995,23 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_NAME && tt != CPP_SCOPE)
{
- error () << "type name expected in db pragma " << p << endl;
+ error (l) << "type name expected in db pragma " << p << endl;
return;
}
view_object vo;
vo.kind = view_object::object;
- vo.obj_node = resolve_scoped_name (t, tt, vo.obj_name, true, p);
+ vo.obj_node = resolve_scoped_name (l, tt, tl, tn, vo.obj_name, true, p);
if (vo.obj_node == 0)
return; // Diagnostics has already been issued.
@@ -1020,36 +1028,37 @@ handle_pragma (cpp_reader* reader,
{
// We have an alias.
//
- if (pragma_lex (&t) != CPP_NAME)
+ if (l.next (tl, &tn) != CPP_NAME)
{
- error () << "alias name expected after '=' in db pragma " << p << endl;
+ error (l) << "alias name expected after '=' in db pragma " << p
+ << endl;
return;
}
- vo.alias = IDENTIFIER_POINTER (t);
- tt = pragma_lex (&t);
+ vo.alias = tl;
+ tt = l.next (tl, &tn);
}
if (tt == CPP_COLON)
{
// We have a condition.
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
- if (!parse_expression (t, tt, vo.cond, p))
+ if (!parse_expression (l, tt, tl, tn, vo.cond, p))
return; // Diagnostics has already been issued.
if (vo.cond.empty ())
{
- error ()
- << "join condition expected after ':' in db pragma " << p << endl;
+ error (l) << "join condition expected after ':' in db pragma " << p
+ << endl;
return;
}
}
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
@@ -1059,7 +1068,7 @@ handle_pragma (cpp_reader* reader,
name = "objects"; // Change the context entry name.
adder = &accumulate<view_object>;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "id")
{
@@ -1071,30 +1080,30 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_OPEN_PAREN)
{
if (qualifier == "member")
{
- error () << "unexpected '(' after db pragma " << p << endl;
+ error (l) << "unexpected '(' after db pragma " << p << endl;
return;
}
- if (pragma_lex (&t) != CPP_CLOSE_PAREN)
+ if (l.next (tl, &tn) != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
val = false; // Object without id.
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else
{
if (qualifier == "object")
{
- error () << "expected '(' after db pragma " << p << endl;
+ error (l) << "expected '(' after db pragma " << p << endl;
return;
}
@@ -1111,7 +1120,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "column")
{
@@ -1127,13 +1136,13 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
bool expr (false);
string expr_str;
@@ -1141,7 +1150,7 @@ handle_pragma (cpp_reader* reader,
{
qname qn;
- if (!parse_qname (t, tt, p, qn, &expr, &expr_str))
+ if (!parse_qname (l, tt, tl, tn, p, qn, &expr, &expr_str))
return; // Diagnostics has already been issued.
if (tt == CPP_CLOSE_PAREN)
@@ -1161,8 +1170,8 @@ handle_pragma (cpp_reader* reader,
}
else if (!expr)
{
- error () << "column name, expression, or data member name expected "
- << "in db pragma " << p << endl;
+ error (l) << "column name, expression, or data member name expected "
+ << "in db pragma " << p << endl;
return;
}
}
@@ -1181,11 +1190,11 @@ handle_pragma (cpp_reader* reader,
if (tt != CPP_PLUS)
{
- error () << "'+' or ')' expected in db pragma " << p << endl;
+ error (l) << "'+' or ')' expected in db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
for (;;)
@@ -1194,29 +1203,30 @@ handle_pragma (cpp_reader* reader,
{
e.push_back (column_expr_part ());
e.back ().kind = column_expr_part::literal;
- e.back ().value = TREE_STRING_POINTER (t);
+ e.back ().value = tl;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (tt == CPP_NAME || tt == CPP_SCOPE)
{
- string name (parse_scoped_name (t, tt, p));
+ string name (parse_scoped_name (l, tt, tl, tn, p));
if (name.empty ())
return; // Diagnostics has already been issued.
// Resolve nested members if any.
//
- for (; tt == CPP_DOT; tt = pragma_lex (&t))
+ for (; tt == CPP_DOT; tt = l.next (tl, &tn))
{
- if (pragma_lex (&t) != CPP_NAME)
+ if (l.next (tl, &tn) != CPP_NAME)
{
- error () << "name expected after '.' in db pragma " << p << endl;
+ error (l) << "name expected after '.' in db pragma " << p
+ << endl;
return;
}
name += '.';
- name += IDENTIFIER_POINTER (t);
+ name += tl;
}
e.push_back (column_expr_part ());
@@ -1227,18 +1237,18 @@ handle_pragma (cpp_reader* reader,
}
else
{
- error () << "column name, expression, or data member name expected "
- << "in db pragma " << p << endl;
+ error (l) << "column name, expression, or data member name expected "
+ << "in db pragma " << p << endl;
return;
}
if (tt == CPP_PLUS)
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
else if (tt == CPP_CLOSE_PAREN)
break;
else
{
- error () << "'+' or ')' expected in db pragma " << p << endl;
+ error (l) << "'+' or ')' expected in db pragma " << p << endl;
return;
}
}
@@ -1248,7 +1258,7 @@ handle_pragma (cpp_reader* reader,
name = "column-expr";
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "value_column" ||
p == "index_column" ||
@@ -1266,29 +1276,29 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_STRING)
{
- error () << "column name expected in db pragma " << p << endl;
+ error (l) << "column name expected in db pragma " << p << endl;
return;
}
- val = string (TREE_STRING_POINTER (t));
+ val = tl;
- if (pragma_lex (&t) != CPP_CLOSE_PAREN)
+ if (l.next (tl, &tn) != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "options" ||
p == "value_options" ||
@@ -1308,25 +1318,23 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_STRING)
{
- string o (TREE_STRING_POINTER (t));
-
// Ignore empty options strings. Internally, we use them to
// indicate options reset (see below).
//
- if (!o.empty ())
- val = string (TREE_STRING_POINTER (t));
+ if (!tl.empty ())
+ val = tl;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (tt == CPP_CLOSE_PAREN)
{
@@ -1337,18 +1345,18 @@ handle_pragma (cpp_reader* reader,
}
else
{
- error () << "options string expected in db pragma " << p << endl;
+ error (l) << "options string expected in db pragma " << p << endl;
return;
}
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
adder = &accumulate<string>;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (qualifier == "map" &&
(p == "type" ||
@@ -1368,19 +1376,19 @@ handle_pragma (cpp_reader* reader,
assert (decl == global_namespace);
custom_db_type& ct (qualifier_value.value<custom_db_type> ());
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (p == "type")
{
if (tt != CPP_STRING)
{
- error () << "type name regex expected in db pragma " << p << endl;
+ error (l) << "type name regex expected in db pragma " << p << endl;
return;
}
@@ -1388,12 +1396,12 @@ handle_pragma (cpp_reader* reader,
{
// Make it case-insensitive.
//
- ct.type.assign (TREE_STRING_POINTER (t), true);
+ ct.type.assign (tl, true);
}
catch (regex_format const& e)
{
- error () << "invalid regex: '" << e.regex () << "' in db pragma " <<
- p << ": " << e.description () << endl;
+ error (l) << "invalid regex: '" << e.regex () << "' in db pragma "
+ << p << ": " << e.description () << endl;
return;
}
}
@@ -1401,41 +1409,41 @@ handle_pragma (cpp_reader* reader,
{
if (tt != CPP_STRING)
{
- error () << "type name expected in db pragma " << p << endl;
+ error (l) << "type name expected in db pragma " << p << endl;
return;
}
- ct.as = TREE_STRING_POINTER (t);
+ ct.as = tl;
}
else if (p == "to")
{
if (tt != CPP_STRING)
{
- error () << "expression expected in db pragma " << p << endl;
+ error (l) << "expression expected in db pragma " << p << endl;
return;
}
- ct.to = TREE_STRING_POINTER (t);
+ ct.to = tl;
}
else if (p == "from")
{
if (tt != CPP_STRING)
{
- error () << "expression expected in db pragma " << p << endl;
+ error (l) << "expression expected in db pragma " << p << endl;
return;
}
- ct.from = TREE_STRING_POINTER (t);
+ ct.from = tl;
}
- if (pragma_lex (&t) != CPP_CLOSE_PAREN)
+ if (l.next (tl, &tn) != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
name.clear (); // We don't need to add anything for this pragma.
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "type" ||
p == "id_type" ||
@@ -1455,29 +1463,29 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_STRING)
{
- error () << "type name expected in db pragma " << p << endl;
+ error (l) << "type name expected in db pragma " << p << endl;
return;
}
- val = string (TREE_STRING_POINTER (t));
+ val = tl;
- if (pragma_lex (&t) != CPP_CLOSE_PAREN)
+ if (l.next (tl, &tn) != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "null" ||
p == "not_null" ||
@@ -1495,7 +1503,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "default")
{
@@ -1513,13 +1521,13 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
default_value dv;
@@ -1535,28 +1543,18 @@ handle_pragma (cpp_reader* reader,
case CPP_STRING:
{
dv.kind = default_value::string;
- dv.value = TREE_STRING_POINTER (t);
- tt = pragma_lex (&t);
+ dv.value = tl;
+ tt = l.next (tl, &tn);
break;
}
case CPP_NAME:
{
- // This can be the null, true, or false keyword or an enumerator
- // name.
+ // This can be null or an enumerator name.
//
- string n (IDENTIFIER_POINTER (t));
-
- if (n == "null")
+ if (tl == "null")
{
dv.kind = default_value::null;
- tt = pragma_lex (&t);
- break;
- }
- else if (n == "true" || n == "false")
- {
- dv.kind = default_value::boolean;
- dv.value = n;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
break;
}
// Fall throught.
@@ -1565,7 +1563,7 @@ handle_pragma (cpp_reader* reader,
{
// We have a potentially scopped enumerator name.
//
- dv.node = resolve_scoped_name (t, tt, dv.value, false, p);
+ dv.node = resolve_scoped_name (l, tt, tl, tn, dv.value, false, p);
if (dv.node == 0)
return; // Diagnostics has already been issued.
@@ -1579,13 +1577,13 @@ handle_pragma (cpp_reader* reader,
if (tt == CPP_MINUS)
dv.value = "-";
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_NUMBER)
{
- error () << "expected numeric constant after '"
- << (tt == CPP_MINUS ? "-" : "+") << "' in db pragma "
- << p << endl;
+ error (l) << "expected numeric constant after '"
+ << (tt == CPP_MINUS ? "-" : "+") << "' in db pragma "
+ << p << endl;
return;
}
@@ -1593,34 +1591,48 @@ handle_pragma (cpp_reader* reader,
}
case CPP_NUMBER:
{
- int tc (TREE_CODE (t));
+ int tc (TREE_CODE (tn));
if (tc != INTEGER_CST && tc != REAL_CST)
{
- error () << "unexpected numeric constant in db pragma " << p << endl;
+ error (l) << "unexpected numeric constant in db pragma " << p
+ << endl;
return;
}
- dv.node = t;
+ dv.node = tn;
dv.kind = default_value::number;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
break;
}
default:
{
- error () << "unexpected expression in db pragma " << p << endl;
- return;
+ // This can be the true or false keyword.
+ //
+ if (tt == CPP_KEYWORD && (tl == "true" || tl == "false"))
+ {
+ dv.kind = default_value::boolean;
+ dv.value = tl;
+ tt = l.next (tl, &tn);
+ }
+ else
+ {
+ error (l) << "unexpected expression in db pragma " << p << endl;
+ return;
+ }
+
+ break;
}
}
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
val = dv;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "inverse")
{
@@ -1632,29 +1644,29 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- if (pragma_lex (&t) != CPP_OPEN_PAREN)
+ if (l.next (tl, &tn) != CPP_OPEN_PAREN)
{
- error () << "'(' expected after db pragma " << p << endl;
+ error (l) << "'(' expected after db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt != CPP_NAME)
{
- error () << "member name expected in db pragma " << p << endl;
+ error (l) << "member name expected in db pragma " << p << endl;
return;
}
- val = string (IDENTIFIER_POINTER (t));
+ val = tl;
- if (pragma_lex (&t) != CPP_CLOSE_PAREN)
+ if (l.next (tl, &tn) != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "unordered")
{
@@ -1666,7 +1678,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "readonly")
{
@@ -1678,7 +1690,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "transient")
{
@@ -1690,7 +1702,7 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "version")
{
@@ -1702,11 +1714,11 @@ handle_pragma (cpp_reader* reader,
if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc))
return;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else
{
- error () << "unknown db pragma " << p << endl;
+ error (l) << "unknown db pragma " << p << endl;
return;
}
@@ -1735,10 +1747,10 @@ handle_pragma (cpp_reader* reader,
// See if there are any more pragmas.
//
- if (tt == CPP_NAME)
+ if (tt == CPP_NAME || tt == CPP_KEYWORD)
{
- handle_pragma (reader,
- IDENTIFIER_POINTER (t),
+ handle_pragma (l,
+ tl,
qualifier,
qualifier_value,
decl,
@@ -1746,7 +1758,7 @@ handle_pragma (cpp_reader* reader,
ns);
}
else if (tt != CPP_EOF)
- error () << "unexpected text after " << p << " in db pragma" << endl;
+ error (l) << "unexpected text after " << p << " in db pragma" << endl;
}
//
@@ -1804,7 +1816,7 @@ check_qual_decl_type (tree d,
}
else
{
- error () << "unknown db pragma " << p << endl;
+ error (l) << "unknown db pragma " << p << endl;
return false;
}
@@ -1829,17 +1841,18 @@ add_qual_entry (compiler::context& ctx,
}
static void
-handle_pragma_qualifier (cpp_reader* reader, string const& p)
+handle_pragma_qualifier (cxx_lexer& l, string const& p)
{
- tree t;
cpp_ttype tt;
+ string tl;
+ tree tn;
tree decl (0), orig_decl (0);
string decl_name;
string name (p); // Pragma name.
any val; // Pragma value.
- location_t loc (input_location); // Pragma location.
+ location_t loc (l. location ()); // Pragma location.
pragma::add_func adder (0); // Custom context adder.
bool ns (false); // Namespace location pragma.
@@ -1857,7 +1870,7 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
name = "custom-db-types";
orig_decl = decl = global_namespace;
adder = &accumulate<custom_db_type>;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (p == "namespace")
{
@@ -1865,15 +1878,15 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
// namespace () (refers to global namespace)
//
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_OPEN_PAREN)
{
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_NAME || tt == CPP_SCOPE)
{
- decl = resolve_scoped_name (t, tt, decl_name, false, p);
+ decl = resolve_scoped_name (l, tt, tl, tn, decl_name, false, p);
if (decl == 0)
return; // Diagnostics has already been issued.
@@ -1889,20 +1902,20 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else if (tt == CPP_CLOSE_PAREN)
{
decl = global_namespace;
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else
{
- error () << "data member name expected in db pragma " << p << endl;
+ error (l) << "data member name expected in db pragma " << p << endl;
return;
}
}
@@ -1912,7 +1925,8 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
//
if (TREE_CODE (current_scope ()) != NAMESPACE_DECL)
{
- error() << "db pragma " << p << " is not in a namespace scope" << endl;
+ error (l) << "db pragma " << p << " is not in a namespace scope"
+ << endl;
return;
}
@@ -1928,15 +1942,17 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
// value [(<identifier>)]
//
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_OPEN_PAREN)
{
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
- if (tt == CPP_NAME || tt == CPP_SCOPE)
+ // Can be built-in type (e.g., bool).
+ //
+ if (tt == CPP_NAME || tt == CPP_KEYWORD || tt == CPP_SCOPE)
{
- orig_decl = resolve_scoped_name (t, tt, decl_name, true, p);
+ orig_decl = resolve_scoped_name (l, tt, tl, tn, decl_name, true, p);
if (orig_decl == 0)
return; // Diagnostics has already been issued.
@@ -1959,15 +1975,15 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else
{
- error () << "type name expected in db pragma " << p << endl;
+ error (l) << "type name expected in db pragma " << p << endl;
return;
}
}
@@ -1977,15 +1993,15 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
// member [(<identifier>)]
//
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_OPEN_PAREN)
{
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
if (tt == CPP_NAME || tt == CPP_SCOPE)
{
- decl = resolve_scoped_name (t, tt, decl_name, false, p);
+ decl = resolve_scoped_name (l, tt, tl, tn, decl_name, false, p);
if (decl == 0)
return; // Diagnostics has already been issued.
@@ -1997,15 +2013,15 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
if (tt != CPP_CLOSE_PAREN)
{
- error () << "')' expected at the end of db pragma " << p << endl;
+ error (l) << "')' expected at the end of db pragma " << p << endl;
return;
}
- tt = pragma_lex (&t);
+ tt = l.next (tl, &tn);
}
else
{
- error () << "data member name expected in db pragma " << p << endl;
+ error (l) << "data member name expected in db pragma " << p << endl;
return;
}
}
@@ -2043,12 +2059,12 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
p == "transient" ||
p == "version")
{
- handle_pragma (reader, p, "member", val, 0, "", false);
+ handle_pragma (l, p, "member", val, 0, "", false);
return;
}
else
{
- error () << "unknown db pragma " << p << endl;
+ error (l) << "unknown db pragma " << p << endl;
return;
}
@@ -2090,15 +2106,15 @@ handle_pragma_qualifier (cpp_reader* reader, string const& p)
// See if there are any more pragmas.
//
- if (tt == CPP_NAME)
+ if (tt == CPP_NAME || tt == CPP_KEYWORD)
{
- handle_pragma (
- reader, IDENTIFIER_POINTER (t), p, *pval, decl, decl_name, ns);
+ handle_pragma (l, tl, p, *pval, decl, decl_name, ns);
}
else if (tt != CPP_EOF)
- error () << "unexpected text after " << p << " in db pragma" << endl;
+ error (l) << "unexpected text after " << p << " in db pragma" << endl;
}
+/*
extern "C" void
handle_pragma_db_map (cpp_reader* r)
{
@@ -2302,23 +2318,27 @@ handle_pragma_db_version (cpp_reader* r)
{
handle_pragma_qualifier (r, "version");
}
+*/
extern "C" void
-handle_pragma_db (cpp_reader* r)
+handle_pragma_db (cpp_reader*)
{
- tree t;
- cpp_ttype tt (pragma_lex (&t));
+ cxx_pragma_lexer l;
+ l.start ();
+
+ string tl;
+ cpp_ttype tt (l.next (tl));
- if (tt != CPP_NAME)
+ if (tt != CPP_NAME && tt != CPP_KEYWORD)
{
if (tt == CPP_EOF)
- error () << "expected specifier after db pragma" << endl;
+ error (l) << "expected specifier after db pragma" << endl;
else
- error () << "unexpected token after db pragma" << endl;
+ error (l) << "unexpected token after db pragma" << endl;
return;
}
- handle_pragma_qualifier (r, IDENTIFIER_POINTER (t));
+ handle_pragma_qualifier (l, tl);
}
extern "C" void
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<view_alias_map> ("alias-map"));
view_object_map const& omap (c.get<view_object_map> ("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;