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