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. --- staptree.cxx | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'staptree.cxx') diff --git a/staptree.cxx b/staptree.cxx index 31330017..811605ca 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -232,6 +232,26 @@ void symbol::print (ostream& o) } +void target_symbol::print (std::ostream& o) +{ + o << base_name; + for (unsigned i = 0; i < components.size(); ++i) + { + switch (components[i].first) + { + case comp_literal_array_index: + o << '[' << components[i].second << ']'; + break; + case comp_struct_pointer_member: + o << "->" << components[i].second; + break; + case comp_struct_member: + o << "." << components[i].second; + } + } +} + + void vardecl::print (ostream& o) { o << name; @@ -540,7 +560,9 @@ return_statement::visit (visitor* u) void delete_statement::visit (visitor* u) { + u->push_active_lvalue (this->value); u->visit_delete_statement (this); + u->pop_active_lvalue (); } void @@ -594,13 +616,17 @@ unary_expression::visit (visitor* u) void pre_crement::visit (visitor* u) { + u->push_active_lvalue (this->operand); u->visit_pre_crement (this); + u->pop_active_lvalue (); } void post_crement::visit (visitor* u) { + u->push_active_lvalue (this->operand); u->visit_post_crement (this); + u->pop_active_lvalue (); } void @@ -642,7 +668,9 @@ ternary_expression::visit (visitor* u) void assignment::visit (visitor* u) { + u->push_active_lvalue (this->left); u->visit_assignment (this); + u->pop_active_lvalue (); } void @@ -651,6 +679,12 @@ symbol::visit (visitor* u) u->visit_symbol (this); } +void +target_symbol::visit (visitor* u) +{ + u->visit_target_symbol(this); +} + void arrayindex::visit (visitor* u) { @@ -663,6 +697,33 @@ functioncall::visit (visitor* u) u->visit_functioncall (this); } +// ------------------------------------------------------------------------ + +bool +visitor::is_active_lvalue(expression *e) +{ + for (unsigned i = 0; i < active_lvalues.size(); ++i) + { + if (active_lvalues[i] == e) + return true; + } + return false; +} + +void +visitor::push_active_lvalue(expression *e) +{ + active_lvalues.push_back(e); +} + +void +visitor::pop_active_lvalue() +{ + assert(!active_lvalues.empty()); + active_lvalues.pop_back(); +} + + // ------------------------------------------------------------------------ @@ -832,6 +893,11 @@ traversing_visitor::visit_symbol (symbol* e) { } +void +traversing_visitor::visit_target_symbol (target_symbol* e) +{ +} + void traversing_visitor::visit_arrayindex (arrayindex* e) { @@ -1017,6 +1083,12 @@ throwing_visitor::visit_symbol (symbol* e) throwone (e->tok); } +void +throwing_visitor::visit_target_symbol (target_symbol* e) +{ + throwone (e->tok); +} + void throwing_visitor::visit_arrayindex (arrayindex* e) { @@ -1298,6 +1370,16 @@ deep_copy_visitor::visit_symbol (symbol* e) provide (this, n); } +void +deep_copy_visitor::visit_target_symbol (target_symbol* e) +{ + target_symbol* n = new target_symbol; + n->tok = e->tok; + n->base_name = e->base_name; + n->components = e->components; + provide (this, n); +} + void deep_copy_visitor::visit_arrayindex (arrayindex* e) { -- cgit