From c8fbf9315897b45e09755de4834b91b12020727e Mon Sep 17 00:00:00 2001 From: Martin Cermak Date: Sat, 14 Nov 2015 19:17:27 +0100 Subject: [PATCH] Terminate parsing on duplicate variable or function declaration. This fixes condition that makes the parser stop on attempt to declare duplicate global variable or function. It also (newly) makes the parser terminate on global versus private variable or function declaration attempt. This update makes parseko/eleven.stp and parseko/twelve.stp expectedly fail. It also adds parseko/private0[12].stp that expectedly fail on attempt do declare conflicting global versus private variable or function. --- parse.cxx | 28 ++++++++++++++++++---------- testsuite/parseko/private01.stp | 4 ++++ testsuite/parseko/private02.stp | 6 ++++++ 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 testsuite/parseko/private01.stp create mode 100644 testsuite/parseko/private02.stp diff --git a/parse.cxx b/parse.cxx index d60db70b9..53ef5fddd 100644 --- a/parse.cxx +++ b/parse.cxx @@ -2238,13 +2238,17 @@ parser::do_parse_global (vector & globals, vector&, string & f if (! (t->type == tok_identifier)) throw PARSE_ERROR (_("expected identifier")); + string gname = "__global_" + string(t->content); + string pname = "__private_" + detox_path(fname) + string(t->content); + string name = priv ? pname : gname; + for (unsigned i=0; iname == t->content) + { + if (globals[i]->name == name) throw PARSE_ERROR (_("duplicate global name")); - - string name = "__global_" + string(t->content); - if (priv) - name = "__private_" + detox_path(fname) + string(t->content); + if ((globals[i]->name == gname) || (globals[i]->name == pname)) + throw PARSE_ERROR (_("global versus private variable declaration conflict")); + } vardecl* d = new vardecl; d->name = name; @@ -2319,13 +2323,17 @@ parser::do_parse_functiondecl (vector& functions, const token* t, && (t->content == "string" || t->content == "long"))) throw PARSE_ERROR (_("expected identifier")); + string gname = "__global_" + string(t->content); + string pname = "__private_" + detox_path(fname) + string(t->content); + string name = priv ? pname : gname; + for (unsigned i=0; iname == t->content) + { + if (functions[i]->name == name) throw PARSE_ERROR (_("duplicate function name")); - - string name = "__global_" + string(t->content); - if (priv) - name = "__private_" + detox_path(fname) + string(t->content); + if ((functions[i]->name == gname) || (functions[i]->name == pname)) + throw PARSE_ERROR (_("global versus private function declaration conflict")); + } functiondecl *fd = new functiondecl (); fd->name = name; diff --git a/testsuite/parseko/private01.stp b/testsuite/parseko/private01.stp new file mode 100644 index 000000000..2a010d155 --- /dev/null +++ b/testsuite/parseko/private01.stp @@ -0,0 +1,4 @@ +#! stap -p1 + +global globalvar +private globalvar diff --git a/testsuite/parseko/private02.stp b/testsuite/parseko/private02.stp new file mode 100644 index 000000000..e2e91d029 --- /dev/null +++ b/testsuite/parseko/private02.stp @@ -0,0 +1,6 @@ +#! stap -p1 + +function foo () {} +private function foo () {} + + -- 2.43.5