From 2b066ec1b8801b08052a68282ce34ef9c425ae8f Mon Sep 17 00:00:00 2001 From: fche Date: Sat, 21 May 2005 01:35:34 +0000 Subject: * at long last, a more full-bodied snapshot 2005-05-20 Frank Ch. Eigler Many changes throughout. Partial sketch of translation output. * elaborate.*: Elaboration pass. * translate.*: Translation pass. * staptree.*: Simplified for visitor concept. * main.cxx: Translator mainline. * *test.cxx: Removed. * testsuite/*: Some new tests, some changed for newer syntax. --- parse.cxx | 59 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index b5881331..2bf0f977 100644 --- a/parse.cxx +++ b/parse.cxx @@ -2,12 +2,13 @@ // Copyright 2005 Red Hat Inc. // GPL -#include +#include "config.h" #include "staptree.h" #include "parse.h" +#include +#include #include #include -#include #include #include @@ -405,28 +406,38 @@ parser::parse_stmt_block () throw parse_error ("expected '{'"); pb->tok = t; + while (1) { try { - // handle empty blocks - t = peek (); - if (t && t->type == tok_operator && t->content == "}") - { - next (); - break; - } - + // handle empty blocks + t = peek (); + if (t && t->type == tok_operator && t->content == "}") + { + next (); + break; + } + pb->statements.push_back (parse_statement ()); // ';' is a statement separator in awk, not a terminator. // Note that ';' is also a possible null statement. t = peek (); - if (t && t->type == tok_operator && t->content == ";") + if (t && t->type == tok_operator && t->content == "}") + { + next (); + break; + } + else if (t && t->type == tok_operator && t->content == ";") { next (); continue; + // this also accepts semicolon as a terminator: + // { a=1; } } + else + throw parse_error ("expected ';' or '}'"); } catch (parse_error& pe) { @@ -496,10 +507,18 @@ parser::parse_global (vector & globals) if (! (t->type == tok_identifier)) throw parse_error ("expected identifier"); - vardecl* d = new vardecl; - d->name = t->content; - d->tok = t; - globals.push_back (d); // XXX: check for duplicates + bool dupe = false; + for (unsigned i=0; iname == t->content) + dupe = true; + + if (! dupe) + { + 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 == ",") @@ -565,6 +584,8 @@ parser::parse_probe_point () { probe_point* pl = new probe_point; + // XXX: add support for probe point aliases + // e.g. probe a.b = a.c = a.d = foo while (1) { const token* t = next (); @@ -596,13 +617,16 @@ parser::parse_probe_point () if (t && t->type == tok_operator && (t->content == "{" || t->content == ",")) break; + else if (t && t->type == tok_operator && + t->content == "(") + throw parse_error ("unexpected '.' or ',' or '{'"); } // fall through if (t && t->type == tok_operator && t->content == ".") next (); else - throw parse_error ("expected '.'"); + throw parse_error ("expected '.' or ',' or '(' or '{'"); } return pl; @@ -717,8 +741,7 @@ parser::parse_assignment () t->content == "+=" || false)) // XXX: add /= etc. { - if (op1->is_lvalue () == 0) - throw parse_error ("assignment not to lvalue"); + // NB: lvalueness is checked during translation / elaboration assignment* e = new assignment; e->left = op1; e->op = t->content; -- cgit