source: src/ResolvExpr/RenameVars.cc @ db46512

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 db46512 was 89e6ffc, checked in by Aaron Moss <a3moss@…>, 8 years ago

Added support for ZeroType? and OneType? to all relevant visitors

  • Property mode set to 100644
File size: 4.1 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// RenameVars.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 12:05:18 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Mar  2 17:36:32 2016
13// Update Count     : 5
14//
15
16#include <sstream>
17
18#include "RenameVars.h"
19#include "SynTree/Visitor.h"
20#include "SynTree/Type.h"
21#include "SynTree/Declaration.h"
22#include "SynTree/Expression.h"
23
24namespace ResolvExpr {
25        RenameVars global_renamer;
26
27        RenameVars::RenameVars() : level( 0 ) {
28                mapStack.push_front( std::map< std::string, std::string >() );
29        }
30
31        void RenameVars::reset() {
32                level = 0;
33        }
34
35        void RenameVars::visit( VoidType *voidType ) {
36                typeBefore( voidType );
37                typeAfter( voidType );
38        }
39
40        void RenameVars::visit( BasicType *basicType ) {
41                typeBefore( basicType );
42                typeAfter( basicType );
43        }
44
45        void RenameVars::visit( PointerType *pointerType ) {
46                typeBefore( pointerType );
47                maybeAccept( pointerType->get_base(), *this );
48                typeAfter( pointerType );
49        }
50
51        void RenameVars::visit( ArrayType *arrayType ) {
52                typeBefore( arrayType );
53                maybeAccept( arrayType->get_dimension(), *this );
54                maybeAccept( arrayType->get_base(), *this );
55                typeAfter( arrayType );
56        }
57
58        void RenameVars::visit( FunctionType *functionType ) {
59                typeBefore( functionType );
60                acceptAll( functionType->get_returnVals(), *this );
61                acceptAll( functionType->get_parameters(), *this );
62                typeAfter( functionType );
63        }
64
65        void RenameVars::visit( StructInstType *aggregateUseType ) {
66                typeBefore( aggregateUseType );
67                acceptAll( aggregateUseType->get_parameters(), *this );
68                typeAfter( aggregateUseType );
69        }
70
71        void RenameVars::visit( UnionInstType *aggregateUseType ) {
72                typeBefore( aggregateUseType );
73                acceptAll( aggregateUseType->get_parameters(), *this );
74                typeAfter( aggregateUseType );
75        }
76
77        void RenameVars::visit( EnumInstType *aggregateUseType ) {
78                typeBefore( aggregateUseType );
79                acceptAll( aggregateUseType->get_parameters(), *this );
80                typeAfter( aggregateUseType );
81        }
82
83        void RenameVars::visit( TraitInstType *aggregateUseType ) {
84                typeBefore( aggregateUseType );
85                acceptAll( aggregateUseType->get_parameters(), *this );
86                acceptAll( aggregateUseType->get_members(), *this );
87                typeAfter( aggregateUseType );
88        }
89
90        void RenameVars::visit( TypeInstType *instType ) {
91                typeBefore( instType );
92                std::map< std::string, std::string >::const_iterator i = mapStack.front().find( instType->get_name() );
93                if ( i != mapStack.front().end() ) {
94                        instType->set_name( i->second );
95                } else {
96                } // if
97                acceptAll( instType->get_parameters(), *this );
98                typeAfter( instType );
99        }
100
101        void RenameVars::visit( TupleType *tupleType ) {
102                typeBefore( tupleType );
103                acceptAll( tupleType->get_types(), *this );
104                typeAfter( tupleType );
105        }
106
107        void RenameVars::visit( VarArgsType *varArgsType ) {
108                typeBefore( varArgsType );
109                typeAfter( varArgsType );
110        }
111
112        void RenameVars::visit( ZeroType *zeroType ) {
113                typeBefore( zeroType );
114                typeAfter( zeroType );
115        }
116
117        void RenameVars::visit( OneType *oneType ) {
118                typeBefore( oneType );
119                typeAfter( oneType );
120        }
121
122        void RenameVars::typeBefore( Type *type ) {
123                if ( ! type->get_forall().empty() ) {
124                        // copies current name mapping into new mapping
125                        mapStack.push_front( mapStack.front() );
126                        // renames all "forall" type names to `_${level}_${name}'
127                        for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
128                                std::ostringstream output;
129                                output << "_" << level << "_" << (*i)->get_name();
130                                std::string newname( output.str() );
131                                mapStack.front()[ (*i)->get_name() ] = newname;
132                                (*i)->set_name( newname );
133                                // ditto for assertion names, the next level in
134                                level++;
135                                acceptAll( (*i)->get_assertions(), *this );
136                        } // for
137                } // if
138        }
139
140        void RenameVars::typeAfter( Type *type ) {
141                // clears name mapping added by typeBefore()
142                if ( ! type->get_forall().empty() ) {
143                        mapStack.pop_front();
144                } // if
145        }
146
147} // namespace ResolvExpr
148
149// Local Variables: //
150// tab-width: 4 //
151// mode: c++ //
152// compile-command: "make install" //
153// End: //
Note: See TracBrowser for help on using the repository browser.