source: src/ResolvExpr/RenameVars.cc@ 2871210

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 2871210 was 937e51d, checked in by Aaron Moss <a3moss@…>, 10 years ago

Merge pointer to pointer to qualified fix into master

  • Property mode set to 100644
File size: 4.4 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 : Mon Jun 8 14:51:35 2015
13// Update Count : 4
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/// std::cout << "do pointer" << std::endl;
48 maybeAccept( pointerType->get_base(), *this );
49/// std::cout << "done pointer" << std::endl;
50 typeAfter( pointerType );
51 }
52
53 void RenameVars::visit( ArrayType *arrayType ) {
54 typeBefore( arrayType );
55 maybeAccept( arrayType->get_dimension(), *this );
56 maybeAccept( arrayType->get_base(), *this );
57 typeAfter( arrayType );
58 }
59
60 void RenameVars::visit( FunctionType *functionType ) {
61 typeBefore( functionType );
62/// std::cout << "return vals" << std::endl;
63 acceptAll( functionType->get_returnVals(), *this );
64/// std::cout << functionType->get_parameters().size() << " parameters" << std::endl;
65 acceptAll( functionType->get_parameters(), *this );
66/// std::cout << "done function" << std::endl;
67 typeAfter( functionType );
68 }
69
70 void RenameVars::visit( StructInstType *aggregateUseType ) {
71 typeBefore( aggregateUseType );
72 acceptAll( aggregateUseType->get_parameters(), *this );
73 typeAfter( aggregateUseType );
74 }
75
76 void RenameVars::visit( UnionInstType *aggregateUseType ) {
77 typeBefore( aggregateUseType );
78 acceptAll( aggregateUseType->get_parameters(), *this );
79 typeAfter( aggregateUseType );
80 }
81
82 void RenameVars::visit( EnumInstType *aggregateUseType ) {
83 typeBefore( aggregateUseType );
84 acceptAll( aggregateUseType->get_parameters(), *this );
85 typeAfter( aggregateUseType );
86 }
87
88 void RenameVars::visit( ContextInstType *aggregateUseType ) {
89 typeBefore( aggregateUseType );
90 acceptAll( aggregateUseType->get_parameters(), *this );
91 acceptAll( aggregateUseType->get_members(), *this );
92 typeAfter( aggregateUseType );
93 }
94
95 void RenameVars::visit( TypeInstType *instType ) {
96 typeBefore( instType );
97/// std::cout << "instance of type " << instType->get_name() << std::endl;
98 std::map< std::string, std::string >::const_iterator i = mapStack.front().find( instType->get_name() );
99 if ( i != mapStack.front().end() ) {
100/// std::cout << "found name " << i->second << std::endl;
101 instType->set_name( i->second );
102 } else {
103/// std::cout << "no name found" << std::endl;
104 } // if
105 acceptAll( instType->get_parameters(), *this );
106 typeAfter( instType );
107 }
108
109 void RenameVars::visit( TupleType *tupleType ) {
110 typeBefore( tupleType );
111 acceptAll( tupleType->get_types(), *this );
112 typeAfter( tupleType );
113 }
114
115 void RenameVars::typeBefore( Type *type ) {
116 if ( ! type->get_forall().empty() ) {
117/// std::cout << "type with forall: ";
118/// type->print( std::cout );
119/// std::cout << std::endl;
120 // copies current name mapping into new mapping
121 mapStack.push_front( mapStack.front() );
122 // renames all "forall" type names to `_${level}_${name}'
123 for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
124 std::ostringstream output;
125 output << "_" << level << "_" << (*i)->get_name();
126 std::string newname( output.str() );
127 mapStack.front()[ (*i)->get_name() ] = newname;
128 (*i)->set_name( newname );
129 // ditto for assertion names, the next level in
130 level++;
131 acceptAll( (*i)->get_assertions(), *this );
132 } // for
133 } // if
134 }
135
136 void RenameVars::typeAfter( Type *type ) {
137 // clears name mapping added by typeBefore()
138 if ( ! type->get_forall().empty() ) {
139 mapStack.pop_front();
140 } // if
141 }
142
143} // namespace ResolvExpr
144
145// Local Variables: //
146// tab-width: 4 //
147// mode: c++ //
148// compile-command: "make install" //
149// End: //
Note: See TracBrowser for help on using the repository browser.