source: src/ResolvExpr/RenameVars.cc@ bdad1679

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 bdad1679 was 44b7088, checked in by Aaron Moss <a3moss@…>, 10 years ago

Added VarArgsType for GCC builtin_va_list var args pack

  • Property mode set to 100644
File size: 4.5 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::visit( VarArgsType *varArgsType ) {
116 typeBefore( varArgsType );
117 typeAfter( varArgsType );
118 }
119
120 void RenameVars::typeBefore( Type *type ) {
121 if ( ! type->get_forall().empty() ) {
122/// std::cout << "type with forall: ";
123/// type->print( std::cout );
124/// std::cout << std::endl;
125 // copies current name mapping into new mapping
126 mapStack.push_front( mapStack.front() );
127 // renames all "forall" type names to `_${level}_${name}'
128 for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
129 std::ostringstream output;
130 output << "_" << level << "_" << (*i)->get_name();
131 std::string newname( output.str() );
132 mapStack.front()[ (*i)->get_name() ] = newname;
133 (*i)->set_name( newname );
134 // ditto for assertion names, the next level in
135 level++;
136 acceptAll( (*i)->get_assertions(), *this );
137 } // for
138 } // if
139 }
140
141 void RenameVars::typeAfter( Type *type ) {
142 // clears name mapping added by typeBefore()
143 if ( ! type->get_forall().empty() ) {
144 mapStack.pop_front();
145 } // if
146 }
147
148} // namespace ResolvExpr
149
150// Local Variables: //
151// tab-width: 4 //
152// mode: c++ //
153// compile-command: "make install" //
154// End: //
Note: See TracBrowser for help on using the repository browser.