Ignore:
Timestamp:
May 30, 2019, 4:15:08 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
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:
a935892, f474e91
Parents:
d76c588 (diff), d88f8b3b (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/DeclReplacer.cc

    rd76c588 r8d70648  
    3838                        void previsit( TypeInstType * inst );
    3939                };
     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                };
    4052        }
    4153
     
    5365                DeclMap declMap;
    5466                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 );
    5572        }
    5673
     
    7996                        }
    8097                }
     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                }
    81113        }
    82114} // namespace VarExprReplacer
Note: See TracChangeset for help on using the changeset viewer.