source: src/SynTree/Visitor.cc @ 0873968c

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 0873968c was 5ea7a22, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Make Attribute a child of BaseSyntaxNode?

  • Property mode set to 100644
File size: 14.9 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 : Thu Aug 17 15:39:38 2017
13// Update Count     : 29
14//
15
16#include <cassert>        // for assert
17#include <list>           // for list
18
19#include "Attribute.h"    // for Attribute
20#include "Constant.h"     // for Constant
21#include "Declaration.h"  // for DeclarationWithType, ObjectDecl, Declaration
22#include "Expression.h"   // for Expression, ConstantExpr, ImplicitCopyCtorExpr
23#include "Initializer.h"  // for Initializer, Designation, ConstructorInit
24#include "Statement.h"    // for Statement, CatchStmt, AsmStmt, CompoundStmt
25#include "Type.h"         // for Type, Type::ForallList, AttrType, FunctionType
26#include "Visitor.h"
27
28class Subrange;
29
30Visitor::Visitor() {}
31
32Visitor::~Visitor() {}
33
34void Visitor::visit( ObjectDecl *objectDecl ) {
35        maybeAccept( objectDecl->get_type(), *this );
36        maybeAccept( objectDecl->get_init(), *this );
37        maybeAccept( objectDecl->get_bitfieldWidth(), *this );
38        acceptAll( objectDecl->attributes, *this );
39}
40
41void Visitor::visit( FunctionDecl *functionDecl ) {
42        maybeAccept( functionDecl->get_functionType(), *this );
43        maybeAccept( functionDecl->get_statements(), *this );
44        acceptAll( functionDecl->attributes, *this );
45}
46
47void Visitor::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
48        acceptAll( aggregateDecl->get_parameters(), *this );
49        acceptAll( aggregateDecl->get_members(), *this );
50}
51
52void Visitor::visit( StructDecl *aggregateDecl ) {
53        handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
54}
55
56void Visitor::visit( UnionDecl *aggregateDecl ) {
57        handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
58}
59
60void Visitor::visit( EnumDecl *aggregateDecl ) {
61        handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
62}
63
64void Visitor::visit( TraitDecl *aggregateDecl ) {
65        handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
66}
67
68void Visitor::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
69        acceptAll( typeDecl->get_parameters(), *this );
70        acceptAll( typeDecl->get_assertions(), *this );
71        maybeAccept( typeDecl->get_base(), *this );
72}
73
74void Visitor::visit( TypeDecl *typeDecl ) {
75        handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
76        maybeAccept( typeDecl->get_init(), *this );
77}
78
79void Visitor::visit( TypedefDecl *typeDecl ) {
80        handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
81}
82
83void Visitor::visit( AsmDecl *asmDecl ) {
84        maybeAccept( asmDecl->get_stmt(), *this );
85}
86
87
88void Visitor::visit( CompoundStmt *compoundStmt ) {
89        acceptAll( compoundStmt->get_kids(), *this );
90}
91
92void Visitor::visit( ExprStmt *exprStmt ) {
93        maybeAccept( exprStmt->get_expr(), *this );
94}
95
96void Visitor::visit( AsmStmt *asmStmt ) {
97        maybeAccept( asmStmt->get_instruction(), *this );
98        acceptAll( asmStmt->get_output(), *this );
99        acceptAll( asmStmt->get_input(), *this );
100        acceptAll( asmStmt->get_clobber(), *this );
101}
102
103void Visitor::visit( IfStmt *ifStmt ) {
104        acceptAll( ifStmt->get_initialization(), *this );
105        maybeAccept( ifStmt->get_condition(), *this );
106        maybeAccept( ifStmt->get_thenPart(), *this );
107        maybeAccept( ifStmt->get_elsePart(), *this );
108}
109
110void Visitor::visit( WhileStmt *whileStmt ) {
111        maybeAccept( whileStmt->get_condition(), *this );
112        maybeAccept( whileStmt->get_body(), *this );
113}
114
115void Visitor::visit( ForStmt *forStmt ) {
116        acceptAll( forStmt->get_initialization(), *this );
117        maybeAccept( forStmt->get_condition(), *this );
118        maybeAccept( forStmt->get_increment(), *this );
119        maybeAccept( forStmt->get_body(), *this );
120}
121
122void Visitor::visit( SwitchStmt *switchStmt ) {
123        maybeAccept( switchStmt->get_condition(), *this );
124        acceptAll( switchStmt->get_statements(), *this );
125}
126
127void Visitor::visit( CaseStmt *caseStmt ) {
128        maybeAccept( caseStmt->get_condition(), *this );
129        acceptAll( caseStmt->get_statements(), *this );
130}
131
132void Visitor::visit( __attribute__((unused)) BranchStmt *branchStmt ) {
133}
134
135void Visitor::visit( ReturnStmt *returnStmt ) {
136        maybeAccept( returnStmt->get_expr(), *this );
137}
138
139void Visitor::visit( ThrowStmt * throwStmt ) {
140        maybeAccept( throwStmt->get_expr(), *this );
141        maybeAccept( throwStmt->get_target(), *this );
142}
143
144void Visitor::visit( TryStmt *tryStmt ) {
145        maybeAccept( tryStmt->get_block(), *this );
146        acceptAll( tryStmt->get_catchers(), *this );
147        maybeAccept( tryStmt->get_finally(), *this );
148}
149
150void Visitor::visit( CatchStmt *catchStmt ) {
151        maybeAccept( catchStmt->get_decl(), *this );
152        maybeAccept( catchStmt->get_cond(), *this );
153        maybeAccept( catchStmt->get_body(), *this );
154}
155
156void Visitor::visit( FinallyStmt *finalStmt ) {
157        maybeAccept( finalStmt->get_block(), *this );
158}
159
160void Visitor::visit( WaitForStmt *waitforStmt ) {
161        for( auto & clause : waitforStmt->clauses ) {
162                maybeAccept( clause.target.function, *this );
163                acceptAll( clause.target.arguments, *this );
164
165                maybeAccept( clause.statement, *this );
166                maybeAccept( clause.condition, *this );
167        }
168
169        maybeAccept( waitforStmt->timeout.time, *this );
170        maybeAccept( waitforStmt->timeout.statement, *this );
171        maybeAccept( waitforStmt->timeout.condition, *this );
172        maybeAccept( waitforStmt->orelse.statement, *this );
173        maybeAccept( waitforStmt->orelse.condition, *this );
174}
175
176void Visitor::visit( __attribute__((unused)) NullStmt *nullStmt ) {
177}
178
179void Visitor::visit( DeclStmt *declStmt ) {
180        maybeAccept( declStmt->get_decl(), *this );
181}
182
183void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) {
184        maybeAccept( impCtorDtorStmt->get_callStmt(), *this );
185}
186
187
188void Visitor::visit( ApplicationExpr *applicationExpr ) {
189        maybeAccept( applicationExpr->get_result(), *this );
190        maybeAccept( applicationExpr->get_function(), *this );
191        acceptAll( applicationExpr->get_args(), *this );
192}
193
194void Visitor::visit( UntypedExpr *untypedExpr ) {
195        maybeAccept( untypedExpr->get_result(), *this );
196        acceptAll( untypedExpr->get_args(), *this );
197}
198
199void Visitor::visit( NameExpr *nameExpr ) {
200        maybeAccept( nameExpr->get_result(), *this );
201}
202
203void Visitor::visit( AddressExpr *addressExpr ) {
204        maybeAccept( addressExpr->get_result(), *this );
205        maybeAccept( addressExpr->get_arg(), *this );
206}
207
208void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
209        maybeAccept( labAddressExpr->get_result(), *this );
210}
211
212void Visitor::visit( CastExpr *castExpr ) {
213        maybeAccept( castExpr->get_result(), *this );
214        maybeAccept( castExpr->get_arg(), *this );
215}
216
217void Visitor::visit( VirtualCastExpr *castExpr ) {
218        maybeAccept( castExpr->get_result(), *this );
219        maybeAccept( castExpr->get_arg(), *this );
220}
221
222void Visitor::visit( UntypedMemberExpr *memberExpr ) {
223        maybeAccept( memberExpr->get_result(), *this );
224        maybeAccept( memberExpr->get_aggregate(), *this );
225        maybeAccept( memberExpr->get_member(), *this );
226}
227
228void Visitor::visit( MemberExpr *memberExpr ) {
229        maybeAccept( memberExpr->get_result(), *this );
230        maybeAccept( memberExpr->get_aggregate(), *this );
231}
232
233void Visitor::visit( VariableExpr *variableExpr ) {
234        maybeAccept( variableExpr->get_result(), *this );
235}
236
237void Visitor::visit( ConstantExpr *constantExpr ) {
238        maybeAccept( constantExpr->get_result(), *this );
239        maybeAccept( constantExpr->get_constant(), *this );
240}
241
242void Visitor::visit( SizeofExpr *sizeofExpr ) {
243        maybeAccept( sizeofExpr->get_result(), *this );
244        if ( sizeofExpr->get_isType() ) {
245                maybeAccept( sizeofExpr->get_type(), *this );
246        } else {
247                maybeAccept( sizeofExpr->get_expr(), *this );
248        }
249}
250
251void Visitor::visit( AlignofExpr *alignofExpr ) {
252        maybeAccept( alignofExpr->get_result(), *this );
253        if ( alignofExpr->get_isType() ) {
254                maybeAccept( alignofExpr->get_type(), *this );
255        } else {
256                maybeAccept( alignofExpr->get_expr(), *this );
257        }
258}
259
260void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
261        maybeAccept( offsetofExpr->get_result(), *this );
262        maybeAccept( offsetofExpr->get_type(), *this );
263}
264
265void Visitor::visit( OffsetofExpr *offsetofExpr ) {
266        maybeAccept( offsetofExpr->get_result(), *this );
267        maybeAccept( offsetofExpr->get_type(), *this );
268        maybeAccept( offsetofExpr->get_member(), *this );
269}
270
271void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
272        maybeAccept( offsetPackExpr->get_result(), *this );
273        maybeAccept( offsetPackExpr->get_type(), *this );
274}
275
276void Visitor::visit( AttrExpr *attrExpr ) {
277        maybeAccept( attrExpr->get_result(), *this );
278        if ( attrExpr->get_isType() ) {
279                maybeAccept( attrExpr->get_type(), *this );
280        } else {
281                maybeAccept( attrExpr->get_expr(), *this );
282        }
283}
284
285void Visitor::visit( LogicalExpr *logicalExpr ) {
286        maybeAccept( logicalExpr->get_result(), *this );
287        maybeAccept( logicalExpr->get_arg1(), *this );
288        maybeAccept( logicalExpr->get_arg2(), *this );
289}
290
291void Visitor::visit( ConditionalExpr *conditionalExpr ) {
292        maybeAccept( conditionalExpr->get_result(), *this );
293        maybeAccept( conditionalExpr->get_arg1(), *this );
294        maybeAccept( conditionalExpr->get_arg2(), *this );
295        maybeAccept( conditionalExpr->get_arg3(), *this );
296}
297
298void Visitor::visit( CommaExpr *commaExpr ) {
299        maybeAccept( commaExpr->get_result(), *this );
300        maybeAccept( commaExpr->get_arg1(), *this );
301        maybeAccept( commaExpr->get_arg2(), *this );
302}
303
304void Visitor::visit( TypeExpr *typeExpr ) {
305        maybeAccept( typeExpr->get_result(), *this );
306        maybeAccept( typeExpr->get_type(), *this );
307}
308
309void Visitor::visit( AsmExpr *asmExpr ) {
310        maybeAccept( asmExpr->get_inout(), *this );
311        maybeAccept( asmExpr->get_constraint(), *this );
312        maybeAccept( asmExpr->get_operand(), *this );
313}
314
315void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) {
316        maybeAccept( impCpCtorExpr->get_result(), *this );
317        maybeAccept( impCpCtorExpr->get_callExpr(), *this );
318        acceptAll( impCpCtorExpr->get_tempDecls(), *this );
319        acceptAll( impCpCtorExpr->get_returnDecls(), *this );
320        acceptAll( impCpCtorExpr->get_dtors(), *this );
321}
322
323void Visitor::visit( ConstructorExpr * ctorExpr ) {
324        maybeAccept( ctorExpr->get_result(), *this );
325        maybeAccept( ctorExpr->get_callExpr(), *this );
326}
327
328void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
329        maybeAccept( compLitExpr->get_result(), *this );
330        maybeAccept( compLitExpr->get_initializer(), *this );
331}
332
333void Visitor::visit( RangeExpr *rangeExpr ) {
334        maybeAccept( rangeExpr->get_low(), *this );
335        maybeAccept( rangeExpr->get_high(), *this );
336}
337
338void Visitor::visit( UntypedTupleExpr *tupleExpr ) {
339        maybeAccept( tupleExpr->get_result(), *this );
340        acceptAll( tupleExpr->get_exprs(), *this );
341}
342
343void Visitor::visit( TupleExpr *tupleExpr ) {
344        maybeAccept( tupleExpr->get_result(), *this );
345        acceptAll( tupleExpr->get_exprs(), *this );
346}
347
348void Visitor::visit( TupleIndexExpr *tupleExpr ) {
349        maybeAccept( tupleExpr->get_result(), *this );
350        maybeAccept( tupleExpr->get_tuple(), *this );
351}
352
353void Visitor::visit( TupleAssignExpr *assignExpr ) {
354        maybeAccept( assignExpr->get_result(), *this );
355        maybeAccept( assignExpr->get_stmtExpr(), *this );
356}
357
358void Visitor::visit( StmtExpr *stmtExpr ) {
359        maybeAccept( stmtExpr->get_result(), *this );
360        maybeAccept( stmtExpr->get_statements(), *this );
361        acceptAll( stmtExpr->get_returnDecls(), *this );
362        acceptAll( stmtExpr->get_dtors(), *this );
363}
364
365void Visitor::visit( UniqueExpr *uniqueExpr ) {
366        maybeAccept( uniqueExpr->get_result(), *this );
367        maybeAccept( uniqueExpr->get_expr(), *this );
368}
369
370void Visitor::visit( UntypedInitExpr * initExpr ) {
371        maybeAccept( initExpr->get_result(), *this );
372        maybeAccept( initExpr->get_expr(), *this );
373        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
374}
375
376void Visitor::visit( InitExpr * initExpr ) {
377        maybeAccept( initExpr->get_result(), *this );
378        maybeAccept( initExpr->get_expr(), *this );
379        maybeAccept( initExpr->get_designation(), *this );
380}
381
382
383void Visitor::visit( VoidType *voidType ) {
384        acceptAll( voidType->get_forall(), *this );
385}
386
387void Visitor::visit( BasicType *basicType ) {
388        acceptAll( basicType->get_forall(), *this );
389}
390
391void Visitor::visit( PointerType *pointerType ) {
392        acceptAll( pointerType->get_forall(), *this );
393        // xxx - should PointerType visit/mutate dimension?
394        maybeAccept( pointerType->get_base(), *this );
395}
396
397void Visitor::visit( ArrayType *arrayType ) {
398        acceptAll( arrayType->get_forall(), *this );
399        maybeAccept( arrayType->get_dimension(), *this );
400        maybeAccept( arrayType->get_base(), *this );
401}
402
403void Visitor::visit( ReferenceType *refType ) {
404        acceptAll( refType->get_forall(), *this );
405        maybeAccept( refType->get_base(), *this );
406}
407
408void Visitor::visit( FunctionType *functionType ) {
409        acceptAll( functionType->get_forall(), *this );
410        acceptAll( functionType->get_returnVals(), *this );
411        acceptAll( functionType->get_parameters(), *this );
412}
413
414void Visitor::handleReferenceToType( ReferenceToType *aggregateUseType ) {
415        acceptAll( aggregateUseType->get_forall(), *this );
416        acceptAll( aggregateUseType->get_parameters(), *this );
417}
418
419void Visitor::visit( StructInstType *aggregateUseType ) {
420        handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
421}
422
423void Visitor::visit( UnionInstType *aggregateUseType ) {
424        handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
425}
426
427void Visitor::visit( EnumInstType *aggregateUseType ) {
428        handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
429}
430
431void Visitor::visit( TraitInstType *aggregateUseType ) {
432        handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
433}
434
435void Visitor::visit( TypeInstType *aggregateUseType ) {
436        handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
437}
438
439void Visitor::visit( TupleType *tupleType ) {
440        acceptAll( tupleType->get_forall(), *this );
441        acceptAll( tupleType->get_types(), *this );
442        acceptAll( tupleType->get_members(), *this );
443}
444
445void Visitor::visit( TypeofType *typeofType ) {
446        assert( typeofType->get_expr() );
447        typeofType->get_expr()->accept( *this );
448}
449
450void Visitor::visit( AttrType *attrType ) {
451        if ( attrType->get_isType() ) {
452                assert( attrType->get_type() );
453                attrType->get_type()->accept( *this );
454        } else {
455                assert( attrType->get_expr() );
456                attrType->get_expr()->accept( *this );
457        } // if
458}
459
460void Visitor::visit( VarArgsType *varArgsType ) {
461        acceptAll( varArgsType->get_forall(), *this );
462}
463
464void Visitor::visit( ZeroType *zeroType ) {
465        acceptAll( zeroType->get_forall(), *this );
466}
467
468void Visitor::visit( OneType *oneType ) {
469        acceptAll( oneType->get_forall(), *this );
470}
471
472void Visitor::visit( Designation * designation ) {
473        acceptAll( designation->get_designators(), *this );
474}
475
476void Visitor::visit( SingleInit *singleInit ) {
477        singleInit->get_value()->accept( *this );
478}
479
480void Visitor::visit( ListInit *listInit ) {
481        acceptAll( listInit->get_designations(), *this );
482        acceptAll( listInit->get_initializers(), *this );
483}
484
485void Visitor::visit( ConstructorInit *ctorInit ) {
486        maybeAccept( ctorInit->get_ctor(), *this );
487        maybeAccept( ctorInit->get_dtor(), *this );
488        maybeAccept( ctorInit->get_init(), *this );
489}
490
491
492void Visitor::visit( Subrange * ) {}
493
494
495void Visitor::visit( Constant * ) {}
496
497void Visitor::visit( Attribute * attribute ) {
498        acceptAll( attribute->parameters, *this );
499}
500
501// Local Variables: //
502// tab-width: 4 //
503// mode: c++ //
504// compile-command: "make install" //
505// End: //
Note: See TracBrowser for help on using the repository browser.