- Timestamp:
- Nov 9, 2017, 1:01:14 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 96fc67b
- Parents:
- 049ead9
- git-author:
- Rob Schluntz <rschlunt@…> (11/08/17 16:40:12)
- git-committer:
- Rob Schluntz <rschlunt@…> (11/09/17 13:01:14)
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
r049ead9 r7543dec 315 315 { 316 316 VarExprReplacer::DeclMap mapping; 317 mapping[ handler_decl ] = local_except;317 mapping[ handler_decl ] = new VariableExpr( local_except ); 318 318 VarExprReplacer mapper( mapping ); 319 handler-> get_body()->accept( mapper );319 handler->body->acceptMutator( mapper ); 320 320 } 321 321 322 block->push_back( handler-> get_body());323 handler-> set_body( nullptr );322 block->push_back( handler->body ); 323 handler->body = nullptr; 324 324 325 325 std::list<Statement *> caseBody -
src/InitTweak/FixInit.cc
r049ead9 r7543dec 676 676 // the original code contains uses of objDecl - replace them with the newly generated 'this' parameter. 677 677 ObjectDecl * thisParam = getParamThis( dtorFunc->type ); 678 VarExprReplacer::replace( dtor, { std::make_pair( objDecl, thisParam) } );678 VarExprReplacer::replace( dtor, { std::make_pair( objDecl, new VariableExpr( thisParam ) ) } ); 679 679 dtorFunc->statements->push_back( dtor ); 680 680 -
src/SynTree/CompoundStmt.cc
r049ead9 r7543dec 59 59 DeclarationWithType * origdwt = strict_dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() ); 60 60 assert( dwt->get_name() == origdwt->get_name() ); 61 declMap[ origdwt ] = dwt;61 declMap[ origdwt ] = new VariableExpr( dwt ); 62 62 } else assert( ! dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() ) ); 63 63 } else assert( ! dynamic_cast< DeclStmt * > ( s ) ); … … 65 65 if ( ! declMap.empty() ) { 66 66 VarExprReplacer replacer( declMap ); 67 accept ( replacer );67 acceptMutator( replacer ); 68 68 } 69 69 } -
src/SynTree/FunctionDecl.cc
r049ead9 r7543dec 43 43 VarExprReplacer::DeclMap declMap; 44 44 for ( auto p : group_iterate( other.type->parameters, type->parameters ) ) { 45 declMap[ std::get<0>(p) ] = std::get<1>(p);45 declMap[ std::get<0>(p) ] = new VariableExpr( std::get<1>(p) ); 46 46 } 47 47 for ( auto p : group_iterate( other.type->returnVals, type->returnVals ) ) { 48 declMap[ std::get<0>(p) ] = std::get<1>(p);48 declMap[ std::get<0>(p) ] = new VariableExpr( std::get<1>(p) ); 49 49 } 50 50 if ( ! declMap.empty() ) { 51 51 VarExprReplacer replacer( declMap ); 52 accept ( replacer );52 acceptMutator( replacer ); 53 53 } 54 54 } -
src/SynTree/VarExprReplacer.cc
r049ead9 r7543dec 22 22 VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {} 23 23 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() ) ); 24 VarExprReplacer::~VarExprReplacer() { 25 for ( auto p : declMap ) { 26 delete p.second; 32 27 } 33 28 } 29 30 // replace variable with new node from decl map 31 Expression * VarExprReplacer::mutate( VariableExpr * varExpr ) { 32 // 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) 33 if ( declMap.count( varExpr->var ) ) { 34 Expression * expr = declMap.at( varExpr->var ); 35 if ( debug ) { 36 std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)expr << " " << expr << std::endl; 37 } 38 delete varExpr; 39 return expr->clone(); 40 } 41 return varExpr; 42 } -
src/SynTree/VarExprReplacer.h
r049ead9 r7543dec 24 24 25 25 /// Visitor that replaces the declarations that VariableExprs refer to, according to the supplied mapping 26 class VarExprReplacer : public Visitor {26 class VarExprReplacer : public Mutator { 27 27 public: 28 typedef std::map< DeclarationWithType *, DeclarationWithType* > DeclMap;28 typedef std::map< DeclarationWithType *, Expression * > DeclMap; 29 29 private: 30 30 const DeclMap & declMap; … … 32 32 public: 33 33 VarExprReplacer( const DeclMap & declMap, bool debug = false ); 34 ~VarExprReplacer(); 34 35 35 36 // replace variable with new node from decl map 36 virtual void visit( VariableExpr * varExpr );37 virtual Expression * mutate( VariableExpr * varExpr ); 37 38 38 static void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ) { 39 template<typename Node> 40 static void replace( Node *& node, const DeclMap & declMap, bool debug = false ) { 39 41 VarExprReplacer replacer( declMap, debug ); 40 maybeAccept( node, replacer );42 node = maybeMutate( node, replacer ); 41 43 } 42 44 };
Note: See TracChangeset
for help on using the changeset viewer.