Changes in src/SynTree/VarExprReplacer.cc [c0b9f5d:ea6332d]
- File:
-
- 1 edited
-
src/SynTree/VarExprReplacer.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/VarExprReplacer.cc
rc0b9f5d rea6332d 16 16 #include <iostream> // for operator<<, basic_ostream, ostream, basic_o... 17 17 18 #include "Common/PassVisitor.h"19 18 #include "Declaration.h" // for operator<<, DeclarationWithType 20 19 #include "Expression.h" // for VariableExpr 21 20 #include "VarExprReplacer.h" 22 21 23 namespace VarExprReplacer { 24 namespace { 25 /// Visitor that replaces the declarations that VariableExprs refer to, according to the supplied mapping 26 struct VarExprReplacer { 27 private: 28 const DeclMap & declMap; 29 bool debug; 30 public: 31 VarExprReplacer( const DeclMap & declMap, bool debug = false ); 22 VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {} 32 23 33 // replace variable with new node from decl map 34 void previsit( VariableExpr * varExpr ); 35 }; 24 // replace variable with new node from decl map 25 void VarExprReplacer::visit( VariableExpr * varExpr ) { 26 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 27 if ( declMap.count( varExpr->get_var() ) ) { 28 if ( debug ) { 29 std::cerr << "replacing variable reference: " << (void*)varExpr->get_var() << " " << varExpr->get_var() << " with " << (void*)declMap.at( varExpr->get_var() ) << " " << declMap.at( varExpr->get_var() ) << std::endl; 30 } 31 varExpr->set_var( declMap.at( varExpr->get_var() ) ); 36 32 } 37 38 void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) { 39 PassVisitor<VarExprReplacer> replacer( declMap, debug ); 40 maybeAccept( node, replacer ); 41 } 42 43 namespace { 44 VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {} 45 46 // replace variable with new node from decl map 47 void VarExprReplacer::previsit( VariableExpr * varExpr ) { 48 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 49 if ( declMap.count( varExpr->var ) ) { 50 if ( debug ) { 51 std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)declMap.at( varExpr->var ) << " " << declMap.at( varExpr->var ) << std::endl; 52 } 53 varExpr->var = declMap.at( varExpr->var ); 54 } 55 } 56 } 57 } // namespace VarExprReplacer 58 59 60 61 62 63 64 33 }
Note:
See TracChangeset
for help on using the changeset viewer.