From 0fefb486c5965e371cb52f55548123233da85f72 Mon Sep 17 00:00:00 2001 From: fche Date: Fri, 4 Mar 2005 20:10:09 +0000 Subject: 2005-03-04 Frank Ch. Eigler * parse.cxx (scan): Support '$' characters in identifiers. (parse_symbol): Support thread-> / process-> shorthand. * staptree.cxx (symresolution_info::find): Split up into find_scalar, find_array, find_function. (resolve_symbols): Call the above for symbol/arrayindex/functioncall. (find_scalar): Add stub support for synthetic builtin variables. * staptree.h: Corresponding changes. * testsuite/*: Some new tests. --- parse.cxx | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index 41ec6fef..640c3715 100644 --- a/parse.cxx +++ b/parse.cxx @@ -157,7 +157,7 @@ lexer::scan () if (isspace (c)) goto skip; - else if (isalpha (c)) + else if (isalpha (c) || c == '$') { n->type = tok_identifier; n->content = (char) c; @@ -166,7 +166,7 @@ lexer::scan () int c2 = input.peek (); if (! input) break; - if ((isalnum(c2) || c2 == '_')) + if ((isalnum(c2) || c2 == '_' || c2 == '$')) { n->content.push_back(c2); input_get (); @@ -247,6 +247,7 @@ lexer::scan () (c == '+' && c2 == '=') || (c == '-' && c2 == '=') || (c == ':' && c2 == ':') || + (c == '-' && c2 == '>') || false) // XXX: etc. n->content.push_back((char) input_get ()); @@ -947,8 +948,9 @@ parser::parse_value () } +// var, var[index], func(parms), thread->var, process->var expression* -parser::parse_symbol () // var, var[index], func(parms) +parser::parse_symbol () { const token* t = next (); if (t->type != tok_identifier) @@ -957,7 +959,34 @@ parser::parse_symbol () // var, var[index], func(parms) string name = t->content; t = peek (); - if (t && t->type == tok_operator && t->content == "[") // array + if (t && t->type == tok_operator && t->content == "->") + { + // shorthand for process- or thread-specific array element + // map "thread->VAR" to "VAR[$tid]", + // and "process->VAR" to "VAR[$pid]" + symbol* sym = new symbol; + if (name == "thread") + sym->name = "$tid"; + else if (name == "process") + sym->name = "$pid"; + else + throw parse_error ("expected 'thread->' or 'process->'"); + struct token* t2prime = new token (*t2); + t2prime->content = sym->name; + sym->tok = t2prime; + + next (); // swallow "->" + t = next (); + if (! (t->type == tok_identifier)) + throw parse_error ("expected identifier"); + + struct arrayindex* ai = new arrayindex; + ai->tok = t; + ai->base = t->content; + ai->indexes.push_back (sym); + return ai; + } + else if (t && t->type == tok_operator && t->content == "[") // array { next (); struct arrayindex* ai = new arrayindex; -- cgit