From 1bbeef03a440e3ac23d6e5148675450597a58e67 Mon Sep 17 00:00:00 2001 From: graydon Date: Fri, 2 Dec 2005 23:28:03 +0000 Subject: 2005-12-02 Graydon Hoare * elaborate.cxx (mutated_var_collector): Forward traversal portion of calls to base class. (mutated_var_collector::visit_arrayindex): Resolve arrayindex-into-histogram expression as pe_long. (typeresolution_info::visit_print_format): Traverse into histogram if present. * parse.cxx (parse_symbol): Handle parse ambiguity surrounding print(@hist_op(...)[...]). * staptree.cxx (traversing_visitor::visit_arrayindex): Visit base member of arrayindex. * translate.cxx (c_unparser::histogram_index_check): New method. (var::hist): Fix bug. (var::buckets): New method. (stmt_expr::stmt_expr): Print with newline. (c_unparser::load_map_indices): Handle indexing-histogram case. (c_tmpcounter::visit_arrayindex): Likewise. (c_unparser::visit_arrayindex): Likewise. (c_tmpcounter_assignment::visit_arrayindex): Throw error when user attempts to write to histogram bucket. (c_unparser_assignment::visit_arrayindex): Likewise. * testsuite/buildok/print_histogram_entry.stp: New test. --- parse.cxx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index fe10c75c..e46d3973 100644 --- a/parse.cxx +++ b/parse.cxx @@ -1997,9 +1997,31 @@ parser::parse_symbol () // construct. This is sort of gross but it avoids // promoting histogram references to typeful // expressions. - fmt->hist = NULL; - t = parse_hist_op_or_bare_name(fmt->hist, name); - assert(fmt->hist); + + hop = NULL; + t = parse_hist_op_or_bare_name(hop, name); + assert(hop); + + // It is, sadly, possible that even while parsing a + // hist_op, we *mis-guessed* and the user wishes to + // print(@hist_op(foo)[bucket]), a scalar. In that case + // we must parse the arrayindex and print an expression. + + if (!peek_op ("[")) + fmt->hist = hop; + else + { + // This is simplified version of the + // multi-array-index parser below, because we can + // only ever have one index on a histogram anyways. + expect_op("["); + struct arrayindex* ai = new arrayindex; + ai->tok = t; + ai->base = hop; + ai->indexes.push_back (parse_expression ()); + expect_op("]"); + fmt->args.push_back(ai); + } } else { -- cgit