From a9c62ac9b339211d80b013eac75ba47f8a39d478 Mon Sep 17 00:00:00 2001 From: fche Date: Mon, 12 Dec 2005 17:39:53 +0000 Subject: 2005-12-12 Frank Ch. Eigler Fix parse tree pretty-printer. * staptree.h (print_format): Add raw_components field. * parse.cxx (parse_symbol): Set it. * staptree.cxx (lex_cast_qstring): Copy it here too. (binary_expression::print): Add a space around operator, due to lexical ambiguity (expr % paren-expr) vs %( preprocessor op. (array_in:: foreach_loop:: arrayindex::print): Print base as indexable. (print_format::string_to_components): Use parse_error, not semantic. (print_format::print): Properly quote formatting string. Print histogram argument. * translate.cxx (visit_print_format): Properly quote formatting string. (varlock): Reword lock timeout error message. * testsuite/buildok/printf.stp: Add some quoting troublemakers. * testsuite/parseok/unparser.stp: New file. --- staptree.cxx | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 87c9b383..0eb898ac 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -17,6 +17,27 @@ using namespace std; +// return as quoted string, with at least '"' backslash-escaped +template inline string +lex_cast_qstring(IN const & in) +{ + stringstream ss; + string out, out2; + if (!(ss << in)) + throw runtime_error("bad lexical cast"); + out = ss.str(); + out2 += '"'; + for (unsigned i=0; i 0) o << ", "; operand->indexes[i]->print (o); } - o << "] in " << operand->base; + o << "] in "; + operand->base->print_indexable (o); } void post_crement::print (ostream& o) const @@ -301,7 +323,8 @@ void functiondecl::printsig (ostream& o) const void arrayindex::print (ostream& o) const { - o << base << "["; + base->print_indexable (o); + o << "["; for (unsigned i=0; i0 ? ", " : "") << *indexes[i]; o << "]"; @@ -541,7 +564,7 @@ print_format::string_to_components(string const & str) } if (curr.type == conv_unspecified) - throw semantic_error("invalid or missing conversion specifier"); + throw parse_error("invalid or missing conversion specifier"); ++i; res.push_back(curr); @@ -554,7 +577,7 @@ print_format::string_to_components(string const & str) if (curr.type == conv_literal) res.push_back(curr); else - throw semantic_error("trailing incomplete print format conversion"); + throw parse_error("trailing incomplete print format conversion"); } return res; @@ -569,12 +592,14 @@ void print_format::print (ostream& o) const o << name << "("; if (print_with_format) { - o << '"' << components_to_string(components) << "\", "; + o << lex_cast_qstring (raw_components); } + if (hist) + hist->print(o); for (vector::const_iterator i = args.begin(); i != args.end(); ++i) { - if (i != args.begin()) + if (i != args.begin() || print_with_format) o << ", "; (*i)->print(o); } @@ -686,7 +711,8 @@ void foreach_loop::print (ostream& o) const if (sort_direction != 0 && sort_column == i+1) o << (sort_direction > 0 ? "+" : "-"); } - o << "] in " << base; + o << "] in "; + base->print_indexable (o); if (sort_direction != 0 && sort_column == 0) o << (sort_direction > 0 ? "+" : "-"); o << ") "; -- cgit