Changeset f240484
- Timestamp:
- Jan 8, 2018, 4:20:38 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:
- 07c178f0
- Parents:
- b3fc977
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
rb3fc977 rf240484 36 36 namespace Tuples { 37 37 namespace { 38 struct MemberTupleExpander final : public Mutator { 39 typedef Mutator Parent; 40 using Parent::mutate; 41 42 virtual Expression * mutate( UntypedMemberExpr * memberExpr ) override; 38 struct MemberTupleExpander final : public WithShortCircuiting, public WithVisitorRef<MemberTupleExpander> { 39 void premutate( UntypedMemberExpr * ) { visit_children = false; } 40 Expression * postmutate( UntypedMemberExpr * memberExpr ); 43 41 }; 44 42 … … 79 77 80 78 void expandMemberTuples( std::list< Declaration * > & translationUnit ) { 81 MemberTupleExpanderexpander;79 PassVisitor<MemberTupleExpander> expander; 82 80 mutateAll( translationUnit, expander ); 83 81 } … … 109 107 // construct a new UntypedMemberExpr with the correct structure , and recursively 110 108 // expand that member expression. 111 MemberTupleExpanderexpander;112 UntypedMemberExpr * inner = new UntypedMemberExpr( memberExpr-> get_aggregate(), aggr->clone() );113 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr-> get_member(), inner );109 PassVisitor<MemberTupleExpander> expander; 110 UntypedMemberExpr * inner = new UntypedMemberExpr( memberExpr->aggregate, aggr->clone() ); 111 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->member, inner ); 114 112 inner->location = newMemberExpr->location = loc; 115 memberExpr-> set_member(nullptr);116 memberExpr-> set_aggregate(nullptr);113 memberExpr->member = nullptr; 114 memberExpr->aggregate = nullptr; 117 115 delete memberExpr; 118 116 return newMemberExpr->acceptMutator( expander ); … … 126 124 } 127 125 128 Expression * MemberTupleExpander:: mutate( UntypedMemberExpr * memberExpr ) {129 if ( UntypedTupleExpr * tupleExpr = dynamic_cast< UntypedTupleExpr * > ( memberExpr-> get_member()) ) {130 Expression * aggr = memberExpr-> get_aggregate()->clone()->acceptMutator( *this);126 Expression * MemberTupleExpander::postmutate( UntypedMemberExpr * memberExpr ) { 127 if ( UntypedTupleExpr * tupleExpr = dynamic_cast< UntypedTupleExpr * > ( memberExpr->member ) ) { 128 Expression * aggr = memberExpr->aggregate->clone()->acceptMutator( *visitor ); 131 129 // aggregate expressions which might be impure must be wrapped in unique expressions 132 130 // xxx - if there's a member-tuple expression nested in the aggregate, this currently generates the wrong code if a UniqueExpr is not used, and it's purely an optimization to remove the UniqueExpr 133 131 // if ( Tuples::maybeImpureIgnoreUnique( memberExpr->get_aggregate() ) ) aggr = new UniqueExpr( aggr ); 134 132 aggr = new UniqueExpr( aggr ); 135 for ( Expression *& expr : tupleExpr-> get_exprs()) {133 for ( Expression *& expr : tupleExpr->exprs ) { 136 134 expr = reconstructMemberExpr( expr, aggr, memberExpr->location ); 137 135 expr->location = memberExpr->location; … … 143 141 // there may be a tuple expr buried in the aggregate 144 142 // xxx - this is a memory leak 145 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr-> get_member()->clone(), memberExpr->get_aggregate()->acceptMutator( *this) );143 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->member->clone(), memberExpr->aggregate->acceptMutator( *visitor ) ); 146 144 newMemberExpr->location = memberExpr->location; 147 145 return newMemberExpr;
Note: See TracChangeset
for help on using the changeset viewer.