From d7f3e0c5d0b0af0dcb5f8168e1184f15a0554a4e Mon Sep 17 00:00:00 2001 From: graydon Date: Wed, 10 Aug 2005 03:15:21 +0000 Subject: 2005-08-09 Graydon Hoare * staptree.{cxx,h} (target_symbol): New struct. (*_visitor::visit_target_symbol): Support it. (visitor::active_lvalues) (visitor::is_active_lvalue) (visitor::push_active_lvalue) (visitor::pop_active_lvalue): Support lvalue-detection. (delete_statement::visit) (pre_crement::visit) (post_crement::visit) (assignment::visit): Push and pop lvalue expressions. * elaborate.{cxx,h} (lvalule_aware_traversing_visitor): Remove class. (no_map_mutation_during_iteration_check) (mutated_map_collector): Update lvalue logic. (typeresolution_info::visit_target_symbol): Add, throw error. * parse.{cxx,h} (tt2str) (tok_is) (parser::expect_*) (parser::peek_*): New helpers. (parser::parse_symbol): Rewrite, support target_symbols. * translate.cxx (c_unparser::visit_target_symbol): Implement. * tapsets.cxx (var_expanding_copy_visitor): Update lvalue logic, change visit_symbol to visit_target_symbol. --- tapsets.cxx | 102 ++++++++++++++++-------------------------------------------- 1 file changed, 26 insertions(+), 76 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 887ddd60..2df8fc65 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -1204,58 +1204,15 @@ struct var_expanding_copy_visitor : public deep_copy_visitor { - // Alas, we cannot easily mixin lvalue_aware_traversing_visitor. - // But behold the *awesome power* of copy and paste. - static unsigned tick; dwarf_query & q; - unsigned lval_depth; Dwarf_Addr addr; var_expanding_copy_visitor(dwarf_query & q, Dwarf_Addr a) - : q(q), lval_depth(0), addr(a) + : q(q), addr(a) {} - - bool is_in_lvalue() - { - return lval_depth > 0; - } - - void visit_pre_crement (pre_crement* e) - { - ++lval_depth; - deep_copy_visitor::visit_pre_crement (e); - --lval_depth; - } - - void visit_post_crement (post_crement* e) - { - ++lval_depth; - deep_copy_visitor::visit_post_crement (e); - --lval_depth; - } - - void visit_assignment (assignment* e) - { - assignment* n = new assignment; - n->op = e->op; - n->tok = e->tok; - ++lval_depth; - require (this, &(n->left), e->left); - --lval_depth; - require (this, &(n->right), e->right); - provide (this, n); - } - - void visit_delete_statement (delete_statement* s) - { - ++lval_depth; - deep_copy_visitor::visit_delete_statement (s); - --lval_depth; - } - - void visit_symbol (symbol* e); + void visit_target_symbol (target_symbol* e); }; @@ -1263,40 +1220,33 @@ unsigned var_expanding_copy_visitor::tick = 0; void -var_expanding_copy_visitor::visit_symbol (symbol *e) +var_expanding_copy_visitor::visit_target_symbol (target_symbol *e) { - if (e->name.size() > 0 && - e->name[0] == '$') - { - if (is_in_lvalue()) - { - throw semantic_error("read-only special variable " - + e->name + " used in lvalue", e->tok); - } - - string fname = "get_" + e->name.substr(1) + "_" + lex_cast(tick++); - - // synthesize a function - functiondecl *fdecl = new functiondecl; - embeddedcode *ec = new embeddedcode; - ec->code = q.dw.literal_stmt_for_local(addr, e->name.substr(1)); - fdecl->name = fname; - fdecl->body = ec; - fdecl->type = pe_long; - q.sess.functions.push_back(fdecl); - - // synthesize a call - functioncall* n = new functioncall; - n->tok = e->tok; - n->function = fname; - n->referent = NULL; - provide (this, n); - - } - else + assert(e->base_name.size() > 0 && e->base_name[0] == '$'); + + if (is_active_lvalue(e)) { - deep_copy_visitor::visit_symbol (e); + throw semantic_error("read-only special variable " + + e->base_name + " used as lvalue", e->tok); } + + string fname = "get_" + e->base_name.substr(1) + "_" + lex_cast(tick++); + + // synthesize a function + functiondecl *fdecl = new functiondecl; + embeddedcode *ec = new embeddedcode; + ec->code = q.dw.literal_stmt_for_local(addr, e->base_name.substr(1)); + fdecl->name = fname; + fdecl->body = ec; + fdecl->type = pe_long; + q.sess.functions.push_back(fdecl); + + // synthesize a call + functioncall* n = new functioncall; + n->tok = e->tok; + n->function = fname; + n->referent = NULL; + provide (this, n); } -- cgit