Changeset c0b9f5d for src/SynTree
- Timestamp:
- Jan 15, 2018, 2:38:39 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 12145b9
- Parents:
- 7dc0246d
- Location:
- src/SynTree
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/CompoundStmt.cc
r7dc0246d rc0b9f5d 64 64 } 65 65 if ( ! declMap.empty() ) { 66 VarExprReplacer replacer( declMap ); 67 accept( replacer ); 66 VarExprReplacer::replace( this, declMap ); 68 67 } 69 68 } -
src/SynTree/FunctionDecl.cc
r7dc0246d rc0b9f5d 49 49 } 50 50 if ( ! declMap.empty() ) { 51 VarExprReplacer replacer( declMap ); 52 accept( replacer ); 51 VarExprReplacer::replace( this, declMap ); 53 52 } 54 53 } -
src/SynTree/VarExprReplacer.cc
r7dc0246d rc0b9f5d 16 16 #include <iostream> // for operator<<, basic_ostream, ostream, basic_o... 17 17 18 #include "Common/PassVisitor.h" 18 19 #include "Declaration.h" // for operator<<, DeclarationWithType 19 20 #include "Expression.h" // for VariableExpr 20 21 #include "VarExprReplacer.h" 21 22 22 VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {} 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 ); 23 32 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; 33 // replace variable with new node from decl map 34 void previsit( VariableExpr * varExpr ); 35 }; 36 } 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 } 30 55 } 31 varExpr->set_var( declMap.at( varExpr->get_var() ) );32 56 } 33 } 57 } // namespace VarExprReplacer 58 59 60 61 62 63 64 -
src/SynTree/VarExprReplacer.h
r7dc0246d rc0b9f5d 23 23 class VariableExpr; 24 24 25 /// Visitor that replaces the declarations that VariableExprs refer to, according to the supplied mapping 26 class VarExprReplacer : public Visitor { 27 public: 25 namespace VarExprReplacer { 28 26 typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap; 29 private:30 const DeclMap & declMap;31 bool debug;32 public:33 VarExprReplacer( const DeclMap & declMap, bool debug = false );34 27 35 // replace variable with new node from decl map 36 virtual void visit( VariableExpr * varExpr ); 37 38 static void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ) { 39 VarExprReplacer replacer( declMap, debug ); 40 maybeAccept( node, replacer ); 41 } 42 }; 28 void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ); 29 } 43 30 44 31 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.