source: src/SynTree/VarExprReplacer.cc @ 827a190

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 827a190 was c0b9f5d, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Convert VarExprReplacer? to PassVisitor?

  • Property mode set to 100644
File size: 2.0 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// VarExprReplacer.h --
8//
9// Author           : Rob Schluntz
10// Created On       : Wed Jan 13 16:29:30 2016
11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri May 13 11:27:52 2016
13// Update Count     : 5
14//
15
16#include <iostream>       // for operator<<, basic_ostream, ostream, basic_o...
17
18#include "Common/PassVisitor.h"
19#include "Declaration.h"  // for operator<<, DeclarationWithType
20#include "Expression.h"   // for VariableExpr
21#include "VarExprReplacer.h"
22
23namespace VarExprReplacer {
24        namespace {
25                /// Visitor that replaces the declarations that VariableExprs refer to, according to the supplied mapping
26                struct VarExprReplacer {
27                private:
28                        const DeclMap & declMap;
29                        bool debug;
30                public:
31                        VarExprReplacer( const DeclMap & declMap, bool debug = false );
32
33                        // replace variable with new node from decl map
34                        void previsit( VariableExpr * varExpr );
35                };
36        }
37
38        void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
39                PassVisitor<VarExprReplacer> replacer( declMap, debug );
40                maybeAccept( node, replacer );
41        }
42
43        namespace {
44                VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {}
45
46                // replace variable with new node from decl map
47                void VarExprReplacer::previsit( VariableExpr * varExpr ) {
48                        // 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)
49                        if ( declMap.count( varExpr->var ) ) {
50                                if ( debug ) {
51                                        std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)declMap.at( varExpr->var ) << " " << declMap.at( varExpr->var ) << std::endl;
52                                }
53                                varExpr->var = declMap.at( varExpr->var );
54                        }
55                }
56        }
57} // namespace VarExprReplacer
58
59
60
61
62
63
64
Note: See TracBrowser for help on using the repository browser.