Changeset 0ce063b
- Timestamp:
- Jun 5, 2019, 4:28:53 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 54d4c0e
- Parents:
- 4864a73
- Location:
- src/SynTree
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/DeclReplacer.cc
r4864a73 r0ce063b 30 30 bool debug; 31 31 public: 32 size_t replaced; 33 34 public: 32 35 DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 33 36 … … 45 48 bool debug; 46 49 public: 50 size_t replaced; 51 52 public: 47 53 ExprDeclReplacer( const ExprMap & exprMap, bool debug = false ); 48 54 … … 52 58 } 53 59 54 voidreplace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {60 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 55 61 PassVisitor<DeclReplacer> replacer( declMap, typeMap, debug ); 56 62 maybeAccept( node, replacer ); 63 return replacer.pass.replaced; 57 64 } 58 65 59 voidreplace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {66 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) { 60 67 TypeMap typeMap; 61 re place( node, declMap, typeMap, debug );68 return replace( node, declMap, typeMap, debug ); 62 69 } 63 70 64 voidreplace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {71 size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) { 65 72 DeclMap declMap; 66 re place( node, declMap, typeMap, debug );73 return replace( node, declMap, typeMap, debug ); 67 74 } 68 75 69 voidreplace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {76 size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) { 70 77 PassVisitor<ExprDeclReplacer> replacer( exprMap, debug ); 71 78 node = maybeMutate( node, replacer ); 79 return replacer.pass.replaced; 72 80 } 73 81 74 82 namespace { 75 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ) {}83 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ), replaced( 0 ) {} 76 84 77 85 // replace variable with new node from decl map … … 79 87 // 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) 80 88 if ( declMap.count( varExpr->var ) ) { 89 replaced++; 81 90 auto replacement = declMap.at( varExpr->var ); 82 91 if ( debug ) { … … 89 98 void DeclReplacer::previsit( TypeInstType * inst ) { 90 99 if ( typeMap.count( inst->baseType ) ) { 100 replaced++; 91 101 auto replacement = typeMap.at( inst->baseType ); 92 102 if ( debug ) { … … 97 107 } 98 108 99 ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ) {}109 ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ), replaced( 0 ) {} 100 110 101 111 Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) { 102 112 if ( exprMap.count( varExpr->var ) ) { 113 replaced++; 103 114 Expression * replacement = exprMap.at( varExpr->var )->clone(); 104 115 if ( debug ) { -
src/SynTree/DeclReplacer.h
r4864a73 r0ce063b 28 28 typedef std::map< DeclarationWithType *, Expression * > ExprMap; 29 29 30 voidreplace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );31 voidreplace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );32 voidreplace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );30 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ); 31 size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false ); 32 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 33 33 34 voidreplace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);34 size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false); 35 35 template<typename T> 36 36 void replace( T *& node, const ExprMap & exprMap, bool debug = false ) {
Note: See TracChangeset
for help on using the changeset viewer.