source: src/SynTree/Visitor.cc @ b18b0b5

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

Added support for alignof expressions for everything but polymorphic types

  • Property mode set to 100644
File size: 10.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// Visitor.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul 24 16:11:05 2015
13// Update Count     : 15
14//
15
16#include <cassert>
17#include "Visitor.h"
18#include "Initializer.h"
19#include "Statement.h"
20#include "Type.h"
21#include "Declaration.h"
22#include "Expression.h"
23#include "Constant.h"
24
25Visitor::Visitor() {}
26
27Visitor::~Visitor() {}
28
29void Visitor::visit( ObjectDecl *objectDecl ) {
30        maybeAccept( objectDecl->get_type(), *this );
31        maybeAccept( objectDecl->get_init(), *this );
32        maybeAccept( objectDecl->get_bitfieldWidth(), *this );
33}
34
35void Visitor::visit( FunctionDecl *functionDecl ) {
36        maybeAccept( functionDecl->get_functionType(), *this );
37        acceptAll( functionDecl->get_oldDecls(), *this );
38        maybeAccept( functionDecl->get_statements(), *this );
39}
40
41void Visitor::visit( AggregateDecl *aggregateDecl ) {
42        acceptAll( aggregateDecl->get_parameters(), *this );
43        acceptAll( aggregateDecl->get_members(), *this );
44}
45
46void Visitor::visit( StructDecl *aggregateDecl ) {
47        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
48}
49
50void Visitor::visit( UnionDecl *aggregateDecl ) {
51        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
52}
53
54void Visitor::visit( EnumDecl *aggregateDecl ) {
55        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
56}
57
58void Visitor::visit( ContextDecl *aggregateDecl ) {
59        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
60}
61
62void Visitor::visit( NamedTypeDecl *typeDecl ) {
63        acceptAll( typeDecl->get_parameters(), *this );
64        acceptAll( typeDecl->get_assertions(), *this );
65        maybeAccept( typeDecl->get_base(), *this );
66}
67
68void Visitor::visit( TypeDecl *typeDecl ) {
69        visit( static_cast< NamedTypeDecl* >( typeDecl ) );
70}
71
72void Visitor::visit( TypedefDecl *typeDecl ) {
73        visit( static_cast< NamedTypeDecl* >( typeDecl ) );
74}
75
76void Visitor::visit( CompoundStmt *compoundStmt ) {
77        acceptAll( compoundStmt->get_kids(), *this );
78}
79
80void Visitor::visit( ExprStmt *exprStmt ) {
81        maybeAccept( exprStmt->get_expr(), *this );
82}
83
84void Visitor::visit( AsmStmt *asmStmt ) {
85        maybeAccept( asmStmt->get_instruction(), *this );
86        acceptAll( asmStmt->get_output(), *this );
87        acceptAll( asmStmt->get_input(), *this );
88        acceptAll( asmStmt->get_clobber(), *this );
89}
90
91void Visitor::visit( IfStmt *ifStmt ) {
92        maybeAccept( ifStmt->get_condition(), *this );
93        maybeAccept( ifStmt->get_thenPart(), *this );
94        maybeAccept( ifStmt->get_elsePart(), *this );
95}
96
97void Visitor::visit( WhileStmt *whileStmt ) {
98        maybeAccept( whileStmt->get_condition(), *this );
99        maybeAccept( whileStmt->get_body(), *this );
100}
101
102void Visitor::visit( ForStmt *forStmt ) {
103        acceptAll( forStmt->get_initialization(), *this );
104        maybeAccept( forStmt->get_condition(), *this );
105        maybeAccept( forStmt->get_increment(), *this );
106        maybeAccept( forStmt->get_body(), *this );
107}
108
109void Visitor::visit( SwitchStmt *switchStmt ) {
110        maybeAccept( switchStmt->get_condition(), *this );
111        acceptAll( switchStmt->get_branches(), *this );
112}
113
114void Visitor::visit( ChooseStmt *switchStmt ) {
115        maybeAccept( switchStmt->get_condition(), *this );
116        acceptAll( switchStmt->get_branches(), *this );
117}
118
119void Visitor::visit( FallthruStmt *fallthruStmt ) {}
120
121void Visitor::visit( CaseStmt *caseStmt ) {
122        maybeAccept( caseStmt->get_condition(), *this );
123        acceptAll( caseStmt->get_statements(), *this );
124}
125
126void Visitor::visit( BranchStmt *branchStmt ) {
127}
128
129void Visitor::visit( ReturnStmt *returnStmt ) {
130        maybeAccept( returnStmt->get_expr(), *this );
131}
132
133void Visitor::visit( TryStmt *tryStmt ) {
134        maybeAccept( tryStmt->get_block(), *this );
135        acceptAll( tryStmt->get_catchers(), *this );
136}
137
138void Visitor::visit( CatchStmt *catchStmt ) {
139        maybeAccept( catchStmt->get_decl(), *this );
140        maybeAccept( catchStmt->get_body(), *this );
141}
142
143void Visitor::visit( FinallyStmt *finalStmt ) {
144        maybeAccept( finalStmt->get_block(), *this );
145}
146
147void Visitor::visit( NullStmt *nullStmt ) {
148}
149
150void Visitor::visit( DeclStmt *declStmt ) {
151        maybeAccept( declStmt->get_decl(), *this );
152}
153
154void Visitor::visit( ApplicationExpr *applicationExpr ) {
155        acceptAll( applicationExpr->get_results(), *this );
156        maybeAccept( applicationExpr->get_function(), *this );
157        acceptAll( applicationExpr->get_args(), *this );
158}
159
160void Visitor::visit( UntypedExpr *untypedExpr ) {
161        acceptAll( untypedExpr->get_results(), *this );
162        acceptAll( untypedExpr->get_args(), *this );
163}
164
165void Visitor::visit( NameExpr *nameExpr ) {
166        acceptAll( nameExpr->get_results(), *this );
167}
168
169void Visitor::visit( AddressExpr *addressExpr ) {
170        acceptAll( addressExpr->get_results(), *this );
171        maybeAccept( addressExpr->get_arg(), *this );
172}
173
174void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
175        acceptAll( labAddressExpr->get_results(), *this );
176        maybeAccept( labAddressExpr->get_arg(), *this );
177}
178
179void Visitor::visit( CastExpr *castExpr ) {
180        acceptAll( castExpr->get_results(), *this );
181        maybeAccept( castExpr->get_arg(), *this );
182}
183
184void Visitor::visit( UntypedMemberExpr *memberExpr ) {
185        acceptAll( memberExpr->get_results(), *this );
186        maybeAccept( memberExpr->get_aggregate(), *this );
187}
188
189void Visitor::visit( MemberExpr *memberExpr ) {
190        acceptAll( memberExpr->get_results(), *this );
191        maybeAccept( memberExpr->get_aggregate(), *this );
192}
193
194void Visitor::visit( VariableExpr *variableExpr ) {
195        acceptAll( variableExpr->get_results(), *this );
196}
197
198void Visitor::visit( ConstantExpr *constantExpr ) {
199        acceptAll( constantExpr->get_results(), *this );
200        maybeAccept( constantExpr->get_constant(), *this );
201}
202
203void Visitor::visit( SizeofExpr *sizeofExpr ) {
204        acceptAll( sizeofExpr->get_results(), *this );
205        if ( sizeofExpr->get_isType() ) {
206                maybeAccept( sizeofExpr->get_type(), *this );
207        } else {
208                maybeAccept( sizeofExpr->get_expr(), *this );
209        }
210}
211
212void Visitor::visit( AlignofExpr *alignofExpr ) {
213        acceptAll( alignofExpr->get_results(), *this );
214        if ( alignofExpr->get_isType() ) {
215                maybeAccept( alignofExpr->get_type(), *this );
216        } else {
217                maybeAccept( alignofExpr->get_expr(), *this );
218        }
219}
220
221void Visitor::visit( AttrExpr *attrExpr ) {
222        acceptAll( attrExpr->get_results(), *this );
223        if ( attrExpr->get_isType() ) {
224                maybeAccept( attrExpr->get_type(), *this );
225        } else {
226                maybeAccept( attrExpr->get_expr(), *this );
227        }
228}
229
230void Visitor::visit( LogicalExpr *logicalExpr ) {
231        acceptAll( logicalExpr->get_results(), *this );
232        maybeAccept( logicalExpr->get_arg1(), *this );
233        maybeAccept( logicalExpr->get_arg2(), *this );
234}
235
236void Visitor::visit( ConditionalExpr *conditionalExpr ) {
237        acceptAll( conditionalExpr->get_results(), *this );
238        maybeAccept( conditionalExpr->get_arg1(), *this );
239        maybeAccept( conditionalExpr->get_arg2(), *this );
240        maybeAccept( conditionalExpr->get_arg3(), *this );
241}
242
243void Visitor::visit( CommaExpr *commaExpr ) {
244        acceptAll( commaExpr->get_results(), *this );
245        maybeAccept( commaExpr->get_arg1(), *this );
246        maybeAccept( commaExpr->get_arg2(), *this );
247}
248
249void Visitor::visit( TupleExpr *tupleExpr ) {
250        acceptAll( tupleExpr->get_results(), *this );
251        acceptAll( tupleExpr->get_exprs(), *this );
252}
253
254void Visitor::visit( SolvedTupleExpr *tupleExpr ) {
255        acceptAll( tupleExpr->get_results(), *this );
256        acceptAll( tupleExpr->get_exprs(), *this );
257}
258
259void Visitor::visit( TypeExpr *typeExpr ) {
260        acceptAll( typeExpr->get_results(), *this );
261        maybeAccept( typeExpr->get_type(), *this );
262}
263
264void Visitor::visit( AsmExpr *asmExpr ) {
265        maybeAccept( asmExpr->get_inout(), *this );
266        maybeAccept( asmExpr->get_constraint(), *this );
267        maybeAccept( asmExpr->get_operand(), *this );
268}
269
270void Visitor::visit( UntypedValofExpr *valofExpr ) {
271        acceptAll( valofExpr->get_results(), *this );
272        maybeAccept( valofExpr->get_body(), *this );
273}
274
275void Visitor::visit( VoidType *voidType ) {
276        acceptAll( voidType->get_forall(), *this );
277}
278
279void Visitor::visit( BasicType *basicType ) {
280        acceptAll( basicType->get_forall(), *this );
281}
282
283void Visitor::visit( PointerType *pointerType ) {
284        acceptAll( pointerType->get_forall(), *this );
285        maybeAccept( pointerType->get_base(), *this );
286}
287
288void Visitor::visit( ArrayType *arrayType ) {
289        acceptAll( arrayType->get_forall(), *this );
290        maybeAccept( arrayType->get_dimension(), *this );
291        maybeAccept( arrayType->get_base(), *this );
292}
293
294void Visitor::visit( FunctionType *functionType ) {
295        acceptAll( functionType->get_forall(), *this );
296        acceptAll( functionType->get_returnVals(), *this );
297        acceptAll( functionType->get_parameters(), *this );
298}
299
300void Visitor::visit( ReferenceToType *aggregateUseType ) {
301        acceptAll( aggregateUseType->get_forall(), *this );
302        acceptAll( aggregateUseType->get_parameters(), *this );
303}
304
305void Visitor::visit( StructInstType *aggregateUseType ) {
306        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
307}
308
309void Visitor::visit( UnionInstType *aggregateUseType ) {
310        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
311}
312
313void Visitor::visit( EnumInstType *aggregateUseType ) {
314        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
315}
316
317void Visitor::visit( ContextInstType *aggregateUseType ) {
318        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
319        acceptAll( aggregateUseType->get_members(), *this );
320}
321
322void Visitor::visit( TypeInstType *aggregateUseType ) {
323        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
324}
325
326void Visitor::visit( TupleType *tupleType ) {
327        acceptAll( tupleType->get_forall(), *this );
328        acceptAll( tupleType->get_types(), *this );
329}
330
331void Visitor::visit( TypeofType *typeofType ) {
332        assert( typeofType->get_expr() );
333        typeofType->get_expr()->accept( *this );
334}
335
336void Visitor::visit( AttrType *attrType ) {
337        if ( attrType->get_isType() ) {
338                assert( attrType->get_type() );
339                attrType->get_type()->accept( *this );
340        } else {
341                assert( attrType->get_expr() );
342                attrType->get_expr()->accept( *this );
343        } // if
344}
345
346void Visitor::visit( SingleInit *singleInit ) {
347        singleInit->get_value()->accept( *this );
348}
349
350void Visitor::visit( ListInit *listInit ) {
351        acceptAll( listInit->get_designators(), *this );
352        acceptAll( listInit->get_initializers(), *this );
353}
354
355void Visitor::visit( Subrange *subrange ) {}
356
357void Visitor::visit( Constant *constant ) {}
358// Local Variables: //
359// tab-width: 4 //
360// mode: c++ //
361// compile-command: "make install" //
362// End: //
Note: See TracBrowser for help on using the repository browser.