Changeset f240484


Ignore:
Timestamp:
Jan 8, 2018, 4:20:38 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
07c178f0
Parents:
b3fc977
Message:

Convert MemberTupleExpander? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    rb3fc977 rf240484  
    3636namespace Tuples {
    3737        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 );
    4341                };
    4442
     
    7977
    8078        void expandMemberTuples( std::list< Declaration * > & translationUnit ) {
    81                 MemberTupleExpander expander;
     79                PassVisitor<MemberTupleExpander> expander;
    8280                mutateAll( translationUnit, expander );
    8381        }
     
    109107                                // construct a new UntypedMemberExpr with the correct structure , and recursively
    110108                                // expand that member expression.
    111                                 MemberTupleExpander expander;
    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 );
    114112                                inner->location = newMemberExpr->location = loc;
    115                                 memberExpr->set_member(nullptr);
    116                                 memberExpr->set_aggregate(nullptr);
     113                                memberExpr->member = nullptr;
     114                                memberExpr->aggregate = nullptr;
    117115                                delete memberExpr;
    118116                                return newMemberExpr->acceptMutator( expander );
     
    126124        }
    127125
    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 );
    131129                        // aggregate expressions which might be impure must be wrapped in unique expressions
    132130                        // 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
    133131                        // if ( Tuples::maybeImpureIgnoreUnique( memberExpr->get_aggregate() ) ) aggr = new UniqueExpr( aggr );
    134132                        aggr = new UniqueExpr( aggr );
    135                         for ( Expression *& expr : tupleExpr->get_exprs() ) {
     133                        for ( Expression *& expr : tupleExpr->exprs ) {
    136134                                expr = reconstructMemberExpr( expr, aggr, memberExpr->location );
    137135                                expr->location = memberExpr->location;
     
    143141                        // there may be a tuple expr buried in the aggregate
    144142                        // 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 ) );
    146144                        newMemberExpr->location = memberExpr->location;
    147145                        return newMemberExpr;
Note: See TracChangeset for help on using the changeset viewer.