Changeset f57dd25 for src/SynTree
- Timestamp:
- May 29, 2019, 3:45:00 PM (6 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:
- 0aedb01
- Parents:
- 157a816 (diff), ebc0a85 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/SynTree
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/DeclReplacer.cc
r157a816 rf57dd25 38 38 void previsit( TypeInstType * inst ); 39 39 }; 40 41 /// Mutator that replaces uses of declarations with arbitrary expressions, according to the supplied mapping 42 struct ExprDeclReplacer { 43 private: 44 const ExprMap & exprMap; 45 bool debug; 46 public: 47 ExprDeclReplacer( const ExprMap & exprMap, bool debug = false ); 48 49 // replace variable with new node from expr map 50 Expression * postmutate( VariableExpr * varExpr ); 51 }; 40 52 } 41 53 … … 53 65 DeclMap declMap; 54 66 replace( node, declMap, typeMap, debug ); 67 } 68 69 void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) { 70 PassVisitor<ExprDeclReplacer> replacer( exprMap, debug ); 71 node = maybeMutate( node, replacer ); 55 72 } 56 73 … … 79 96 } 80 97 } 98 99 ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ) {} 100 101 Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) { 102 if ( exprMap.count( varExpr->var ) ) { 103 Expression * replacement = exprMap.at( varExpr->var )->clone(); 104 if ( debug ) { 105 std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)replacement << " " << replacement << std::endl; 106 } 107 std::swap( varExpr->env, replacement->env ); 108 delete varExpr; 109 return replacement; 110 } 111 return varExpr; 112 } 81 113 } 82 114 } // namespace VarExprReplacer -
src/SynTree/DeclReplacer.h
r157a816 rf57dd25 26 26 typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap; 27 27 typedef std::map< TypeDecl *, TypeDecl * > TypeMap; 28 typedef std::map< DeclarationWithType *, Expression * > ExprMap; 28 29 29 30 void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ); 30 31 void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false ); 31 32 void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 33 34 void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false); 35 template<typename T> 36 void replace( T *& node, const ExprMap & exprMap, bool debug = false ) { 37 if ( ! node ) return; 38 BaseSyntaxNode * arg = node; 39 replace( arg, exprMap, debug ); 40 node = dynamic_cast<T *>( arg ); 41 assertf( node, "DeclReplacer fundamentally changed the type of its argument." ); 42 } 32 43 } 33 44 -
src/SynTree/Expression.cc
r157a816 rf57dd25 538 538 assert( callExpr ); 539 539 assert( callExpr->result ); 540 set_result( callExpr-> get_result()->clone() );540 set_result( callExpr->result->clone() ); 541 541 } 542 542 543 543 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { 544 cloneAll( other.tempDecls, tempDecls );545 cloneAll( other.returnDecls, returnDecls );546 cloneAll( other.dtors, dtors );547 544 } 548 545 … … 550 547 set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment 551 548 delete callExpr; 552 deleteAll( tempDecls );553 deleteAll( returnDecls );554 deleteAll( dtors );555 549 } 556 550 … … 558 552 os << "Implicit Copy Constructor Expression: " << std::endl << indent+1; 559 553 callExpr->print( os, indent+1 ); 560 os << std::endl << indent << "... with temporaries:" << std::endl;561 printAll( tempDecls, os, indent+1 );562 os << std::endl << indent << "... with return temporaries:" << std::endl;563 printAll( returnDecls, os, indent+1 );564 Expression::print( os, indent );565 554 } 566 555 -
src/SynTree/Expression.h
r157a816 rf57dd25 593 593 class ImplicitCopyCtorExpr : public Expression { 594 594 public: 595 ApplicationExpr * callExpr; 596 std::list< ObjectDecl * > tempDecls; 597 std::list< ObjectDecl * > returnDecls; 598 std::list< Expression * > dtors; 595 ApplicationExpr * callExpr = nullptr; 599 596 600 597 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 601 598 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 602 599 virtual ~ImplicitCopyCtorExpr(); 603 604 ApplicationExpr * get_callExpr() const { return callExpr; }605 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }606 607 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }608 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }609 std::list< Expression * > & get_dtors() { return dtors; }610 600 611 601 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
Note:
See TracChangeset
for help on using the changeset viewer.