From f0454224b73cb253a087f918196789a1f0527a98 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 29 Oct 2013 15:07:04 -0400 Subject: [PATCH] PR16019: use PARSE_ERROR macro in call sites Same as previous, but for PARSE_ERROR. --- parse.cxx | 246 +++++++++++++++++++++++++-------------------------- session.h | 12 +-- staptree.cxx | 4 +- 3 files changed, 131 insertions(+), 131 deletions(-) diff --git a/parse.cxx b/parse.cxx index 1c2154335..bac768061 100644 --- a/parse.cxx +++ b/parse.cxx @@ -339,7 +339,7 @@ bool eval_comparison (const OPERAND& lhs, const token* op, const OPERAND& rhs) else if (op->type == tok_operator && op->content == "!=") { return lhs != rhs; } else - throw parse_error (_("expected comparison operator"), op); + throw PARSE_ERROR (_("expected comparison operator"), op); } @@ -426,24 +426,24 @@ parser::scan_pp1 () if (t->type == tok_operator && t->content == "@define") { if (!pp1_state.empty()) - throw parse_error (_("'@define' forbidden inside macro body"), t); + throw PARSE_ERROR (_("'@define' forbidden inside macro body"), t); delete t; // handle macro definition // (1) consume macro signature t = input.scan(); if (! (t && t->type == tok_identifier)) - throw parse_error (_("expected identifier"), t); + throw PARSE_ERROR (_("expected identifier"), t); string name = t->content; // check for redefinition of existing macro if (pp1_namespace.find(name) != pp1_namespace.end()) { - parse_error er (_F("attempt to redefine macro '@%s' in the same file", name.c_str ()), t); + parse_error er (ERR_SRC, _F("attempt to redefine macro '@%s' in the same file", name.c_str ()), t); // Also point to pp1_namespace[name]->tok, the site of // the original definition: - er.chain = new parse_error (_F("macro '@%s' first defined here", + er.chain = new PARSE_ERROR (_F("macro '@%s' first defined here", name.c_str()), pp1_namespace[name]->tok); throw er; } @@ -458,7 +458,7 @@ parser::scan_pp1 () // that the uses of parameters aren't nonexistent // macros.....) if (name == "define") - throw parse_error (_("attempt to redefine '@define'"), t); + throw PARSE_ERROR (_("attempt to redefine '@define'"), t); if (input.atwords.count("@" + name)) session.print_warning (_F("macro redefines built-in operator '@%s'", name.c_str()), t); @@ -477,7 +477,7 @@ parser::scan_pp1 () t = input.scan (); if (! (t && t->type == tok_identifier)) - throw parse_error(_("expected identifier"), t); + throw PARSE_ERROR(_("expected identifier"), t); decl->formal_args.push_back(t->content); delete t; @@ -494,7 +494,7 @@ parser::scan_pp1 () } else { - throw parse_error (_("expected ',' or ')'"), t); + throw PARSE_ERROR (_("expected ',' or ')'"), t); } } while (true); @@ -504,15 +504,15 @@ parser::scan_pp1 () if (! (t && t->type == tok_operator && t->content == "%(")) { if (saw_params) - throw parse_error (_("expected '%('"), t); + throw PARSE_ERROR (_("expected '%('"), t); else - throw parse_error (_("expected '%(' or '('"), t); + throw PARSE_ERROR (_("expected '%(' or '('"), t); } delete t; t = slurp_pp1_body (decl->body); if (!t) - throw parse_error (_("incomplete macro definition - missing '%)'"), decl->tok); + throw PARSE_ERROR (_("incomplete macro definition - missing '%)'"), decl->tok); delete t; // Now loop around to look for a real token. @@ -565,7 +565,7 @@ parser::scan_pp1 () if (! (t && t->type == tok_operator && t->content == "(")) { delete new_act; - throw parse_error (_NF + throw PARSE_ERROR (_NF ("expected '(' in invocation of macro '@%s'" " taking %d parameter", "expected '(' in invocation of macro '@%s'" @@ -597,14 +597,14 @@ parser::scan_pp1 () // invocations in piecemeal fashion?? const token* orig_t = new token(*new_act->tok); delete new_act; - throw parse_error (_("could not find end of macro invocation"), orig_t); + throw PARSE_ERROR (_("could not find end of macro invocation"), orig_t); } if (t->type == tok_operator && t->content == ",") { if (i + 1 == num_params) { delete new_act; - throw parse_error (_F("too many parameters for macro '@%s' (expected %d)", name.c_str(), num_params), t); + throw PARSE_ERROR (_F("too many parameters for macro '@%s' (expected %d)", name.c_str(), num_params), t); } } else if (t->type == tok_operator && t->content == ")") @@ -612,14 +612,14 @@ parser::scan_pp1 () if (i + 1 != num_params) { delete new_act; - throw parse_error (_F("too few parameters for macro '@%s' (expected %d)", name.c_str(), num_params), t); + throw PARSE_ERROR (_F("too few parameters for macro '@%s' (expected %d)", name.c_str(), num_params), t); } } else { // XXX this is, incidentally, impossible delete new_act; - throw parse_error(_("expected ',' or ')' after macro parameter"), t); + throw PARSE_ERROR(_("expected ',' or ')' after macro parameter"), t); } } @@ -707,7 +707,7 @@ parser::parse_library_macros () // XXX should we prevent macro invocations even if they expand to empty?? if (t != 0) - throw parse_error (_F("library macro file '%s' contains non-@define construct", input_name.c_str()), t); + throw PARSE_ERROR (_F("library macro file '%s' contains non-@define construct", input_name.c_str()), t); // We need to first check whether *any* of the macros are duplicates, // then commit to including the entire file in the global namespace @@ -719,8 +719,8 @@ parser::parse_library_macros () if (session.library_macros.find(name) != session.library_macros.end()) { - parse_error er(_F("duplicate definition of library macro '@%s'", name.c_str()), it->second->tok); - er.chain = new parse_error (_F("macro '@%s' first defined here", name.c_str()), session.library_macros[name]->tok); + parse_error er(ERR_SRC, _F("duplicate definition of library macro '@%s'", name.c_str()), it->second->tok); + er.chain = new PARSE_ERROR (_F("macro '@%s' first defined here", name.c_str()), session.library_macros[name]->tok); print_error (er); delete er.chain; @@ -781,7 +781,7 @@ bool eval_pp_conditional (systemtap_session& s, l->content == "systemtap_v")) { if (! (r->type == tok_string)) - throw parse_error (_("expected string literal"), r); + throw PARSE_ERROR (_("expected string literal"), r); string target_kernel_vr = s.kernel_release; string target_kernel_v = s.kernel_base_release; @@ -811,10 +811,10 @@ bool eval_pp_conditional (systemtap_session& s, else if (op->type == tok_operator && op->content == "!=") { rvc_ok1 = -1; rvc_ok2 = 1; wc_ok = true; } else - throw parse_error (_("expected comparison operator"), op); + throw PARSE_ERROR (_("expected comparison operator"), op); if ((!wc_ok) && rhs_wildcard) - throw parse_error (_("wildcard not allowed with order comparison operators"), op); + throw PARSE_ERROR (_("wildcard not allowed with order comparison operators"), op); if (rhs_wildcard) { @@ -843,7 +843,7 @@ bool eval_pp_conditional (systemtap_session& s, assert(target_privilege != "none"); if (! (r->type == tok_string)) - throw parse_error (_("expected string literal"), r); + throw PARSE_ERROR (_("expected string literal"), r); string query_privilege = r->content; bool nomatch = (target_privilege != query_privilege); @@ -854,7 +854,7 @@ bool eval_pp_conditional (systemtap_session& s, else if (op->type == tok_operator && op->content == "!=") result = nomatch; else - throw parse_error (_("expected '==' or '!='"), op); + throw PARSE_ERROR (_("expected '==' or '!='"), op); /* XXX perhaps allow <= >= and similar comparisons */ return result; @@ -863,7 +863,7 @@ bool eval_pp_conditional (systemtap_session& s, { string target_architecture = s.architecture; if (! (r->type == tok_string)) - throw parse_error (_("expected string literal"), r); + throw PARSE_ERROR (_("expected string literal"), r); string query_architecture = r->content; int nomatch = fnmatch (query_architecture.c_str(), @@ -876,14 +876,14 @@ bool eval_pp_conditional (systemtap_session& s, else if (op->type == tok_operator && op->content == "!=") result = nomatch; else - throw parse_error (_("expected '==' or '!='"), op); + throw PARSE_ERROR (_("expected '==' or '!='"), op); return result; } else if (l->type == tok_identifier && l->content == "runtime") { if (! (r->type == tok_string)) - throw parse_error (_("expected string literal"), r); + throw PARSE_ERROR (_("expected string literal"), r); string query_runtime = r->content; string target_runtime; @@ -900,7 +900,7 @@ bool eval_pp_conditional (systemtap_session& s, else if (op->type == tok_operator && op->content == "!=") result = nomatch; else - throw parse_error (_("expected '==' or '!='"), op); + throw PARSE_ERROR (_("expected '==' or '!='"), op); return result; } @@ -919,7 +919,7 @@ bool eval_pp_conditional (systemtap_session& s, else if (op->type == tok_operator && op->content == "!=") result = nomatch; else - throw parse_error (_("expected '==' or '!='"), op); + throw PARSE_ERROR (_("expected '==' or '!='"), op); return result; } @@ -930,7 +930,7 @@ bool eval_pp_conditional (systemtap_session& s, errno = 0; int64_t lhs = (int64_t) strtoll (startp, & endp, 0); if (errno == ERANGE || errno == EINVAL || *endp != '\0') - throw parse_error ("Config option value not a number", l); + throw PARSE_ERROR ("Config option value not a number", l); int64_t rhs = lex_cast(r->content); return eval_comparison (lhs, op, rhs); @@ -960,7 +960,7 @@ bool eval_pp_conditional (systemtap_session& s, return eval_comparison (lhs, op, rhs); } else - throw parse_error (_("expected string, number literal or other CONFIG_... as right side operand"), r); + throw PARSE_ERROR (_("expected string, number literal or other CONFIG_... as right side operand"), r); } else if (l->type == tok_string && r->type == tok_string) { @@ -978,13 +978,13 @@ bool eval_pp_conditional (systemtap_session& s, } else if (l->type == tok_string && r->type == tok_number && op->type == tok_operator) - throw parse_error (_("expected string literal as right value"), r); + throw PARSE_ERROR (_("expected string literal as right value"), r); else if (l->type == tok_number && r->type == tok_string && op->type == tok_operator) - throw parse_error (_("expected number literal as right value"), r); + throw PARSE_ERROR (_("expected number literal as right value"), r); else - throw parse_error (_("expected 'arch', 'kernel_v', 'kernel_vr', 'systemtap_v',\n" + throw PARSE_ERROR (_("expected 'arch', 'kernel_v', 'kernel_vr', 'systemtap_v',\n" " 'runtime', 'systemtap_privilege', 'CONFIG_...', or\n" " comparison between strings or integers"), l); } @@ -1013,22 +1013,22 @@ parser::scan_pp () t = pp_state.back().first; pp_state.pop_back(); // so skip_some doesn't keep trying to close this //TRANSLATORS: 'conditional' meaning 'conditional preprocessing' - throw parse_error (_("incomplete conditional at end of file"), t); + throw PARSE_ERROR (_("incomplete conditional at end of file"), t); } return t; } // misplaced preprocessor "then" if (t->type == tok_operator && t->content == "%?") - throw parse_error (_("incomplete conditional - missing '%('"), t); + throw PARSE_ERROR (_("incomplete conditional - missing '%('"), t); // preprocessor "else" if (t->type == tok_operator && t->content == "%:") { if (pp == PP_NONE) - throw parse_error (_("incomplete conditional - missing '%('"), t); + throw PARSE_ERROR (_("incomplete conditional - missing '%('"), t); if (pp == PP_KEEP_ELSE || pp == PP_SKIP_ELSE) - throw parse_error (_("invalid conditional - duplicate '%:'"), t); + throw PARSE_ERROR (_("invalid conditional - duplicate '%:'"), t); // XXX: here and elsewhere, error cascades might be avoided // by dropping tokens until we reach the closing %) @@ -1042,7 +1042,7 @@ parser::scan_pp () if (t->type == tok_operator && t->content == "%)") { if (pp == PP_NONE) - throw parse_error (_("incomplete conditional - missing '%('"), t); + throw PARSE_ERROR (_("incomplete conditional - missing '%('"), t); delete pp_state.back().first; delete t; //this is the closing bracket pp_state.pop_back(); @@ -1063,7 +1063,7 @@ parser::scan_pp () op = scan_pp1 (); r = scan_pp1 (); if (l == 0 || op == 0 || r == 0) - throw parse_error (_("incomplete condition after '%('"), t); + throw PARSE_ERROR (_("incomplete condition after '%('"), t); // NB: consider generalizing to consume all tokens until %?, and // passing that as a vector to an evaluator. @@ -1095,7 +1095,7 @@ parser::scan_pp () const token *m = n; if (! (m && m->type == tok_operator && m->content == "%?")) - throw parse_error (_("expected '%?' marker for conditional"), t); + throw PARSE_ERROR (_("expected '%?' marker for conditional"), t); delete m; // "%?" pp = result ? PP_KEEP_THEN : PP_SKIP_THEN; @@ -1145,7 +1145,7 @@ parser::next () if (! next_t) next_t = scan_pp (); if (! next_t) - throw parse_error (_("unexpected end-of-file")); + throw PARSE_ERROR (_("unexpected end-of-file")); last_t = next_t; // advance by zeroing next_t @@ -1189,7 +1189,7 @@ parser::expect_known (token_type tt, string const & expected) { const token *t = next(); if (! (t && t->type == tt && t->content == expected)) - throw parse_error (_F("expected '%s'", expected.c_str())); + throw PARSE_ERROR (_F("expected '%s'", expected.c_str())); swallow (); // We are done with it, content was copied. } @@ -1199,7 +1199,7 @@ parser::expect_unknown (token_type tt, string & target) { const token *t = next(); if (!(t && t->type == tt)) - throw parse_error (_("expected ") + tt2str(tt)); + throw PARSE_ERROR (_("expected ") + tt2str(tt)); target = t->content; swallow (); // We are done with it, content was copied. } @@ -1210,7 +1210,7 @@ parser::expect_unknown2 (token_type tt1, token_type tt2, string & target) { const token *t = next(); if (!(t && (t->type == tt1 || t->type == tt2))) - throw parse_error (_F("expected %s or %s", tt2str(tt1).c_str(), tt2str(tt2).c_str())); + throw PARSE_ERROR (_F("expected %s or %s", tt2str(tt1).c_str(), tt2str(tt2).c_str())); target = t->content; swallow (); // We are done with it, content was copied. } @@ -1234,7 +1234,7 @@ parser::expect_kw_token (std::string const & expected) { const token *t = next(); if (! (t && t->type == tok_keyword && t->content == expected)) - throw parse_error (_F("expected '%s'", expected.c_str())); + throw PARSE_ERROR (_F("expected '%s'", expected.c_str())); return t; } @@ -1250,7 +1250,7 @@ parser::expect_number (int64_t & value) t = next (); } if (!(t && t->type == tok_number)) - throw parse_error (_("expected number")); + throw PARSE_ERROR (_("expected number")); const char* startp = t->content.c_str (); char* endp = (char*) startp; @@ -1265,7 +1265,7 @@ parser::expect_number (int64_t & value) || (neg && (unsigned long long) value > 9223372036854775808ULL) || (unsigned long long) value > 18446744073709551615ULL || value < -9223372036854775807LL-1) - throw parse_error (_("number invalid or out of range")); + throw PARSE_ERROR (_("number invalid or out of range")); if (neg) value = -value; @@ -1284,7 +1284,7 @@ parser::expect_ident_or_atword (std::string & target) && (t->type != tok_operator || t->content[0] != '@'))) // XXX currently this is only called from parse_hist_op_or_bare_name(), // so the message is accurate, but keep an eye out in the future: - throw parse_error (_F("expected %s or statistical operation", tt2str(tok_identifier).c_str())); + throw PARSE_ERROR (_F("expected %s or statistical operation", tt2str(tok_identifier).c_str())); target = t->content; return t; @@ -1795,7 +1795,7 @@ parser::parse () else { context = con_unknown; - throw parse_error (_("expected 'probe', 'global', 'function', or '%{'")); + throw PARSE_ERROR (_("expected 'probe', 'global', 'function', or '%{'")); } } catch (parse_error& pe) @@ -1855,7 +1855,7 @@ parser::parse_probe (std::vector & probe_ret, { const token* t0 = next (); if (! (t0->type == tok_keyword && t0->content == "probe")) - throw parse_error (_("expected 'probe'")); + throw PARSE_ERROR (_("expected 'probe'")); vector aliases; vector locations; @@ -1873,7 +1873,7 @@ parser::parse_probe (std::vector & probe_ret, && t->type == tok_operator && t->content == "=") { if (pp->optional || pp->sufficient) - throw parse_error (_("probe point alias name cannot be optional nor sufficient"), pp->components.front()->tok); + throw PARSE_ERROR (_("probe point alias name cannot be optional nor sufficient"), pp->components.front()->tok); aliases.push_back(pp); swallow (); continue; @@ -1882,7 +1882,7 @@ parser::parse_probe (std::vector & probe_ret, && t->type == tok_operator && t->content == "+=") { if (pp->optional || pp->sufficient) - throw parse_error (_("probe point alias name cannot be optional nor sufficient"), pp->components.front()->tok); + throw PARSE_ERROR (_("probe point alias name cannot be optional nor sufficient"), pp->components.front()->tok); aliases.push_back(pp); epilogue_alias = 1; swallow (); @@ -1901,7 +1901,7 @@ parser::parse_probe (std::vector & probe_ret, break; } else - throw parse_error (_("expected probe point specifier")); + throw PARSE_ERROR (_("expected probe point specifier")); } if (aliases.empty()) @@ -1937,10 +1937,10 @@ parser::parse_embeddedcode () embeddedcode* e = new embeddedcode; const token* t = next (); if (t->type != tok_embedded) - throw parse_error (_("expected '%{'")); + throw PARSE_ERROR (_("expected '%{'")); if (! privileged) - throw parse_error (_("embedded code in unprivileged script; need stap -g"), + throw PARSE_ERROR (_("embedded code in unprivileged script; need stap -g"), false /* don't skip tokens for parse resumption */); e->tok = t; @@ -1956,7 +1956,7 @@ parser::parse_stmt_block () const token* t = next (); if (! (t->type == tok_operator && t->content == "{")) - throw parse_error (_("expected '{'")); + throw PARSE_ERROR (_("expected '{'")); pb->tok = t; @@ -1991,7 +1991,7 @@ parser::parse_try_block () t = next(); if (! (t->type == tok_identifier)) - throw parse_error (_("expected identifier")); + throw PARSE_ERROR (_("expected identifier")); symbol* sym = new symbol; sym->tok = t; sym->name = t->content; @@ -2046,7 +2046,7 @@ parser::parse_statement () ret = parse_expr_statement (); // XXX: consider generally accepting tok_embedded here too else - throw parse_error (_("expected statement")); + throw PARSE_ERROR (_("expected statement")); // Squash "empty" trailing colons after any "non-block-like" statement. t = peek (); @@ -2064,18 +2064,18 @@ parser::parse_global (vector & globals, vector&) { const token* t0 = next (); if (! (t0->type == tok_keyword && t0->content == "global")) - throw parse_error (_("expected 'global'")); + throw PARSE_ERROR (_("expected 'global'")); swallow (); while (1) { const token* t = next (); if (! (t->type == tok_identifier)) - throw parse_error (_("expected identifier")); + throw PARSE_ERROR (_("expected identifier")); for (unsigned i=0; iname == t->content) - throw parse_error (_("duplicate global name")); + throw PARSE_ERROR (_("duplicate global name")); vardecl* d = new vardecl; d->name = t->content; @@ -2098,7 +2098,7 @@ parser::parse_global (vector & globals, vector&) swallow (); expect_number(size); if (size <= 0 || size > 1000000) // arbitrary max - throw parse_error(_("array size out of range")); + throw PARSE_ERROR(_("array size out of range")); d->maxsize = (int)size; expect_known(tok_operator, "]"); t = peek (); @@ -2107,7 +2107,7 @@ parser::parse_global (vector & globals, vector&) if (t && t->type == tok_operator && t->content == "=") // initialization { if (!d->compatible_arity(0)) - throw parse_error(_("only scalar globals can be initialized")); + throw PARSE_ERROR(_("only scalar globals can be initialized")); d->set_arity(0, t); next (); // Don't swallow, set_arity() used the peeked token. d->init = parse_literal (); @@ -2137,18 +2137,18 @@ parser::parse_functiondecl (std::vector& functions) { const token* t = next (); if (! (t->type == tok_keyword && t->content == "function")) - throw parse_error (_("expected 'function'")); + throw PARSE_ERROR (_("expected 'function'")); swallow (); t = next (); if (! (t->type == tok_identifier) && ! (t->type == tok_keyword && (t->content == "string" || t->content == "long"))) - throw parse_error (_("expected identifier")); + throw PARSE_ERROR (_("expected identifier")); for (unsigned i=0; iname == t->content) - throw parse_error (_("duplicate function name")); + throw PARSE_ERROR (_("duplicate function name")); functiondecl *fd = new functiondecl (); fd->name = t->content; @@ -2163,14 +2163,14 @@ parser::parse_functiondecl (std::vector& functions) fd->type = pe_string; else if (t->type == tok_keyword && t->content == "long") fd->type = pe_long; - else throw parse_error (_("expected 'string' or 'long'")); + else throw PARSE_ERROR (_("expected 'string' or 'long'")); swallow (); t = next (); } if (! (t->type == tok_operator && t->content == "(")) - throw parse_error (_("expected '('")); + throw PARSE_ERROR (_("expected '('")); swallow (); while (1) @@ -2184,7 +2184,7 @@ parser::parse_functiondecl (std::vector& functions) break; } else if (! (t->type == tok_identifier)) - throw parse_error (_("expected identifier")); + throw PARSE_ERROR (_("expected identifier")); vardecl* vd = new vardecl; vd->name = t->content; vd->tok = t; @@ -2200,7 +2200,7 @@ parser::parse_functiondecl (std::vector& functions) vd->type = pe_string; else if (t->type == tok_keyword && t->content == "long") vd->type = pe_long; - else throw parse_error (_("expected 'string' or 'long'")); + else throw PARSE_ERROR (_("expected 'string' or 'long'")); swallow (); t = next (); } @@ -2215,7 +2215,7 @@ parser::parse_functiondecl (std::vector& functions) continue; } else - throw parse_error (_("expected ',' or ')'")); + throw PARSE_ERROR (_("expected ',' or ')'")); } t = peek (); @@ -2241,7 +2241,7 @@ parser::parse_probe_point () || t->type == tok_keyword // we must allow "*", due to being an operator || (t->type == tok_operator && t->content == "*"))) - throw parse_error (_("expected identifier or '*'")); + throw PARSE_ERROR (_("expected identifier or '*'")); // loop which reconstitutes an identifier with wildcards string content = t->content; @@ -2288,7 +2288,7 @@ parser::parse_probe_point () t = next (); if (! (t->type == tok_operator && t->content == ")")) - throw parse_error (_("expected ')'")); + throw PARSE_ERROR (_("expected ')'")); swallow (); t = peek (); @@ -2319,14 +2319,14 @@ parser::parse_probe_point () swallow (); t = peek (); if (!(t && t->type == tok_operator && t->content == "(")) - throw parse_error (_("expected '('")); + throw PARSE_ERROR (_("expected '('")); swallow (); pl->condition = parse_expression (); t = peek (); if (!(t && t->type == tok_operator && t->content == ")")) - throw parse_error (_("expected ')'")); + throw PARSE_ERROR (_("expected ')'")); swallow (); t = peek (); // fall through @@ -2337,7 +2337,7 @@ parser::parse_probe_point () t->content == "=" || t->content == "+=" )) break; - throw parse_error (_("expected one of '. , ( ? ! { = +='")); + throw PARSE_ERROR (_("expected one of '. , ( ? ! { = +='")); } return pl; @@ -2375,7 +2375,7 @@ parser::parse_literal_string () if (t->type == tok_string) l = consume_string_literals (t); else - throw parse_error (_("expected literal string")); + throw PARSE_ERROR (_("expected literal string")); l->tok = t; return l; @@ -2416,7 +2416,7 @@ parser::parse_literal () || (neg && (unsigned long long) value > 9223372036854775808ULL) || (unsigned long long) value > 18446744073709551615ULL || value < -9223372036854775807LL-1) - throw parse_error (_("number invalid or out of range")); + throw PARSE_ERROR (_("number invalid or out of range")); if (neg) value = -value; @@ -2424,7 +2424,7 @@ parser::parse_literal () l = new literal_number (value); } else - throw parse_error (_("expected literal string or number")); + throw PARSE_ERROR (_("expected literal string or number")); } l->tok = t; @@ -2437,20 +2437,20 @@ parser::parse_if_statement () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "if")) - throw parse_error (_("expected 'if'")); + throw PARSE_ERROR (_("expected 'if'")); if_statement* s = new if_statement; s->tok = t; t = next (); if (! (t->type == tok_operator && t->content == "(")) - throw parse_error (_("expected '('")); + throw PARSE_ERROR (_("expected '('")); swallow (); s->condition = parse_expression (); t = next (); if (! (t->type == tok_operator && t->content == ")")) - throw parse_error (_("expected ')'")); + throw PARSE_ERROR (_("expected ')'")); swallow (); s->thenblock = parse_statement (); @@ -2474,7 +2474,7 @@ parser::parse_expr_statement () expr_statement *es = new expr_statement; const token* t = peek (); if (t == NULL) - throw parse_error (_("expression statement expected")); + throw PARSE_ERROR (_("expression statement expected")); // Copy, we only peeked, parse_expression might swallow. es->tok = new token (*t); es->value = parse_expression (); @@ -2487,9 +2487,9 @@ parser::parse_return_statement () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "return")) - throw parse_error (_("expected 'return'")); + throw PARSE_ERROR (_("expected 'return'")); if (context != con_function) - throw parse_error (_("found 'return' not in function context")); + throw PARSE_ERROR (_("found 'return' not in function context")); return_statement* s = new return_statement; s->tok = t; s->value = parse_expression (); @@ -2502,7 +2502,7 @@ parser::parse_delete_statement () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "delete")) - throw parse_error (_("expected 'delete'")); + throw PARSE_ERROR (_("expected 'delete'")); delete_statement* s = new delete_statement; s->tok = t; s->value = parse_expression (); @@ -2515,9 +2515,9 @@ parser::parse_next_statement () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "next")) - throw parse_error (_("expected 'next'")); + throw PARSE_ERROR (_("expected 'next'")); if (context != con_probe) - throw parse_error (_("found 'next' not in probe context")); + throw PARSE_ERROR (_("found 'next' not in probe context")); next_statement* s = new next_statement; s->tok = t; return s; @@ -2529,7 +2529,7 @@ parser::parse_break_statement () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "break")) - throw parse_error (_("expected 'break'")); + throw PARSE_ERROR (_("expected 'break'")); break_statement* s = new break_statement; s->tok = t; return s; @@ -2541,7 +2541,7 @@ parser::parse_continue_statement () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "continue")) - throw parse_error (_("expected 'continue'")); + throw PARSE_ERROR (_("expected 'continue'")); continue_statement* s = new continue_statement; s->tok = t; return s; @@ -2553,13 +2553,13 @@ parser::parse_for_loop () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "for")) - throw parse_error (_("expected 'for'")); + throw PARSE_ERROR (_("expected 'for'")); for_loop* s = new for_loop; s->tok = t; t = next (); if (! (t->type == tok_operator && t->content == "(")) - throw parse_error (_("expected '('")); + throw PARSE_ERROR (_("expected '('")); swallow (); // initializer + ";" @@ -2574,7 +2574,7 @@ parser::parse_for_loop () s->init = parse_expr_statement (); t = next (); if (! (t->type == tok_operator && t->content == ";")) - throw parse_error (_("expected ';'")); + throw PARSE_ERROR (_("expected ';'")); swallow (); } @@ -2591,7 +2591,7 @@ parser::parse_for_loop () s->cond = parse_expression (); t = next (); if (! (t->type == tok_operator && t->content == ";")) - throw parse_error (_("expected ';'")); + throw PARSE_ERROR (_("expected ';'")); swallow (); } @@ -2607,7 +2607,7 @@ parser::parse_for_loop () s->incr = parse_expr_statement (); t = next (); if (! (t->type == tok_operator && t->content == ")")) - throw parse_error (_("expected ')'")); + throw PARSE_ERROR (_("expected ')'")); swallow (); } @@ -2623,13 +2623,13 @@ parser::parse_while_loop () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "while")) - throw parse_error (_("expected 'while'")); + throw PARSE_ERROR (_("expected 'while'")); for_loop* s = new for_loop; s->tok = t; t = next (); if (! (t->type == tok_operator && t->content == "(")) - throw parse_error (_("expected '('")); + throw PARSE_ERROR (_("expected '('")); swallow (); // dummy init and incr fields @@ -2641,7 +2641,7 @@ parser::parse_while_loop () t = next (); if (! (t->type == tok_operator && t->content == ")")) - throw parse_error (_("expected ')'")); + throw PARSE_ERROR (_("expected ')'")); swallow (); // block @@ -2656,7 +2656,7 @@ parser::parse_foreach_loop () { const token* t = next (); if (! (t->type == tok_keyword && t->content == "foreach")) - throw parse_error (_("expected 'foreach'")); + throw PARSE_ERROR (_("expected 'foreach'")); foreach_loop* s = new foreach_loop; s->tok = t; s->sort_direction = 0; @@ -2666,7 +2666,7 @@ parser::parse_foreach_loop () t = next (); if (! (t->type == tok_operator && t->content == "(")) - throw parse_error (_("expected '('")); + throw PARSE_ERROR (_("expected '('")); swallow (); symbol* lookahead_sym = NULL; @@ -2726,7 +2726,7 @@ parser::parse_foreach_loop () { t = next (); if (! (t->type == tok_identifier)) - throw parse_error (_("expected identifier")); + throw PARSE_ERROR (_("expected identifier")); symbol* sym = new symbol; sym->tok = t; sym->name = t->content; @@ -2737,7 +2737,7 @@ parser::parse_foreach_loop () (t->content == "+" || t->content == "-")) { if (s->sort_direction) - throw parse_error (_("multiple sort directives")); + throw PARSE_ERROR (_("multiple sort directives")); s->sort_direction = (t->content == "+") ? 1 : -1; s->sort_column = s->indexes.size(); swallow (); @@ -2757,7 +2757,7 @@ parser::parse_foreach_loop () break; } else - throw parse_error (_("expected ',' or ']'")); + throw PARSE_ERROR (_("expected ',' or ']'")); } else break; // expecting only one expression @@ -2765,7 +2765,7 @@ parser::parse_foreach_loop () t = next (); if (! (t->type == tok_keyword && t->content == "in")) - throw parse_error (_("expected 'in'")); + throw PARSE_ERROR (_("expected 'in'")); swallow (); s->base = parse_indexable(); @@ -2779,12 +2779,12 @@ parser::parse_foreach_loop () else if (t->content == "@max") s->sort_aggr = sc_max; else if (t->content == "@count") s->sort_aggr = sc_count; else if (t->content == "@sum") s->sort_aggr = sc_sum; - else throw parse_error(_("expected statistical operation")); + else throw PARSE_ERROR(_("expected statistical operation")); swallow(); t = peek (); if (! (t && t->type == tok_operator && (t->content == "+" || t->content == "-"))) - throw parse_error(_("expected sort directive")); + throw PARSE_ERROR(_("expected sort directive")); } t = peek (); @@ -2792,7 +2792,7 @@ parser::parse_foreach_loop () (t->content == "+" || t->content == "-")) { if (s->sort_direction) - throw parse_error (_("multiple sort directives")); + throw PARSE_ERROR (_("multiple sort directives")); s->sort_direction = (t->content == "+") ? 1 : -1; s->sort_column = 0; swallow (); @@ -2807,7 +2807,7 @@ parser::parse_foreach_loop () t = next (); if (! (t->type == tok_operator && t->content == ")")) - throw parse_error ("expected ')'"); + throw PARSE_ERROR ("expected ')'"); swallow (); s->block = parse_statement (); @@ -2875,7 +2875,7 @@ parser::parse_ternary () t = next (); if (! (t->type == tok_operator && t->content == ":")) - throw parse_error (_("expected ':'")); + throw PARSE_ERROR (_("expected ':'")); swallow (); e->falsevalue = parse_expression (); // XXX @@ -3030,7 +3030,7 @@ parser::parse_array_in () break; } else - throw parse_error (_("expected ',' or ']'")); + throw PARSE_ERROR (_("expected ',' or ']'")); } else break; // expecting only one expression @@ -3053,7 +3053,7 @@ parser::parse_array_in () else if (indexes.size() == 1) // no "in" - need one expression only return indexes[0]; else - throw parse_error (_("unexpected comma-separated expression list")); + throw PARSE_ERROR (_("unexpected comma-separated expression list")); } @@ -3260,12 +3260,12 @@ parser::parse_value () { const token* t = peek (); if (! t) - throw parse_error (_("expected value")); + throw PARSE_ERROR (_("expected value")); if (t->type == tok_embedded) { if (! privileged) - throw parse_error (_("embedded expression code in unprivileged script; need stap -g"), false); + throw PARSE_ERROR (_("embedded expression code in unprivileged script; need stap -g"), false); embedded_expr *e = new embedded_expr; e->tok = t; @@ -3280,7 +3280,7 @@ parser::parse_value () expression* e = parse_expression (); t = next (); if (! (t->type == tok_operator && t->content == ")")) - throw parse_error (_("expected ')'")); + throw PARSE_ERROR (_("expected ')'")); swallow (); return e; } @@ -3391,7 +3391,7 @@ expression* parser::parse_symbol () else if (name == "@max") sop->ctype = sc_max; else - throw parse_error(_("unknown operator ") + name); + throw PARSE_ERROR(_("unknown operator ") + name); expect_op("("); sop->tok = t; sop->stat = parse_expression (); @@ -3518,7 +3518,7 @@ expression* parser::parse_symbol () continue; } else - throw parse_error (_("expected ',' or ')'")); + throw PARSE_ERROR (_("expected ',' or ')'")); } return f; } @@ -3563,7 +3563,7 @@ expression* parser::parse_symbol () continue; } else - throw parse_error (_("expected ',' or ']'")); + throw PARSE_ERROR (_("expected ',' or ']'")); } return ai; } @@ -3573,7 +3573,7 @@ expression* parser::parse_symbol () // so we throw a parse error. if (hop) - throw parse_error(_("base histogram operator where expression expected"), t); + throw PARSE_ERROR(_("base histogram operator where expression expected"), t); return sym; } @@ -3648,7 +3648,7 @@ target_symbol* parser::parse_target_symbol (const token* t) return aop; } - throw parse_error (_("expected @cast, @var or $var")); + throw PARSE_ERROR (_("expected @cast, @var or $var")); } @@ -3684,13 +3684,13 @@ expression* parser::parse_perf_op (const token* t) perf_op* pop = new perf_op; if (strverscmp(session.compatible.c_str(), "2.1") < 0) - throw parse_error (_("expected @cast, @var or $var")); + throw PARSE_ERROR (_("expected @cast, @var or $var")); pop->tok = t; expect_op("("); pop->operand = parse_literal_string (); if (pop->operand->value == "") - throw parse_error (_("expected non-empty string")); + throw PARSE_ERROR (_("expected non-empty string")); expect_op(")"); return pop; } @@ -3766,7 +3766,7 @@ parser::parse_target_symbol_components (target_symbol* e) } if (pprint && (peek_op ("->") || peek_op("["))) - throw parse_error(_("-> and [ are not accepted for a pretty-printing variable")); + throw PARSE_ERROR(_("-> and [ are not accepted for a pretty-printing variable")); } /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ diff --git a/session.h b/session.h index 1d9a1cf1d..55b091dd3 100644 --- a/session.h +++ b/session.h @@ -97,12 +97,12 @@ struct parse_error: public std::runtime_error const parse_error *chain; const std::string errsrc; ~parse_error () throw () {} - parse_error (const std::string& msg): - runtime_error (msg), tok (0), skip_some (true), chain(0), errsrc(msg) {} - parse_error (const std::string& msg, const token* t): - runtime_error (msg), tok (t), skip_some (true), chain(0), errsrc(msg) {} - parse_error (const std::string& msg, bool skip): - runtime_error (msg), tok (0), skip_some (skip), chain(0), errsrc(msg) {} + parse_error (const std::string& src, const std::string& msg): + runtime_error (msg), tok (0), skip_some (true), chain(0), errsrc(src) {} + parse_error (const std::string& src, const std::string& msg, const token* t): + runtime_error (msg), tok (t), skip_some (true), chain(0), errsrc(src) {} + parse_error (const std::string& src, const std::string& msg, bool skip): + runtime_error (msg), tok (0), skip_some (skip), chain(0), errsrc(src) {} std::string errsrc_chain(void) const { diff --git a/staptree.cxx b/staptree.cxx index 812ef7baf..c484c0b4d 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -900,7 +900,7 @@ print_format::string_to_components(string const & str) } if (curr.type == conv_unspecified) - throw parse_error(_("invalid or missing conversion specifier")); + throw PARSE_ERROR(_("invalid or missing conversion specifier")); ++i; res.push_back(curr); @@ -913,7 +913,7 @@ print_format::string_to_components(string const & str) if (curr.type == conv_literal) res.push_back(curr); else - throw parse_error(_("trailing incomplete print format conversion")); + throw PARSE_ERROR(_("trailing incomplete print format conversion")); } return res; -- 2.43.5