From d3bc48f01479cc6d511bd94d296789ee6139d0d0 Mon Sep 17 00:00:00 2001 From: Serguei Makarov Date: Fri, 5 Apr 2013 11:39:26 -0400 Subject: [PATCH] stapregex cleanup: ditch redundant regex_query::re field in favour of dynamic_cast<...> use --- elaborate.cxx | 8 ++++++-- parse.cxx | 2 +- staptree.cxx | 2 +- staptree.h | 3 +-- translate.cxx | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/elaborate.cxx b/elaborate.cxx index 28282cd47..a39694d9f 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1504,17 +1504,21 @@ public: regex_collecting_visitor (systemtap_session& s): session(s) { } void visit_regex_query (regex_query *q) { - functioncall_traversing_visitor::visit_regex_query (q); // TODOXXX test necessity + functioncall_traversing_visitor::visit_regex_query (q); - string re = q->re->value; try { + string re = dynamic_cast(q->right)->value; regex_to_stapdfa (&session, re, session.dfa_counter); } catch (const semantic_error &e) { throw semantic_error(e.what(), q->right->tok); } + catch (exception &e) // dynamic_cast<...> failed + { + throw semantic_error(_F("BUG %s", e.what()), q->right->tok); + } } }; diff --git a/parse.cxx b/parse.cxx index 383befe3a..d726e6fe7 100644 --- a/parse.cxx +++ b/parse.cxx @@ -3098,7 +3098,7 @@ parser::parse_comparison_or_regex_query () r->op = t->content; r->tok = t; next (); - r->right = r->re = parse_literal_string(); + r->right = parse_literal_string(); op1 = r; t = peek (); } diff --git a/staptree.cxx b/staptree.cxx index 95c441519..4df0745b2 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -1780,7 +1780,7 @@ void traversing_visitor::visit_regex_query (regex_query* e) { e->left->visit (this); - e->right->visit (this); // TODOXXX do we need to traverse the literal in RHS? + e->right->visit (this); } void diff --git a/staptree.h b/staptree.h index 9f321c1ec..bef2a4245 100644 --- a/staptree.h +++ b/staptree.h @@ -168,8 +168,7 @@ struct array_in: public expression struct regex_query: public binary_expression { - literal_string *re; // XXX somewhat redundant with right - void print (std::ostream& o) const; + // XXX: right MUST be a literal_string* void visit (visitor* u); }; diff --git a/translate.cxx b/translate.cxx index e30d97cf3..b7879e32d 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4078,7 +4078,7 @@ c_unparser::visit_regex_query (regex_query* e) o->indent(1); o->newline(); if (e->op == "!~") o->line() << "!"; - stapdfa *dfa = session->dfas[e->re->value]; + stapdfa *dfa = session->dfas[dynamic_cast(e->right)->value]; // TODOXXX error checking??? dfa->emit_matchop_start (o); e->left->visit(this); dfa->emit_matchop_end (o); -- 2.43.5