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