- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
rac10576 rba912706 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T us Jul 18 10:09:00 201713 // Update Count : 412 // Last Modified On : Thr Jun 22 15:57:00 2017 13 // Update Count : 0 14 14 // 15 15 16 16 #include "ExceptTranslate.h" 17 17 #include "Common/PassVisitor.h" 18 #include "SynTree/Statement.h" 19 #include "SynTree/Declaration.h" 20 #include "SynTree/Expression.h" 21 #include "SynTree/Type.h" 22 #include "SynTree/Attribute.h" 23 24 namespace ControlStruct { 18 19 namespace ControlFlow { 25 20 26 21 // This (large) section could probably be moved out of the class … … 29 24 // Type(Qualifiers &, false, std::list<Attribute *> &) 30 25 31 // void (*function)() ;32 static FunctionType try_func_t(Type::Qualifiers(), false);26 // void (*function)() 27 static FunctionType void_func_t(Type::Qualifiers(), false); 33 28 // void (*function)(int, exception); 34 29 static FunctionType catch_func_t(Type::Qualifiers(), false); … … 37 32 // bool (*function)(exception); 38 33 static FunctionType handle_func_t(Type::Qualifiers(), false); 39 // void (*function)(__attribute__((unused)) void *);40 static FunctionType finally_func_t(Type::Qualifiers(), false);41 34 42 35 static void init_func_types() { 43 static boolinit_complete = false;36 static init_complete = false; 44 37 if (init_complete) { 45 38 return; 46 39 } 47 40 ObjectDecl index_obj( 48 " __handler_index",41 "index_t", 49 42 Type::StorageClasses(), 50 43 LinkageSpec::Cforall, 51 44 /*bitfieldWidth*/ NULL, 52 new BasicType( noQualifiers, BasicType::SignedInt),45 new BasicType(emptyQualifiers, BasicType::UnsignedInt), 53 46 /*init*/ NULL 54 47 ); 55 48 ObjectDecl exception_obj( 56 " __exception_inst",49 "exception_t", 57 50 Type::StorageClasses(), 58 51 LinkageSpec::Cforall, 59 52 /*bitfieldWidth*/ NULL, 60 new PointerType( 61 noQualifiers, 62 new BasicType( noQualifiers, BasicType::SignedInt ) 63 ), 53 new BasicType(emptyQualifiers, BasicType::UnsignedInt), 64 54 /*init*/ NULL 65 55 ); 66 56 ObjectDecl bool_obj( 67 " __ret_bool",57 "bool_t", 68 58 Type::StorageClasses(), 69 59 LinkageSpec::Cforall, 70 60 /*bitfieldWidth*/ NULL, 71 new BasicType( noQualifiers, BasicType::Bool),61 new BasicType(emptyQualifiers, BasicType::Bool), 72 62 /*init*/ NULL 73 ); 74 ObjectDecl voidptr_obj( 75 "__hook", 76 Type::StorageClasses(), 77 LinkageSpec::Cforall, 78 NULL, 79 new PointerType( 80 noQualifiers, 81 new VoidType( 82 noQualifiers 83 ), 84 std::list<Attribute *>{new Attribute("unused")} 85 ), 86 NULL 87 ); 88 89 catch_func_t.get_parameters().push_back( index_obj.clone() ); 90 catch_func_t.get_parameters().push_back( exception_obj.clone() ); 91 match_func_t.get_returnVals().push_back( index_obj.clone() ); 92 match_func_t.get_parameters().push_back( exception_obj.clone() ); 93 handle_func_t.get_returnVals().push_back( bool_obj.clone() ); 94 handle_func_t.get_parameters().push_back( exception_obj.clone() ); 95 finally_func_t.get_parameters().push_back( voidptr_obj.clone() ); 63 ); 64 65 catch_func_t.get_parameters().push_back(index_obj.clone()); 66 catch_func_t.get_parameters().push_back(exception_obj.clone()); 67 match_func_t.get_returnVals().push_back(index_obj.clone()); 68 match_func_t.get_parameters().push_back(exception_obj.clone()); 69 handle_func_t.get_returnVals().push_back(bool_obj.clone()); 70 handle_func_t.get_parameters().push_back(exception_obj.clone()); 96 71 97 72 init_complete = true; … … 103 78 104 79 void split( CatchList& allHandlers, CatchList& terHandlers, 105 80 CatchList& resHandlers ) { 106 81 while ( !allHandlers.empty() ) { 107 CatchStmt * stmt = allHandlers.front();82 Statement * stmt = allHandlers.front(); 108 83 allHandlers.pop_front(); 109 if (Ca tchStmt::Terminate == stmt->get_kind()) {84 if (CaseStmt::Terminate == stmt->get_kind()) { 110 85 terHandlers.push_back(stmt); 111 86 } else { … … 117 92 template<typename T> 118 93 void free_all( std::list<T *> &list ) { 119 typenamestd::list<T *>::iterator it;94 std::list<T *>::iterator it; 120 95 for ( it = list.begin() ; it != list.end() ; ++it ) { 121 96 delete *it; … … 125 100 126 101 void appendDeclStmt( CompoundStmt * block, Declaration * item ) { 127 block->push_back(new DeclStmt(no Labels, item));128 } 129 130 Expression * nameOf( DeclarationWithType * decl) {131 return new VariableExpr( decl);102 block->push_back(new DeclStmt(no_labels, item)); 103 } 104 105 Expression * nameOf( FunctionDecl * function ) { 106 return new VariableExpr( function ); 132 107 } 133 108 134 109 // ThrowStmt Mutation Helpers 135 110 136 Statement * create_given_throw( 137 const char * throwFunc, ThrowStmt * throwStmt ) { 138 // { int NAME = EXPR; throwFunc( &NAME ); } 139 CompoundStmt * result = new CompoundStmt( noLabels ); 140 ObjectDecl * local = new ObjectDecl( 141 "__local_exception_copy", 142 Type::StorageClasses(), 143 LinkageSpec::Cforall, 144 NULL, 145 new BasicType( noQualifiers, BasicType::SignedInt ), 146 new SingleInit( throwStmt->get_expr() ) 147 ); 148 appendDeclStmt( result, local ); 149 UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) ); 150 call->get_args().push_back( new AddressExpr( nameOf( local ) ) ); 151 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) ); 111 Statement * create_terminate_throw( ThrowStmt *throwStmt ) { 112 // __throw_terminate( EXPR ); 113 ApplicationExpr * call = new ApplicationExpr( /* ... */ ); 114 call->get_args.push_back( throwStmt->get_expr() ); 115 Statement * result = new ExprStmt( throwStmt->get_labels(), call ); 152 116 throwStmt->set_expr( nullptr ); 153 117 delete throwStmt; 154 118 return result; 155 119 } 156 157 Statement * create_terminate_throw( ThrowStmt *throwStmt ) {158 // { int NAME = EXPR; __throw_terminate( &NAME ); }159 return create_given_throw( "__cfaehm__throw_terminate", throwStmt );160 }161 120 Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) { 162 121 // __rethrow_terminate(); 163 assert( nullptr == throwStmt->get_expr() );164 122 Statement * result = new ExprStmt( 165 123 throwStmt->get_labels(), 166 new UntypedExpr( new NameExpr( "__cfaehm__rethrow_terminate" ) )124 new ApplicationExpr( /* ... */ ); 167 125 ); 168 126 delete throwStmt; … … 171 129 Statement * create_resume_throw( ThrowStmt *throwStmt ) { 172 130 // __throw_resume( EXPR ); 173 return create_given_throw( "__cfaehm__throw_resume", throwStmt ); 131 ApplicationExpr * call = new ApplicationExpr( /* ... */ ); 132 call->get_args.push_back( throwStmt->get_expr() ); 133 Statement * result = new ExprStmt( throwStmt->get_labels(), call ); 134 throwStmt->set_expr( nullptr ); 135 delete throwStmt; 136 return result; 174 137 } 175 138 Statement * create_resume_rethrow( ThrowStmt *throwStmt ) { … … 177 140 Statement * result = new ReturnStmt( 178 141 throwStmt->get_labels(), 179 new ConstantExpr( Constant::from_bool( false ) ) 142 new ConstantExpr( 143 Constant( 144 new BasicType( 145 Type::Qualifiers(), 146 BasicType::Bool 147 ), 148 "0") 149 ) 180 150 ); 181 151 delete throwStmt; … … 190 160 return block; 191 161 } 192 FunctionDecl * create_try_wrapper( CompoundStmt *body ) { 193 194 return new FunctionDecl( "try", Type::StorageClasses(), 195 LinkageSpec::Cforall, try_func_t.clone(), body ); 162 FunctionDecl * create_try_wrapper( TryStmt *tryStmt ) { 163 CompoundStmt * body = base_try->get_block(); 164 base_try->set_block(nullptr); 165 166 return new FunctionDecl("try", Type::StorageClasses(), 167 LinkageSpec::Cforall, void_func_t, body); 196 168 } 197 169 198 170 FunctionDecl * create_terminate_catch( CatchList &handlers ) { 199 171 std::list<CaseStmt *> handler_wrappers; 200 201 FunctionType *func_type = catch_func_t.clone();202 DeclarationWithType * index_obj = func_type->get_parameters().front();203 // DeclarationWithType * except_obj = func_type->get_parameters().back();204 172 205 173 // Index 1..{number of handlers} … … 210 178 CatchStmt * handler = *it; 211 179 212 // INTEGERconstant Version 213 // case `index`: 214 // { 215 // `handler.body` 216 // } 217 // return; 218 std::list<Statement *> caseBody; 219 caseBody.push_back( handler->get_body() ); 220 handler->set_body( nullptr ); 221 caseBody.push_back( new ReturnStmt( noLabels, nullptr ) ); 222 223 handler_wrappers.push_back( new CaseStmt( 180 std::list<Statement *> core; 181 if ( /*the exception is named*/ ) { 182 ObjectDecl * local_except = /* Dynamic case, same */; 183 core->push_back( new DeclStmt( noLabel, local_except ) ); 184 } 185 // Append the provided statement to the handler. 186 core->push_back( cur_handler->get_body() ); 187 // Append return onto the inner block? case stmt list? 188 CaseStmt * wrapper = new CaseStmt( 224 189 noLabels, 225 190 new ConstantExpr( Constant::from_int( index ) ), 226 caseBody 227 ) ); 191 core 192 ); 193 handler_wrappers.push_back(wrapper); 228 194 } 229 195 // TODO: Some sort of meaningful error on default perhaps? 230 231 std::list<Statement*> stmt_handlers;232 while ( !handler_wrappers.empty() ) {233 stmt_handlers.push_back( handler_wrappers.front() );234 handler_wrappers.pop_front();235 }236 196 237 197 SwitchStmt * handler_lookup = new SwitchStmt( 238 198 noLabels, 239 nameOf( index_obj ), 240 stmt_handlers 199 /*parameter 0: index*/, 200 handler_wrappers, 201 false 241 202 ); 242 203 CompoundStmt * body = new CompoundStmt( noLabels ); … … 244 205 245 206 return new FunctionDecl("catch", Type::StorageClasses(), 246 LinkageSpec::Cforall, func_type, body);207 LinkageSpec::Cforall, catch_func_t, body); 247 208 } 248 209 249 210 // Create a single check from a moddified handler. 250 // except_obj is referenced, modded_handler will be freed. 251 CompoundStmt *create_single_matcher( 252 DeclarationWithType * except_obj, CatchStmt * modded_handler ) { 253 CompoundStmt * block = new CompoundStmt( noLabels ); 254 255 // INTEGERconstant Version 256 assert( nullptr == modded_handler->get_decl() ); 257 ConstantExpr * number = 258 dynamic_cast<ConstantExpr*>( modded_handler->get_cond() ); 259 assert( number ); 260 modded_handler->set_cond( nullptr ); 261 262 Expression * cond; 263 { 264 std::list<Expression *> args; 265 args.push_back( number ); 266 267 std::list<Expression *> rhs_args; 268 rhs_args.push_back( nameOf( except_obj ) ); 269 Expression * rhs = new UntypedExpr( 270 new NameExpr( "*?" ), rhs_args ); 271 args.push_back( rhs ); 272 273 cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args ); 274 } 211 CompoundStmt *create_single_matcher( CatchStmt * modded_handler ) { 212 CompoundStmt * block = new CompoundStmt( noLables ); 213 214 appendDeclStmt( block, modded_handler->get_decl() ); 215 216 // TODO: This is not the actual check. 217 LogicalExpr * cond = new ConstantExpr( Constant::from_bool( false ) ); 275 218 276 219 if ( modded_handler->get_cond() ) { 277 cond = new LogicalExpr( cond, modded_handler->get_cond() ) ;220 cond = new LogicalExpr( cond, modded_handler->get_cond() )q 278 221 } 279 222 block->push_back( new IfStmt( noLabels, 280 cond, modded_handler->get_body() , nullptr ));223 cond, modded_handler->get_body() ); 281 224 282 225 modded_handler->set_decl( nullptr ); … … 289 232 FunctionDecl * create_terminate_match( CatchList &handlers ) { 290 233 CompoundStmt * body = new CompoundStmt( noLabels ); 291 292 FunctionType * func_type = match_func_t.clone();293 DeclarationWithType * except_obj = func_type->get_parameters().back();294 234 295 235 // Index 1..{number of handlers} … … 300 240 CatchStmt * handler = *it; 301 241 302 // Body should have been taken by create_terminate_catch. 303 assert( nullptr == handler->get_body() ); 304 305 // Create new body. 242 // body should have been taken by create_terminate_catch. 243 // assert( nullptr == handler->get_body() ); 306 244 handler->set_body( new ReturnStmt( noLabels, 307 245 new ConstantExpr( Constant::from_int( index ) ) ) ); 308 246 309 // Create the handler. 310 body->push_back( create_single_matcher( except_obj, handler ) ); 311 *it = nullptr; 312 } 313 314 body->push_back( new ReturnStmt( noLabels, new ConstantExpr( 315 Constant::from_int( 0 ) ) ) ); 247 body->push_back( create_single_matcher( handler ) ); 248 } 316 249 317 250 return new FunctionDecl("match", Type::StorageClasses(), 318 LinkageSpec::Cforall, func_type, body);319 } 320 321 CompoundStmt * create_terminate_caller(251 LinkageSpec::Cforall, match_func_t, body); 252 } 253 254 Statement * create_terminate_caller( 322 255 FunctionDecl * try_wrapper, 323 256 FunctionDecl * terminate_catch, 324 257 FunctionDecl * terminate_match) { 325 258 326 UntypedExpr * caller = new UntypedExpr( new NameExpr( 327 "__cfaehm__try_terminate" ) ); 328 std::list<Expression *>& args = caller->get_args(); 259 ApplicationExpr * caller = new ApplicationExpr( /* ... */ ); 260 std::list<Expression *>& args = caller.get_args(); 329 261 args.push_back( nameOf( try_wrapper ) ); 330 262 args.push_back( nameOf( terminate_catch ) ); 331 263 args.push_back( nameOf( terminate_match ) ); 332 264 333 CompoundStmt * callStmt = new CompoundStmt( noLabels ); 334 callStmt->push_back( new ExprStmt( noLabels, caller ) ); 335 return callStmt; 265 return new ExprStmt( noLabels, caller ); 336 266 } 337 267 338 268 FunctionDecl * create_resume_handler( CatchList &handlers ) { 339 CompoundStmt * body = new CompoundStmt( noLabels ); 340 341 FunctionType * func_type = match_func_t.clone(); 342 DeclarationWithType * except_obj = func_type->get_parameters().back(); 269 CompoundStmt * body = new CompountStmt( noLabels ); 343 270 344 271 CatchList::iterator it; … … 353 280 handling_code->push_back( handler->get_body() ); 354 281 } 355 handling_code->push_back( new ReturnStmt( noLabel s,356 new ConstantExpr( Constant::from_bool( true ) ) ) );282 handling_code->push_back( new ReturnStmt( noLabel, 283 new ConstantExpr( Constant::from_bool( false ) ) ) ); 357 284 handler->set_body( handling_code ); 358 285 359 286 // Create the handler. 360 body->push_back( create_single_matcher( except_obj, handler ) ); 361 *it = nullptr; 362 } 363 364 body->push_back( new ReturnStmt( noLabels, new ConstantExpr( 365 Constant::from_bool( false ) ) ) ); 287 body->push_back( create_single_matcher( handler ) ); 288 } 366 289 367 290 return new FunctionDecl("handle", Type::StorageClasses(), 368 LinkageSpec::Cforall, func_type, body); 369 } 370 371 CompoundStmt * create_resume_wrapper( 372 StructDecl * node_decl, 291 LinkageSpec::Cforall, handle_func_t, body); 292 } 293 294 Statement * create_resume_wrapper( 373 295 Statement * wraps, 374 296 FunctionDecl * resume_handler ) { 375 297 CompoundStmt * body = new CompoundStmt( noLabels ); 376 298 377 // struct __try_resume_node __resume_node 378 // __attribute__((cleanup( __cfaehm__try_resume_cleanup ))); 379 // ** unwinding of the stack here could cause problems ** 380 // ** however I don't think that can happen currently ** 381 // __cfaehm__try_resume_setup( &__resume_node, resume_handler ); 299 // struct node = {current top resume handler, call to resume_handler}; 300 // __attribute__((cleanup( ... ))); 301 // set top resume handler to node. 302 // The wrapped statement. 303 304 ListInit * node_init; 305 { 306 std::list<Initializer*> field_inits; 307 field_inits.push_back( new SingleInit( /* ... */ ) ); 308 field_inits.push_back( new SingleInit( nameOf( resume_handler ) ) ); 309 node_init = new ListInit( field_inits ); 310 } 382 311 383 312 std::list< Attribute * > attributes; 384 313 { 385 314 std::list< Expression * > attr_params; 386 attr_params.push_back( n ew NameExpr(387 "__cfaehm__try_resume_cleanup") );388 attributes.push_back( new Attribute( "cleanup", attr_params ) );389 } 390 391 ObjectDecl * obj = newObjectDecl(392 " __resume_node",315 attr_params.push_back( nameOf( /* ... deconstructor ... */ ) ); 316 attrributes.push_back( new Attribute( "cleanup", attr_params ) ); 317 } 318 319 appendDeclStmt( body, 320 /**/ ObjectDecl( 321 "resume_node", 393 322 Type::StorageClasses(), 394 323 LinkageSpec::Cforall, 395 324 nullptr, 396 new StructInstType( 397 Type::Qualifiers(), 398 node_decl 399 ), 400 nullptr, 325 /* Type* = resume_node */, 326 node_init, 401 327 attributes 402 ); 403 appendDeclStmt( body, obj ); 404 405 UntypedExpr *setup = new UntypedExpr( new NameExpr( 406 "__cfaehm__try_resume_setup" ) ); 407 setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) ); 408 setup->get_args().push_back( nameOf( resume_handler ) ); 409 410 body->push_back( new ExprStmt( noLabels, setup ) ); 411 328 ) 329 ); 412 330 body->push_back( wraps ); 413 331 return body; … … 415 333 416 334 FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ) { 417 FinallyStmt * finally = tryStmt->get_finally(); 418 CompoundStmt * body = finally->get_block(); 419 finally->set_block( nullptr ); 420 delete finally; 335 CompoundStmt * body = tryStmt->get_finally(); 421 336 tryStmt->set_finally( nullptr ); 422 337 423 338 return new FunctionDecl("finally", Type::StorageClasses(), 424 LinkageSpec::Cforall, finally_func_t.clone(), body); 425 } 426 427 ObjectDecl * create_finally_hook( 428 StructDecl * hook_decl, FunctionDecl * finally_wrapper ) { 429 // struct __cfaehm__cleanup_hook __finally_hook 430 // __attribute__((cleanup( finally_wrapper ))); 339 LinkageSpec::Cforall, void_func_t, body); 340 } 341 342 ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper ) { 343 // struct _cleanup_hook NAME __attribute__((cleanup( ... ))); 431 344 432 345 // Make Cleanup Attribute. … … 435 348 std::list< Expression * > attr_params; 436 349 attr_params.push_back( nameOf( finally_wrapper ) ); 437 attr ibutes.push_back( new Attribute( "cleanup", attr_params ) );438 } 439 440 return new ObjectDecl(441 "__finally_hook",350 attrributes.push_back( new Attribute( "cleanup", attr_params ) ); 351 } 352 353 return ObjectDecl( /* ... */ 354 const std::string &name "finally_hook", 442 355 Type::StorageClasses(), 443 356 LinkageSpec::Cforall, 444 357 nullptr, 445 new StructInstType( 446 noQualifiers, 447 hook_decl 448 ), 358 /* ... Type * ... */, 449 359 nullptr, 450 360 attributes … … 453 363 454 364 455 class ExceptionMutatorCore : public With Guards{365 class ExceptionMutatorCore : public WithScoping { 456 366 enum Context { NoHandler, TerHandler, ResHandler }; 457 367 … … 460 370 // loop, switch or the goto stays within the function. 461 371 462 Context cur _context;372 Context curContext; 463 373 464 374 // We might not need this, but a unique base for each try block's … … 467 377 //unsigned int try_count = 0; 468 378 469 StructDecl *node_decl;470 StructDecl *hook_decl;471 379 472 380 public: 473 381 ExceptionMutatorCore() : 474 cur_context(NoHandler), 475 node_decl(nullptr), hook_decl(nullptr) 382 curContext(NoHandler) 476 383 {} 477 384 478 void premutate( CatchStmt *catchStmt ); 479 void premutate( StructDecl *structDecl ); 385 void premutate( CatchStmt *tryStmt ); 480 386 Statement * postmutate( ThrowStmt *throwStmt ); 481 387 Statement * postmutate( TryStmt *tryStmt ); … … 487 393 if ( throwStmt->get_expr() ) { 488 394 return create_terminate_throw( throwStmt ); 489 } else if ( TerHandler == cur _context ) {395 } else if ( TerHandler == curContext ) { 490 396 return create_terminate_rethrow( throwStmt ); 491 397 } else { 492 398 assertf(false, "Invalid throw in %s at %i\n", 493 throwStmt->location.filename .c_str(),399 throwStmt->location.filename, 494 400 throwStmt->location.linenumber); 495 401 return nullptr; … … 498 404 if ( throwStmt->get_expr() ) { 499 405 return create_resume_throw( throwStmt ); 500 } else if ( ResHandler == cur _context ) {406 } else if ( ResHandler == curContext ) { 501 407 return create_resume_rethrow( throwStmt ); 502 408 } else { 503 409 assertf(false, "Invalid throwResume in %s at %i\n", 504 throwStmt->location.filename .c_str(),410 throwStmt->location.filename, 505 411 throwStmt->location.linenumber); 506 412 return nullptr; … … 510 416 511 417 Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) { 512 assert( node_decl );513 assert( hook_decl );514 515 418 // Generate a prefix for the function names? 516 419 517 CompoundStmt * block = new CompoundStmt( noLabels);518 CompoundStmt * inner = take_try_block( tryStmt );420 CompoundStmt * block = new CompoundStmt(); 421 Statement * inner = take_try_block( tryStmt ); 519 422 520 423 if ( tryStmt->get_finally() ) { … … 524 427 appendDeclStmt( block, finally_block ); 525 428 // Create and add the finally cleanup hook. 526 appendDeclStmt( block, 527 create_finally_hook( hook_decl, finally_block ) ); 528 } 529 530 CatchList termination_handlers; 531 CatchList resumption_handlers; 532 split( tryStmt->get_catchers(), 533 termination_handlers, resumption_handlers ); 534 535 if ( resumption_handlers.size() ) { 429 appendDeclStmt( block, create_finally_hook( finally_block ) ); 430 } 431 432 StatementList termination_handlers; 433 StatementList resumption_handlers; 434 split( tryStmt->get_handlers(), 435 termination_handlers, resumption_handlers ); 436 437 if ( resumeption_handlers.size() ) { 536 438 // Define the helper function. 537 439 FunctionDecl * resume_handler = … … 539 441 appendDeclStmt( block, resume_handler ); 540 442 // Prepare hooks 541 inner = create_resume_wrapper( node_decl,inner, resume_handler );443 inner = create_resume_wrapper( inner, resume_handler ); 542 444 } 543 445 … … 560 462 block->push_back( inner ); 561 463 562 //free_all( termination_handlers );563 //free_all( resumption_handlers );464 free_all( termination_handlers ); 465 free_all( resumption_handlers ); 564 466 565 467 return block; … … 567 469 568 470 void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) { 569 GuardValue( cur _context );570 if ( CatchStmt::Terminat e== catchStmt->get_kind() ) {571 cur _context = TerHandler;471 GuardValue( curContext ); 472 if ( CatchStmt::Termination == catchStmt->get_kind() ) { 473 curContext = TerHandler; 572 474 } else { 573 cur_context = ResHandler; 574 } 575 } 576 577 void ExceptionMutatorCore::premutate( StructDecl *structDecl ) { 578 if ( !structDecl->has_body() ) { 579 // Skip children? 580 return; 581 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) { 582 assert( nullptr == node_decl ); 583 node_decl = structDecl; 584 } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) { 585 assert( nullptr == hook_decl ); 586 hook_decl = structDecl; 587 } 588 // Later we might get the exception type as well. 589 } 590 591 void translateEHM( std::list< Declaration *> & translationUnit ) { 592 init_func_types(); 593 475 curContext = ResHandler; 476 } 477 } 478 479 void translateEHM( std::list< Declaration *> & translationUnit ) { 594 480 PassVisitor<ExceptionMutatorCore> translator; 595 mutateAll( translationUnit, translator ); 481 for ( Declaration * decl : translationUnit ) { 482 decl->mutate( translator ); 483 } 596 484 } 597 485 }
Note:
See TracChangeset
for help on using the changeset viewer.