Changeset cbce272 for src/ControlStruct
- Timestamp:
- Aug 9, 2017, 2:08:14 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 65cdc1e
- Parents:
- e195093
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
re195093 rcbce272 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 02 12:09:00 201712 // Last Modified On : Tus Aug 8 16:54:00 2017 13 13 // Update Count : 7 14 14 // … … 116 116 handle_func_t( noQualifiers, false ), 117 117 finally_func_t( noQualifiers, false ) 118 { 119 init_func_types(); 120 } 118 {} 121 119 122 120 void premutate( CatchStmt *catchStmt ); … … 127 125 128 126 void ExceptionMutatorCore::init_func_types() { 127 assert( except_decl ); 128 129 129 ObjectDecl index_obj( 130 130 "__handler_index", … … 142 142 new PointerType( 143 143 noQualifiers, 144 //new StructInstType( noQualifiers, except_decl ) 145 new BasicType( noQualifiers, BasicType::SignedInt ) 144 new StructInstType( noQualifiers, except_decl ) 146 145 ), 147 146 /*init*/ NULL … … 183 182 Statement * ExceptionMutatorCore::create_given_throw( 184 183 const char * throwFunc, ThrowStmt * throwStmt ) { 185 // There is an extra copy here we might be able to remove with 186 // references. 187 // { int NAME = EXPR; throwFunc( &NAME ); } 188 CompoundStmt * result = new CompoundStmt( noLabels ); 189 ObjectDecl * local = new ObjectDecl( 190 "__local_exception_copy", 191 Type::StorageClasses(), 192 LinkageSpec::Cforall, 193 NULL, 194 new BasicType( noQualifiers, BasicType::SignedInt ), 195 new SingleInit( throwStmt->get_expr() ) 196 ); 197 appendDeclStmt( result, local ); 184 // `throwFunc`( `throwStmt->get_name` ); 198 185 UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) ); 199 call->get_args().push_back( new AddressExpr( nameOf( local ) ) ); 200 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) ); 186 call->get_args().push_back( throwStmt->get_expr() ); 201 187 throwStmt->set_expr( nullptr ); 202 188 delete throwStmt; 203 return result;189 return new ExprStmt( noLabels, call ); 204 190 } 205 191 206 192 Statement * ExceptionMutatorCore::create_terminate_throw( 207 193 ThrowStmt *throwStmt ) { 208 // { int NAME = EXPR; __throw_terminate( &NAME); }194 // __throw_terminate( `throwStmt->get_name()` ); } 209 195 return create_given_throw( "__cfaehm__throw_terminate", throwStmt ); 210 196 } … … 236 222 Statement * ExceptionMutatorCore::create_resume_throw( 237 223 ThrowStmt *throwStmt ) { 238 // __throw_resume( EXPR);224 // __throw_resume( `throwStmt->get_name` ); 239 225 return create_given_throw( "__cfaehm__throw_resume", throwStmt ); 240 226 } … … 253 239 // TryStmt Mutation Helpers 254 240 255 // XXX: Leave out?256 241 CompoundStmt * ExceptionMutatorCore::take_try_block( TryStmt *tryStmt ) { 257 242 CompoundStmt * block = tryStmt->get_block(); … … 282 267 CatchStmt * handler = *it; 283 268 284 // INTEGERconstant Version285 // case `index`:286 // {287 // `handler.decl` {inserted} = { except_obj };288 // `handler.body`289 // }290 // return;291 CompoundStmt * block = new CompoundStmt( noLabels );292 293 // Just copy the exception value. (Post Validation)294 ObjectDecl * handler_decl =295 static_cast<ObjectDecl *>( handler->get_decl() );296 ObjectDecl * local_except = handler_decl->clone();297 local_except->set_init(298 new ListInit({ new SingleInit( nameOf( except_obj ) ) }) );299 #if 0300 // Virtual Exception Vision301 269 // case `index`: 302 270 // { … … 305 273 // } 306 274 // return; 307 308 // Save a cast copy of the exception (should always succeed). 275 CompoundStmt * block = new CompoundStmt( noLabels ); 276 277 // Just copy the exception value. (Post Validation) 278 ObjectDecl * handler_decl = 279 static_cast<ObjectDecl *>( handler->get_decl() ); 280 ObjectDecl * local_except = handler_decl->clone(); 309 281 local_except->set_init( 310 282 new ListInit({ new SingleInit( … … 314 286 ) }) 315 287 ); 316 #endif317 288 block->push_back( new DeclStmt( noLabels, local_except ) ); 318 289 … … 366 337 CompoundStmt * ExceptionMutatorCore::create_single_matcher( 367 338 DeclarationWithType * except_obj, CatchStmt * modded_handler ) { 339 // { 340 // `modded_handler.decl` 341 // if ( `decl.name = (virtual `decl.type`)`except` 342 // [&& `modded_handler.cond`] ) { 343 // `modded_handler.body` 344 // } 345 // } 346 368 347 CompoundStmt * block = new CompoundStmt( noLabels ); 369 348 349 // Local Declaration 370 350 ObjectDecl * local_except = 371 351 dynamic_cast<ObjectDecl *>( modded_handler->get_decl() ); 372 352 assert( local_except ); 373 353 block->push_back( new DeclStmt( noLabels, local_except ) ); 374 #if 0375 // Virtual Exception Version376 // {377 // `modded_handler.decl`378 // if ( `decl.name = (virtual)`except`379 // [&& `modded_handler.cond`] ) {380 // `modded_handler.body`381 // }382 // }383 354 384 355 // Check for type match. … … 386 357 new VirtualCastExpr( nameOf( except_obj ), 387 358 local_except->get_type()->clone() ) ); 388 #endif389 390 // INTEGERconstant Version391 // {392 // `modded_handler.decl` = *`except`393 // if ( `decl.name` == `modded_handler.cond` ) {394 // `modded_handler.body`395 // }396 // }397 ConstantExpr * number =398 dynamic_cast<ConstantExpr*>( modded_handler->get_cond() );399 assert( number );400 modded_handler->set_cond( nullptr );401 402 Expression * cond;403 {404 std::list<Expression *> args;405 args.push_back( number );406 407 std::list<Expression *> rhs_args;408 rhs_args.push_back( nameOf( except_obj ) );409 Expression * rhs = new UntypedExpr(410 new NameExpr( "*?" ), rhs_args );411 args.push_back( rhs );412 413 cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args );414 }415 359 416 360 // Add the check on the conditional if it is provided. … … 607 551 // Visiting/Mutating Functions 608 552 void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) { 609 // Currently, we make up the declaration, as there isn't one for610 // integers.611 assert( ! catchStmt->get_decl() );612 ObjectDecl * tmp = new ObjectDecl(613 "_hidden_local",614 Type::StorageClasses(),615 LinkageSpec::Cforall,616 nullptr,617 new PointerType(618 noQualifiers,619 new BasicType( noQualifiers, BasicType::SignedInt )620 ),621 nullptr622 );623 catchStmt->set_decl( tmp );624 625 553 // Validate the Statement's form. 626 554 ObjectDecl * decl = … … 650 578 // Skip children? 651 579 return; 580 } else if ( structDecl->get_name() == "__cfaehm__base_exception_t" ) { 581 assert( nullptr == except_decl ); 582 except_decl = structDecl; 583 init_func_types(); 652 584 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) { 653 585 assert( nullptr == node_decl ); … … 661 593 662 594 Statement * ExceptionMutatorCore::postmutate( ThrowStmt *throwStmt ) { 595 assert( except_decl ); 596 663 597 // Ignoring throwStmt->get_target() for now. 664 598 if ( ThrowStmt::Terminate == throwStmt->get_kind() ) { … … 688 622 689 623 Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) { 624 assert( except_decl ); 690 625 assert( node_decl ); 691 626 assert( hook_decl );
Note: See TracChangeset
for help on using the changeset viewer.