From 69c68955b910a9f284fa25b9ebb30eff5c040e0b Mon Sep 17 00:00:00 2001 From: fche Date: Thu, 2 Jun 2005 19:43:55 +0000 Subject: 2005-06-02 Frank Ch. Eigler Parse foreach construct. Added fuller copyright notices throughout. * staptree.h (foreach_loop): New tree node type. * staptree.cxx: Print it, visit it, love it, leave it. * parse.cxx: Parse it. (parse_stmt_block): Don't require ";" separators between statements. (parse_array_in): Use [] as index group operator instead of (). * elaborate.cxx (visit_foreach_loop): New code. * translate.cxx: Slightly tighten errorcount/actioncount handling. * main.cxx: Accept "-" as script file name standing for stdin. (visit_arrayindex): Switch to simpler set_arity call. * configure.ac: Generate DATE macro. * Makefile.in, configure, config.in: Regenerated. * testsuite/*: New/updated tests for syntax changes, foreach (). --- staptree.cxx | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index cf934fa2..d0fd79be 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -1,6 +1,10 @@ // parse tree functions -// Copyright 2005 Red Hat Inc. -// GPL +// Copyright (C) 2005 Red Hat Inc. +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. #include "config.h" #include "staptree.h" @@ -169,6 +173,16 @@ void unary_expression::print (ostream& o) o << op << '(' << *operand << ")"; } +void array_in::print (ostream& o) +{ + o << "["; + for (unsigned i=0; iindexes.size(); i++) + { + if (i > 0) o << ", "; + operand->indexes[i]->print (o); + } + o << "] in " << operand->base; +} void post_crement::print (ostream& o) { @@ -262,7 +276,7 @@ void block::print (ostream& o) { o << "{" << endl; for (unsigned i=0; i 0) o << ", "; + indexes[i]->print (o); + } + o << "] in " << base << ")" << endl; + block->print (o); +} + + void null_statement::print (ostream& o) { o << ";"; @@ -394,6 +421,12 @@ for_loop::visit (visitor* u) u->visit_for_loop (this); } +void +foreach_loop::visit (visitor* u) +{ + u->visit_foreach_loop (this); +} + void null_statement::visit (visitor* u) { @@ -565,6 +598,14 @@ traversing_visitor::visit_for_loop (for_loop* s) s->block->visit (this); } +void +traversing_visitor::visit_foreach_loop (foreach_loop* s) +{ + for (unsigned i=0; iindexes.size(); i++) + s->indexes[i]->visit (this); + s->block->visit (this); +} + void traversing_visitor::visit_return_statement (return_statement* s) { @@ -732,6 +773,12 @@ throwing_visitor::visit_for_loop (for_loop* s) throwone (s->tok); } +void +throwing_visitor::visit_foreach_loop (foreach_loop* s) +{ + throwone (s->tok); +} + void throwing_visitor::visit_return_statement (return_statement* s) { -- cgit