[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 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Mon May 18 11:14:51 2015 |
---|
| 13 | // Update Count : 2 |
---|
| 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 | |
---|
[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 ); |
---|
[51b7345] | 88 | } |
---|
| 89 | |
---|
[0dd3a2f] | 90 | void Visitor::visit( WhileStmt *whileStmt ) { |
---|
| 91 | maybeAccept( whileStmt->get_condition(), *this ); |
---|
| 92 | maybeAccept( whileStmt->get_body(), *this ); |
---|
[51b7345] | 93 | } |
---|
| 94 | |
---|
[0dd3a2f] | 95 | void Visitor::visit( ForStmt *forStmt ) { |
---|
| 96 | // ForStmt still needs to be fixed |
---|
| 97 | maybeAccept( forStmt->get_initialization(), *this ); |
---|
| 98 | maybeAccept( forStmt->get_condition(), *this ); |
---|
| 99 | maybeAccept( forStmt->get_increment(), *this ); |
---|
| 100 | maybeAccept( forStmt->get_body(), *this ); |
---|
[51b7345] | 101 | } |
---|
| 102 | |
---|
[0dd3a2f] | 103 | void Visitor::visit( SwitchStmt *switchStmt ) { |
---|
| 104 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
| 105 | acceptAll( switchStmt->get_branches(), *this ); |
---|
[51b7345] | 106 | } |
---|
| 107 | |
---|
[0dd3a2f] | 108 | void Visitor::visit( ChooseStmt *switchStmt ) { |
---|
| 109 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
| 110 | acceptAll( switchStmt->get_branches(), *this ); |
---|
[51b7345] | 111 | } |
---|
| 112 | |
---|
[a08ba92] | 113 | void Visitor::visit( FallthruStmt *fallthruStmt ) {} |
---|
[51b7345] | 114 | |
---|
[0dd3a2f] | 115 | void Visitor::visit( CaseStmt *caseStmt ) { |
---|
| 116 | maybeAccept( caseStmt->get_condition(), *this ); |
---|
| 117 | acceptAll( caseStmt->get_statements(), *this ); |
---|
[51b7345] | 118 | } |
---|
| 119 | |
---|
[0dd3a2f] | 120 | void Visitor::visit( BranchStmt *branchStmt ) { |
---|
[51b7345] | 121 | } |
---|
| 122 | |
---|
[0dd3a2f] | 123 | void Visitor::visit( ReturnStmt *returnStmt ) { |
---|
| 124 | maybeAccept( returnStmt->get_expr(), *this ); |
---|
[51b7345] | 125 | } |
---|
| 126 | |
---|
[0dd3a2f] | 127 | void Visitor::visit( TryStmt *tryStmt ) { |
---|
| 128 | maybeAccept( tryStmt->get_block(), *this ); |
---|
| 129 | acceptAll( tryStmt->get_catchers(), *this ); |
---|
[51b7345] | 130 | } |
---|
| 131 | |
---|
[0dd3a2f] | 132 | void Visitor::visit( CatchStmt *catchStmt ) { |
---|
| 133 | maybeAccept( catchStmt->get_decl(), *this ); |
---|
| 134 | maybeAccept( catchStmt->get_body(), *this ); |
---|
[51b7345] | 135 | } |
---|
| 136 | |
---|
[0dd3a2f] | 137 | void Visitor::visit( FinallyStmt *finalStmt ) { |
---|
| 138 | maybeAccept( finalStmt->get_block(), *this ); |
---|
[51b7345] | 139 | } |
---|
| 140 | |
---|
[0dd3a2f] | 141 | void Visitor::visit( NullStmt *nullStmt ) { |
---|
[51b7345] | 142 | } |
---|
| 143 | |
---|
[0dd3a2f] | 144 | void Visitor::visit( DeclStmt *declStmt ) { |
---|
| 145 | maybeAccept( declStmt->get_decl(), *this ); |
---|
[51b7345] | 146 | } |
---|
| 147 | |
---|
[0dd3a2f] | 148 | void Visitor::visit( ApplicationExpr *applicationExpr ) { |
---|
| 149 | acceptAll( applicationExpr->get_results(), *this ); |
---|
| 150 | maybeAccept( applicationExpr->get_function(), *this ); |
---|
| 151 | acceptAll( applicationExpr->get_args(), *this ); |
---|
[51b7345] | 152 | } |
---|
| 153 | |
---|
[0dd3a2f] | 154 | void Visitor::visit( UntypedExpr *untypedExpr ) { |
---|
| 155 | acceptAll( untypedExpr->get_results(), *this ); |
---|
| 156 | acceptAll( untypedExpr->get_args(), *this ); |
---|
[51b7345] | 157 | } |
---|
| 158 | |
---|
[0dd3a2f] | 159 | void Visitor::visit( NameExpr *nameExpr ) { |
---|
| 160 | acceptAll( nameExpr->get_results(), *this ); |
---|
[51b7345] | 161 | } |
---|
| 162 | |
---|
[0dd3a2f] | 163 | void Visitor::visit( AddressExpr *addressExpr ) { |
---|
| 164 | acceptAll( addressExpr->get_results(), *this ); |
---|
| 165 | maybeAccept( addressExpr->get_arg(), *this ); |
---|
[51b7345] | 166 | } |
---|
| 167 | |
---|
[0dd3a2f] | 168 | void Visitor::visit( LabelAddressExpr *labAddressExpr ) { |
---|
| 169 | acceptAll( labAddressExpr->get_results(), *this ); |
---|
| 170 | maybeAccept( labAddressExpr->get_arg(), *this ); |
---|
[51b7345] | 171 | } |
---|
| 172 | |
---|
[0dd3a2f] | 173 | void Visitor::visit( CastExpr *castExpr ) { |
---|
| 174 | acceptAll( castExpr->get_results(), *this ); |
---|
| 175 | maybeAccept( castExpr->get_arg(), *this ); |
---|
[51b7345] | 176 | } |
---|
| 177 | |
---|
[0dd3a2f] | 178 | void Visitor::visit( UntypedMemberExpr *memberExpr ) { |
---|
| 179 | acceptAll( memberExpr->get_results(), *this ); |
---|
| 180 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
[51b7345] | 181 | } |
---|
| 182 | |
---|
[0dd3a2f] | 183 | void Visitor::visit( MemberExpr *memberExpr ) { |
---|
| 184 | acceptAll( memberExpr->get_results(), *this ); |
---|
| 185 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
[51b7345] | 186 | } |
---|
| 187 | |
---|
[0dd3a2f] | 188 | void Visitor::visit( VariableExpr *variableExpr ) { |
---|
| 189 | acceptAll( variableExpr->get_results(), *this ); |
---|
[51b7345] | 190 | } |
---|
| 191 | |
---|
[0dd3a2f] | 192 | void Visitor::visit( ConstantExpr *constantExpr ) { |
---|
| 193 | acceptAll( constantExpr->get_results(), *this ); |
---|
| 194 | maybeAccept( constantExpr->get_constant(), *this ); |
---|
[51b7345] | 195 | } |
---|
| 196 | |
---|
[0dd3a2f] | 197 | void Visitor::visit( SizeofExpr *sizeofExpr ) { |
---|
| 198 | acceptAll( sizeofExpr->get_results(), *this ); |
---|
| 199 | if ( sizeofExpr->get_isType() ) { |
---|
| 200 | maybeAccept( sizeofExpr->get_type(), *this ); |
---|
| 201 | } else { |
---|
| 202 | maybeAccept( sizeofExpr->get_expr(), *this ); |
---|
| 203 | } |
---|
[51b7345] | 204 | } |
---|
| 205 | |
---|
[0dd3a2f] | 206 | void Visitor::visit( AttrExpr *attrExpr ) { |
---|
| 207 | acceptAll( attrExpr->get_results(), *this ); |
---|
| 208 | if ( attrExpr->get_isType() ) { |
---|
| 209 | maybeAccept( attrExpr->get_type(), *this ); |
---|
| 210 | } else { |
---|
| 211 | maybeAccept( attrExpr->get_expr(), *this ); |
---|
| 212 | } |
---|
[51b7345] | 213 | } |
---|
| 214 | |
---|
[0dd3a2f] | 215 | void Visitor::visit( LogicalExpr *logicalExpr ) { |
---|
| 216 | acceptAll( logicalExpr->get_results(), *this ); |
---|
| 217 | maybeAccept( logicalExpr->get_arg1(), *this ); |
---|
| 218 | maybeAccept( logicalExpr->get_arg2(), *this ); |
---|
[51b7345] | 219 | } |
---|
| 220 | |
---|
[0dd3a2f] | 221 | void Visitor::visit( ConditionalExpr *conditionalExpr ) { |
---|
| 222 | acceptAll( conditionalExpr->get_results(), *this ); |
---|
| 223 | maybeAccept( conditionalExpr->get_arg1(), *this ); |
---|
| 224 | maybeAccept( conditionalExpr->get_arg2(), *this ); |
---|
| 225 | maybeAccept( conditionalExpr->get_arg3(), *this ); |
---|
[51b7345] | 226 | } |
---|
| 227 | |
---|
[0dd3a2f] | 228 | void Visitor::visit( CommaExpr *commaExpr ) { |
---|
| 229 | acceptAll( commaExpr->get_results(), *this ); |
---|
| 230 | maybeAccept( commaExpr->get_arg1(), *this ); |
---|
| 231 | maybeAccept( commaExpr->get_arg2(), *this ); |
---|
[51b7345] | 232 | } |
---|
| 233 | |
---|
[0dd3a2f] | 234 | void Visitor::visit( TupleExpr *tupleExpr ) { |
---|
| 235 | acceptAll( tupleExpr->get_results(), *this ); |
---|
| 236 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
[51b7345] | 237 | } |
---|
| 238 | |
---|
[0dd3a2f] | 239 | void Visitor::visit( SolvedTupleExpr *tupleExpr ) { |
---|
| 240 | acceptAll( tupleExpr->get_results(), *this ); |
---|
| 241 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
[51b7345] | 242 | } |
---|
| 243 | |
---|
[0dd3a2f] | 244 | void Visitor::visit( TypeExpr *typeExpr ) { |
---|
| 245 | acceptAll( typeExpr->get_results(), *this ); |
---|
| 246 | maybeAccept( typeExpr->get_type(), *this ); |
---|
[51b7345] | 247 | } |
---|
| 248 | |
---|
[0dd3a2f] | 249 | void Visitor::visit( UntypedValofExpr *valofExpr ) { |
---|
| 250 | acceptAll( valofExpr->get_results(), *this ); |
---|
| 251 | maybeAccept( valofExpr->get_body(), *this ); |
---|
[51b7345] | 252 | } |
---|
| 253 | |
---|
[0dd3a2f] | 254 | void Visitor::visit( VoidType *voidType ) { |
---|
| 255 | acceptAll( voidType->get_forall(), *this ); |
---|
[51b7345] | 256 | } |
---|
| 257 | |
---|
[0dd3a2f] | 258 | void Visitor::visit( BasicType *basicType ) { |
---|
| 259 | acceptAll( basicType->get_forall(), *this ); |
---|
[51b7345] | 260 | } |
---|
| 261 | |
---|
[0dd3a2f] | 262 | void Visitor::visit( PointerType *pointerType ) { |
---|
| 263 | acceptAll( pointerType->get_forall(), *this ); |
---|
| 264 | maybeAccept( pointerType->get_base(), *this ); |
---|
[51b7345] | 265 | } |
---|
| 266 | |
---|
[0dd3a2f] | 267 | void Visitor::visit( ArrayType *arrayType ) { |
---|
| 268 | acceptAll( arrayType->get_forall(), *this ); |
---|
| 269 | maybeAccept( arrayType->get_dimension(), *this ); |
---|
| 270 | maybeAccept( arrayType->get_base(), *this ); |
---|
[51b7345] | 271 | } |
---|
| 272 | |
---|
[0dd3a2f] | 273 | void Visitor::visit( FunctionType *functionType ) { |
---|
| 274 | acceptAll( functionType->get_forall(), *this ); |
---|
| 275 | acceptAll( functionType->get_returnVals(), *this ); |
---|
| 276 | acceptAll( functionType->get_parameters(), *this ); |
---|
[51b7345] | 277 | } |
---|
| 278 | |
---|
[0dd3a2f] | 279 | void Visitor::visit( ReferenceToType *aggregateUseType ) { |
---|
| 280 | acceptAll( aggregateUseType->get_forall(), *this ); |
---|
| 281 | acceptAll( aggregateUseType->get_parameters(), *this ); |
---|
[51b7345] | 282 | } |
---|
| 283 | |
---|
[0dd3a2f] | 284 | void Visitor::visit( StructInstType *aggregateUseType ) { |
---|
| 285 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
[51b7345] | 286 | } |
---|
| 287 | |
---|
[0dd3a2f] | 288 | void Visitor::visit( UnionInstType *aggregateUseType ) { |
---|
| 289 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
[51b7345] | 290 | } |
---|
| 291 | |
---|
[0dd3a2f] | 292 | void Visitor::visit( EnumInstType *aggregateUseType ) { |
---|
| 293 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
[51b7345] | 294 | } |
---|
| 295 | |
---|
[0dd3a2f] | 296 | void Visitor::visit( ContextInstType *aggregateUseType ) { |
---|
| 297 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
| 298 | acceptAll( aggregateUseType->get_members(), *this ); |
---|
[51b7345] | 299 | } |
---|
| 300 | |
---|
[0dd3a2f] | 301 | void Visitor::visit( TypeInstType *aggregateUseType ) { |
---|
| 302 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
[51b7345] | 303 | } |
---|
| 304 | |
---|
[0dd3a2f] | 305 | void Visitor::visit( TupleType *tupleType ) { |
---|
| 306 | acceptAll( tupleType->get_forall(), *this ); |
---|
| 307 | acceptAll( tupleType->get_types(), *this ); |
---|
[51b7345] | 308 | } |
---|
| 309 | |
---|
[0dd3a2f] | 310 | void Visitor::visit( TypeofType *typeofType ) { |
---|
| 311 | assert( typeofType->get_expr() ); |
---|
| 312 | typeofType->get_expr()->accept( *this ); |
---|
[51b7345] | 313 | } |
---|
| 314 | |
---|
[0dd3a2f] | 315 | void Visitor::visit( AttrType *attrType ) { |
---|
| 316 | if ( attrType->get_isType() ) { |
---|
| 317 | assert( attrType->get_type() ); |
---|
| 318 | attrType->get_type()->accept( *this ); |
---|
| 319 | } else { |
---|
| 320 | assert( attrType->get_expr() ); |
---|
| 321 | attrType->get_expr()->accept( *this ); |
---|
| 322 | } // if |
---|
[51b7345] | 323 | } |
---|
| 324 | |
---|
[0dd3a2f] | 325 | void Visitor::visit( SingleInit *singleInit ) { |
---|
| 326 | singleInit->get_value()->accept( *this ); |
---|
[51b7345] | 327 | } |
---|
| 328 | |
---|
[0dd3a2f] | 329 | void Visitor::visit( ListInit *listInit ) { |
---|
| 330 | acceptAll( listInit->get_designators(), *this ); |
---|
| 331 | acceptAll( listInit->get_initializers(), *this ); |
---|
[51b7345] | 332 | } |
---|
| 333 | |
---|
[0dd3a2f] | 334 | void Visitor::visit( Subrange *subrange ) {} |
---|
[51b7345] | 335 | |
---|
[0dd3a2f] | 336 | void Visitor::visit( Constant *constant ) {} |
---|
| 337 | // Local Variables: // |
---|
| 338 | // tab-width: 4 // |
---|
| 339 | // mode: c++ // |
---|
| 340 | // compile-command: "make install" // |
---|
| 341 | // End: // |
---|