Changeset 0dd3a2f for translator/SynTree/Mutator.cc
- Timestamp:
- May 18, 2015, 11:20:23 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 51587aa
- Parents:
- a32b204
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/Mutator.cc
ra32b204 r0dd3a2f 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 // Mutator.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 10:10:46 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 17 #include "Mutator.h" … … 14 29 15 30 ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) { 16 17 18 19 31 objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) ); 32 objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) ); 33 objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) ); 34 return objectDecl; 20 35 } 21 36 22 37 DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) { 23 24 25 26 38 functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) ); 39 mutateAll( functionDecl->get_oldDecls(), *this ); 40 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 41 return functionDecl; 27 42 } 28 43 29 44 Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) { 30 31 32 45 mutateAll( aggregateDecl->get_parameters(), *this ); 46 mutateAll( aggregateDecl->get_members(), *this ); 47 return aggregateDecl; 33 48 } 34 49 35 50 Declaration *Mutator::mutate( StructDecl *aggregateDecl ) { 36 37 51 handleAggregateDecl( aggregateDecl ); 52 return aggregateDecl; 38 53 } 39 54 40 55 Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) { 41 42 56 handleAggregateDecl( aggregateDecl ); 57 return aggregateDecl; 43 58 } 44 59 45 60 Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) { 46 47 61 handleAggregateDecl( aggregateDecl ); 62 return aggregateDecl; 48 63 } 49 64 50 65 Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) { 51 52 66 handleAggregateDecl( aggregateDecl ); 67 return aggregateDecl; 53 68 } 54 69 55 70 Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) { 56 57 58 59 71 mutateAll( typeDecl->get_parameters(), *this ); 72 mutateAll( typeDecl->get_assertions(), *this ); 73 typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) ); 74 return typeDecl; 60 75 } 61 76 62 77 TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) { 63 64 78 handleNamedTypeDecl( typeDecl ); 79 return typeDecl; 65 80 } 66 81 67 82 Declaration *Mutator::mutate( TypedefDecl *typeDecl ) { 68 69 83 handleNamedTypeDecl( typeDecl ); 84 return typeDecl; 70 85 } 71 86 72 87 CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) { 73 74 88 mutateAll( compoundStmt->get_kids(), *this ); 89 return compoundStmt; 75 90 } 76 91 77 92 Statement *Mutator::mutate( ExprStmt *exprStmt ) { 78 79 93 exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) ); 94 return exprStmt; 80 95 } 81 96 82 97 Statement *Mutator::mutate( IfStmt *ifStmt ) { 83 84 85 86 98 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 99 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); 100 ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) ); 101 return ifStmt; 87 102 } 88 103 89 104 Statement *Mutator::mutate( WhileStmt *whileStmt ) { 90 91 92 105 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); 106 whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) ); 107 return whileStmt; 93 108 } 94 109 95 110 Statement *Mutator::mutate( ForStmt *forStmt ) { 96 97 98 99 100 111 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) ); 112 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); 113 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); 114 forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) ); 115 return forStmt; 101 116 } 102 117 103 118 Statement *Mutator::mutate( SwitchStmt *switchStmt ) { 104 105 106 119 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 120 mutateAll( switchStmt->get_branches(), *this ); 121 return switchStmt; 107 122 } 108 123 109 124 Statement *Mutator::mutate( ChooseStmt *switchStmt ) { 110 111 112 125 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 126 mutateAll( switchStmt->get_branches(), *this ); 127 return switchStmt; 113 128 } 114 129 115 130 Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) { 116 131 return fallthruStmt; 117 132 } 118 133 119 134 Statement *Mutator::mutate( CaseStmt *caseStmt ) { 120 121 122 123 135 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); 136 mutateAll (caseStmt->get_statements(), *this ); 137 138 return caseStmt; 124 139 } 125 140 126 141 Statement *Mutator::mutate( BranchStmt *branchStmt ) { 127 142 return branchStmt; 128 143 } 129 144 130 145 Statement *Mutator::mutate( ReturnStmt *returnStmt ) { 131 132 146 returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) ); 147 return returnStmt; 133 148 } 134 149 135 150 Statement *Mutator::mutate( TryStmt *tryStmt ) { 136 137 138 151 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); 152 mutateAll( tryStmt->get_catchers(), *this ); 153 return tryStmt; 139 154 } 140 155 141 156 Statement *Mutator::mutate( CatchStmt *catchStmt ) { 142 143 144 157 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 158 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); 159 return catchStmt; 145 160 } 146 161 147 162 Statement *Mutator::mutate( FinallyStmt *finalStmt ) { 148 149 163 finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) ); 164 return finalStmt; 150 165 } 151 166 152 167 NullStmt *Mutator::mutate( NullStmt *nullStmt ) { 153 168 return nullStmt; 154 169 } 155 170 156 171 Statement *Mutator::mutate( DeclStmt *declStmt ) { 157 158 172 declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) ); 173 return declStmt; 159 174 } 160 175 161 176 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 162 163 164 165 177 mutateAll( applicationExpr->get_results(), *this ); 178 applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) ); 179 mutateAll( applicationExpr->get_args(), *this ); 180 return applicationExpr; 166 181 } 167 182 168 183 Expression *Mutator::mutate( UntypedExpr *untypedExpr ) { 169 170 171 184 mutateAll( untypedExpr->get_results(), *this ); 185 mutateAll( untypedExpr->get_args(), *this ); 186 return untypedExpr; 172 187 } 173 188 174 189 Expression *Mutator::mutate( NameExpr *nameExpr ) { 175 176 190 mutateAll( nameExpr->get_results(), *this ); 191 return nameExpr; 177 192 } 178 193 179 194 Expression *Mutator::mutate( AddressExpr *addressExpr ) { 180 181 182 195 mutateAll( addressExpr->get_results(), *this ); 196 addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) ); 197 return addressExpr; 183 198 } 184 199 185 200 Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) { 186 187 188 201 mutateAll( labelAddressExpr->get_results(), *this ); 202 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) ); 203 return labelAddressExpr; 189 204 } 190 205 191 206 Expression *Mutator::mutate( CastExpr *castExpr ) { 192 193 194 207 mutateAll( castExpr->get_results(), *this ); 208 castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) ); 209 return castExpr; 195 210 } 196 211 197 212 Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) { 198 199 200 213 mutateAll( memberExpr->get_results(), *this ); 214 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 215 return memberExpr; 201 216 } 202 217 203 218 Expression *Mutator::mutate( MemberExpr *memberExpr ) { 204 205 206 219 mutateAll( memberExpr->get_results(), *this ); 220 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 221 return memberExpr; 207 222 } 208 223 209 224 Expression *Mutator::mutate( VariableExpr *variableExpr ) { 210 211 225 mutateAll( variableExpr->get_results(), *this ); 226 return variableExpr; 212 227 } 213 228 214 229 Expression *Mutator::mutate( ConstantExpr *constantExpr ) { 215 230 mutateAll( constantExpr->get_results(), *this ); 216 231 // maybeMutate( constantExpr->get_constant(), *this ) 217 232 return constantExpr; 218 233 } 219 234 220 235 Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) { 221 222 223 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );224 225 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );226 227 236 mutateAll( sizeofExpr->get_results(), *this ); 237 if ( sizeofExpr->get_isType() ) { 238 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) ); 239 } else { 240 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) ); 241 } 242 return sizeofExpr; 228 243 } 229 244 230 245 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 231 232 233 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );234 235 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );236 237 246 mutateAll( attrExpr->get_results(), *this ); 247 if ( attrExpr->get_isType() ) { 248 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) ); 249 } else { 250 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) ); 251 } 252 return attrExpr; 238 253 } 239 254 240 255 Expression *Mutator::mutate( LogicalExpr *logicalExpr ) { 241 242 243 244 256 mutateAll( logicalExpr->get_results(), *this ); 257 logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) ); 258 logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) ); 259 return logicalExpr; 245 260 } 246 261 247 262 Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) { 248 249 250 251 252 263 mutateAll( conditionalExpr->get_results(), *this ); 264 conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) ); 265 conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) ); 266 conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) ); 267 return conditionalExpr; 253 268 } 254 269 255 270 Expression *Mutator::mutate( CommaExpr *commaExpr ) { 256 257 258 259 271 mutateAll( commaExpr->get_results(), *this ); 272 commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) ); 273 commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) ); 274 return commaExpr; 260 275 } 261 276 262 277 Expression *Mutator::mutate( TupleExpr *tupleExpr ) { 263 264 265 278 mutateAll( tupleExpr->get_results(), *this ); 279 mutateAll( tupleExpr->get_exprs(), *this ); 280 return tupleExpr; 266 281 } 267 282 268 283 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) { 269 270 271 284 mutateAll( tupleExpr->get_results(), *this ); 285 mutateAll( tupleExpr->get_exprs(), *this ); 286 return tupleExpr; 272 287 } 273 288 274 289 Expression *Mutator::mutate( TypeExpr *typeExpr ) { 275 276 277 290 mutateAll( typeExpr->get_results(), *this ); 291 typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) ); 292 return typeExpr; 278 293 } 279 294 280 295 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 281 282 296 mutateAll( valofExpr->get_results(), *this ); 297 return valofExpr; 283 298 } 284 299 285 300 Type *Mutator::mutate( VoidType *voidType ) { 286 287 301 mutateAll( voidType->get_forall(), *this ); 302 return voidType; 288 303 } 289 304 290 305 Type *Mutator::mutate( BasicType *basicType ) { 291 292 306 mutateAll( basicType->get_forall(), *this ); 307 return basicType; 293 308 } 294 309 295 310 Type *Mutator::mutate( PointerType *pointerType ) { 296 297 298 311 mutateAll( pointerType->get_forall(), *this ); 312 pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) ); 313 return pointerType; 299 314 } 300 315 301 316 Type *Mutator::mutate( ArrayType *arrayType ) { 302 303 304 305 317 mutateAll( arrayType->get_forall(), *this ); 318 arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) ); 319 arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) ); 320 return arrayType; 306 321 } 307 322 308 323 Type *Mutator::mutate( FunctionType *functionType ) { 309 310 311 312 324 mutateAll( functionType->get_forall(), *this ); 325 mutateAll( functionType->get_returnVals(), *this ); 326 mutateAll( functionType->get_parameters(), *this ); 327 return functionType; 313 328 } 314 329 315 330 Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) { 316 317 318 331 mutateAll( aggregateUseType->get_forall(), *this ); 332 mutateAll( aggregateUseType->get_parameters(), *this ); 333 return aggregateUseType; 319 334 } 320 335 321 336 Type *Mutator::mutate( StructInstType *aggregateUseType ) { 322 323 337 handleReferenceToType( aggregateUseType ); 338 return aggregateUseType; 324 339 } 325 340 326 341 Type *Mutator::mutate( UnionInstType *aggregateUseType ) { 327 328 342 handleReferenceToType( aggregateUseType ); 343 return aggregateUseType; 329 344 } 330 345 331 346 Type *Mutator::mutate( EnumInstType *aggregateUseType ) { 332 333 347 handleReferenceToType( aggregateUseType ); 348 return aggregateUseType; 334 349 } 335 350 336 351 Type *Mutator::mutate( ContextInstType *aggregateUseType ) { 337 338 339 352 handleReferenceToType( aggregateUseType ); 353 mutateAll( aggregateUseType->get_members(), *this ); 354 return aggregateUseType; 340 355 } 341 356 342 357 Type *Mutator::mutate( TypeInstType *aggregateUseType ) { 343 344 358 handleReferenceToType( aggregateUseType ); 359 return aggregateUseType; 345 360 } 346 361 347 362 Type *Mutator::mutate( TupleType *tupleType ) { 348 349 350 363 mutateAll( tupleType->get_forall(), *this ); 364 mutateAll( tupleType->get_types(), *this ); 365 return tupleType; 351 366 } 352 367 353 368 Type *Mutator::mutate( TypeofType *typeofType ) { 354 355 356 369 assert( typeofType->get_expr() ); 370 typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) ); 371 return typeofType; 357 372 } 358 373 359 374 Type *Mutator::mutate( AttrType *attrType ) { 360 361 assert( attrType->get_type() );362 attrType->set_type( attrType->get_type()->acceptMutator( *this ) );363 364 assert( attrType->get_expr() );365 attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );366 367 375 if ( attrType->get_isType() ) { 376 assert( attrType->get_type() ); 377 attrType->set_type( attrType->get_type()->acceptMutator( *this ) ); 378 } else { 379 assert( attrType->get_expr() ); 380 attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) ); 381 } 382 return attrType; 368 383 } 369 384 370 385 Initializer *Mutator::mutate( SingleInit *singleInit ) { 371 372 386 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); 387 return singleInit; 373 388 } 374 389 375 390 Initializer *Mutator::mutate( ListInit *listInit ) { 376 377 378 391 mutateAll( listInit->get_designators(), *this ); 392 mutateAll( listInit->get_initializers(), *this ); 393 return listInit; 379 394 } 380 395 381 396 Subrange *Mutator::mutate( Subrange *subrange ) { 382 397 return subrange; 383 398 } 384 399 385 400 Constant *Mutator::mutate( Constant *constant ) { 386 return constant; 387 } 401 return constant; 402 } 403 404 // Local Variables: // 405 // tab-width: 4 // 406 // mode: c++ // 407 // compile-command: "make install" // 408 // End: //
Note: See TracChangeset
for help on using the changeset viewer.