From 24cb178fd82936f55d254ebd0cd79802da21134a Mon Sep 17 00:00:00 2001 From: fche Date: Thu, 28 Jul 2005 18:07:02 +0000 Subject: 2005-07-28 Frank Ch. Eigler translator/1120 * main.cxx (main): Preset -R and -I options from environment variables (if set). Pass guru mode flags to parser. * parse.cxx (privileged): New parser operation flag. Update callers. (parse_embeddedcode): Throw an error if !privileged. (parse_functiondecl): Change signature. Prevent duplicates. (parse_globals): Ditto. * parse.h: Corresponding changes. * tapset/*.stp: Beginnings of real tapset library, to replace previous builtins. * tapsets.cxx: Greatly reduce verbose mode output. * Makefile.am: Install & dist it. * runtest.sh: Refer to it. * Makefile.in, aclocal.m4: Regenerated. * testsuite/*/*.stp: Set guru mode via /bin/sh if needed. * testusite/*/*ko.stp: Homogenize shell scripts. --- parse.cxx | 68 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index 988262ce..ca3337b6 100644 --- a/parse.cxx +++ b/parse.cxx @@ -22,14 +22,15 @@ using namespace std; -parser::parser (istream& i): - input_name (""), free_input (0), input (i, input_name), +parser::parser (istream& i, bool p): + input_name (""), free_input (0), + input (i, input_name), privileged (p), last_t (0), next_t (0), num_errors (0) { } -parser::parser (const string& fn): +parser::parser (const string& fn, bool p): input_name (fn), free_input (new ifstream (input_name.c_str(), ios::in)), - input (* free_input, input_name), + input (* free_input, input_name), privileged (p), last_t (0), next_t (0), num_errors (0) { } @@ -40,17 +41,17 @@ parser::~parser() stapfile* -parser::parse (std::istream& i) +parser::parse (std::istream& i, bool pr) { - parser p (i); + parser p (i, pr); return p.parse (); } stapfile* -parser::parse (const std::string& n) +parser::parse (const std::string& n, bool pr) { - parser p (n); + parser p (n, pr); return p.parse (); } @@ -66,14 +67,16 @@ operator << (ostream& o, const token& t) t.type == tok_embedded ? "embedded-code" : "unknown token"); - // XXX: filter out embedded-code contents? - o << " '"; - for (unsigned i=0; itype == tok_identifier && t->content == "global") parse_global (f->globals); else if (t->type == tok_identifier && t->content == "function") - f->functions.push_back (parse_functiondecl ()); + parse_functiondecl (f->functions); else if (t->type == tok_embedded) f->embeds.push_back (parse_embeddedcode ()); else - throw parse_error ("expected 'probe', 'global', 'function', or embedded code"); + throw parse_error ("expected 'probe', 'global', 'function', or '%{'"); } catch (parse_error& pe) { @@ -516,7 +519,10 @@ parser::parse_embeddedcode () embeddedcode* e = new embeddedcode; const token* t = next (); if (t->type != tok_embedded) - throw parse_error ("expected embedded code"); + throw parse_error ("expected '%{'"); + + if (! privileged) + throw parse_error ("embedded code in unprivileged script"); e->tok = t; e->code = t->content; @@ -624,18 +630,14 @@ parser::parse_global (vector & globals) if (! (t->type == tok_identifier)) throw parse_error ("expected identifier"); - bool dupe = false; for (unsigned i=0; iname == t->content) - dupe = true; + throw parse_error ("duplicate global name"); - if (! dupe) - { - vardecl* d = new vardecl; - d->name = t->content; - d->tok = t; - globals.push_back (d); - } + vardecl* d = new vardecl; + d->name = t->content; + d->tok = t; + globals.push_back (d); t = peek (); if (t && t->type == tok_operator && t->content == ",") @@ -649,18 +651,23 @@ parser::parse_global (vector & globals) } -functiondecl* -parser::parse_functiondecl () +void +parser::parse_functiondecl (std::vector& functions) { const token* t = next (); if (! (t->type == tok_identifier && t->content == "function")) throw parse_error ("expected 'function'"); - functiondecl *fd = new functiondecl (); t = next (); if (! (t->type == tok_identifier)) throw parse_error ("expected identifier"); + + for (unsigned i=0; iname == t->content) + throw parse_error ("duplicate function name"); + + functiondecl *fd = new functiondecl (); fd->name = t->content; fd->tok = t; @@ -696,7 +703,8 @@ parser::parse_functiondecl () fd->body = parse_embeddedcode (); else fd->body = parse_stmt_block (); - return fd; + + functions.push_back (fd); } -- cgit