source: src/ResolvExpr/RenameVars.cc@ a465caff

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

Clean up code documentation

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