Ignore:
Timestamp:
Aug 9, 2017, 2:08:14 PM (7 years ago)
Author:
Andrew Beach <ajbeach@…>
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
Message:

Structure based exception handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    re195093 rcbce272  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug 02 12:09:00 2017
     12// Last Modified On : Tus Aug  8 16:54:00 2017
    1313// Update Count     : 7
    1414//
     
    116116                        handle_func_t( noQualifiers, false ),
    117117                        finally_func_t( noQualifiers, false )
    118                 {
    119                         init_func_types();
    120                 }
     118                {}
    121119
    122120                void premutate( CatchStmt *catchStmt );
     
    127125
    128126        void ExceptionMutatorCore::init_func_types() {
     127                assert( except_decl );
     128
    129129                ObjectDecl index_obj(
    130130                        "__handler_index",
     
    142142                        new PointerType(
    143143                                noQualifiers,
    144                                 //new StructInstType( noQualifiers, except_decl )
    145                                 new BasicType( noQualifiers, BasicType::SignedInt )
     144                                new StructInstType( noQualifiers, except_decl )
    146145                                ),
    147146                        /*init*/ NULL
     
    183182        Statement * ExceptionMutatorCore::create_given_throw(
    184183                        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` );
    198185                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() );
    201187                throwStmt->set_expr( nullptr );
    202188                delete throwStmt;
    203                 return result;
     189                return new ExprStmt( noLabels, call );
    204190        }
    205191
    206192        Statement * ExceptionMutatorCore::create_terminate_throw(
    207193                        ThrowStmt *throwStmt ) {
    208                 // { int NAME = EXPR; __throw_terminate( &NAME ); }
     194                // __throw_terminate( `throwStmt->get_name()` ); }
    209195                return create_given_throw( "__cfaehm__throw_terminate", throwStmt );
    210196        }
     
    236222        Statement * ExceptionMutatorCore::create_resume_throw(
    237223                        ThrowStmt *throwStmt ) {
    238                 // __throw_resume( EXPR );
     224                // __throw_resume( `throwStmt->get_name` );
    239225                return create_given_throw( "__cfaehm__throw_resume", throwStmt );
    240226        }
     
    253239        // TryStmt Mutation Helpers
    254240
    255         // XXX: Leave out?
    256241        CompoundStmt * ExceptionMutatorCore::take_try_block( TryStmt *tryStmt ) {
    257242                CompoundStmt * block = tryStmt->get_block();
     
    282267                        CatchStmt * handler = *it;
    283268
    284                         // INTEGERconstant Version
    285                         // 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 0
    300                         // Virtual Exception Vision
    301269                        // case `index`:
    302270                        // {
     
    305273                        // }
    306274                        // 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();
    309281                        local_except->set_init(
    310282                                new ListInit({ new SingleInit(
     
    314286                                        ) })
    315287                                );
    316 #endif
    317288                        block->push_back( new DeclStmt( noLabels, local_except ) );
    318289
     
    366337        CompoundStmt * ExceptionMutatorCore::create_single_matcher(
    367338                        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
    368347                CompoundStmt * block = new CompoundStmt( noLabels );
    369348
     349                // Local Declaration
    370350                ObjectDecl * local_except =
    371351                        dynamic_cast<ObjectDecl *>( modded_handler->get_decl() );
    372352                assert( local_except );
    373353                block->push_back( new DeclStmt( noLabels, local_except ) );
    374 #if 0
    375                 // Virtual Exception Version
    376                 // {
    377                 //     `modded_handler.decl`
    378                 //     if ( `decl.name = (virtual)`except`
    379                 //             [&& `modded_handler.cond`] ) {
    380                 //         `modded_handler.body`
    381                 //     }
    382                 // }
    383354
    384355                // Check for type match.
     
    386357                        new VirtualCastExpr( nameOf( except_obj ),
    387358                                local_except->get_type()->clone() ) );
    388 #endif
    389 
    390                 // INTEGERconstant Version
    391                 // {
    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                 }
    415359
    416360                // Add the check on the conditional if it is provided.
     
    607551        // Visiting/Mutating Functions
    608552        void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
    609                 // Currently, we make up the declaration, as there isn't one for
    610                 // 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                         nullptr
    622                         );
    623                 catchStmt->set_decl( tmp );
    624 
    625553                // Validate the Statement's form.
    626554                ObjectDecl * decl =
     
    650578                        // Skip children?
    651579                        return;
     580                } else if ( structDecl->get_name() == "__cfaehm__base_exception_t" ) {
     581                        assert( nullptr == except_decl );
     582                        except_decl = structDecl;
     583                        init_func_types();
    652584                } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {
    653585                        assert( nullptr == node_decl );
     
    661593
    662594        Statement * ExceptionMutatorCore::postmutate( ThrowStmt *throwStmt ) {
     595                assert( except_decl );
     596
    663597                // Ignoring throwStmt->get_target() for now.
    664598                if ( ThrowStmt::Terminate == throwStmt->get_kind() ) {
     
    688622
    689623        Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) {
     624                assert( except_decl );
    690625                assert( node_decl );
    691626                assert( hook_decl );
Note: See TracChangeset for help on using the changeset viewer.