Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    rbfc7811 r7862059  
    3434#include "SynTree/Statement.h"        // for CompoundStmt, CatchStmt, ThrowStmt
    3535#include "SynTree/Type.h"             // for FunctionType, Type, noQualifiers
    36 #include "SynTree/VarExprReplacer.h"  // for VarExprReplacer, VarExprReplace...
     36#include "SynTree/DeclReplacer.h"     // for DeclReplacer
    3737#include "SynTree/Visitor.h"          // for acceptAll
    3838
     
    104104                // Types used in translation, make sure to use clone.
    105105                // void (*function)();
    106                 FunctionType * try_func_t;
     106                FunctionType try_func_t;
    107107                // void (*function)(int, exception);
    108                 FunctionType * catch_func_t;
     108                FunctionType catch_func_t;
    109109                // int (*function)(exception);
    110                 FunctionType * match_func_t;
     110                FunctionType match_func_t;
    111111                // bool (*function)(exception);
    112                 FunctionType * handle_func_t;
     112                FunctionType handle_func_t;
    113113                // void (*function)(__attribute__((unused)) void *);
    114                 FunctionType * finally_func_t;
     114                FunctionType finally_func_t;
    115115
    116116                StructInstType * create_except_type() {
     
    125125                        handler_except_decl( nullptr ),
    126126                        except_decl( nullptr ), node_decl( nullptr ), hook_decl( nullptr ),
    127                         try_func_t( new FunctionType(noQualifiers, false) ),
    128                         catch_func_t( new FunctionType(noQualifiers, false) ),
    129                         match_func_t( new FunctionType(noQualifiers, false) ),
    130                         handle_func_t( new FunctionType(noQualifiers, false) ),
    131                         finally_func_t( new FunctionType(noQualifiers, false) )
     127                        try_func_t( noQualifiers, false ),
     128                        catch_func_t( noQualifiers, false ),
     129                        match_func_t( noQualifiers, false ),
     130                        handle_func_t( noQualifiers, false ),
     131                        finally_func_t( noQualifiers, false )
    132132                {}
    133133
     
    141141                assert( except_decl );
    142142
    143                 auto index_obj = new ObjectDecl(
     143                ObjectDecl index_obj(
    144144                        "__handler_index",
    145145                        Type::StorageClasses(),
     
    149149                        /*init*/ NULL
    150150                        );
    151                 auto exception_obj = new ObjectDecl(
     151                ObjectDecl exception_obj(
    152152                        "__exception_inst",
    153153                        Type::StorageClasses(),
     
    160160                        /*init*/ NULL
    161161                        );
    162                 auto bool_obj = new ObjectDecl(
     162                ObjectDecl bool_obj(
    163163                        "__ret_bool",
    164164                        Type::StorageClasses(),
     
    169169                        std::list<Attribute *>{ new Attribute( "unused" ) }
    170170                        );
    171                 auto voidptr_obj = new ObjectDecl(
     171                ObjectDecl voidptr_obj(
    172172                        "__hook",
    173173                        Type::StorageClasses(),
     
    184184                        );
    185185
    186                 ObjectDecl * unused_index_obj = index_obj->clone();
     186                ObjectDecl * unused_index_obj = index_obj.clone();
    187187                unused_index_obj->attributes.push_back( new Attribute( "unused" ) );
    188188
    189                 catch_func_t->get_parameters().push_back( index_obj );
    190                 catch_func_t->get_parameters().push_back( exception_obj->clone() );
    191                 match_func_t->get_returnVals().push_back( unused_index_obj );
    192                 match_func_t->get_parameters().push_back( exception_obj->clone() );
    193                 handle_func_t->get_returnVals().push_back( bool_obj );
    194                 handle_func_t->get_parameters().push_back( exception_obj );
    195                 finally_func_t->get_parameters().push_back( voidptr_obj );
     189                catch_func_t.get_parameters().push_back( index_obj.clone() );
     190                catch_func_t.get_parameters().push_back( exception_obj.clone() );
     191                match_func_t.get_returnVals().push_back( unused_index_obj );
     192                match_func_t.get_parameters().push_back( exception_obj.clone() );
     193                handle_func_t.get_returnVals().push_back( bool_obj.clone() );
     194                handle_func_t.get_parameters().push_back( exception_obj.clone() );
     195                finally_func_t.get_parameters().push_back( voidptr_obj.clone() );
    196196        }
    197197
     
    204204                call->get_args().push_back( throwStmt->get_expr() );
    205205                throwStmt->set_expr( nullptr );
     206                delete throwStmt;
    206207                return new ExprStmt( call );
    207208        }
     
    233234                        new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) )
    234235                        ) );
     236                delete throwStmt;
    235237                return result;
    236238        }
     
    249251                        );
    250252                result->labels = throwStmt->labels;
     253                delete throwStmt;
    251254                return result;
    252255        }
     
    264267
    265268                return new FunctionDecl( "try", Type::StorageClasses(),
    266                         LinkageSpec::Cforall, try_func_t->clone(), body );
     269                        LinkageSpec::Cforall, try_func_t.clone(), body );
    267270        }
    268271
     
    271274                std::list<CaseStmt *> handler_wrappers;
    272275
    273                 FunctionType *func_type = catch_func_t->clone();
     276                FunctionType *func_type = catch_func_t.clone();
    274277                DeclarationWithType * index_obj = func_type->get_parameters().front();
    275278                DeclarationWithType * except_obj = func_type->get_parameters().back();
     
    311314                        // Update variables in the body to point to this local copy.
    312315                        {
    313                                 VarExprReplacer::DeclMap mapping;
     316                                DeclReplacer::DeclMap mapping;
    314317                                mapping[ handler_decl ] = local_except;
    315                                 VarExprReplacer::replace( handler->body, mapping );
     318                                DeclReplacer::replace( handler->body, mapping );
    316319                        }
    317320
     
    381384                modded_handler->set_cond( nullptr );
    382385                modded_handler->set_body( nullptr );
     386                delete modded_handler;
    383387                return block;
    384388        }
     
    392396                CompoundStmt * body = new CompoundStmt();
    393397
    394                 FunctionType * func_type = match_func_t->clone();
     398                FunctionType * func_type = match_func_t.clone();
    395399                DeclarationWithType * except_obj = func_type->get_parameters().back();
    396400
     
    446450                CompoundStmt * body = new CompoundStmt();
    447451
    448                 FunctionType * func_type = handle_func_t->clone();
     452                FunctionType * func_type = handle_func_t.clone();
    449453                DeclarationWithType * except_obj = func_type->get_parameters().back();
    450454
     
    526530                CompoundStmt * body = finally->get_block();
    527531                finally->set_block( nullptr );
     532                delete finally;
    528533                tryStmt->set_finally( nullptr );
    529534
    530535                return new FunctionDecl("finally", Type::StorageClasses(),
    531                         LinkageSpec::Cforall, finally_func_t->clone(), body);
     536                        LinkageSpec::Cforall, finally_func_t.clone(), body);
    532537        }
    533538
Note: See TracChangeset for help on using the changeset viewer.