Ignore:
Timestamp:
Nov 9, 2017, 1:01:14 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
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)
Message:

Modify VarExprReplacer? to replace VariableExpr? with arbitrary expression

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/VarExprReplacer.cc

    r049ead9 r7543dec  
    2222VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {}
    2323
    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() ) );
     24VarExprReplacer::~VarExprReplacer() {
     25        for ( auto p : declMap ) {
     26                delete p.second;
    3227        }
    3328}
     29
     30// replace variable with new node from decl map
     31Expression * 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}
Note: See TracChangeset for help on using the changeset viewer.