]> sourceware.org Git - systemtap.git/commitdiff
Terminate parsing on duplicate variable or function declaration.
authorMartin Cermak <mcermak@redhat.com>
Sat, 14 Nov 2015 18:17:27 +0000 (19:17 +0100)
committerMartin Cermak <mcermak@redhat.com>
Sat, 14 Nov 2015 18:17:27 +0000 (19:17 +0100)
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
testsuite/parseko/private01.stp [new file with mode: 0644]
testsuite/parseko/private02.stp [new file with mode: 0644]

index d60db70b9f88d0c480c3f98af48314e331924675..53ef5fdddf199bb8ce98ebf05508c868369123e5 100644 (file)
--- a/parse.cxx
+++ b/parse.cxx
@@ -2238,13 +2238,17 @@ parser::do_parse_global (vector <vardecl*>& globals, vector<probe*>&, 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; i<globals.size(); i++)
-       if (globals[i]->name == 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<functiondecl*>& 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; i<functions.size(); i++)
-    if (functions[i]->name == 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 (file)
index 0000000..2a010d1
--- /dev/null
@@ -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 (file)
index 0000000..e2e91d0
--- /dev/null
@@ -0,0 +1,6 @@
+#! stap -p1
+
+function foo () {}
+private function foo () {}
+
+
This page took 0.031481 seconds and 5 git commands to generate.