source: translator/ResolvExpr/RenameVars.cc @ 3c70d38

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 3c70d38 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: RenameVars.cc,v 1.4 2005/08/29 20:14:16 rcbilson Exp $
5 *
6 */
7
8#include <strstream>
9
10#include "RenameVars.h"
11#include "SynTree/Visitor.h"
12#include "SynTree/Type.h"
13#include "SynTree/Declaration.h"
14#include "SynTree/Expression.h"
15
16namespace ResolvExpr {
17
18RenameVars global_renamer;
19
20RenameVars::RenameVars()
21  : level( 0 )
22{
23  mapStack.push_front( std::map< std::string, std::string >() );
24}
25
26void 
27RenameVars::reset()
28{
29  level = 0;
30}
31
32void 
33RenameVars::visit( VoidType *voidType )
34{
35  typeBefore( voidType );
36  typeAfter( voidType );
37}
38
39void 
40RenameVars::visit( BasicType *basicType )
41{
42  typeBefore( basicType );
43  typeAfter( basicType );
44}
45
46void 
47RenameVars::visit( PointerType *pointerType )
48{
49  typeBefore( pointerType );
50///   std::cout << "do pointer" << std::endl;
51  maybeAccept( pointerType->get_base(), *this );
52///   std::cout << "done pointer" << std::endl;
53  typeAfter( pointerType );
54}
55
56void 
57RenameVars::visit( ArrayType *arrayType )
58{
59  typeBefore( arrayType );
60  maybeAccept( arrayType->get_dimension(), *this );
61  maybeAccept( arrayType->get_base(), *this );
62  typeAfter( arrayType );
63}
64
65void 
66RenameVars::visit( FunctionType *functionType )
67{
68  typeBefore( functionType );
69///   std::cout << "return vals" << std::endl;
70  acceptAll( functionType->get_returnVals(), *this );
71///   std::cout << functionType->get_parameters().size() << " parameters" << std::endl;
72  acceptAll( functionType->get_parameters(), *this );
73///   std::cout << "done function" << std::endl;
74  typeAfter( functionType );
75}
76
77void 
78RenameVars::visit( StructInstType *aggregateUseType )
79{
80  typeBefore( aggregateUseType );
81  acceptAll( aggregateUseType->get_parameters(), *this );
82  typeAfter( aggregateUseType );
83}
84
85void 
86RenameVars::visit( UnionInstType *aggregateUseType )
87{
88  typeBefore( aggregateUseType );
89  acceptAll( aggregateUseType->get_parameters(), *this );
90  typeAfter( aggregateUseType );
91}
92
93void 
94RenameVars::visit( EnumInstType *aggregateUseType )
95{
96  typeBefore( aggregateUseType );
97  acceptAll( aggregateUseType->get_parameters(), *this );
98  typeAfter( aggregateUseType );
99}
100
101void 
102RenameVars::visit( ContextInstType *aggregateUseType )
103{
104  typeBefore( aggregateUseType );
105  acceptAll( aggregateUseType->get_parameters(), *this );
106  acceptAll( aggregateUseType->get_members(), *this );
107  typeAfter( aggregateUseType );
108}
109
110void 
111RenameVars::visit( TypeInstType *instType )
112{
113  typeBefore( instType );
114///   std::cout << "instance of type " << instType->get_name() << std::endl;
115  std::map< std::string, std::string >::const_iterator i = mapStack.front().find( instType->get_name() );
116  if( i != mapStack.front().end() ) {
117///     std::cout << "found name " << i->second << std::endl;
118    instType->set_name( i->second );
119  } else {
120///     std::cout << "no name found" << std::endl;
121  }
122  acceptAll( instType->get_parameters(), *this );
123  typeAfter( instType );
124}
125
126void 
127RenameVars::visit( TupleType *tupleType )
128{
129  typeBefore( tupleType );
130  acceptAll( tupleType->get_types(), *this );
131  typeAfter( tupleType );
132}
133
134void 
135RenameVars::typeBefore( Type *type )
136{
137  if( !type->get_forall().empty() ) {
138///     std::cout << "type with forall: ";
139///     type->print( std::cout );
140///     std::cout << std::endl;
141    mapStack.push_front( mapStack.front() );
142    for( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
143      std::ostrstream output;
144      output << "_" << level << "_" << (*i)->get_name();
145      std::string newname( output.str(), output.pcount() );
146      mapStack.front()[ (*i)->get_name() ] = newname;
147      (*i)->set_name( newname );
148      level++;
149      acceptAll( (*i)->get_assertions(), *this );
150    }
151  }
152}
153
154void 
155RenameVars::typeAfter( Type *type )
156{
157  if( !type->get_forall().empty() ) {
158    mapStack.pop_front();
159  }
160}
161
162} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.