Changeset cbce272
- Timestamp:
- Aug 9, 2017, 2:08:14 PM (8 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
- Location:
- src
- Files:
-
- 12 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 ); -
src/Parser/TypeData.cc
re195093 rcbce272 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 18 10:10:00 201713 // Update Count : 56 612 // Last Modified On : Wed Aug 9 13:50:00 2017 13 // Update Count : 567 14 14 // 15 15 … … 748 748 } // buildAggInst 749 749 750 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs ) {750 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) { 751 751 assert( td->kind == TypeData::Symbolic ); 752 752 NamedTypeDecl * ret; 753 753 assert( td->base ); 754 754 if ( td->symbolic.isTypedef ) { 755 ret = new TypedefDecl( name, scs, typebuild( td->base ) );755 ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage ); 756 756 } else { 757 757 ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Any ); … … 817 817 return buildEnum( td, attributes ); 818 818 } else if ( td->kind == TypeData::Symbolic ) { 819 return buildSymbolic( td, name, scs );819 return buildSymbolic( td, name, scs, linkage ); 820 820 } else { 821 821 return (new ObjectDecl( name, scs, linkage, bitfieldWidth, typebuild( td ), init, attributes ))->set_asmName( asmName ); -
src/Parser/parser.yy
re195093 rcbce272 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jul 31 14:54:32201713 // Update Count : 247 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 4 13:33:00 2017 13 // Update Count : 2475 14 14 // 15 15 … … 182 182 %type<en> asm_clobbers_list_opt 183 183 %type<flag> asm_volatile_opt 184 %type<en> handler_predicate_opt 184 185 185 186 // statements … … 968 969 969 970 handler_clause: 970 // TEMPORARY, TEST EXCEPTIONS 971 handler_key '(' push push INTEGERconstant pop ')' compound_statement pop 972 { $$ = new StatementNode( build_catch( $1, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); } 973 | handler_clause handler_key '(' push push INTEGERconstant pop ')' compound_statement pop 974 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); } 975 976 | handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 977 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $9 ) ); } 971 handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 972 { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); } 978 973 | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 979 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $10 ) ) ); }974 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); } 980 975 ; 981 976 982 977 handler_predicate_opt: 983 978 //empty 979 { $$ = nullptr; } 984 980 | ';' conditional_expression 981 { $$ = $2; } 985 982 ; 986 983 … … 1674 1671 | aggregate_key attribute_list_opt typegen_name // CFA 1675 1672 { $$ = $3->addQualifiers( $2 ); } 1676 1677 // Temp, testing TreeStruct1678 | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name1679 {1680 typedefTable.makeTypedef( *$4 ); // create typedef1681 if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $1682 forall = false; // reset1683 }1684 '{' field_declaration_list '}'1685 {1686 $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,1687 $4, nullptr, nullptr, $7, true )->addQualifiers( $3 );1688 }1689 | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name TYPEDEFname1690 {1691 typedefTable.makeTypedef( *$4 ); // create typedef1692 if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $1693 forall = false; // reset1694 }1695 '{' field_declaration_list '}'1696 {1697 $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,1698 $4, $5, nullptr, $8, true )->addQualifiers( $3 );1699 }1700 1673 ; 1701 1674 -
src/ResolvExpr/Resolver.cc
re195093 rcbce272 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 23 17:23:14201713 // Update Count : 21 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Aug 8 16:06:00 2017 13 // Update Count : 212 14 14 // 15 15 … … 71 71 virtual void visit( ReturnStmt *returnStmt ) override; 72 72 virtual void visit( ThrowStmt *throwStmt ) override; 73 virtual void visit( CatchStmt *catchStmt ) override; 73 74 74 75 virtual void visit( SingleInit *singleInit ) override; … … 368 369 369 370 void Resolver::visit( ThrowStmt *throwStmt ) { 371 // TODO: Replace *exception type with &exception type. 370 372 if ( throwStmt->get_expr() ) { 371 Expression * wrapped = new CastExpr( throwStmt->get_expr(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 373 StructDecl * exception_decl = 374 lookupStruct( "__cfaehm__base_exception_t" ); 375 assert( exception_decl ); 376 Expression * wrapped = new CastExpr( 377 throwStmt->get_expr(), 378 new PointerType( 379 noQualifiers, 380 new StructInstType( 381 noQualifiers, 382 exception_decl 383 ) 384 ) 385 ); 372 386 Expression * newExpr = findSingleExpression( wrapped, *this ); 373 387 throwStmt->set_expr( newExpr ); 388 } 389 } 390 391 void Resolver::visit( CatchStmt *catchStmt ) { 392 if ( catchStmt->get_cond() ) { 393 Expression * wrapped = new CastExpr( 394 catchStmt->get_cond(), 395 new BasicType( noQualifiers, BasicType::Bool ) 396 ); 397 catchStmt->set_cond( findSingleExpression( wrapped, *this ) ); 374 398 } 375 399 } -
src/SymTab/Validate.cc
re195093 rcbce272 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 30 16:50:13201713 // Update Count : 35 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Aug 8 13:27:00 2017 13 // Update Count : 358 14 14 // 15 15 … … 686 686 Type *designatorType = tyDecl->get_base()->stripDeclarator(); 687 687 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) { 688 return new StructDecl( aggDecl->get_name() );688 return new StructDecl( aggDecl->get_name(), DeclarationNode::Struct, noAttributes, tyDecl->get_linkage() ); 689 689 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) { 690 return new UnionDecl( aggDecl->get_name() );690 return new UnionDecl( aggDecl->get_name(), noAttributes, tyDecl->get_linkage() ); 691 691 } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) { 692 return new EnumDecl( enumDecl->get_name() );692 return new EnumDecl( enumDecl->get_name(), noAttributes, tyDecl->get_linkage() ); 693 693 } else { 694 694 return ret->clone(); … … 783 783 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 784 784 } // if 785 TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type ) );785 TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type, aggDecl->get_linkage() ) ); 786 786 typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel ); 787 787 } // if -
src/SynTree/AggregateDecl.cc
re195093 rcbce272 10 10 // Created On : Sun May 17 23:56:39 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jun 27 15:30:00 201713 // Update Count : 2 112 // Last Modified On : Fri Aug 4 14:22:00 2017 13 // Update Count : 22 14 14 // 15 15 … … 40 40 using std::endl; 41 41 42 os << typeString() << " " << get_name(); 43 os << string( indent+2, ' ' ) << "with body " << has_body() << endl; 42 os << typeString() << " " << get_name() << ":"; 43 if ( get_linkage() != LinkageSpec::Cforall ) { 44 os << " " << LinkageSpec::linkageName( get_linkage() ); 45 } // if 46 os << " with body " << has_body() << endl; 44 47 45 48 if ( ! parameters.empty() ) { -
src/SynTree/Declaration.h
re195093 rcbce272 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:52:59201713 // Update Count : 12 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Aug 8 13:25:00 2017 13 // Update Count : 125 14 14 // 15 15 … … 223 223 typedef NamedTypeDecl Parent; 224 224 public: 225 TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type ) : Parent( name, scs, type ) {}225 TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) : Parent( name, scs, type ) { set_linkage( spec ); } 226 226 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} 227 227 -
src/SynTree/NamedTypeDecl.cc
re195093 rcbce272 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 16 07:49:44201713 // Update Count : 1 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 13:28:00 2017 13 // Update Count : 14 14 14 // 15 15 … … 38 38 if ( get_name() != "" ) { 39 39 os << get_name() << ": "; 40 } // if 41 if ( get_linkage() != LinkageSpec::Cforall ) { 42 os << LinkageSpec::linkageName( get_linkage() ) << " "; 40 43 } // if 41 44 get_storageClasses().print( os ); -
src/Virtual/ExpandCasts.cc
re195093 rcbce272 10 10 // Created On : Mon Jul 24 13:59:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 26 14:16:00 201713 // Update Count : 012 // Last Modified On : Tus Aug 2 14:59:00 2017 13 // Update Count : 1 14 14 // 15 15 … … 78 78 79 79 void VirtualCastCore::premutate( FunctionDecl * functionDecl ) { 80 if ( (! vcast_decl) && functionDecl->get_statements() &&80 if ( (! vcast_decl) && 81 81 functionDecl->get_name() == "__cfa__virtual_cast" ) { 82 82 vcast_decl = functionDecl; … … 101 101 assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." ); 102 102 103 //assert( vcast_decl );103 assert( vcast_decl ); 104 104 assert( pvt_decl ); 105 105 106 106 // May only cast to a pointer or reference type. 107 107 // A earlier validation should give a syntax error, this is 108 // just to make sure errors don't creep in. 108 // just to make sure errors don't creep during translation. 109 // Move to helper with more detailed error messages. 109 110 PointerType * target_type = 110 111 dynamic_cast<PointerType *>( castExpr->get_result() ); 111 112 assert( target_type ); 112 113 113 114 StructInstType * target_struct = 114 115 dynamic_cast<StructInstType *>( target_type->get_base() ); 116 assert( target_struct ); 117 115 118 StructDecl * target_decl = target_struct->get_baseStruct(); 116 119 … … 124 127 125 128 Expression * result = new CastExpr( 126 //new ApplicationExpr( new VariableExpr( vcast_decl ), { 129 //new ApplicationExpr( 130 //new AddressExpr( new VariableExpr( vcast_decl ) ), 131 //new CastExpr( new VariableExpr( vcast_decl ), 132 // new PointerType( noQualifiers, 133 // vcast_decl->get_type()->clone() 134 // ) 135 // ), 127 136 new UntypedExpr( new NameExpr( "__cfa__virtual_cast" ), { 128 new CastExpr(129 new AddressExpr( new VariableExpr( table ) ),130 pointer_to_pvt(1)131 ),132 new CastExpr(133 castExpr->get_arg(),134 pointer_to_pvt(2)135 ) }136 ),137 castExpr->get_result() 137 new CastExpr( 138 new AddressExpr( new VariableExpr( table ) ), 139 pointer_to_pvt(1) 140 ), 141 new CastExpr( 142 castExpr->get_arg(), 143 pointer_to_pvt(2) 144 ) 145 } ), 146 castExpr->get_result()->clone() 138 147 ); 139 148 -
src/libcfa/exception.c
re195093 rcbce272 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 31 13:51:00 201713 // Update Count : 412 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 6 14 14 // 15 16 #include <stddef.h> // for size_t 15 17 16 18 #include "exception.h" … … 32 34 #include "lsda.h" 33 35 36 37 // Base exception vtable is abstract, you should not have base exceptions. 38 struct __cfaehm__base_exception_t_vtable 39 ___cfaehm__base_exception_t_vtable_instance = { 40 .parent = NULL, 41 .size = 0, 42 .copy = NULL, 43 .free = NULL, 44 .msg = NULL 45 }; 46 47 34 48 // Temperary global exception context. Does not work with concurency. 35 49 struct exception_context_t { … … 39 53 exception * current_exception; 40 54 int current_handler_index; 41 42 // Storage to avoid using the heap for exceptions. 43 exception built_in_storage; 44 } shared_stack = {NULL, NULL, 0, 0, 0}; 55 } shared_stack = {NULL, NULL, 0, 0}; 45 56 46 57 // Get the current exception context. … … 69 80 70 81 // DEBUG 71 printf("Throwing resumption exception %d\n", *except);82 printf("Throwing resumption exception\n"); 72 83 73 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 83 94 } 84 95 85 printf("Unhandled exception %d\n", *except);96 printf("Unhandled exception\n"); 86 97 shared_stack.current_resume = original_head; 87 98 … … 124 135 // Allocate memory for the exception. 125 136 struct __cfaehm__node * store = malloc( 126 sizeof( except ) + sizeof( struct __cfaehm__node ));137 sizeof( struct __cfaehm__node ) + except->virtual_table->size ); 127 138 128 139 if ( ! store ) { … … 136 147 137 148 // Copy the exception to storage. 138 *context->current_exception = *except;149 except->virtual_table->copy( context->current_exception, except ); 139 150 } 140 151 … … 144 155 145 156 // DEBUG 146 printf( "Deleting Exception %d\n", *except);157 printf( "Deleting Exception\n"); 147 158 148 159 // Remove the exception from the list. … … 163 174 164 175 // Free the old exception node. 176 except->virtual_table->free( except ); 165 177 free( to_free ); 166 178 } 167 179 168 180 // If this isn't a rethrow (*except==0), delete the provided exception. 169 void __cfaehm__cleanup_terminate( exception ** except ) {170 if ( * except ) __cfaehm__delete_exception( *except );181 void __cfaehm__cleanup_terminate( void * except ) { 182 if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except ); 171 183 } 172 184 -
src/libcfa/exception.h
re195093 rcbce272 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 27 12:42:00 201713 // Update Count : 412 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 5 14 14 // 15 15 … … 21 21 #endif 22 22 23 #if 1 24 typedef int exception; 25 #else 26 struct exception_t; 27 struct exception_t_vtable { 28 struct exception_t_vtable const * parent; 23 struct __cfaehm__base_exception_t; 24 typedef struct __cfaehm__base_exception_t exception; 25 struct __cfaehm__base_exception_t_vtable { 26 const struct __cfaehm__base_exception_t_vtable * parent; 29 27 size_t size; 30 void (*copy)(struct exception_t *this, struct exception_t * other); 31 void (*free)(struct exception_t *this); 32 const char (*msg)(struct exception_t *this); 28 void (*copy)(struct __cfaehm__base_exception_t *this, 29 struct __cfaehm__base_exception_t * other); 30 void (*free)(struct __cfaehm__base_exception_t *this); 31 const char (*msg)(struct __cfaehm__base_exception_t *this); 33 32 }; 34 struct exception_t {35 struct exception_vtable const * virtual_table;33 struct __cfaehm__base_exception_t { 34 struct __cfaehm__base_exception_t_vtable const * virtual_table; 36 35 }; 37 typedef struct exception_t exception; 38 #endif 36 extern struct __cfaehm__base_exception_t_vtable 37 ___cfaehm__base_exception_t_vtable_instance; 39 38 40 39 … … 51 50 52 51 // Clean-up the exception in catch blocks. 53 void __cfaehm__cleanup_terminate( exception ** except);52 void __cfaehm__cleanup_terminate(void * except); 54 53 55 54 // Data structure creates a list of resume handlers. -
src/tests/except-0.c
re195093 rcbce272 6 6 #include <stdbool.h> 7 7 8 // Local type to mark exits from scopes. (see ERROR) 8 9 struct signal_exit { 9 10 const char * area; … … 19 20 } 20 21 21 void terminate(int except_value) { 22 23 // Local Exception Types and manual vtable types. 24 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin) 25 struct yin; 26 struct yin_vtable { 27 struct exception_t_vtable const * parent; 28 size_t size; 29 void (*copy)(yin *this, yin * other); 30 void (*free)(yin *this); 31 const char (*msg)(yin *this); 32 }; 33 struct yin { 34 struct yin_vtable const * parent; 35 }; 36 void yin_msg(yin) { 37 return "in"; 38 } 39 yin_vtable _yin_vtable_instance = { 40 &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg 41 } 42 43 44 void terminate(exception * except_value) { 22 45 signal_exit a = {"terminate function"}; 23 46 throw except_value; … … 25 48 } 26 49 27 void resume( intexcept_value) {50 void resume(exception * except_value) { 28 51 signal_exit a = {"resume function"}; 29 52 throwResume except_value;
Note: See TracChangeset
for help on using the changeset viewer.