From 3cb170588c9b180fb4d28af04e44ac87481560a7 Mon Sep 17 00:00:00 2001 From: jistone Date: Fri, 17 Aug 2007 01:54:28 +0000 Subject: 2007-08-16 Josh Stone PR 4591 * parse.cxx (parser::parse_symbol): Tweak 'print' matching to allow all the new variants with printd and println. * staptree.h (struct print_format): Add fields for the new print variants, and parse_print() to help matching. * staptree.cxx (print_format::parse_print): New static method to match the print variants and determine their properties. (print_format::print): Handle the new print types. (deep_copy_visitor::visit_print_format): Copy the new fields. * translate.cxx (c_unparser::visit_print_format): Insert delims and newlines where appropriate for new print functions. * stap1.in: Document the new print functions. testsuite/ * lib/stap_run.exp: Make sure to match the entire output, in case there are multiple pass/fail messages. * buildok/printf.stp: Add lines for new print variants. * parseko/printd01.stp: Make sure that bad printd calls are handled. * parseko/printd02.stp: Ditto. * parseko/printd03.stp: Ditto. * parseko/printd04.stp: Ditto. * systemtap.base/print.stp: Try a bunch of different print calls. * systemtap.base/print.exp: Driver for above. --- staptree.cxx | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 9 deletions(-) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 05d3428b..10572803 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -338,6 +338,49 @@ void functioncall::print (ostream& o) const } +bool +print_format::parse_print(const std::string &name, + bool &stream, bool &format, bool &delim, bool &newline) +{ + const char *n = name.c_str(); + + stream = true; + format = delim = newline = false; + + if (*n == 's') + { + stream = false; + ++n; + } + + if (0 != strncmp(n, "print", 5)) + return false; + n += 5; + + if (*n == 'f') + { + format = true; + ++n; + } + else + { + if (*n == 'd') + { + delim = true; + ++n; + } + + if (*n == 'l' && *(n+1) == 'n') + { + newline = true; + n += 2; + } + } + + return (*n == '\0'); +} + + string print_format::components_to_string(vector const & components) { @@ -611,20 +654,17 @@ print_format::string_to_components(string const & str) void print_format::print (ostream& o) const { - string name = (string(print_to_stream ? "" : "s") - + string("print") - + string(print_with_format ? "f" : "")); - o << name << "("; + o << tok->content << "("; if (print_with_format) - { - o << lex_cast_qstring (raw_components); - } + o << lex_cast_qstring (raw_components); + if (print_with_delim) + o << lex_cast_qstring (delimiter.literal_string); if (hist) hist->print(o); for (vector::const_iterator i = args.begin(); i != args.end(); ++i) { - if (i != args.begin() || print_with_format) + if (i != args.begin() || print_with_format || print_with_delim) o << ", "; (*i)->print(o); } @@ -2252,10 +2292,13 @@ deep_copy_visitor::visit_print_format (print_format* e) { print_format* n = new print_format; n->tok = e->tok; - n->print_with_format = e->print_with_format; n->print_to_stream = e->print_to_stream; + n->print_with_format = e->print_with_format; + n->print_with_delim = e->print_with_delim; + n->print_with_newline = e->print_with_newline; n->raw_components = e->raw_components; n->components = e->components; + n->delimiter = e->delimiter; for (unsigned i = 0; i < e->args.size(); ++i) { expression* na; -- cgit