From f946b10fbd72dd760f04ad9475f2ba3ccb56666f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 19 Feb 2010 17:44:44 -0800 Subject: Simplify null_statement construction It only needs a token*, so build that into the constructor. --- elaborate.cxx | 9 +++------ parse.cxx | 6 +----- staptree.cxx | 12 ++++++++++++ staptree.h | 2 ++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/elaborate.cxx b/elaborate.cxx index 88a856c2..b349ff8c 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -2449,8 +2449,7 @@ dead_stmtexpr_remover::visit_for_loop (for_loop *s) else { // Can't elide this whole statement; put a null in there. - s->block = new null_statement(); - s->block->tok = s->tok; + s->block = new null_statement(s->tok); } } provide (s); @@ -2526,8 +2525,7 @@ void semantic_pass_opt4 (systemtap_session& s, bool& relaxed_p) && ! s.timing) // PR10070 s.print_warning ("side-effect-free probe '" + p->name + "'", p->tok); - p->body = new null_statement(); - p->body->tok = p->tok; + p->body = new null_statement(p->tok); // XXX: possible duplicate warnings; see below } @@ -2551,8 +2549,7 @@ void semantic_pass_opt4 (systemtap_session& s, bool& relaxed_p) if (! s.suppress_warnings) s.print_warning ("side-effect-free function '" + fn->name + "'", fn->tok); - fn->body = new null_statement(); - fn->body->tok = fn->tok; + fn->body = new null_statement(fn->tok); // XXX: the next iteration of the outer optimization loop may // take this new null_statement away again, and thus give us a diff --git a/parse.cxx b/parse.cxx index f99a440b..79784490 100644 --- a/parse.cxx +++ b/parse.cxx @@ -1289,11 +1289,7 @@ parser::parse_statement () statement *ret; const token* t = peek (); if (t && t->type == tok_operator && t->content == ";") - { - null_statement* n = new null_statement (); - n->tok = next (); - return n; - } + return new null_statement (next ()); else if (t && t->type == tok_operator && t->content == "{") return parse_stmt_block (); // Don't squash semicolons. else if (t && t->type == tok_keyword && t->content == "if") diff --git a/staptree.cxx b/staptree.cxx index 7a335fc3..a31112cb 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -42,6 +42,18 @@ statement::statement (): } +statement::statement (const token* tok): + tok (tok) +{ +} + + +null_statement::null_statement (const token* tok): + statement(tok) +{ +} + + statement::~statement () { } diff --git a/staptree.h b/staptree.h index a654a7b4..bc5f0bfc 100644 --- a/staptree.h +++ b/staptree.h @@ -492,6 +492,7 @@ struct statement virtual void visit (visitor* u) = 0; const token* tok; statement (); + statement (const token* tok); virtual ~statement (); }; @@ -547,6 +548,7 @@ struct null_statement: public statement { void print (std::ostream& o) const; void visit (visitor* u); + null_statement (const token* tok); }; -- cgit