[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 | // |
---|
[71f4e4f] | 7 | // Visitor.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[71f4e4f] | 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Wed Jan 13 15:27:23 2016 |
---|
| 13 | // Update Count : 18 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 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() {} |
---|
[51b7345] | 26 | |
---|
[d9a0e76] | 27 | Visitor::~Visitor() {} |
---|
[51b7345] | 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 ); |
---|
[51b7345] | 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 ); |
---|
[51b7345] | 39 | } |
---|
| 40 | |
---|
[0dd3a2f] | 41 | void Visitor::visit( AggregateDecl *aggregateDecl ) { |
---|
| 42 | acceptAll( aggregateDecl->get_parameters(), *this ); |
---|
| 43 | acceptAll( aggregateDecl->get_members(), *this ); |
---|
[51b7345] | 44 | } |
---|
| 45 | |
---|
[0dd3a2f] | 46 | void Visitor::visit( StructDecl *aggregateDecl ) { |
---|
| 47 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
[51b7345] | 48 | } |
---|
| 49 | |
---|
[0dd3a2f] | 50 | void Visitor::visit( UnionDecl *aggregateDecl ) { |
---|
| 51 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
[51b7345] | 52 | } |
---|
| 53 | |
---|
[0dd3a2f] | 54 | void Visitor::visit( EnumDecl *aggregateDecl ) { |
---|
| 55 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
[51b7345] | 56 | } |
---|
| 57 | |
---|
[0dd3a2f] | 58 | void Visitor::visit( ContextDecl *aggregateDecl ) { |
---|
| 59 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
[51b7345] | 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 ); |
---|
[51b7345] | 66 | } |
---|
| 67 | |
---|
[0dd3a2f] | 68 | void Visitor::visit( TypeDecl *typeDecl ) { |
---|
| 69 | visit( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
[51b7345] | 70 | } |
---|
| 71 | |
---|
[0dd3a2f] | 72 | void Visitor::visit( TypedefDecl *typeDecl ) { |
---|
| 73 | visit( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
[51b7345] | 74 | } |
---|
| 75 | |
---|
[0dd3a2f] | 76 | void Visitor::visit( CompoundStmt *compoundStmt ) { |
---|
| 77 | acceptAll( compoundStmt->get_kids(), *this ); |
---|
[51b7345] | 78 | } |
---|
| 79 | |
---|
[0dd3a2f] | 80 | void Visitor::visit( ExprStmt *exprStmt ) { |
---|
| 81 | maybeAccept( exprStmt->get_expr(), *this ); |
---|
[51b7345] | 82 | } |
---|
| 83 | |
---|
[7f5566b] | 84 | void 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 | |
---|
[0dd3a2f] | 91 | void Visitor::visit( IfStmt *ifStmt ) { |
---|
| 92 | maybeAccept( ifStmt->get_condition(), *this ); |
---|
| 93 | maybeAccept( ifStmt->get_thenPart(), *this ); |
---|
| 94 | maybeAccept( ifStmt->get_elsePart(), *this ); |
---|
[51b7345] | 95 | } |
---|
| 96 | |
---|
[0dd3a2f] | 97 | void Visitor::visit( WhileStmt *whileStmt ) { |
---|
| 98 | maybeAccept( whileStmt->get_condition(), *this ); |
---|
| 99 | maybeAccept( whileStmt->get_body(), *this ); |
---|
[51b7345] | 100 | } |
---|
| 101 | |
---|
[0dd3a2f] | 102 | void Visitor::visit( ForStmt *forStmt ) { |
---|
[145f1fc] | 103 | acceptAll( forStmt->get_initialization(), *this ); |
---|
[0dd3a2f] | 104 | maybeAccept( forStmt->get_condition(), *this ); |
---|
| 105 | maybeAccept( forStmt->get_increment(), *this ); |
---|
| 106 | maybeAccept( forStmt->get_body(), *this ); |
---|
[51b7345] | 107 | } |
---|
| 108 | |
---|
[0dd3a2f] | 109 | void Visitor::visit( SwitchStmt *switchStmt ) { |
---|
| 110 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
| 111 | acceptAll( switchStmt->get_branches(), *this ); |
---|
[51b7345] | 112 | } |
---|
| 113 | |
---|
[0dd3a2f] | 114 | void Visitor::visit( ChooseStmt *switchStmt ) { |
---|
| 115 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
| 116 | acceptAll( switchStmt->get_branches(), *this ); |
---|
[51b7345] | 117 | } |
---|
| 118 | |
---|
[a08ba92] | 119 | void Visitor::visit( FallthruStmt *fallthruStmt ) {} |
---|
[51b7345] | 120 | |
---|
[0dd3a2f] | 121 | void Visitor::visit( CaseStmt *caseStmt ) { |
---|
| 122 | maybeAccept( caseStmt->get_condition(), *this ); |
---|
| 123 | acceptAll( caseStmt->get_statements(), *this ); |
---|
[51b7345] | 124 | } |
---|
| 125 | |
---|
[0dd3a2f] | 126 | void Visitor::visit( BranchStmt *branchStmt ) { |
---|
[51b7345] | 127 | } |
---|
| 128 | |
---|
[0dd3a2f] | 129 | void Visitor::visit( ReturnStmt *returnStmt ) { |
---|
| 130 | maybeAccept( returnStmt->get_expr(), *this ); |
---|
[51b7345] | 131 | } |
---|
| 132 | |
---|
[0dd3a2f] | 133 | void Visitor::visit( TryStmt *tryStmt ) { |
---|
| 134 | maybeAccept( tryStmt->get_block(), *this ); |
---|
| 135 | acceptAll( tryStmt->get_catchers(), *this ); |
---|
[51b7345] | 136 | } |
---|
| 137 | |
---|
[0dd3a2f] | 138 | void Visitor::visit( CatchStmt *catchStmt ) { |
---|
| 139 | maybeAccept( catchStmt->get_decl(), *this ); |
---|
| 140 | maybeAccept( catchStmt->get_body(), *this ); |
---|
[51b7345] | 141 | } |
---|
| 142 | |
---|
[0dd3a2f] | 143 | void Visitor::visit( FinallyStmt *finalStmt ) { |
---|
| 144 | maybeAccept( finalStmt->get_block(), *this ); |
---|
[51b7345] | 145 | } |
---|
| 146 | |
---|
[0dd3a2f] | 147 | void Visitor::visit( NullStmt *nullStmt ) { |
---|
[51b7345] | 148 | } |
---|
| 149 | |
---|
[0dd3a2f] | 150 | void Visitor::visit( DeclStmt *declStmt ) { |
---|
| 151 | maybeAccept( declStmt->get_decl(), *this ); |
---|
[51b7345] | 152 | } |
---|
| 153 | |
---|
[0dd3a2f] | 154 | void Visitor::visit( ApplicationExpr *applicationExpr ) { |
---|
| 155 | acceptAll( applicationExpr->get_results(), *this ); |
---|
| 156 | maybeAccept( applicationExpr->get_function(), *this ); |
---|
| 157 | acceptAll( applicationExpr->get_args(), *this ); |
---|
[51b7345] | 158 | } |
---|
| 159 | |
---|
[0dd3a2f] | 160 | void Visitor::visit( UntypedExpr *untypedExpr ) { |
---|
| 161 | acceptAll( untypedExpr->get_results(), *this ); |
---|
| 162 | acceptAll( untypedExpr->get_args(), *this ); |
---|
[51b7345] | 163 | } |
---|
| 164 | |
---|
[0dd3a2f] | 165 | void Visitor::visit( NameExpr *nameExpr ) { |
---|
| 166 | acceptAll( nameExpr->get_results(), *this ); |
---|
[51b7345] | 167 | } |
---|
| 168 | |
---|
[0dd3a2f] | 169 | void Visitor::visit( AddressExpr *addressExpr ) { |
---|
| 170 | acceptAll( addressExpr->get_results(), *this ); |
---|
| 171 | maybeAccept( addressExpr->get_arg(), *this ); |
---|
[51b7345] | 172 | } |
---|
| 173 | |
---|
[0dd3a2f] | 174 | void Visitor::visit( LabelAddressExpr *labAddressExpr ) { |
---|
| 175 | acceptAll( labAddressExpr->get_results(), *this ); |
---|
| 176 | maybeAccept( labAddressExpr->get_arg(), *this ); |
---|
[51b7345] | 177 | } |
---|
| 178 | |
---|
[0dd3a2f] | 179 | void Visitor::visit( CastExpr *castExpr ) { |
---|
| 180 | acceptAll( castExpr->get_results(), *this ); |
---|
| 181 | maybeAccept( castExpr->get_arg(), *this ); |
---|
[51b7345] | 182 | } |
---|
| 183 | |
---|
[0dd3a2f] | 184 | void Visitor::visit( UntypedMemberExpr *memberExpr ) { |
---|
| 185 | acceptAll( memberExpr->get_results(), *this ); |
---|
| 186 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
[51b7345] | 187 | } |
---|
| 188 | |
---|
[0dd3a2f] | 189 | void Visitor::visit( MemberExpr *memberExpr ) { |
---|
| 190 | acceptAll( memberExpr->get_results(), *this ); |
---|
| 191 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
[51b7345] | 192 | } |
---|
| 193 | |
---|
[0dd3a2f] | 194 | void Visitor::visit( VariableExpr *variableExpr ) { |
---|
| 195 | acceptAll( variableExpr->get_results(), *this ); |
---|
[51b7345] | 196 | } |
---|
| 197 | |
---|
[0dd3a2f] | 198 | void Visitor::visit( ConstantExpr *constantExpr ) { |
---|
| 199 | acceptAll( constantExpr->get_results(), *this ); |
---|
| 200 | maybeAccept( constantExpr->get_constant(), *this ); |
---|
[51b7345] | 201 | } |
---|
| 202 | |
---|
[0dd3a2f] | 203 | void 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 | } |
---|
[51b7345] | 210 | } |
---|
| 211 | |
---|
[47534159] | 212 | void 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 | |
---|
[2a4b088] | 221 | void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) { |
---|
| 222 | acceptAll( offsetofExpr->get_results(), *this ); |
---|
| 223 | maybeAccept( offsetofExpr->get_type(), *this ); |
---|
| 224 | } |
---|
| 225 | |
---|
[25a054f] | 226 | void Visitor::visit( OffsetofExpr *offsetofExpr ) { |
---|
| 227 | acceptAll( offsetofExpr->get_results(), *this ); |
---|
| 228 | maybeAccept( offsetofExpr->get_type(), *this ); |
---|
| 229 | maybeAccept( offsetofExpr->get_member(), *this ); |
---|
| 230 | } |
---|
| 231 | |
---|
[0dd3a2f] | 232 | void Visitor::visit( AttrExpr *attrExpr ) { |
---|
| 233 | acceptAll( attrExpr->get_results(), *this ); |
---|
| 234 | if ( attrExpr->get_isType() ) { |
---|
| 235 | maybeAccept( attrExpr->get_type(), *this ); |
---|
| 236 | } else { |
---|
| 237 | maybeAccept( attrExpr->get_expr(), *this ); |
---|
| 238 | } |
---|
[51b7345] | 239 | } |
---|
| 240 | |
---|
[0dd3a2f] | 241 | void Visitor::visit( LogicalExpr *logicalExpr ) { |
---|
| 242 | acceptAll( logicalExpr->get_results(), *this ); |
---|
| 243 | maybeAccept( logicalExpr->get_arg1(), *this ); |
---|
| 244 | maybeAccept( logicalExpr->get_arg2(), *this ); |
---|
[51b7345] | 245 | } |
---|
| 246 | |
---|
[0dd3a2f] | 247 | void Visitor::visit( ConditionalExpr *conditionalExpr ) { |
---|
| 248 | acceptAll( conditionalExpr->get_results(), *this ); |
---|
| 249 | maybeAccept( conditionalExpr->get_arg1(), *this ); |
---|
| 250 | maybeAccept( conditionalExpr->get_arg2(), *this ); |
---|
| 251 | maybeAccept( conditionalExpr->get_arg3(), *this ); |
---|
[51b7345] | 252 | } |
---|
| 253 | |
---|
[0dd3a2f] | 254 | void Visitor::visit( CommaExpr *commaExpr ) { |
---|
| 255 | acceptAll( commaExpr->get_results(), *this ); |
---|
| 256 | maybeAccept( commaExpr->get_arg1(), *this ); |
---|
| 257 | maybeAccept( commaExpr->get_arg2(), *this ); |
---|
[51b7345] | 258 | } |
---|
| 259 | |
---|
[0dd3a2f] | 260 | void Visitor::visit( TupleExpr *tupleExpr ) { |
---|
| 261 | acceptAll( tupleExpr->get_results(), *this ); |
---|
| 262 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
[51b7345] | 263 | } |
---|
| 264 | |
---|
[0dd3a2f] | 265 | void Visitor::visit( SolvedTupleExpr *tupleExpr ) { |
---|
| 266 | acceptAll( tupleExpr->get_results(), *this ); |
---|
| 267 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
[51b7345] | 268 | } |
---|
| 269 | |
---|
[0dd3a2f] | 270 | void Visitor::visit( TypeExpr *typeExpr ) { |
---|
| 271 | acceptAll( typeExpr->get_results(), *this ); |
---|
| 272 | maybeAccept( typeExpr->get_type(), *this ); |
---|
[51b7345] | 273 | } |
---|
| 274 | |
---|
[7f5566b] | 275 | void Visitor::visit( AsmExpr *asmExpr ) { |
---|
| 276 | maybeAccept( asmExpr->get_inout(), *this ); |
---|
| 277 | maybeAccept( asmExpr->get_constraint(), *this ); |
---|
| 278 | maybeAccept( asmExpr->get_operand(), *this ); |
---|
| 279 | } |
---|
| 280 | |
---|
[0dd3a2f] | 281 | void Visitor::visit( UntypedValofExpr *valofExpr ) { |
---|
| 282 | acceptAll( valofExpr->get_results(), *this ); |
---|
| 283 | maybeAccept( valofExpr->get_body(), *this ); |
---|
[51b7345] | 284 | } |
---|
| 285 | |
---|
[0dd3a2f] | 286 | void Visitor::visit( VoidType *voidType ) { |
---|
| 287 | acceptAll( voidType->get_forall(), *this ); |
---|
[51b7345] | 288 | } |
---|
| 289 | |
---|
[0dd3a2f] | 290 | void Visitor::visit( BasicType *basicType ) { |
---|
| 291 | acceptAll( basicType->get_forall(), *this ); |
---|
[51b7345] | 292 | } |
---|
| 293 | |
---|
[0dd3a2f] | 294 | void Visitor::visit( PointerType *pointerType ) { |
---|
| 295 | acceptAll( pointerType->get_forall(), *this ); |
---|
| 296 | maybeAccept( pointerType->get_base(), *this ); |
---|
[51b7345] | 297 | } |
---|
| 298 | |
---|
[0dd3a2f] | 299 | void Visitor::visit( ArrayType *arrayType ) { |
---|
| 300 | acceptAll( arrayType->get_forall(), *this ); |
---|
| 301 | maybeAccept( arrayType->get_dimension(), *this ); |
---|
| 302 | maybeAccept( arrayType->get_base(), *this ); |
---|
[51b7345] | 303 | } |
---|
| 304 | |
---|
[0dd3a2f] | 305 | void Visitor::visit( FunctionType *functionType ) { |
---|
| 306 | acceptAll( functionType->get_forall(), *this ); |
---|
| 307 | acceptAll( functionType->get_returnVals(), *this ); |
---|
| 308 | acceptAll( functionType->get_parameters(), *this ); |
---|
[51b7345] | 309 | } |
---|
| 310 | |
---|
[0dd3a2f] | 311 | void Visitor::visit( ReferenceToType *aggregateUseType ) { |
---|
| 312 | acceptAll( aggregateUseType->get_forall(), *this ); |
---|
| 313 | acceptAll( aggregateUseType->get_parameters(), *this ); |
---|
[51b7345] | 314 | } |
---|
| 315 | |
---|
[0dd3a2f] | 316 | void Visitor::visit( StructInstType *aggregateUseType ) { |
---|
[7f5566b] | 317 | visit( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
[51b7345] | 318 | } |
---|
| 319 | |
---|
[0dd3a2f] | 320 | void Visitor::visit( UnionInstType *aggregateUseType ) { |
---|
[7f5566b] | 321 | visit( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
[51b7345] | 322 | } |
---|
| 323 | |
---|
[0dd3a2f] | 324 | void Visitor::visit( EnumInstType *aggregateUseType ) { |
---|
[7f5566b] | 325 | visit( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
[51b7345] | 326 | } |
---|
| 327 | |
---|
[0dd3a2f] | 328 | void Visitor::visit( ContextInstType *aggregateUseType ) { |
---|
[7f5566b] | 329 | visit( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
[0dd3a2f] | 330 | acceptAll( aggregateUseType->get_members(), *this ); |
---|
[51b7345] | 331 | } |
---|
| 332 | |
---|
[0dd3a2f] | 333 | void Visitor::visit( TypeInstType *aggregateUseType ) { |
---|
[7f5566b] | 334 | visit( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
[51b7345] | 335 | } |
---|
| 336 | |
---|
[0dd3a2f] | 337 | void Visitor::visit( TupleType *tupleType ) { |
---|
| 338 | acceptAll( tupleType->get_forall(), *this ); |
---|
| 339 | acceptAll( tupleType->get_types(), *this ); |
---|
[51b7345] | 340 | } |
---|
| 341 | |
---|
[0dd3a2f] | 342 | void Visitor::visit( TypeofType *typeofType ) { |
---|
| 343 | assert( typeofType->get_expr() ); |
---|
| 344 | typeofType->get_expr()->accept( *this ); |
---|
[51b7345] | 345 | } |
---|
| 346 | |
---|
[0dd3a2f] | 347 | void Visitor::visit( AttrType *attrType ) { |
---|
| 348 | if ( attrType->get_isType() ) { |
---|
| 349 | assert( attrType->get_type() ); |
---|
| 350 | attrType->get_type()->accept( *this ); |
---|
| 351 | } else { |
---|
| 352 | assert( attrType->get_expr() ); |
---|
| 353 | attrType->get_expr()->accept( *this ); |
---|
| 354 | } // if |
---|
[51b7345] | 355 | } |
---|
| 356 | |
---|
[0dd3a2f] | 357 | void Visitor::visit( SingleInit *singleInit ) { |
---|
| 358 | singleInit->get_value()->accept( *this ); |
---|
[51b7345] | 359 | } |
---|
| 360 | |
---|
[0dd3a2f] | 361 | void Visitor::visit( ListInit *listInit ) { |
---|
| 362 | acceptAll( listInit->get_designators(), *this ); |
---|
| 363 | acceptAll( listInit->get_initializers(), *this ); |
---|
[51b7345] | 364 | } |
---|
| 365 | |
---|
[71f4e4f] | 366 | void Visitor::visit( ConstructorInit *ctorInit ) { |
---|
| 367 | maybeAccept( ctorInit->get_ctor(), *this ); |
---|
| 368 | maybeAccept( ctorInit->get_init(), *this ); |
---|
| 369 | } |
---|
| 370 | |
---|
[0dd3a2f] | 371 | void Visitor::visit( Subrange *subrange ) {} |
---|
[51b7345] | 372 | |
---|
[0dd3a2f] | 373 | void Visitor::visit( Constant *constant ) {} |
---|
| 374 | // Local Variables: // |
---|
| 375 | // tab-width: 4 // |
---|
| 376 | // mode: c++ // |
---|
| 377 | // compile-command: "make install" // |
---|
| 378 | // End: // |
---|