Changes in / [eba74ba:58e822a]


Ignore:
Location:
src
Files:
4 deleted
90 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    reba74ba r58e822a  
    11501150unsigned Indenter::tabsize = 2;
    11511151
     1152std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {
     1153        if ( node ) {
     1154                node->print( out );
     1155        } else {
     1156                out << "nullptr";
     1157        }
     1158        return out;
     1159}
     1160
    11521161// Local Variables: //
    11531162// tab-width: 4 //
  • src/CodeGen/FixMain.cc

    reba74ba r58e822a  
    2929namespace CodeGen {
    3030        bool FixMain::replace_main = false;
    31         FunctionDecl* FixMain::main_signature = nullptr;
     31        std::unique_ptr<FunctionDecl> FixMain::main_signature = nullptr;
    3232
    3333        template<typename container>
     
    4141                        SemanticError(functionDecl, "Multiple definition of main routine\n");
    4242                }
    43                 main_signature = functionDecl;
     43                main_signature.reset( functionDecl->clone() );
    4444        }
    4545
  • src/CodeGen/FixMain.h

    reba74ba r58e822a  
    4040          private:
    4141                static bool replace_main;
    42                 static FunctionDecl* main_signature;
     42                static std::unique_ptr<FunctionDecl> main_signature;
    4343        };
    4444};
  • src/CodeGen/FixNames.cc

    reba74ba r58e822a  
    1616#include "FixNames.h"
    1717
     18#include <memory>                  // for unique_ptr
    1819#include <string>                  // for string, operator!=, operator==
    1920
     
    4647        std::string mangle_main() {
    4748                FunctionType* main_type;
    48                 FunctionDecl* mainDecl = new FunctionDecl{
    49                         "main", Type::StorageClasses(), LinkageSpec::Cforall,
    50                         main_type = new FunctionType{ Type::Qualifiers(), true }, nullptr };
     49                std::unique_ptr<FunctionDecl> mainDecl { new FunctionDecl( "main", Type::StorageClasses(), LinkageSpec::Cforall,
     50                                                                                                                                   main_type = new FunctionType( Type::Qualifiers(), true ), nullptr )
     51                                };
    5152                main_type->get_returnVals().push_back(
    5253                        new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr )
    5354                );
    5455
    55                 auto && name = SymTab::Mangler::mangle( mainDecl );
     56                auto && name = SymTab::Mangler::mangle( mainDecl.get() );
    5657                // std::cerr << name << std::endl;
    5758                return std::move(name);
     
    5960        std::string mangle_main_args() {
    6061                FunctionType* main_type;
    61                 FunctionDecl* mainDecl = new FunctionDecl{
    62                         "main", Type::StorageClasses(), LinkageSpec::Cforall,
    63                         main_type = new FunctionType{ Type::Qualifiers(), false }, nullptr };
     62                std::unique_ptr<FunctionDecl> mainDecl { new FunctionDecl( "main", Type::StorageClasses(), LinkageSpec::Cforall,
     63                                                                                                                                   main_type = new FunctionType( Type::Qualifiers(), false ), nullptr )
     64                                };
    6465                main_type->get_returnVals().push_back(
    6566                        new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr )
     
    7677                );
    7778
    78                 auto&& name = SymTab::Mangler::mangle( mainDecl );
     79                auto&& name = SymTab::Mangler::mangle( mainDecl.get() );
    7980                // std::cerr << name << std::endl;
    8081                return std::move(name);
  • src/CodeGen/Generate.cc

    reba74ba r58e822a  
    4141                void cleanTree( std::list< Declaration * > & translationUnit ) {
    4242                        PassVisitor<TreeCleaner> cleaner;
    43                         filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); } );
     43                        filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); }, false );
    4444                        mutateAll( translationUnit, cleaner );
    4545                } // cleanTree
     
    7979                                }
    8080                                return false;
    81                         } );
     81                        }, false );
    8282                }
    8383
     
    8585                        Statement * callStmt = nullptr;
    8686                        std::swap( stmt->callStmt, callStmt );
     87                        delete stmt;
    8788                        return callStmt;
    8889                }
  • src/Common/PassVisitor.h

    reba74ba r58e822a  
    151151        virtual void visit( Subrange * subrange ) override final;
    152152
    153         virtual void visit( Constant * constant ) final;
     153        virtual void visit( Constant * constant ) override final;
    154154
    155155        virtual void visit( Attribute * attribute ) override final;
    156 
    157         virtual void visit( TypeSubstitution * sub ) final;
    158156
    159157        virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override final;
     
    251249        virtual Subrange * mutate( Subrange * subrange ) override final;
    252250
    253         virtual Constant * mutate( Constant * constant ) final;
     251        virtual Constant * mutate( Constant * constant ) override final;
    254252
    255253        virtual Attribute * mutate( Attribute * attribute ) override final;
  • src/Common/PassVisitor.impl.h

    reba74ba r58e822a  
    3838        MUTATE_END( type, node );      \
    3939
    40 #include "Common/GC.h"
     40
    4141
    4242template<typename T>
     
    397397                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    398398                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    399                         static ObjectDecl* func = new_static_root<ObjectDecl>(
     399                        static ObjectDecl func(
    400400                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    401401                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    402402                                nullptr
    403403                        );
    404                         indexerAddId( func );
     404                        indexerAddId( &func );
    405405                        maybeAccept_impl( node->type, *this );
    406406                        maybeAccept_impl( node->statements, *this );
     
    427427                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    428428                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    429                         static ObjectDecl* func = new_static_root<ObjectDecl>(
     429                        static ObjectDecl func(
    430430                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    431431                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    432432                                nullptr
    433433                        );
    434                         indexerAddId( func );
     434                        indexerAddId( &func );
    435435                        maybeMutate_impl( node->type, *this );
    436436                        maybeMutate_impl( node->statements, *this );
     
    12091209        indexerScopedAccept( node->result, *this );
    12101210
    1211         // xxx - not quite sure why this doesn't visit( node->function );
    12121211        for ( auto expr : node->args ) {
    12131212                visitExpression( expr );
     
    26162615// TypeSubstitution
    26172616template< typename pass_type >
    2618 void PassVisitor< pass_type >::visit( TypeSubstitution * node ) {
    2619         VISIT_START( node );
    2620 
    2621         for ( auto & p : node->typeEnv ) {
    2622                 indexerScopedAccept( p.second, *this );
    2623         }
    2624         for ( auto & p : node->varEnv ) {
    2625                 indexerScopedAccept( p.second, *this );
    2626         }
    2627 
    2628         VISIT_END( node );
    2629 }
    2630 
    2631 template< typename pass_type >
    26322617TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
    26332618        MUTATE_START( node );
  • src/Common/module.mk

    reba74ba r58e822a  
    66## file "LICENCE" distributed with Cforall.
    77##
    8 ## module.mk -- 
     8## module.mk --
    99##
    1010## Author           : Richard C. Bilson
     
    1818       Common/UniqueName.cc \
    1919       Common/DebugMalloc.cc \
    20        Common/GC.cc \
    2120       Common/Assert.cc \
    2221       Common/Heap.cc
  • src/Common/utility.h

    reba74ba r58e822a  
    190190
    191191template <typename E, typename UnaryPredicate, template< typename, typename...> class Container, typename... Args >
    192 void filter( Container< E *, Args... > & container, UnaryPredicate pred ) {
     192void filter( Container< E *, Args... > & container, UnaryPredicate pred, bool doDelete ) {
    193193        auto i = begin( container );
    194194        while ( i != end( container ) ) {
    195195                auto it = next( i );
    196196                if ( pred( *i ) ) {
     197                        if ( doDelete ) {
     198                                delete *i;
     199                        } // if
    197200                        container.erase( i );
    198201                } // if
  • src/Concurrency/Keywords.cc

    reba74ba r58e822a  
    1919#include <string>                  // for string, operator==
    2020
    21 #include "Common/GC.h"             // for new_static_root
    2221#include "Common/PassVisitor.h"    // for PassVisitor
    2322#include "Common/SemanticError.h"  // for SemanticError
     
    207206                StructDecl* dtor_guard_decl = nullptr;
    208207
    209                 static Type* generic_func;
     208                static std::unique_ptr< Type > generic_func;
    210209        };
    211210
    212         Type* MutexKeyword::generic_func = new_static_root<FunctionType>( noQualifiers, true );
     211        std::unique_ptr< Type > MutexKeyword::generic_func = std::unique_ptr< Type >(
     212                new FunctionType(
     213                        noQualifiers,
     214                        true
     215                )
     216        );
    213217
    214218        //-----------------------------------------------------------------------------
     
    284288                        // convert (thread &)t to (thread_desc &)*get_thread(t), etc.
    285289                        if( !type_decl ) SemanticError( cast, context_error );
     290                        Expression * arg = cast->arg;
     291                        cast->arg = nullptr;
     292                        delete cast;
    286293                        return new CastExpr(
    287294                                UntypedExpr::createDeref(
    288                                         new UntypedExpr( new NameExpr( getter_name ), { cast->arg } )
     295                                        new UntypedExpr( new NameExpr( getter_name ), { arg } )
    289296                                ),
    290297                                new ReferenceType(
     
    311318                StructDecl * forward = decl->clone();
    312319                forward->set_body( false );
     320                deleteAll( forward->get_members() );
    313321                forward->get_members().clear();
    314322
     
    374382                        fixupGenerics(main_type, decl);
    375383                }
     384
     385                delete this_decl;
    376386
    377387                declsToAddBefore.push_back( forward );
  • src/Concurrency/Waitfor.cc

    reba74ba r58e822a  
    137137                StructDecl          * decl_acceptable = nullptr;
    138138                StructDecl          * decl_monitor    = nullptr;
     139
     140                static std::unique_ptr< Type > generic_func;
    139141
    140142                UniqueName namer_acc = "__acceptables_"s;
     
    474476                }
    475477
     478                delete setter;
     479
    476480                return new VariableExpr( timeout );
    477481        }
  • src/ControlStruct/ExceptTranslate.cc

    reba74ba r58e822a  
    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();
     
    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
  • src/ControlStruct/MLEMutator.cc

    reba74ba r58e822a  
    226226
    227227                // transform break/continue statements into goto to simplify later handling of branches
     228                delete branchStmt;
    228229                return new BranchStmt( exitLabel, BranchStmt::Goto );
    229230        }
  • src/GenPoly/Box.cc

    reba74ba r58e822a  
    281281        /// Adds parameters for otype layout to a function type
    282282        void addOtypeParams( FunctionType *layoutFnType, std::list< TypeDecl* > &otypeParams ) {
    283                 auto sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    284 
    285                 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin();
    286                                 param != otypeParams.end(); ++param ) {
    287                         auto paramType = new TypeInstType( Type::Qualifiers(), (*param)->get_name(), *param );
    288                         std::string paramName = mangleType( paramType );
    289                         layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) );
    290                         layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) );
     283                BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     284
     285                for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
     286                        TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );
     287                        std::string paramName = mangleType( &paramType );
     288                        layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
     289                        layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
    291290                }
    292291        }
     
    743742                                Type * newType = param->clone();
    744743                                if ( env ) env->apply( newType );
    745                                 ObjectDecl *newObj = ObjectDecl::newObject(
    746                                         tempNamer.newName(), newType, nullptr );
     744                                ObjectDecl *newObj = ObjectDecl::newObject( tempNamer.newName(), newType, nullptr );
    747745                                newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
    748746                                stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
     
    864862                        // do not carry over attributes to real type parameters/return values
    865863                        for ( DeclarationWithType * dwt : realType->parameters ) {
     864                                deleteAll( dwt->get_type()->attributes );
    866865                                dwt->get_type()->attributes.clear();
    867866                        }
    868867                        for ( DeclarationWithType * dwt : realType->returnVals ) {
     868                                deleteAll( dwt->get_type()->attributes );
    869869                                dwt->get_type()->attributes.clear();
    870870                        }
     
    987987                        } // if
    988988                        appExpr->get_args().clear();
     989                        delete appExpr;
    989990                        return addAssign;
    990991                }
     
    10171018                                                } // if
    10181019                                                if ( baseType1 || baseType2 ) {
     1020                                                        delete ret->get_result();
    10191021                                                        ret->set_result( appExpr->get_result()->clone() );
    10201022                                                        if ( appExpr->get_env() ) {
     
    10231025                                                        } // if
    10241026                                                        appExpr->get_args().clear();
     1027                                                        delete appExpr;
    10251028                                                        return ret;
    10261029                                                } // if
     
    10321035                                                        Expression *ret = appExpr->get_args().front();
    10331036                                                        // fix expr type to remove pointer
     1037                                                        delete ret->get_result();
    10341038                                                        ret->set_result( appExpr->get_result()->clone() );
    10351039                                                        if ( appExpr->get_env() ) {
     
    10381042                                                        } // if
    10391043                                                        appExpr->get_args().clear();
     1044                                                        delete appExpr;
    10401045                                                        return ret;
    10411046                                                } // if
     
    11771182                                                Expression *ret = expr->args.front();
    11781183                                                expr->args.clear();
     1184                                                delete expr;
    11791185                                                return ret;
    11801186                                        } // if
     
    12101216                        if ( polytype || needs ) {
    12111217                                Expression *ret = addrExpr->arg;
     1218                                delete ret->result;
    12121219                                ret->result = addrExpr->result->clone();
    12131220                                addrExpr->arg = nullptr;
     1221                                delete addrExpr;
    12141222                                return ret;
    12151223                        } else {
     
    12211229                        if ( retval && returnStmt->expr ) {
    12221230                                assert( returnStmt->expr->result && ! returnStmt->expr->result->isVoid() );
     1231                                delete returnStmt->expr;
    12231232                                returnStmt->expr = nullptr;
    12241233                        } // if
     
    12631272                                }
    12641273                        }
     1274//  deleteAll( functions );
    12651275                }
    12661276
     
    12821292                        for ( Declaration * param : functionDecl->type->parameters ) {
    12831293                                if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( param ) ) {
     1294                                        delete obj->init;
    12841295                                        obj->init = nullptr;
    12851296                                }
     
    13291340                        std::list< DeclarationWithType *> inferredParams;
    13301341                        // size/align/offset parameters may not be used in body, pass along with unused attribute.
    1331                         auto newObj = new ObjectDecl(
    1332                                 "", Type::StorageClasses(), LinkageSpec::C, 0,
    1333                                 new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0,
    1334                             { new Attribute( "unused" ) } );
    1335                         auto newPtr = new ObjectDecl(
    1336                                 "", Type::StorageClasses(), LinkageSpec::C, 0,
    1337                             new PointerType( Type::Qualifiers(),
    1338                                         new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
    1339                         for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin();
    1340                                         tyParm != funcType->get_forall().end(); ++tyParm ) {
     1342                        ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0,
     1343                                           { new Attribute( "unused" ) } );
     1344                        ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0,
     1345                                           new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
     1346                        for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    13411347                                ObjectDecl *sizeParm, *alignParm;
    13421348                                // add all size and alignment parameters to parameter list
    13431349                                if ( (*tyParm)->isComplete() ) {
    1344                                         auto parmType = new TypeInstType(
    1345                                                 Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
    1346                                         std::string parmName = mangleType( parmType );
    1347 
    1348                                         sizeParm = newObj->clone();
     1350                                        TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
     1351                                        std::string parmName = mangleType( &parmType );
     1352
     1353                                        sizeParm = newObj.clone();
    13491354                                        sizeParm->set_name( sizeofName( parmName ) );
    13501355                                        last = funcType->get_parameters().insert( last, sizeParm );
    13511356                                        ++last;
    13521357
    1353                                         alignParm = newObj->clone();
     1358                                        alignParm = newObj.clone();
    13541359                                        alignParm->set_name( alignofName( parmName ) );
    13551360                                        last = funcType->get_parameters().insert( last, alignParm );
     
    13741379
    13751380                                        ObjectDecl *sizeParm, *alignParm, *offsetParm;
    1376                                         sizeParm = newObj->clone();
     1381                                        sizeParm = newObj.clone();
    13771382                                        sizeParm->set_name( sizeofName( typeName ) );
    13781383                                        last = funcType->get_parameters().insert( last, sizeParm );
    13791384                                        ++last;
    13801385
    1381                                         alignParm = newObj->clone();
     1386                                        alignParm = newObj.clone();
    13821387                                        alignParm->set_name( alignofName( typeName ) );
    13831388                                        last = funcType->get_parameters().insert( last, alignParm );
     
    13871392                                                // NOTE zero-length arrays are illegal in C, so empty structs have no offset array
    13881393                                                if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) {
    1389                                                         offsetParm = newPtr->clone();
     1394                                                        offsetParm = newPtr.clone();
    13901395                                                        offsetParm->set_name( offsetofName( typeName ) );
    13911396                                                        last = funcType->get_parameters().insert( last, offsetParm );
     
    14381443                        if ( Type * base = typeDecl->base ) {
    14391444                                // add size/align variables for opaque type declarations
    1440                                 auto inst = new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl );
    1441                                 std::string typeName = mangleType( inst );
     1445                                TypeInstType inst( Type::Qualifiers(), typeDecl->name, typeDecl );
     1446                                std::string typeName = mangleType( &inst );
    14421447                                Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    14431448
     
    14961501                                                        // polymorphic aggregate members should be converted into monomorphic members.
    14971502                                                        // Using char[size_T] here respects the expected sizing rules of an aggregate type.
    1498                                                         field->type = polyToMonoType( field->type );
     1503                                                        Type * newType = polyToMonoType( field->type );
     1504                                                        delete field->type;
     1505                                                        field->type = newType;
    14991506                                                }
    15001507                                        }
     
    15191526                                        stmtsToAddBefore.push_back( new DeclStmt( newBuf ) );
    15201527
     1528                                        delete objectDecl->get_init();
    15211529                                        objectDecl->set_init( new SingleInit( new VariableExpr( newBuf ) ) );
    15221530                                }
     
    15971605                        }
    15981606
     1607                        delete memberType;
     1608                        delete memberExpr;
    15991609                        return newMemberExpr;
    16001610                }
     
    16161626                                                addrExpr->arg = nullptr;
    16171627                                                std::swap( addrExpr->env, ret->env );
     1628                                                delete addrExpr;
    16181629                                                return ret;
    16191630                                        }
     
    16241635
    16251636                ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) {
    1626                         ObjectDecl *newObj = new ObjectDecl(
    1627                                 name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init );
     1637                        ObjectDecl *newObj = new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init );
    16281638                        stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
    16291639                        return newObj;
     
    17581768                       
    17591769                        Expression * gen = genSizeof( ty );
    1760                         return gen ? gen : sizeofExpr;
     1770                        if ( gen ) {
     1771                                delete sizeofExpr;
     1772                                return gen;
     1773                        } else return sizeofExpr;
    17611774                }
    17621775
     
    17641777                        Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result();
    17651778                        if ( findGeneric( ty ) ) {
    1766                                 return new NameExpr( alignofName( mangleType( ty ) ) );
     1779                                Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) );
     1780                                delete alignofExpr;
     1781                                return ret;
    17671782                        }
    17681783                        return alignofExpr;
     
    17791794                                if ( i == -1 ) return offsetofExpr;
    17801795
    1781                                 return makeOffsetIndex( ty, i );
     1796                                Expression *offsetInd = makeOffsetIndex( ty, i );
     1797                                delete offsetofExpr;
     1798                                return offsetInd;
    17821799                        } else if ( dynamic_cast< UnionInstType* >( ty ) ) {
    17831800                                // all union members are at offset zero
     1801                                delete offsetofExpr;
    17841802                                return new ConstantExpr( Constant::from_ulong( 0 ) );
    17851803                        } else return offsetofExpr;
     
    18211839                        }
    18221840
     1841                        delete offsetPackExpr;
    18231842                        return ret;
    18241843                }
  • src/GenPoly/GenPoly.cc

    reba74ba r58e822a  
    445445                Type * newType = arg->clone();
    446446                if ( env ) env->apply( newType );
     447                std::unique_ptr<Type> manager( newType );
    447448                // if the argument's type is polymorphic, we don't need to box again!
    448449                return ! isPolyType( newType );
  • src/GenPoly/InstantiateGeneric.cc

    reba74ba r58e822a  
    5858
    5959                TypeList& operator= ( const TypeList &that ) {
     60                        deleteAll( params );
     61
    6062                        params.clear();
    6163                        cloneAll( that.params, params );
     
    6567
    6668                TypeList& operator= ( TypeList &&that ) {
     69                        deleteAll( params );
     70
    6771                        params = std::move( that.params );
    6872
     
    7074                }
    7175
    72                 ~TypeList() {}
     76                ~TypeList() { deleteAll( params ); }
    7377
    7478                bool operator== ( const TypeList& that ) const {
     
    289293        /// Strips the instances's type parameters
    290294        void stripInstParams( ReferenceToType *inst ) {
     295                deleteAll( inst->get_parameters() );
    291296                inst->get_parameters().clear();
    292297        }
     
    295300                substituteMembers( base->get_members(), baseParams, typeSubs );
    296301
     302                // xxx - can't delete type parameters because they may have assertions that are used
     303                // deleteAll( baseParams );
    297304                baseParams.clear();
    298305
     
    373380                        newInst->set_baseStruct( concDecl );
    374381
     382                        delete inst;
    375383                        inst = newInst;
    376384                        break;
     
    382390                }
    383391
     392                deleteAll( typeSubs );
    384393                return inst;
    385394        }
     
    421430                        newInst->set_baseUnion( concDecl );
    422431
     432                        delete inst;
    423433                        inst = newInst;
    424434                        break;
     
    429439                }
    430440
     441                deleteAll( typeSubs );
    431442                return inst;
    432443        }
     
    466477                        ResolvExpr::adjustExprType( ret->result ); // pointer decay
    467478                        std::swap( ret->env, memberExpr->env );
     479                        delete memberExpr;
    468480                        return ret;
    469481                }
  • src/GenPoly/Lvalue.cc

    reba74ba r58e822a  
    5151                                assertf( base, "expected pointer type in dereference (type was %s)", toString( arg->result ).c_str() );
    5252                                ApplicationExpr * ret = new ApplicationExpr( deref, { arg } );
     53                                delete ret->result;
    5354                                ret->result = base->clone();
    5455                                ret->result->set_lvalue( true );
     
    175176                                        return ret;
    176177                                }
     178                                delete result;
    177179                        }
    178180                        return appExpr;
     
    233235                                                        Type * baseType = InitTweak::getPointerBase( arg->result );
    234236                                                        assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg->result ).c_str() );
    235                                                         arg->set_result( new PointerType( Type::Qualifiers(), baseType->clone() ) );
     237                                                        PointerType * ptrType = new PointerType( Type::Qualifiers(), baseType->clone() );
     238                                                        delete arg->result;
     239                                                        arg->result = ptrType;
    236240                                                        arg = mkDeref( arg );
    237241                                                        // assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) );
     
    405409                                }
    406410                                ret->env = castExpr->env;
     411                                delete ret->result;
    407412                                ret->result = castExpr->result;
    408413                                castExpr->env = nullptr;
    409414                                castExpr->arg = nullptr;
    410415                                castExpr->result = nullptr;
     416                                delete castExpr;
    411417                                return ret;
    412418                        } else if ( diff < 0 ) {
     
    424430                                }
    425431                                ret->env = castExpr->env;
     432                                delete ret->result;
    426433                                ret->result = castExpr->result;
    427434                                ret->result->set_lvalue( true ); // ensure result is lvalue
     
    429436                                castExpr->arg = nullptr;
    430437                                castExpr->result = nullptr;
     438                                delete castExpr;
    431439                                return ret;
    432440                        } else {
     
    443451                                        castExpr->arg = nullptr;
    444452                                        std::swap( castExpr->env, ret->env );
     453                                        delete castExpr;
    445454                                        return ret;
    446455                                }
     
    453462                        Type::Qualifiers qualifiers = refType->get_qualifiers();
    454463                        refType->base = nullptr;
     464                        delete refType;
    455465                        return new PointerType( qualifiers, base );
    456466                }
     
    464474                                ret->env = expr->env;
    465475                                expr->env = nullptr;
     476                                delete expr;
    466477                                return ret;
    467478                        } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) {
     
    472483                                ret->env = expr->env;
    473484                                expr->env = nullptr;
     485                                delete expr;
    474486
    475487                                // conditional expr type may not be either of the argument types, need to unify
     
    504516                                        arg0 = nullptr;
    505517                                        addrExpr->env = nullptr;
     518                                        delete addrExpr;
    506519                                        return ret;
    507520                                }
     
    533546                                                addrExpr->arg = nullptr;
    534547                                                appExpr->env = nullptr;
     548                                                delete appExpr;
    535549                                                return ret;
    536550                                        }
  • src/GenPoly/ScrubTyVars.cc

    reba74ba r58e822a  
    2828                if ( ! tyVars ) {
    2929                        if ( typeInst->get_isFtype() ) {
    30                                 return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) };
     30                                delete typeInst;
     31                                return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
    3132                        } else {
    32                                 return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) };
     33                                PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
     34                                delete typeInst;
     35                                return ret;
    3336                        }
    3437                }
     
    3942                          case TypeDecl::Dtype:
    4043                          case TypeDecl::Ttype:
    41                                 return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) };
     44                                {
     45                                        PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
     46                                        delete typeInst;
     47                                        return ret;
     48                                }
    4249                          case TypeDecl::Ftype:
    43                                 return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) };
     50                                delete typeInst;
     51                                return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
    4452                        } // switch
    4553                } // if
     
    4957        Type * ScrubTyVars::mutateAggregateType( Type * ty ) {
    5058                if ( shouldScrub( ty ) ) {
    51                         return new PointerType{ Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) };
     59                        PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) );
     60                        delete ty;
     61                        return ret;
    5262                }
    5363                return ty;
     
    94104                        Type * ret = dynType->acceptMutator( *visitor );
    95105                        ret->get_qualifiers() |= pointer->get_qualifiers();
     106                        pointer->base = nullptr;
     107                        delete pointer;
    96108                        return ret;
    97109                }
  • src/GenPoly/Specialize.cc

    reba74ba r58e822a  
    1717#include <iterator>                      // for back_insert_iterator, back_i...
    1818#include <map>                           // for _Rb_tree_iterator, _Rb_tree_...
     19#include <memory>                        // for unique_ptr
    1920#include <string>                        // for string
    2021#include <tuple>                         // for get
     
    192193                                explodeSimple( new TupleIndexExpr( expr->clone(), i ), out );
    193194                        }
     195                        delete expr;
    194196                } else {
    195197                        // non-tuple type - output a clone of the expression
     
    224226                        env->apply( actualType );
    225227                }
     228                std::unique_ptr< FunctionType > actualTypeManager( actualType ); // for RAII
    226229                std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin();
    227230                std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end();
  • src/InitTweak/FixGlobalInit.cc

    reba74ba r58e822a  
    5757                GlobalFixer & fixer = visitor.pass;
    5858                // don't need to include function if it's empty
    59                 if ( ! fixer.initFunction->get_statements()->get_kids().empty() ) {
     59                if ( fixer.initFunction->get_statements()->get_kids().empty() ) {
     60                        delete fixer.initFunction;
     61                } else {
    6062                        translationUnit.push_back( fixer.initFunction );
    6163                } // if
    6264
    63                 if ( ! fixer.destroyFunction->get_statements()->get_kids().empty() ) {
     65                if ( fixer.destroyFunction->get_statements()->get_kids().empty() ) {
     66                        delete fixer.destroyFunction;
     67                } else {
    6468                        translationUnit.push_back( fixer.destroyFunction );
    6569                } // if
     
    126130                                objDecl->set_init( NULL );
    127131                        } // if
     132                        delete ctorInit;
    128133                } // if
    129134        }
  • src/InitTweak/FixInit.cc

    reba74ba r58e822a  
    454454                                resolved->env = nullptr;
    455455                        } // if
     456                        delete stmt;
    456457                        if ( TupleAssignExpr * assign = dynamic_cast< TupleAssignExpr * >( resolved ) ) {
    457458                                // fix newly generated StmtExpr
     
    553554                                result = result->clone();
    554555                                env->apply( result );
    555                                 if ( ! InitTweak::isConstructable( result ) ) return;
     556                                if ( ! InitTweak::isConstructable( result ) ) {
     557                                        delete result;
     558                                        return;
     559                                }
    556560
    557561                                // create variable that will hold the result of the stmt expr
     
    648652                        std::swap( impCpCtorExpr->env, callExpr->env );
    649653                        assert( impCpCtorExpr->env == nullptr );
     654                        delete impCpCtorExpr;
    650655
    651656                        if ( returnDecl ) {
     
    706711                        if ( unqMap.count( unqExpr->get_id() ) ) {
    707712                                // take data from other UniqueExpr to ensure consistency
     713                                delete unqExpr->get_expr();
    708714                                unqExpr->set_expr( unqMap[unqExpr->get_id()]->get_expr()->clone() );
     715                                delete unqExpr->get_result();
    709716                                unqExpr->set_result( maybeClone( unqExpr->get_expr()->get_result() ) );
    710717                                if ( unqCount[ unqExpr->get_id() ] == 0 ) {  // insert destructor after the last use of the unique expression
     
    817824                                                        // create a new object which is never used
    818825                                                        static UniqueName dummyNamer( "_dummy" );
    819                                                         return new ObjectDecl{
    820                                                                 dummyNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0,
    821                                                                 new PointerType{ Type::Qualifiers(), new VoidType( Type::Qualifiers() ) },
    822                                                                 0, std::list< Attribute * >{ new Attribute("unused") } };
     826                                                        ObjectDecl * dummy = new ObjectDecl( dummyNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ), 0, std::list< Attribute * >{ new Attribute("unused") } );
     827                                                        delete ctorInit;
     828                                                        return dummy;
    823829                                                }
    824830                                        } else {
     
    846852                                        objDecl->init = nullptr;
    847853                                } // if
     854                                delete ctorInit;
    848855                        } // if
    849856                        return objDecl;
     
    12211228                        ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr );
    12221229                        declsToAddBefore.push_back( tmp );
     1230                        delete ctorExpr;
    12231231
    12241232                        // build assignment and replace constructor's first argument with new temporary
     
    12291237                        // resolve assignment and dispose of new env
    12301238                        ResolvExpr::findVoidExpression( assign, indexer );
     1239                        delete assign->env;
    12311240                        assign->env = nullptr;
    12321241
  • src/InitTweak/GenInit.cc

    reba74ba r58e822a  
    258258                                        // generic parameters should not play a role in determining whether a generic type is constructed - construct all generic types, so that
    259259                                        // polymorphic constructors make generic types managed types
    260                                         auto inst = new StructInstType( Type::Qualifiers(), aggregateDecl );
    261                                         managedTypes.insert( SymTab::Mangler::mangleConcrete( inst ) );
     260                                        StructInstType inst( Type::Qualifiers(), aggregateDecl );
     261                                        managedTypes.insert( SymTab::Mangler::mangleConcrete( &inst ) );
    262262                                        break;
    263263                                }
  • src/InitTweak/InitTweak.cc

    reba74ba r58e822a  
    55#include <memory>                  // for __shared_ptr
    66
    7 #include "Common/GC.h"             // for new_static_root
    87#include "Common/PassVisitor.h"
    98#include "Common/SemanticError.h"  // for SemanticError
     
    123122        public:
    124123                ExprImpl( Expression * expr ) : arg( expr ) {}
    125                 virtual ~ExprImpl() = default;
     124                virtual ~ExprImpl() { delete arg; }
    126125
    127126                virtual std::list< Expression * > next( std::list< Expression * > & indices ) {
     
    167166
    168167        void InitExpander::clearArrayIndices() {
     168                deleteAll( indices );
    169169                indices.clear();
    170170        }
     
    263263                build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) );
    264264                if ( block->get_kids().empty() ) {
     265                        delete block;
    265266                        return nullptr;
    266267                } else {
     
    524525                        // This operator could easily exist as a real function, but it's tricky because nothing should resolve to this function.
    525526                        TypeDecl * td = new TypeDecl( "T", noStorageClasses, nullptr, TypeDecl::Dtype, true );
    526                         assign = new_static_root<FunctionDecl>(
    527                                 "?=?", noStorageClasses, LinkageSpec::Intrinsic,
    528                                 SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr );
     527                        assign = new FunctionDecl( "?=?", noStorageClasses, LinkageSpec::Intrinsic, SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr );
    529528                }
    530529                if ( dynamic_cast< ReferenceType * >( dst->result ) ) {
  • src/MakeLibCfa.cc

    reba74ba r58e822a  
    6565                struct ZeroOneReplacer {
    6666                        ZeroOneReplacer( Type * t ) : type( t ) {}
     67                        ~ZeroOneReplacer() { delete type; }
    6768                        Type * type = nullptr;
    6869
    6970                        Type * common( Type * t ) {
    7071                                if ( ! type ) return t;
     72                                delete t;
    7173                                return type->clone();
    7274                        }
  • src/Makefile.in

    reba74ba r58e822a  
    163163        Common/driver_cfa_cpp-UniqueName.$(OBJEXT) \
    164164        Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT) \
    165         Common/driver_cfa_cpp-GC.$(OBJEXT) \
    166165        Common/driver_cfa_cpp-Assert.$(OBJEXT) \
    167166        Common/driver_cfa_cpp-Heap.$(OBJEXT) \
     
    251250        SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \
    252251        SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \
    253         SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT) \
    254252        SynTree/driver_cfa_cpp-DeclReplacer.$(OBJEXT) \
    255253        Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT) \
     
    488486        CodeTools/TrackLoc.cc Concurrency/Keywords.cc \
    489487        Concurrency/Waitfor.cc Common/SemanticError.cc \
    490         Common/UniqueName.cc Common/DebugMalloc.cc Common/GC.cc \
    491         Common/Assert.cc Common/Heap.cc \
    492         ControlStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \
    493         ControlStruct/MLEMutator.cc ControlStruct/Mutate.cc \
    494         ControlStruct/ForExprMutator.cc \
     488        Common/UniqueName.cc Common/DebugMalloc.cc Common/Assert.cc \
     489        Common/Heap.cc ControlStruct/LabelGenerator.cc \
     490        ControlStruct/LabelFixer.cc ControlStruct/MLEMutator.cc \
     491        ControlStruct/Mutate.cc ControlStruct/ForExprMutator.cc \
    495492        ControlStruct/ExceptTranslate.cc GenPoly/Box.cc \
    496493        GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc \
     
    530527        SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \
    531528        SynTree/Initializer.cc SynTree/TypeSubstitution.cc \
    532         SynTree/Attribute.cc SynTree/BaseSyntaxNode.cc \
    533         SynTree/DeclReplacer.cc Tuples/TupleAssignment.cc \
    534         Tuples/TupleExpansion.cc Tuples/Explode.cc \
    535         Virtual/ExpandCasts.cc
     529        SynTree/Attribute.cc SynTree/DeclReplacer.cc \
     530        Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \
     531        Tuples/Explode.cc Virtual/ExpandCasts.cc
    536532MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \
    537533        ${cfa_cpplib_PROGRAMS}}
     
    675671        Common/$(DEPDIR)/$(am__dirstamp)
    676672Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT): Common/$(am__dirstamp) \
    677         Common/$(DEPDIR)/$(am__dirstamp)
    678 Common/driver_cfa_cpp-GC.$(OBJEXT): Common/$(am__dirstamp) \
    679673        Common/$(DEPDIR)/$(am__dirstamp)
    680674Common/driver_cfa_cpp-Assert.$(OBJEXT): Common/$(am__dirstamp) \
     
    921915SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \
    922916        SynTree/$(DEPDIR)/$(am__dirstamp)
    923 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT):  \
    924         SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp)
    925917SynTree/driver_cfa_cpp-DeclReplacer.$(OBJEXT):  \
    926918        SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp)
     
    984976@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Assert.Po@am__quote@
    985977@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-DebugMalloc.Po@am__quote@
    986 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-GC.Po@am__quote@
    987978@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Heap.Po@am__quote@
    988979@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-SemanticError.Po@am__quote@
     
    10481039@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@
    10491040@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@
    1050 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po@am__quote@
    10511041@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@
    10521042@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@
     
    13081298@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Common/driver_cfa_cpp-DebugMalloc.obj `if test -f 'Common/DebugMalloc.cc'; then $(CYGPATH_W) 'Common/DebugMalloc.cc'; else $(CYGPATH_W) '$(srcdir)/Common/DebugMalloc.cc'; fi`
    13091299
    1310 Common/driver_cfa_cpp-GC.o: Common/GC.cc
    1311 @am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Common/driver_cfa_cpp-GC.o -MD -MP -MF Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo -c -o Common/driver_cfa_cpp-GC.o `test -f 'Common/GC.cc' || echo '$(srcdir)/'`Common/GC.cc
    1312 @am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo Common/$(DEPDIR)/driver_cfa_cpp-GC.Po
    1313 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='Common/GC.cc' object='Common/driver_cfa_cpp-GC.o' libtool=no @AMDEPBACKSLASH@
    1314 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1315 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Common/driver_cfa_cpp-GC.o `test -f 'Common/GC.cc' || echo '$(srcdir)/'`Common/GC.cc
    1316 
    1317 Common/driver_cfa_cpp-GC.obj: Common/GC.cc
    1318 @am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Common/driver_cfa_cpp-GC.obj -MD -MP -MF Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo -c -o Common/driver_cfa_cpp-GC.obj `if test -f 'Common/GC.cc'; then $(CYGPATH_W) 'Common/GC.cc'; else $(CYGPATH_W) '$(srcdir)/Common/GC.cc'; fi`
    1319 @am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo Common/$(DEPDIR)/driver_cfa_cpp-GC.Po
    1320 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='Common/GC.cc' object='Common/driver_cfa_cpp-GC.obj' libtool=no @AMDEPBACKSLASH@
    1321 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1322 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Common/driver_cfa_cpp-GC.obj `if test -f 'Common/GC.cc'; then $(CYGPATH_W) 'Common/GC.cc'; else $(CYGPATH_W) '$(srcdir)/Common/GC.cc'; fi`
    1323 
    13241300Common/driver_cfa_cpp-Assert.o: Common/Assert.cc
    13251301@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Common/driver_cfa_cpp-Assert.o -MD -MP -MF Common/$(DEPDIR)/driver_cfa_cpp-Assert.Tpo -c -o Common/driver_cfa_cpp-Assert.o `test -f 'Common/Assert.cc' || echo '$(srcdir)/'`Common/Assert.cc
     
    25392515@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    25402516@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi`
    2541 
    2542 SynTree/driver_cfa_cpp-BaseSyntaxNode.o: SynTree/BaseSyntaxNode.cc
    2543 @am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc
    2544 @am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po
    2545 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.o' libtool=no @AMDEPBACKSLASH@
    2546 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    2547 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc
    2548 
    2549 SynTree/driver_cfa_cpp-BaseSyntaxNode.obj: SynTree/BaseSyntaxNode.cc
    2550 @am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi`
    2551 @am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po
    2552 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.obj' libtool=no @AMDEPBACKSLASH@
    2553 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    2554 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi`
    25552517
    25562518SynTree/driver_cfa_cpp-DeclReplacer.o: SynTree/DeclReplacer.cc
  • src/Parser/DeclarationNode.cc

    reba74ba r58e822a  
    9494
    9595        delete assert.condition;
     96        delete assert.message;
    9697}
    9798
     
    10031004                                        obj->location = cur->location;
    10041005                                        * out++ = obj;
     1006                                        delete agg;
    10051007                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    10061008                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
  • src/Parser/ExpressionNode.cc

    reba74ba r58e822a  
    407407        Type * targetType = maybeMoveBuildType( decl_node );
    408408        if ( dynamic_cast< VoidType * >( targetType ) ) {
     409                delete targetType;
    409410                return new CastExpr( maybeMoveBuild< Expression >(expr_node), false );
    410411        } else {
     
    434435
    435436Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
    436         return new UntypedOffsetofExpr{ maybeMoveBuildType( decl_node ), member->get_name() };
     437        Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
     438        delete member;
     439        return ret;
    437440} // build_offsetOf
    438441
  • src/Parser/ParseNode.h

    reba74ba r58e822a  
    124124
    125125        virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
    126                 os << expr << std::endl;
     126                os << expr.get() << std::endl;
    127127        }
    128128        void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
    129129
    130130        template<typename T>
    131         bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr); }
    132 
    133         Expression * build() const { return expr; }
     131        bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); }
     132
     133        Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }
    134134  private:
    135135        bool extension = false;
    136         Expression* expr;
     136        std::unique_ptr<Expression> expr;
    137137}; // ExpressionNode
    138138
     
    360360
    361361        virtual StatementNode * clone() const final { assert( false ); return nullptr; }
    362         Statement * build() const { return stmt; }
     362        Statement * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }
    363363
    364364        virtual StatementNode * add_label( const std::string * name, DeclarationNode * attr = nullptr ) {
     
    372372
    373373        virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
    374                 os << stmt << std::endl;
     374                os << stmt.get() << std::endl;
    375375        }
    376376  private:
    377         Statement* stmt;
     377        std::unique_ptr<Statement> stmt;
    378378}; // StatementNode
    379379
  • src/Parser/StatementNode.cc

    reba74ba r58e822a  
    5050                agg = decl;
    5151        } // if
    52         stmt = new DeclStmt{ maybeMoveBuild< Declaration >(agg) };
     52        stmt.reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );
    5353} // StatementNode::StatementNode
    5454
     
    5858        for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) {
    5959                StatementNode * node = strict_dynamic_cast< StatementNode * >(curr);
    60                 assert( dynamic_cast< CaseStmt * >(node->stmt) );
     60                assert( dynamic_cast< CaseStmt * >(node->stmt.get()) );
    6161                prev = curr;
    6262        } // for
     
    6666        buildMoveList( stmt, stmts );
    6767        // splice any new Statements to end of current Statements
    68         CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt);
     68        CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt.get());
    6969        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    7070        return this;
  • src/ResolvExpr/AdjustExprType.cc

    reba74ba r58e822a  
    6666
    6767        Type * AdjustExprType::postmutate( ArrayType * arrayType ) {
    68                 return new PointerType{ arrayType->get_qualifiers(), arrayType->base };
     68                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base );
     69                arrayType->base = nullptr;
     70                delete arrayType;
     71                return pointerType;
    6972        }
    7073
    7174        Type * AdjustExprType::postmutate( FunctionType * functionType ) {
    72                 return new PointerType{ Type::Qualifiers(), functionType };
     75                return new PointerType( Type::Qualifiers(), functionType );
    7376        }
    7477
     
    7780                if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
    7881                        if ( eqvClass.data.kind == TypeDecl::Ftype ) {
    79                                 return new PointerType{ Type::Qualifiers(), typeInst };
     82                                PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
     83                                return pointerType;
    8084                        }
    8185                } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
    8286                        if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
    8387                                if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
    84                                         return new PointerType{ Type::Qualifiers(), typeInst };
     88                                        PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
     89                                        return pointerType;
    8590                                } // if
    8691                        } // if
  • src/ResolvExpr/Alternative.cc

    reba74ba r58e822a  
    2020#include <utility>                       // for move
    2121
    22 #include "Common/GC.h"
    23 #include "Common/PassVisitor.h"
    2422#include "Common/utility.h"              // for maybeClone
    2523#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
    2624#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    2725#include "SynTree/Expression.h"          // for Expression
    28 #include "SynTree/GcTracer.h"
    2926#include "SynTree/Type.h"                // for Type
    3027
     
    3734        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
    3835                : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
    39        
    40         Alternative::Alternative( const Alternative& o )
    41                 : cost( o.cost ), cvtCost( o.cvtCost ), expr( maybeClone( o.expr ) ), env( o.env ) {}
    42        
    43         Alternative & Alternative::operator= ( const Alternative& o ) {
    44                 if ( &o == this ) return *this;
    45                 cost = o.cost;
    46                 cvtCost = o.cvtCost;
    47                 expr = maybeClone( o.expr );
    48                 env = o.env;
     36
     37        Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
     38        }
     39
     40        Alternative &Alternative::operator=( const Alternative &other ) {
     41                if ( &other == this ) return *this;
     42                delete expr;
     43                cost = other.cost;
     44                cvtCost = other.cvtCost;
     45                expr = maybeClone( other.expr );
     46                env = other.env;
    4947                return *this;
     48        }
     49
     50        Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
     51                other.expr = nullptr;
     52        }
     53
     54        Alternative & Alternative::operator=( Alternative && other ) {
     55                if ( &other == this )  return *this;
     56                delete expr;
     57                cost = other.cost;
     58                cvtCost = other.cvtCost;
     59                expr = other.expr;
     60                env = other.env;
     61                other.expr = nullptr;
     62                return *this;
     63        }
     64
     65        Alternative::~Alternative() {
     66                delete expr;
    5067        }
    5168
     
    7996        }
    8097
    81         const GC& operator<< ( const GC& gc, const Alternative& alt ) {
    82                 PassVisitor<GcTracer> tracer{ gc };
    83                 maybeAccept( alt.expr, tracer );
    84                 tracer << alt.env;
    85                 return gc;
    86         }
    87 
    8898} // namespace ResolvExpr
    8999
  • src/ResolvExpr/Alternative.h

    reba74ba r58e822a  
    2424class Expression;
    2525
    26 class GC;
    27 
    2826namespace ResolvExpr {
    2927        struct Alternative {
     
    3230                Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost, const Cost &cvtCost );
    3331                Alternative( const Alternative &other );
    34                 Alternative & operator= ( const Alternative &other );
    35                 Alternative( Alternative&& other ) = default;
    36                 Alternative & operator= ( Alternative&& other ) = default;
     32                Alternative &operator=( const Alternative &other );
     33                Alternative( Alternative && other );
     34                Alternative &operator=( Alternative && other );
     35                ~Alternative();
    3736
    3837                void print( std::ostream &os, Indenter indent = {} ) const;
    3938
     39                /// Returns the stored expression, but released from management of this Alternative
     40                Expression* release_expr() {
     41                        Expression* tmp = expr;
     42                        expr = nullptr;
     43                        return tmp;
     44                }
     45
    4046                Cost cost;
    4147                Cost cvtCost;
    42                 Expression * expr;
     48                Expression *expr;
    4349                TypeEnvironment env;
    4450        };
     
    5662                return os;
    5763        }
    58 
    59         const GC& operator<< ( const GC&, const Alternative& );
    6064} // namespace ResolvExpr
    6165
  • src/ResolvExpr/AlternativeFinder.cc

    reba74ba r58e822a  
    2121#include <list>                    // for _List_iterator, list, _List_const_...
    2222#include <map>                     // for _Rb_tree_iterator, map, _Rb_tree_c...
    23 #include <memory>                  // for allocator_traits<>::value_type
     23#include <memory>                  // for allocator_traits<>::value_type, unique_ptr
    2424#include <utility>                 // for pair
    2525#include <vector>                  // for vector
     
    3535#include "ResolveTypeof.h"         // for resolveTypeof
    3636#include "Resolver.h"              // for resolveStmtExpr
    37 #include "Common/GC.h"             // for new_static_root
    3837#include "SymTab/Indexer.h"        // for Indexer
    3938#include "SymTab/Mangler.h"        // for Mangler
     
    102101                void addAnonConversions( const Alternative & alt );
    103102                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    104                 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name );
     103                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
    105104                /// Adds alternatives for member expressions where the left side has tuple type
    106105                void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
     
    166165                                        candidate->env.apply( newType );
    167166                                        mangleName = SymTab::Mangler::mangle( newType );
     167                                        delete newType;
    168168                                }
    169169                                std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName );
     
    297297                // adds anonymous member interpretations whenever an aggregate value type is seen.
    298298                // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value
    299                 Expression* aggrExpr = alt.expr->clone();
     299                std::unique_ptr<Expression> aggrExpr( alt.expr->clone() );
    300300                alt.env.apply( aggrExpr->get_result() );
    301301                Type * aggrType = aggrExpr->get_result();
    302302                if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
    303303                        aggrType = aggrType->stripReferences();
    304                         aggrExpr = new CastExpr{ aggrExpr, aggrType->clone() };
     304                        aggrExpr.reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );
    305305                }
    306306
    307307                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    308                         addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" );
     308                        NameExpr nameExpr( "" );
     309                        addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
    309310                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    310                         addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" );
     311                        NameExpr nameExpr( "" );
     312                        addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
    311313                } // if
    312314        }
    313315
    314316        template< typename StructOrUnionType >
    315         void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ) {
     317        void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) {
     318                // by this point, member must be a name expr
     319                NameExpr * nameExpr = dynamic_cast< NameExpr * >( member );
     320                if ( ! nameExpr ) return;
     321                const std::string & name = nameExpr->get_name();
    316322                std::list< Declaration* > members;
    317323                aggInst->lookup( name, members );
     
    562568
    563569                                Expression *varExpr = data.combine( newerAlt.cvtCost );
     570                                delete varExpr->get_result();
    564571                                varExpr->set_result( adjType->clone() );
    565572                                PRINT(
     
    578585                                (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr );
    579586                                inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out );
     587                        } else {
     588                                delete adjType;
    580589                        }
    581590                }
     
    625634        struct ArgPack {
    626635                std::size_t parent;                ///< Index of parent pack
    627                 Expression* expr;                  ///< The argument stored here
     636                std::unique_ptr<Expression> expr;  ///< The argument stored here
    628637                Cost cost;                         ///< The cost of this argument
    629638                TypeEnvironment env;               ///< Environment for this pack
     
    672681                        std::list<Expression*> exprs;
    673682                        const ArgPack* pack = this;
    674                         if ( expr ) { exprs.push_front( expr ); }
     683                        if ( expr ) { exprs.push_front( expr.release() ); }
    675684                        while ( pack->tupleStart == 0 ) {
    676685                                pack = &packs[pack->parent];
     
    679688                        }
    680689                        // reset pack to appropriate tuple
    681                         expr = new TupleExpr{ exprs };
     690                        expr.reset( new TupleExpr( exprs ) );
    682691                        tupleStart = pack->tupleStart - 1;
    683692                        parent = pack->parent;
     
    732741
    733742                                                results.emplace_back(
    734                                                         i, expl.exprs[results[i].nextExpl], copy(results[i].env),
     743                                                        i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env),
    735744                                                        copy(results[i].need), copy(results[i].have),
    736745                                                        copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl,
     
    753762                                                        newResult.parent = i;
    754763                                                        std::list<Expression*> emptyList;
    755                                                         newResult.expr = new TupleExpr{ emptyList };
     764                                                        newResult.expr.reset( new TupleExpr( emptyList ) );
    756765                                                        argType = newResult.expr->get_result();
    757766                                                } else {
     
    760769                                                        newResult.cost = results[i].cost;
    761770                                                        newResult.tupleStart = results[i].tupleStart;
    762                                                         newResult.expr = results[i].expr->clone();
     771                                                        newResult.expr.reset( results[i].expr->clone() );
    763772                                                        argType = newResult.expr->get_result();
    764773
     
    810819                                                // add new result
    811820                                                results.emplace_back(
    812                                                         i, expl.exprs.front(), move(env), copy(results[i].need),
     821                                                        i, expl.exprs.front().get(), move(env), copy(results[i].need),
    813822                                                        copy(results[i].have), move(openVars), nextArg + 1,
    814823                                                        nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
     
    836845                        if ( results[i].hasExpl() ) {
    837846                                const ExplodedActual& expl = results[i].getExpl( args );
    838                                 Expression* expr = expl.exprs[results[i].nextExpl];
     847                                Expression* expr = expl.exprs[results[i].nextExpl].get();
    839848
    840849                                TypeEnvironment env = results[i].env;
     
    907916
    908917                                // consider only first exploded actual
    909                                 Expression* expr = expl.exprs.front();
     918                                Expression* expr = expl.exprs.front().get();
    910919                                Type* actualType = expr->result->clone();
    911920
     
    10101019
    10111020                                                results.emplace_back(
    1012                                                         i, expl.exprs[results[i].nextExpl], copy(results[i].env),
     1021                                                        i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env),
    10131022                                                        copy(results[i].need), copy(results[i].have),
    10141023                                                        copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl,
     
    10461055                                                // add new result
    10471056                                                results.emplace_back(
    1048                                                         i, expl.exprs.front(), move(env), copy(results[i].need),
     1057                                                        i, expl.exprs.front().get(), move(env), copy(results[i].need),
    10491058                                                        copy(results[i].have), move(openVars), nextArg + 1, 0,
    10501059                                                        expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
     
    10801089
    10811090                // find function operators
    1082                 static auto *opExpr = new_static_root<NameExpr>( "?()" );
     1091                static NameExpr *opExpr = new NameExpr( "?()" );
    10831092                AlternativeFinder funcOpFinder( indexer, env );
    10841093                // it's ok if there aren't any defined function ops
    1085                 funcOpFinder.maybeFind( opExpr );
     1094                funcOpFinder.maybeFind( opExpr);
    10861095                PRINT(
    10871096                        std::cerr << "known function ops:" << std::endl;
     
    11121121                                )
    11131122                                // check if the type is pointer to function
    1114                                 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) {
    1115                                         if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     1123                                if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->result->stripReferences() ) ) {
     1124                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->base ) ) {
    11161125                                                Alternative newFunc( *func );
    11171126                                                referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11191128                                                        std::back_inserter( candidates ) );
    11201129                                        }
    1121                                 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
     1130                                } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
    11221131                                        EqvClass eqvClass;
    1123                                         if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) {
     1132                                        if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) {
    11241133                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    11251134                                                        Alternative newFunc( *func );
     
    11501159                                        // check if type is a pointer to function
    11511160                                        if ( PointerType* pointer = dynamic_cast<PointerType*>(
    1152                                                         funcOp->expr->get_result()->stripReferences() ) ) {
     1161                                                        funcOp->expr->result->stripReferences() ) ) {
    11531162                                                if ( FunctionType* function =
    1154                                                                 dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
     1163                                                                dynamic_cast<FunctionType*>( pointer->base ) ) {
    11551164                                                        Alternative newFunc( *funcOp );
    11561165                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11741183                        PRINT(
    11751184                                ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr );
    1176                                 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
    1177                                 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
    1178                                 std::cerr << "Case +++++++++++++ " << appExpr->get_function() << std::endl;
     1185                                PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->function->result );
     1186                                FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->base );
     1187                                std::cerr << "Case +++++++++++++ " << appExpr->function << std::endl;
    11791188                                std::cerr << "formals are:" << std::endl;
    1180                                 printAll( function->get_parameters(), std::cerr, 8 );
     1189                                printAll( function->parameters, std::cerr, 8 );
    11811190                                std::cerr << "actuals are:" << std::endl;
    1182                                 printAll( appExpr->get_args(), std::cerr, 8 );
     1191                                printAll( appExpr->args, std::cerr, 8 );
    11831192                                std::cerr << "bindings are:" << std::endl;
    11841193                                withFunc.env.print( std::cerr, 8 );
     
    12211230        bool isLvalue( Expression *expr ) {
    12221231                // xxx - recurse into tuples?
    1223                 return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );
     1232                return expr->result && ( expr->result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result ) );
    12241233        }
    12251234
     
    12561265                                componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) );
    12571266                        }
     1267                        delete argExpr;
    12581268                        assert( componentExprs.size() > 0 );
    12591269                        // produce the tuple of casts
     
    13361346        }
    13371347
    1338         namespace {
    1339                 /// Gets name from untyped member expression (member must be NameExpr)
    1340                 const std::string& get_member_name( UntypedMemberExpr *memberExpr ) {
    1341                         NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() );
    1342                         assert( nameExpr );
    1343                         return nameExpr->get_name();
    1344                 }
    1345         }
    1346 
    13471348        void AlternativeFinder::Finder::postvisit( UntypedMemberExpr *memberExpr ) {
    13481349                AlternativeFinder funcFinder( indexer, env );
     
    13531354                        Expression * aggrExpr = agg->expr->clone();
    13541355                        referenceToRvalueConversion( aggrExpr, cost );
     1356                        std::unique_ptr<Expression> guard( aggrExpr );
    13551357
    13561358                        // find member of the given type
    13571359                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    1358                                 addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) );
     1360                                addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13591361                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    1360                                 addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) );
     1362                                addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13611363                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) {
    13621364                                addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
     
    16031605                        alternatives.push_back( Alternative( new CommaExpr( newFirstArg->clone(), alt.expr->clone() ), alt.env, alt.cost ) );
    16041606                } // for
     1607                delete newFirstArg;
    16051608        }
    16061609
  • src/ResolvExpr/ConversionCost.cc

    reba74ba r58e822a  
    2020#include <string>                        // for operator==, string
    2121
    22 #include "Common/GC.h"                   // for new_static_root
    2322#include "ResolvExpr/Cost.h"             // for Cost
    2423#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
     
    352351        void ConversionCost::postvisit( EnumInstType * ) {
    353352                static Type::Qualifiers q;
    354                 static BasicType* integer = new_static_root<BasicType>( q, BasicType::SignedInt );
    355                 cost = costFunc( integer, dest, indexer, env );  // safe if dest >= int
     353                static BasicType integer( q, BasicType::SignedInt );
     354                cost = costFunc( &integer, dest, indexer, env );  // safe if dest >= int
    356355                if ( cost < Cost::unsafe ) {
    357356                        cost.incSafe();
  • src/ResolvExpr/ExplodedActual.h

    reba74ba r58e822a  
    1616#pragma once
    1717
     18#include <memory>
    1819#include <vector>
    1920
     
    2829                TypeEnvironment env;
    2930                Cost cost;
    30                 std::vector< Expression* > exprs;
     31                std::vector< std::unique_ptr<Expression> > exprs;
    3132
    3233                ExplodedActual() : env(), cost(Cost::zero), exprs() {}
  • src/ResolvExpr/ResolveTypeof.cc

    reba74ba r58e822a  
    7070                        Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer );
    7171                        assert( newExpr->result && ! newExpr->result->isVoid() );
    72                         return newExpr->result;
     72                        Type * newType = newExpr->result;
     73                        newExpr->result = nullptr;
     74                        delete typeofType;
     75                        delete newExpr;
     76                        return newType;
    7377                } // if
    7478                return typeofType;
  • src/ResolvExpr/Resolver.cc

    reba74ba r58e822a  
    2222#include "Alternative.h"                 // for Alternative, AltList
    2323#include "AlternativeFinder.h"           // for AlternativeFinder, resolveIn...
    24 #include "Common/GC.h"                   // for new_generation, collect_young
    2524#include "Common/PassVisitor.h"          // for PassVisitor
    2625#include "Common/SemanticError.h"        // for SemanticError
     
    159158                                        castExpr->arg = nullptr;
    160159                                        std::swap( expr->env, castExpr->env );
     160                                        delete castExpr;
    161161                                }
    162162                        }
     
    167167                void findUnfinishedKindExpression(Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {
    168168                        assertf( untyped, "expected a non-null expression." );
    169 
    170                         auto guard = new_generation();  // set up GC generation for this top-level expression
    171 
    172169                        TypeEnvironment env;
    173170                        AlternativeFinder finder( indexer, env );
     
    210207                        Alternative & choice = winners.front();
    211208                        if ( findDeletedExpr( choice.expr ) ) {
    212                                 trace( choice.expr );
    213209                                SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
    214210                        }
    215211                        alt = std::move( choice );
    216                         trace( alt );
    217212                }
    218213
     
    223218                        findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast );
    224219                        finishExpr( choice.expr, choice.env, untyped->env );
     220                        delete untyped;
    225221                        untyped = choice.expr;
    226222                        choice.expr = nullptr;
     
    245241                assertf( expr, "expected a non-null expression." );
    246242
    247                 auto untyped = new CastExpr{ expr }; // cast to void
     243                static CastExpr untyped( nullptr ); // cast to void
    248244
    249245                // set up and resolve expression cast to void
     246                untyped.arg = expr;
    250247                Alternative choice;
    251                 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true );
     248                findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );
    252249                CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr );
    253250                env = std::move( choice.env );
    254251
    255252                // clean up resolved expression
    256                 return castExpr->arg;
     253                Expression * ret = castExpr->arg;
     254                castExpr->arg = nullptr;
     255
     256                // unlink the arg so that it isn't deleted twice at the end of the program
     257                untyped.arg = nullptr;
     258                return ret;
    257259        }
    258260
     
    262264                Expression * newExpr = resolveInVoidContext( untyped, indexer, env );
    263265                finishExpr( newExpr, env, untyped->env );
     266                delete untyped;
    264267                untyped = newExpr;
    265268        }
     
    442445                                castExpr->arg = nullptr;
    443446                                std::swap( newExpr->env, castExpr->env );
     447                                delete castExpr;
    444448                        }
    445449                        caseStmt->condition = newExpr;
     
    741745                // and newExpr may already have inferParams of its own, so a simple swap is not sufficient.
    742746                newExpr->spliceInferParams( initExpr );
     747                delete initExpr;
    743748
    744749                // get the actual object's type (may not exactly match what comes back from the resolver due to conversions)
     
    758763                                                        ce->set_arg( nullptr );
    759764                                                        std::swap( ce->env, newExpr->env );
     765                                                        delete ce;
    760766                                                }
    761767                                        }
     
    808814                // could not find valid constructor, or found an intrinsic constructor
    809815                // fall back on C-style initializer
    810                 ctorInit->set_ctor( nullptr );
    811                 ctorInit->set_dtor( nullptr );
     816                delete ctorInit->get_ctor();
     817                ctorInit->set_ctor( NULL );
     818                delete ctorInit->get_dtor();
     819                ctorInit->set_dtor( NULL );
    812820                maybeAccept( ctorInit->get_init(), *visitor );
    813821        }
     
    835843
    836844                // found a constructor - can get rid of C-style initializer
     845                delete ctorInit->init;
    837846                ctorInit->init = nullptr;
    838847
     
    841850                // to clean up generated code.
    842851                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
     852                        delete ctorInit->ctor;
    843853                        ctorInit->ctor = nullptr;
    844854                }
    845855
    846856                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
     857                        delete ctorInit->dtor;
    847858                        ctorInit->dtor = nullptr;
    848859                }
  • src/ResolvExpr/TypeEnvironment.cc

    reba74ba r58e822a  
    1919#include <utility>                     // for pair
    2020
    21 #include "Common/PassVisitor.h"        // for PassVisitor<GcTracer>
    2221#include "Common/utility.h"            // for maybeClone
    23 #include "SynTree/GcTracer.h"          // for PassVisitor<GcTracer>
    2422#include "SynTree/Type.h"              // for Type, FunctionType, Type::Fora...
    2523#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
     
    6159        EqvClass &EqvClass::operator=( const EqvClass &other ) {
    6260                if ( this == &other ) return *this;
     61                delete type;
    6362                initialize( other, *this );
    6463                return *this;
     64        }
     65
     66        EqvClass::~EqvClass() {
     67                delete type;
    6568        }
    6669
     
    144147///         std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl;
    145148                                        sub.add( *theVar, newTypeInst );
     149                                        delete newTypeInst;
    146150                                } // if
    147151                        } // for
     
    184188                                        if ( secondClass->type ) {
    185189                                                if ( newClass.type ) {
    186                                                         newClass.type = combineFunc( newClass.type, secondClass->type );
     190                                                        Type *newType = combineFunc( newClass.type, secondClass->type );
     191                                                        delete newClass.type;
     192                                                        newClass.type = newType;
    187193                                                        newClass.allowWidening = newClass.allowWidening && secondClass->allowWidening;
    188194                                                } else {
     
    224230                return out;
    225231        }
    226 
    227         PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ) {
    228                 for ( const EqvClass & c : env ) {
    229                         maybeAccept( c.type, gc );
    230                 }
    231                 return gc;
    232         }
    233232} // namespace ResolvExpr
    234233
  • src/ResolvExpr/TypeEnvironment.h

    reba74ba r58e822a  
    2626#include "SynTree/Type.h"              // for Type, Type::ForallList
    2727#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
    28 
    29 template< typename Pass >
    30 class PassVisitor;
    31 class GcTracer;
    3228
    3329namespace ResolvExpr {
     
    8076                EqvClass( const EqvClass &other );
    8177                EqvClass &operator=( const EqvClass &other );
     78                ~EqvClass();
    8279                void print( std::ostream &os, Indenter indent = {} ) const;
    8380        };
     
    129126
    130127        std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env );
    131 
    132         PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env );
    133128} // namespace ResolvExpr
    134129
  • src/ResolvExpr/Unify.cc

    reba74ba r58e822a  
    1717#include <iterator>               // for back_insert_iterator, back_inserter
    1818#include <map>                    // for _Rb_tree_const_iterator, _Rb_tree_i...
     19#include <memory>                 // for unique_ptr
    1920#include <set>                    // for set
    2021#include <string>                 // for string, operator==, operator!=, bas...
     
    9899                findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );
    99100
    100                 return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     101                bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     102                delete newFirst;
     103                delete newSecond;
     104                return result;
    101105        }
    102106
     
    119123///   newSecond->print( std::cerr );
    120124///   std::cerr << std::endl;
    121                 return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     125                bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     126                delete newFirst;
     127                delete newSecond;
     128                return result;
    122129        }
    123130
     
    164171                                Type *common = 0;
    165172                                // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to
    166                                 Type* newType = curClass.type->clone();
     173                                std::unique_ptr< Type > newType( curClass.type->clone() );
    167174                                newType->get_qualifiers() = typeInst->get_qualifiers();
    168                                 if ( unifyInexact( newType, other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) {
     175                                if ( unifyInexact( newType.get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) {
    169176                                        if ( common ) {
    170177                                                common->get_qualifiers() = Type::Qualifiers();
     178                                                delete curClass.type;
    171179                                                curClass.type = common;
    172180                                                env.add( curClass );
     
    231239                                if ( common ) {
    232240                                        common->get_qualifiers() = Type::Qualifiers();
     241                                        delete class1.type;
    233242                                        class1.type = common;
    234243                                } // if
     
    263272                        env.add( newClass );
    264273                } // if
     274                delete type1;
     275                delete type2;
    265276                return result;
    266277        }
     
    271282                findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true );
    272283                Type *commonType = 0;
    273                 return unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType );
     284                if ( unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) {
     285                        if ( commonType ) {
     286                                delete commonType;
     287                        } // if
     288                        return true;
     289                } else {
     290                        return false;
     291                } // if
    274292        }
    275293
     
    465483
    466484        template< typename Iterator, typename Func >
    467         Type* combineTypes( Iterator begin, Iterator end, Func & toType ) {
     485        std::unique_ptr<Type> combineTypes( Iterator begin, Iterator end, Func & toType ) {
    468486                std::list< Type * > types;
    469487                for ( ; begin != end; ++begin ) {
     
    471489                        flatten( toType( *begin ), back_inserter( types ) );
    472490                }
    473                 return new TupleType{ Type::Qualifiers(), types };
     491                return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );
    474492        }
    475493
     
    486504                        if ( isTtype1 && ! isTtype2 ) {
    487505                                // combine all of the things in list2, then unify
    488                                 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     506                                return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    489507                        } else if ( isTtype2 && ! isTtype1 ) {
    490508                                // combine all of the things in list1, then unify
    491                                 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     509                                return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    492510                        } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
    493511                                return false;
     
    499517                        Type * t1 = (*list1Begin)->get_type();
    500518                        if ( Tuples::isTtype( t1 ) ) {
    501                                 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     519                                return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    502520                        } else return false;
    503521                } else if ( list2Begin != list2End ) {
     
    505523                        Type * t2 = (*list2Begin)->get_type();
    506524                        if ( Tuples::isTtype( t2 ) ) {
    507                                 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     525                                return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    508526                        } else return false;
    509527                } else {
     
    526544                                        // expand ttype parameter into its actual type
    527545                                        if ( eqvClass.type ) {
     546                                                delete typeInst;
    528547                                                return eqvClass.type->clone();
    529548                                        }
     
    550569                                dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) );
    551570                        }
     571                        delete dcl;
    552572                }
    553573        }
     
    558578                        // flatten the parameter lists for both functions so that tuple structure
    559579                        // doesn't affect unification. Must be a clone so that the types don't change.
    560                         FunctionType* flatFunc = functionType->clone();
    561                         FunctionType* flatOther = otherFunction->clone();
     580                        std::unique_ptr<FunctionType> flatFunc( functionType->clone() );
     581                        std::unique_ptr<FunctionType> flatOther( otherFunction->clone() );
    562582                        flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env );
    563583                        flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env );
     
    700720                        if ( isTtype1 && ! isTtype2 ) {
    701721                                // combine all of the things in list2, then unify
    702                                 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     722                                return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    703723                        } else if ( isTtype2 && ! isTtype1 ) {
    704724                                // combine all of the things in list1, then unify
    705                                 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     725                                return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    706726                        } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
    707727                                return false;
     
    713733                        Type * t1 = *list1Begin;
    714734                        if ( Tuples::isTtype( t1 ) ) {
    715                                 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     735                                return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    716736                        } else return false;
    717737                } else if ( list2Begin != list2End ) {
     
    719739                        Type * t2 = *list2Begin;
    720740                        if ( Tuples::isTtype( t2 ) ) {
    721                                 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     741                                return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    722742                        } else return false;
    723743                } else {
     
    728748        void Unify::postvisit(TupleType *tupleType) {
    729749                if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) {
    730                         TupleType* flat1 = tupleType->clone();
    731                         TupleType* flat2 = otherTuple->clone();
     750                        std::unique_ptr<TupleType> flat1( tupleType->clone() );
     751                        std::unique_ptr<TupleType> flat2( otherTuple->clone() );
    732752                        std::list<Type *> types1, types2;
    733753
     
    736756                        flat2->acceptMutator( expander );
    737757
    738                         flatten( flat1, back_inserter( types1 ) );
    739                         flatten( flat2, back_inserter( types2 ) );
     758                        flatten( flat1.get(), back_inserter( types1 ) );
     759                        flatten( flat2.get(), back_inserter( types2 ) );
    740760
    741761                        result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, indexer );
  • src/ResolvExpr/Unify.h

    reba74ba r58e822a  
    6464        bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
    6565                std::list< Type* > commonTypes;
    66                 return unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes );
     66                if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) {
     67                        deleteAll( commonTypes );
     68                        return true;
     69                } else {
     70                        return false;
     71                } // if
    6772        }
    6873
  • src/SymTab/Autogen.cc

    reba74ba r58e822a  
    214214        void addForwardDecl( FunctionDecl * functionDecl, std::list< Declaration * > & declsToAdd ) {
    215215                FunctionDecl * decl = functionDecl->clone();
     216                delete decl->statements;
    216217                decl->statements = nullptr;
    217218                declsToAdd.push_back( decl );
     
    332333                } catch ( SemanticErrorException & ) {
    333334                        // okay if decl does not resolve - that means the function should not be generated
     335                        delete dcl;
    334336                }
    335337        }
     
    371373                        // do not carry over field's attributes to parameter type
    372374                        Type * paramType = field->get_type()->clone();
     375                        deleteAll( paramType->attributes );
    373376                        paramType->attributes.clear();
    374377                        // add a parameter corresponding to this field
     
    380383                        resolve( ctor );
    381384                }
     385                delete memCtorType;
    382386        }
    383387
     
    507511                        // do not carry over field's attributes to parameter type
    508512                        Type * paramType = field->get_type()->clone();
     513                        deleteAll( paramType->attributes );
    509514                        paramType->attributes.clear();
    510515                        // add a parameter corresponding to this field
     
    519524                        break;
    520525                }
     526                delete memCtorType;
    521527        }
    522528
     
    588594                // must visit children (enum constants) to add them to the indexer
    589595                if ( enumDecl->has_body() ) {
    590                         auto enumInst = new EnumInstType{ Type::Qualifiers(), enumDecl->get_name() };
    591                         enumInst->set_baseEnum( enumDecl );
    592                         EnumFuncGenerator gen( enumInst, data, functionNesting, indexer );
     596                        EnumInstType enumInst( Type::Qualifiers(), enumDecl->get_name() );
     597                        enumInst.set_baseEnum( enumDecl );
     598                        EnumFuncGenerator gen( &enumInst, data, functionNesting, indexer );
    593599                        generateFunctions( gen, declsToAddAfter );
    594600                }
     
    598604                visit_children = false;
    599605                if ( structDecl->has_body() ) {
    600                         auto structInst = new StructInstType{ Type::Qualifiers(), structDecl->name };
    601                         structInst->set_baseStruct( structDecl );
     606                        StructInstType structInst( Type::Qualifiers(), structDecl->name );
     607                        structInst.set_baseStruct( structDecl );
    602608                        for ( TypeDecl * typeDecl : structDecl->parameters ) {
    603                                 structInst->parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) );
    604                         }
    605                         StructFuncGenerator gen( structDecl, structInst, data, functionNesting, indexer );
     609                                structInst.parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) );
     610                        }
     611                        StructFuncGenerator gen( structDecl, &structInst, data, functionNesting, indexer );
    606612                        generateFunctions( gen, declsToAddAfter );
    607613                } // if
     
    611617                visit_children = false;
    612618                if ( unionDecl->has_body()  ) {
    613                         auto unionInst = new UnionInstType{ Type::Qualifiers(), unionDecl->get_name() };
    614                         unionInst->set_baseUnion( unionDecl );
     619                        UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() );
     620                        unionInst.set_baseUnion( unionDecl );
    615621                        for ( TypeDecl * typeDecl : unionDecl->get_parameters() ) {
    616                                 unionInst->get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );
    617                         }
    618                         UnionFuncGenerator gen( unionDecl, unionInst, data, functionNesting, indexer );
     622                                unionInst.get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );
     623                        }
     624                        UnionFuncGenerator gen( unionDecl, &unionInst, data, functionNesting, indexer );
    619625                        generateFunctions( gen, declsToAddAfter );
    620626                } // if
     
    625631                if ( ! typeDecl->base ) return;
    626632
    627                 auto refType = new TypeInstType{ Type::Qualifiers(), typeDecl->name, typeDecl };
    628                 TypeFuncGenerator gen( typeDecl, refType, data, functionNesting, indexer );
     633                TypeInstType refType( Type::Qualifiers(), typeDecl->name, typeDecl );
     634                TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer );
    629635                generateFunctions( gen, declsToAddAfter );
    630636
  • src/SymTab/Autogen.h

    reba74ba r58e822a  
    9797                // return if adding reference fails - will happen on default constructor and destructor
    9898                if ( isReferenceCtorDtor && ! srcParam.addReference() ) {
     99                        delete fExpr;
    99100                        return listInit;
    100101                }
  • src/SymTab/FixFunction.cc

    reba74ba r58e822a  
    2828
    2929        DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) {
    30                 return new ObjectDecl{
    31                         functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr,
    32                         new PointerType{ Type::Qualifiers(), functionDecl->type },
    33                         nullptr, functionDecl->attributes };
     30                // can't delete function type because it may contain assertions, so transfer ownership to new object
     31                ObjectDecl *pointer = new ObjectDecl( functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, new PointerType( Type::Qualifiers(), functionDecl->type ), nullptr, functionDecl->attributes );
     32                functionDecl->attributes.clear();
     33                functionDecl->type = nullptr;
     34                delete functionDecl;
     35                return pointer;
    3436        }
    3537
     
    4042        Type * FixFunction::postmutate(ArrayType *arrayType) {
    4143                // need to recursively mutate the base type in order for multi-dimensional arrays to work.
    42                 return new PointerType{ arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic };
     44                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic );
     45                arrayType->base = nullptr;
     46                arrayType->dimension = nullptr;
     47                delete arrayType;
     48                return pointerType;
    4349        }
    4450
  • src/SymTab/Validate.cc

    reba74ba r58e822a  
    4848#include "CodeGen/CodeGenerator.h"     // for genName
    4949#include "CodeGen/OperatorTable.h"     // for isCtorDtor, isCtorDtorAssign
    50 #include "Common/GC.h"                 // for new_static_root, register_static_root
    5150#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
    5251#include "Common/ScopedMap.h"          // for ScopedMap
     
    200199                void addImplicitTypedef( AggDecl * aggDecl );
    201200
    202                 typedef ScopedMap< std::string, std::pair< TypedefDecl*, int > > TypedefMap;
     201                typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr;
     202                typedef ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap;
    203203                typedef std::map< std::string, TypeDecl * > TypeDeclMap;
    204204                TypedefMap typedefNames;
     
    312312                } // if
    313313                // Always remove the hoisted aggregate from the inner structure.
    314                 GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist ); } );
     314                GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist, false ); } );
    315315        }
    316316
     
    373373                        // one void is the only thing in the list; remove it.
    374374                        if ( containsVoid ) {
     375                                delete dwts.front();
    375376                                dwts.clear();
    376377                        }
     
    499500                                }
    500501                        }
     502                        deleteAll( td->assertions );
    501503                        td->assertions.clear();
    502504                } // for
     
    614616                                        // expand trait instance into all of its members
    615617                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     618                                        delete traitInst;
    616619                                } else {
    617620                                        // pass other assertions through
     
    685688                        // grab and remember declaration of size_t
    686689                        SizeType = eliminator.pass.typedefNames["size_t"].first->get_base()->clone();
    687                         GC::get().register_static_root( SizeType );
    688690                } else {
    689691                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
    690692                        // eventually should have a warning for this case.
    691                         SizeType =
    692                                 new_static_root<BasicType>( Type::Qualifiers(), BasicType::LongUnsignedInt );
    693                 }
    694                 filter( translationUnit, isTypedef );
     693                        SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     694                }
     695                filter( translationUnit, isTypedef, true );
    695696        }
    696697
     
    706707                                ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
    707708                        } else {
     709                                deleteAll( ret->attributes );
    708710                                ret->attributes.clear();
    709711                        }
     
    718720                                mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
    719721                        } // if
     722                        delete typeInst;
    720723                        return ret;
    721724                } else {
     
    759762                        }
    760763                } else {
    761                         typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     764                        typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );
    762765                } // if
    763766
     
    803806                if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->get_type() ) ) { // function type?
    804807                        // replace the current object declaration with a function declaration
    805                         return new FunctionDecl{
    806                                 objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(),
    807                                 funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() };
     808                        FunctionDecl * newDecl = new FunctionDecl( objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() );
     809                        objDecl->get_attributes().clear();
     810                        objDecl->set_type( nullptr );
     811                        delete objDecl;
     812                        return newDecl;
    808813                } // if
    809814                return objDecl;
     
    829834                        } // if
    830835                        return false;
    831                 } );
     836                }, true);
    832837                return compoundStmt;
    833838        }
     
    837842        template<typename AggDecl>
    838843        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
    839                 filter( aggDecl->members, isTypedef );
     844                filter( aggDecl->members, isTypedef, true );
    840845                return aggDecl;
    841846        }
     
    852857                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
    853858                        } // if
    854                         TypedefDecl* tyDecl = new TypedefDecl{ aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() };
    855                         typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     859                        TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() ) );
     860                        typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
    856861                } // if
    857862        }
     
    967972                static UniqueName indexName( "_compLit" );
    968973
    969                 ObjectDecl * tempvar = new ObjectDecl{
    970                         indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() };
     974                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
     975                compLitExpr->set_result( nullptr );
     976                compLitExpr->set_initializer( nullptr );
     977                delete compLitExpr;
    971978                declsToAddBefore.push_back( tempvar );                                  // add modified temporary to current block
    972979                return new VariableExpr( tempvar );
     
    10041011                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
    10051012                        ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
     1013                        deleteAll( retVals );
    10061014                        retVals.clear();
    10071015                        retVals.push_back( newRet );
     
    10441052                        if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) {
    10451053                                if ( labels.count( nameExpr->name ) ) {
    1046                                         return new LabelAddressExpr{ nameExpr->name };
     1054                                        Label name = nameExpr->name;
     1055                                        delete addrExpr;
     1056                                        return new LabelAddressExpr( name );
    10471057                                }
    10481058                        }
  • src/SynTree/AddressExpr.cc

    reba74ba r58e822a  
    5858}
    5959
     60AddressExpr::~AddressExpr() {
     61        delete arg;
     62}
     63
    6064void AddressExpr::print( std::ostream &os, Indenter indent ) const {
    6165        os << "Address of:" << std::endl;
     
    7175}
    7276LabelAddressExpr::LabelAddressExpr( const LabelAddressExpr & other ) : Expression( other ), arg( other.arg ) {}
     77LabelAddressExpr::~LabelAddressExpr() {}
    7378
    7479void LabelAddressExpr::print( std::ostream & os, Indenter ) const {
  • src/SynTree/AggregateDecl.cc

    reba74ba r58e822a  
    3333        cloneAll( other.attributes, attributes );
    3434        body = other.body;
     35}
     36
     37AggregateDecl::~AggregateDecl() {
     38        deleteAll( attributes );
     39        deleteAll( parameters );
     40        deleteAll( members );
    3541}
    3642
  • src/SynTree/ApplicationExpr.cc

    reba74ba r58e822a  
    1717#include <list>                  // for list
    1818#include <map>                   // for _Rb_tree_const_iterator, map, map<>:...
     19#include <memory>                // for unique_ptr
    1920#include <ostream>               // for operator<<, ostream, basic_ostream
    2021#include <string>                // for operator<<, string, char_traits
     
    4243}
    4344
     45ParamEntry::~ParamEntry() {
     46        delete actualType;
     47        delete formalType;
     48        delete expr;
     49}
     50
    4451ParamEntry::ParamEntry( ParamEntry && other ) :
    4552                decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ), inferParams( std::move( other.inferParams ) ) {
     
    5158ParamEntry & ParamEntry::operator=( ParamEntry && other ) {
    5259        if ( &other == this ) return *this;
     60        delete actualType;
     61        delete formalType;
     62        delete expr;
    5363        decl = other.decl;
    5464        actualType = other.actualType;
     
    7686}
    7787
     88ApplicationExpr::~ApplicationExpr() {
     89        delete function;
     90        deleteAll( args );
     91}
     92
    7893void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
    7994        os << "Application of" << std::endl << indent+1;
  • src/SynTree/ArrayType.cc

    reba74ba r58e822a  
    3434}
    3535
     36ArrayType::~ArrayType() {
     37        delete base;
     38        delete dimension;
     39}
     40
    3641void ArrayType::print( std::ostream &os, Indenter indent ) const {
    3742        Type::print( os, indent );
  • src/SynTree/AttrType.cc

    reba74ba r58e822a  
    3737}
    3838
     39AttrType::~AttrType() {
     40        delete expr;
     41        delete type;
     42}
     43
    3944void AttrType::print( std::ostream &os, Indenter indent ) const {
    4045        Type::print( os, indent );
  • src/SynTree/Attribute.cc

    reba74ba r58e822a  
    2323Attribute::Attribute( const Attribute &other ) : name( other.name ) {
    2424        cloneAll( other.parameters, parameters );
     25}
     26
     27Attribute::~Attribute() {
     28        deleteAll( parameters );
    2529}
    2630
  • src/SynTree/Attribute.h

    reba74ba r58e822a  
    3636        Attribute( std::string name = "", const std::list< Expression * > & parameters = std::list< Expression * >() ) : name( name ), parameters( parameters ) {}
    3737        Attribute( const Attribute &other );
     38        virtual ~Attribute();
    3839
    3940        std::string get_name() const { return name; }
  • src/SynTree/BaseSyntaxNode.h

    reba74ba r58e822a  
    1717
    1818#include "Common/CodeLocation.h"
    19 #include "Common/GC.h"
    2019#include "Common/Indenter.h"
    21 
    2220class Visitor;
    2321class Mutator;
    2422
    25 class BaseSyntaxNode : public GC_Object {
    26   friend class GcTracer;
    27 public:
     23class BaseSyntaxNode {
     24  public:
    2825        CodeLocation location;
     26
     27        virtual ~BaseSyntaxNode() {}
    2928
    3029        virtual BaseSyntaxNode * clone() const = 0;
  • src/SynTree/CommaExpr.cc

    reba74ba r58e822a  
    3434}
    3535
     36CommaExpr::~CommaExpr() {
     37        delete arg1;
     38        delete arg2;
     39}
     40
    3641void CommaExpr::print( std::ostream &os, Indenter indent ) const {
    3742        os << "Comma Expression:" << std::endl;
  • src/SynTree/CompoundStmt.cc

    reba74ba r58e822a  
    6868}
    6969
     70CompoundStmt::~CompoundStmt() {
     71        deleteAll( kids );
     72}
     73
    7074void CompoundStmt::print( std::ostream &os, Indenter indent ) const {
    7175        os << "CompoundStmt" << endl;
  • src/SynTree/Constant.cc

    reba74ba r58e822a  
    2727        type = other.type->clone();
    2828}
     29
     30Constant::~Constant() { delete type; }
    2931
    3032Constant Constant::from_bool( bool b ) {
  • src/SynTree/Constant.h

    reba74ba r58e822a  
    1919#include <string>     // for string
    2020
     21#include "BaseSyntaxNode.h"
    2122#include "Mutator.h"  // for Mutator
    2223#include "Visitor.h"  // for Visitor
    2324
    24 #include "Common/Indenter.h"  // for Indenter
    25 
    2625class Type;
    2726
    28 class Constant {
     27class Constant : public BaseSyntaxNode {
    2928  public:
    3029        Constant( Type * type, std::string rep, unsigned long long val );
    3130        Constant( Type * type, std::string rep, double val );
    3231        Constant( const Constant & other );
    33        
     32        virtual ~Constant();
     33
    3434        virtual Constant * clone() const { return new Constant( *this ); }
    3535
  • src/SynTree/DeclStmt.cc

    reba74ba r58e822a  
    2929}
    3030
     31DeclStmt::~DeclStmt() {
     32        delete decl;
     33}
     34
    3135void DeclStmt::print( std::ostream &os, Indenter indent ) const {
    3236        assert( decl != 0 );
  • src/SynTree/Declaration.cc

    reba74ba r58e822a  
    3838}
    3939
     40Declaration::~Declaration() {
     41}
     42
    4043void Declaration::fixUniqueId() {
    4144        // don't need to set unique ID twice
     
    6568}
    6669
     70AsmDecl::~AsmDecl() {
     71        delete stmt;
     72}
     73
    6774void AsmDecl::print( std::ostream &os, Indenter indent ) const {
    6875        stmt->print( os, indent );
     
    7885
    7986StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
     87}
     88
     89StaticAssertDecl::~StaticAssertDecl() {
     90        delete condition;
     91        delete message;
    8092}
    8193
  • src/SynTree/Declaration.h

    reba74ba r58e822a  
    4545        Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
    4646        Declaration( const Declaration &other );
     47        virtual ~Declaration();
    4748
    4849        const std::string &get_name() const { return name; }
     
    8687        DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
    8788        DeclarationWithType( const DeclarationWithType &other );
    88        
     89        virtual ~DeclarationWithType();
     90
    8991        std::string get_mangleName() const { return mangleName; }
    9092        DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
     
    124126                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
    125127        ObjectDecl( const ObjectDecl &other );
     128        virtual ~ObjectDecl();
    126129
    127130        virtual Type * get_type() const override { return type; }
     
    153156                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
    154157        FunctionDecl( const FunctionDecl &other );
     158        virtual ~FunctionDecl();
    155159
    156160        virtual Type * get_type() const override { return type; }
     
    180184        NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
    181185        NamedTypeDecl( const NamedTypeDecl &other );
     186        virtual ~NamedTypeDecl();
    182187
    183188        Type *get_base() const { return base; }
     
    214219        TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init = nullptr );
    215220        TypeDecl( const TypeDecl &other );
     221        virtual ~TypeDecl();
    216222
    217223        Kind get_kind() const { return kind; }
     
    262268        AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
    263269        AggregateDecl( const AggregateDecl &other );
    264        
     270        virtual ~AggregateDecl();
     271
    265272        std::list<Declaration*>& get_members() { return members; }
    266273        std::list<TypeDecl*>& get_parameters() { return parameters; }
     
    346353        AsmDecl( AsmStmt *stmt );
    347354        AsmDecl( const AsmDecl &other );
     355        virtual ~AsmDecl();
    348356
    349357        AsmStmt *get_stmt() { return stmt; }
     
    364372        StaticAssertDecl( Expression * condition, ConstantExpr * message );
    365373        StaticAssertDecl( const StaticAssertDecl & other );
     374        virtual ~StaticAssertDecl();
    366375
    367376        virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
  • src/SynTree/DeclarationWithType.cc

    reba74ba r58e822a  
    3434}
    3535
     36DeclarationWithType::~DeclarationWithType() {
     37        deleteAll( attributes );
     38        delete asmName;
     39}
     40
    3641// Local Variables: //
    3742// tab-width: 4 //
  • src/SynTree/Expression.cc

    reba74ba r58e822a  
    5959Expression::~Expression() {
    6060        delete env;
     61        delete result;
    6162}
    6263
     
    8081ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
    8182}
     83
     84ConstantExpr::~ConstantExpr() {}
    8285
    8386void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
     
    124127}
    125128
     129VariableExpr::~VariableExpr() {
     130        // don't delete the declaration, since it points somewhere else in the tree
     131}
     132
    126133VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) {
    127134        VariableExpr * funcExpr = new VariableExpr( func );
     
    150157}
    151158
     159SizeofExpr::~SizeofExpr() {
     160        delete expr;
     161        delete type;
     162}
     163
    152164void SizeofExpr::print( std::ostream &os, Indenter indent) const {
    153165        os << "Sizeof Expression on: ";
     
    171183}
    172184
     185AlignofExpr::~AlignofExpr() {
     186        delete expr;
     187        delete type;
     188}
     189
    173190void AlignofExpr::print( std::ostream &os, Indenter indent) const {
    174191        os << "Alignof Expression on: ";
     
    186203UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
    187204        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
     205
     206UntypedOffsetofExpr::~UntypedOffsetofExpr() {
     207        delete type;
     208}
    188209
    189210void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
     
    203224        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
    204225
     226OffsetofExpr::~OffsetofExpr() {
     227        delete type;
     228}
     229
    205230void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
    206231        os << "Offsetof Expression on member " << member->name << " of ";
     
    216241OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
    217242
     243OffsetPackExpr::~OffsetPackExpr() { delete type; }
     244
    218245void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
    219246        os << "Offset pack expression on ";
     
    232259AttrExpr::AttrExpr( const AttrExpr &other ) :
    233260                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
     261}
     262
     263AttrExpr::~AttrExpr() {
     264        delete attr;
     265        delete expr;
     266        delete type;
    234267}
    235268
     
    254287
    255288CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
     289}
     290
     291CastExpr::~CastExpr() {
     292        delete arg;
    256293}
    257294
     
    275312}
    276313
     314KeywordCastExpr::~KeywordCastExpr() {
     315        delete arg;
     316}
     317
    277318const std::string & KeywordCastExpr::targetString() const {
    278319        static const std::string targetStrs[] = {
     
    299340
    300341VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
     342}
     343
     344VirtualCastExpr::~VirtualCastExpr() {
     345        delete arg;
    301346}
    302347
     
    323368}
    324369
     370UntypedMemberExpr::~UntypedMemberExpr() {
     371        delete aggregate;
     372        delete member;
     373}
     374
    325375void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const {
    326376        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
     
    349399}
    350400
     401MemberExpr::~MemberExpr() {
     402        // don't delete the member declaration, since it points somewhere else in the tree
     403        delete aggregate;
     404}
     405
    351406void MemberExpr::print( std::ostream &os, Indenter indent ) const {
    352407        os << "Member Expression, with field: " << std::endl;
     
    364419                Expression( other ), function( maybeClone( other.function ) ) {
    365420        cloneAll( other.args, args );
     421}
     422
     423UntypedExpr::~UntypedExpr() {
     424        delete function;
     425        deleteAll( args );
    366426}
    367427
     
    412472}
    413473
     474NameExpr::~NameExpr() {}
     475
    414476void NameExpr::print( std::ostream &os, Indenter indent ) const {
    415477        os << "Name: " << get_name();
     
    424486LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
    425487                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
     488}
     489
     490LogicalExpr::~LogicalExpr() {
     491        delete arg1;
     492        delete arg2;
    426493}
    427494
     
    439506ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
    440507                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
     508}
     509
     510ConditionalExpr::~ConditionalExpr() {
     511        delete arg1;
     512        delete arg2;
     513        delete arg3;
    441514}
    442515
     
    476549ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
    477550        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
     551        delete callExpr;
     552        deleteAll( tempDecls );
     553        deleteAll( returnDecls );
     554        deleteAll( dtors );
    478555}
    479556
     
    500577}
    501578
     579ConstructorExpr::~ConstructorExpr() {
     580        delete callExpr;
     581}
     582
    502583void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
    503584        os <<  "Constructor Expression: " << std::endl << indent+1;
     
    514595
    515596CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
     597
     598CompoundLiteralExpr::~CompoundLiteralExpr() {
     599        delete initializer;
     600}
    516601
    517602void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
     
    540625        cloneAll( other.dtors, dtors );
    541626}
     627StmtExpr::~StmtExpr() {
     628        delete statements;
     629        deleteAll( dtors );
     630        deleteAll( returnDecls );
     631}
    542632void StmtExpr::computeResult() {
    543633        assert( statements );
    544634        std::list< Statement * > & body = statements->kids;
     635        delete result;
    545636        result = nullptr;
    546637        if ( ! returnDecls.empty() ) {
     
    585676UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
    586677}
    587 
     678UniqueExpr::~UniqueExpr() {
     679        delete expr;
     680        delete object;
     681        delete var;
     682}
    588683void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
    589684        os << "Unique Expression with id:" << id << std::endl << indent+1;
     
    598693InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
    599694InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
     695InitAlternative::~InitAlternative() {
     696        delete type;
     697        delete designation;
     698}
    600699
    601700UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
    602701UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
     702UntypedInitExpr::~UntypedInitExpr() {
     703        delete expr;
     704}
    603705
    604706void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
     
    618720}
    619721InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
     722InitExpr::~InitExpr() {
     723        delete expr;
     724        delete designation;
     725}
    620726
    621727void InitExpr::print( std::ostream & os, Indenter indent ) const {
     
    631737}
    632738DeletedExpr::DeletedExpr( const DeletedExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), deleteStmt( other.deleteStmt ) {}
     739DeletedExpr::~DeletedExpr() {
     740        delete expr;
     741}
    633742
    634743void DeletedExpr::print( std::ostream & os, Indenter indent ) const {
  • src/SynTree/Expression.h

    reba74ba r58e822a  
    4141        ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
    4242        ParamEntry( const ParamEntry & other );
    43         ParamEntry( ParamEntry&& other );
     43        ParamEntry( ParamEntry && other );
     44        ~ParamEntry();
    4445        ParamEntry & operator=( const ParamEntry & other );
    4546        ParamEntry & operator=( ParamEntry && other );
     
    5455/// Expression is the root type for all expressions
    5556class Expression : public BaseSyntaxNode {
    56   protected:
    57         virtual ~Expression();
    58 
    5957  public:
    6058        Type * result;
     
    6563        Expression();
    6664        Expression( const Expression & other );
     65        virtual ~Expression();
    6766
    6867        Type *& get_result() { return result; }
     
    9594        ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
    9695        ApplicationExpr( const ApplicationExpr & other );
     96        virtual ~ApplicationExpr();
    9797
    9898        Expression * get_function() const { return function; }
     
    116116        UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
    117117        UntypedExpr( const UntypedExpr & other );
     118        virtual ~UntypedExpr();
    118119
    119120        Expression * get_function() const { return function; }
     
    140141        NameExpr( std::string name );
    141142        NameExpr( const NameExpr & other );
     143        virtual ~NameExpr();
    142144
    143145        const std::string & get_name() const { return name; }
     
    160162        AddressExpr( Expression * arg );
    161163        AddressExpr( const AddressExpr & other );
     164        virtual ~AddressExpr();
    162165
    163166        Expression * get_arg() const { return arg; }
     
    178181        LabelAddressExpr( const Label &arg );
    179182        LabelAddressExpr( const LabelAddressExpr & other );
     183        virtual ~LabelAddressExpr();
    180184
    181185        virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
     
    195199        CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
    196200        CastExpr( const CastExpr & other );
     201        virtual ~CastExpr();
    197202
    198203        Expression * get_arg() const { return arg; }
     
    215220        KeywordCastExpr( Expression * arg, Target target );
    216221        KeywordCastExpr( const KeywordCastExpr & other );
     222        virtual ~KeywordCastExpr();
    217223
    218224        const std::string & targetString() const;
     
    231237        VirtualCastExpr( Expression * arg, Type * toType );
    232238        VirtualCastExpr( const VirtualCastExpr & other );
     239        virtual ~VirtualCastExpr();
    233240
    234241        Expression * get_arg() const { return arg; }
     
    249256        UntypedMemberExpr( Expression * member, Expression * aggregate );
    250257        UntypedMemberExpr( const UntypedMemberExpr & other );
     258        virtual ~UntypedMemberExpr();
    251259
    252260        Expression * get_member() const { return member; }
     
    270278        MemberExpr( DeclarationWithType * member, Expression * aggregate );
    271279        MemberExpr( const MemberExpr & other );
     280        virtual ~MemberExpr();
    272281
    273282        DeclarationWithType * get_member() const { return member; }
     
    290299        VariableExpr( DeclarationWithType * var );
    291300        VariableExpr( const VariableExpr & other );
     301        virtual ~VariableExpr();
    292302
    293303        DeclarationWithType * get_var() const { return var; }
     
    309319        ConstantExpr( Constant constant );
    310320        ConstantExpr( const ConstantExpr & other );
     321        virtual ~ConstantExpr();
    311322
    312323        Constant * get_constant() { return & constant; }
     
    332343        SizeofExpr( const SizeofExpr & other );
    333344        SizeofExpr( Type * type );
     345        virtual ~SizeofExpr();
    334346
    335347        Expression * get_expr() const { return expr; }
     
    356368        AlignofExpr( const AlignofExpr & other );
    357369        AlignofExpr( Type * type );
     370        virtual ~AlignofExpr();
    358371
    359372        Expression * get_expr() const { return expr; }
     
    378391        UntypedOffsetofExpr( Type * type, const std::string & member );
    379392        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
     393        virtual ~UntypedOffsetofExpr();
    380394
    381395        std::string get_member() const { return member; }
     
    398412        OffsetofExpr( Type * type, DeclarationWithType * member );
    399413        OffsetofExpr( const OffsetofExpr & other );
     414        virtual ~OffsetofExpr();
    400415
    401416        Type * get_type() const { return type; }
     
    417432        OffsetPackExpr( StructInstType * type );
    418433        OffsetPackExpr( const OffsetPackExpr & other );
     434        virtual ~OffsetPackExpr();
    419435
    420436        StructInstType * get_type() const { return type; }
     
    438454        AttrExpr( const AttrExpr & other );
    439455        AttrExpr( Expression * attr, Type * type );
     456        virtual ~AttrExpr();
    440457
    441458        Expression * get_attr() const { return attr; }
     
    462479        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
    463480        LogicalExpr( const LogicalExpr & other );
     481        virtual ~LogicalExpr();
    464482
    465483        bool get_isAnd() const { return isAnd; }
     
    487505        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
    488506        ConditionalExpr( const ConditionalExpr & other );
     507        virtual ~ConditionalExpr();
    489508
    490509        Expression * get_arg1() const { return arg1; }
     
    509528        CommaExpr( Expression * arg1, Expression * arg2 );
    510529        CommaExpr( const CommaExpr & other );
     530        virtual ~CommaExpr();
    511531
    512532        Expression * get_arg1() const { return arg1; }
     
    528548        TypeExpr( Type * type );
    529549        TypeExpr( const TypeExpr & other );
     550        virtual ~TypeExpr();
    530551
    531552        Type * get_type() const { return type; }
     
    547568        AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    548569        AsmExpr( const AsmExpr & other );
     570        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
    549571
    550572        Expression * get_inout() const { return inout; }
     
    568590/// along with a set of copy constructor calls, one for each argument.
    569591class ImplicitCopyCtorExpr : public Expression {
    570 protected:
    571         virtual ~ImplicitCopyCtorExpr();
    572 
    573592public:
    574593        ApplicationExpr * callExpr;
     
    579598        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
    580599        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
     600        virtual ~ImplicitCopyCtorExpr();
    581601
    582602        ApplicationExpr * get_callExpr() const { return callExpr; }
     
    600620        ConstructorExpr( Expression * callExpr );
    601621        ConstructorExpr( const ConstructorExpr & other );
     622        ~ConstructorExpr();
    602623
    603624        Expression * get_callExpr() const { return callExpr; }
     
    617638        CompoundLiteralExpr( Type * type, Initializer * initializer );
    618639        CompoundLiteralExpr( const CompoundLiteralExpr & other );
     640        virtual ~CompoundLiteralExpr();
    619641
    620642        Initializer * get_initializer() const { return initializer; }
     
    653675        UntypedTupleExpr( const std::list< Expression * > & exprs );
    654676        UntypedTupleExpr( const UntypedTupleExpr & other );
     677        virtual ~UntypedTupleExpr();
    655678
    656679        std::list<Expression*>& get_exprs() { return exprs; }
     
    669692        TupleExpr( const std::list< Expression * > & exprs );
    670693        TupleExpr( const TupleExpr & other );
     694        virtual ~TupleExpr();
    671695
    672696        std::list<Expression*>& get_exprs() { return exprs; }
     
    686710        TupleIndexExpr( Expression * tuple, unsigned int index );
    687711        TupleIndexExpr( const TupleIndexExpr & other );
     712        virtual ~TupleIndexExpr();
    688713
    689714        Expression * get_tuple() const { return tuple; }
     
    705730        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
    706731        TupleAssignExpr( const TupleAssignExpr & other );
     732        virtual ~TupleAssignExpr();
    707733
    708734        TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
     
    724750        StmtExpr( CompoundStmt * statements );
    725751        StmtExpr( const StmtExpr & other );
     752        virtual ~StmtExpr();
    726753
    727754        CompoundStmt * get_statements() const { return statements; }
     
    748775        UniqueExpr( Expression * expr, long long idVal = -1 );
    749776        UniqueExpr( const UniqueExpr & other );
     777        ~UniqueExpr();
    750778
    751779        Expression * get_expr() const { return expr; }
     
    777805        InitAlternative( const InitAlternative & other );
    778806        InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
     807        ~InitAlternative();
    779808};
    780809
     
    786815        UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
    787816        UntypedInitExpr( const UntypedInitExpr & other );
     817        ~UntypedInitExpr();
    788818
    789819        Expression * get_expr() const { return expr; }
     
    805835        InitExpr( Expression * expr, Designation * designation );
    806836        InitExpr( const InitExpr & other );
     837        ~InitExpr();
    807838
    808839        Expression * get_expr() const { return expr; }
     
    826857        DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt );
    827858        DeletedExpr( const DeletedExpr & other );
     859        ~DeletedExpr();
    828860
    829861        virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); }
  • src/SynTree/FunctionDecl.cc

    reba74ba r58e822a  
    5252        }
    5353        cloneAll( other.withExprs, withExprs );
     54}
     55
     56FunctionDecl::~FunctionDecl() {
     57        delete type;
     58        delete statements;
     59        deleteAll( withExprs );
    5460}
    5561
  • src/SynTree/FunctionType.cc

    reba74ba r58e822a  
    3131        cloneAll( other.returnVals, returnVals );
    3232        cloneAll( other.parameters, parameters );
     33}
     34
     35FunctionType::~FunctionType() {
     36        deleteAll( returnVals );
     37        deleteAll( parameters );
    3338}
    3439
  • src/SynTree/Initializer.cc

    reba74ba r58e822a  
    3232}
    3333
     34Designation::~Designation() {
     35        // std::cerr << "destroying designation" << std::endl;
     36        deleteAll( designators );
     37        // std::cerr << "finished destroying designation" << std::endl;
     38}
     39
    3440void Designation::print( std::ostream &os, Indenter indent ) const {
    3541        if ( ! designators.empty() ) {
     
    4652Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) {
    4753}
     54Initializer::~Initializer() {}
    4855
    4956SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) {
     
    5158
    5259SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
     60}
     61
     62SingleInit::~SingleInit() {
     63        delete value;
    5364}
    5465
     
    7687}
    7788
     89ListInit::~ListInit() {
     90        deleteAll( initializers );
     91        deleteAll( designations );
     92}
     93
    7894void ListInit::print( std::ostream &os, Indenter indent ) const {
    7995        os << "Compound initializer: " << std::endl;
     
    94110ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
    95111ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) {
     112}
     113
     114ConstructorInit::~ConstructorInit() {
     115        delete ctor;
     116        delete dtor;
     117        delete init;
    96118}
    97119
  • src/SynTree/Initializer.h

    reba74ba r58e822a  
    3333        Designation( const std::list< Expression * > & designators );
    3434        Designation( const Designation & other );
     35        virtual ~Designation();
    3536
    3637        std::list< Expression * > & get_designators() { return designators; }
     
    4950        Initializer( bool maybeConstructed );
    5051        Initializer( const Initializer & other );
     52        virtual ~Initializer();
    5153
    5254        bool get_maybeConstructed() { return maybeConstructed; }
     
    6870        SingleInit( Expression *value, bool maybeConstructed = false );
    6971        SingleInit( const SingleInit &other );
     72        virtual ~SingleInit();
    7073
    7174        Expression *get_value() { return value; }
     
    8891                          const std::list<Designation *> &designators = {}, bool maybeConstructed = false );
    8992        ListInit( const ListInit & other );
     93        virtual ~ListInit();
    9094
    9195        std::list<Designation *> & get_designations() { return designations; }
     
    119123        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
    120124        ConstructorInit( const ConstructorInit &other );
     125        virtual ~ConstructorInit();
    121126
    122127        void set_ctor( Statement * newValue ) { ctor = newValue; }
  • src/SynTree/NamedTypeDecl.cc

    reba74ba r58e822a  
    3030        cloneAll( other.parameters, parameters );
    3131        cloneAll( other.assertions, assertions );
     32}
     33
     34NamedTypeDecl::~NamedTypeDecl() {
     35        delete base;
     36        deleteAll( parameters );
     37        deleteAll( assertions );
    3238}
    3339
  • src/SynTree/ObjectDecl.cc

    reba74ba r58e822a  
    3232ObjectDecl::ObjectDecl( const ObjectDecl &other )
    3333        : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
     34}
     35
     36ObjectDecl::~ObjectDecl() {
     37        delete type;
     38        delete init;
     39        delete bitfieldWidth;
    3440}
    3541
  • src/SynTree/PointerType.cc

    reba74ba r58e822a  
    3636}
    3737
     38PointerType::~PointerType() {
     39        delete base;
     40        delete dimension;
     41}
     42
    3843void PointerType::print( std::ostream &os, Indenter indent ) const {
    3944        Type::print( os, indent );
  • src/SynTree/ReferenceToType.cc

    reba74ba r58e822a  
    3232ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
    3333        cloneAll( other.parameters, parameters );
     34}
     35
     36ReferenceToType::~ReferenceToType() {
     37        deleteAll( parameters );
    3438}
    3539
     
    166170}
    167171
     172TraitInstType::~TraitInstType() {
     173}
     174
    168175bool TraitInstType::isComplete() const { assert( false ); }
    169176
     
    176183
    177184TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
     185}
     186
     187
     188TypeInstType::~TypeInstType() {
     189        // delete baseType; //This is shared and should not be deleted
    178190}
    179191
  • src/SynTree/ReferenceType.cc

    reba74ba r58e822a  
    2828}
    2929
     30ReferenceType::~ReferenceType() {
     31        delete base;
     32}
     33
    3034int ReferenceType::referenceDepth() const {
    3135        return base->referenceDepth()+1;
  • src/SynTree/Statement.cc

    reba74ba r58e822a  
    4444}
    4545
     46Statement::~Statement() {}
     47
    4648ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}
    4749
    4850ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     51
     52ExprStmt::~ExprStmt() {
     53        delete expr;
     54}
    4955
    5056void ExprStmt::print( std::ostream &os, Indenter indent ) const {
     
    6066  cloneAll( other.input, input );
    6167  cloneAll( other.clobber, clobber );
     68}
     69
     70AsmStmt::~AsmStmt() {
     71        delete instruction;
     72        deleteAll( output );
     73        deleteAll( input );
     74        deleteAll( clobber );
    6275}
    6376
     
    116129ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    117130
     131ReturnStmt::~ReturnStmt() {
     132        delete expr;
     133}
     134
    118135void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
    119136        os << "Return Statement, returning: ";
     
    131148        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
    132149        cloneAll( other.initialization, initialization );
     150}
     151
     152IfStmt::~IfStmt() {
     153        deleteAll( initialization );
     154        delete condition;
     155        delete thenPart;
     156        delete elsePart;
    133157}
    134158
     
    168192}
    169193
     194SwitchStmt::~SwitchStmt() {
     195        delete condition;
     196        // destroy statements
     197        deleteAll( statements );
     198}
     199
    170200void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
    171201        os << "Switch on condition: ";
     
    186216        Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {
    187217        cloneAll( other.stmts, stmts );
     218}
     219
     220CaseStmt::~CaseStmt() {
     221        delete condition;
     222        deleteAll( stmts );
    188223}
    189224
     
    216251}
    217252
     253WhileStmt::~WhileStmt() {
     254        delete body;
     255        delete condition;
     256}
     257
    218258void WhileStmt::print( std::ostream &os, Indenter indent ) const {
    219259        os << "While on condition: " << endl ;
     
    233273                cloneAll( other.initialization, initialization );
    234274
     275}
     276
     277ForStmt::~ForStmt() {
     278        deleteAll( initialization );
     279        delete condition;
     280        delete increment;
     281        delete body;
    235282}
    236283
     
    272319ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
    273320        Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
     321}
     322
     323ThrowStmt::~ThrowStmt() {
     324        delete expr;
     325        delete target;
    274326}
    275327
     
    292344}
    293345
     346TryStmt::~TryStmt() {
     347        delete block;
     348        deleteAll( handlers );
     349        delete finallyBlock;
     350}
     351
    294352void TryStmt::print( std::ostream &os, Indenter indent ) const {
    295353        os << "Try Statement" << endl;
     
    320378}
    321379
     380CatchStmt::~CatchStmt() {
     381        delete decl;
     382        delete body;
     383}
     384
    322385void CatchStmt::print( std::ostream &os, Indenter indent ) const {
    323386        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
     
    342405
    343406FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
     407}
     408
     409FinallyStmt::~FinallyStmt() {
     410        delete block;
    344411}
    345412
     
    373440        orelse .statement = other.orelse .statement->clone();
    374441        orelse .condition = other.orelse .condition->clone();
     442}
     443
     444WaitForStmt::~WaitForStmt() {
     445        for( auto & clause : clauses ) {
     446                delete clause.target.function;
     447                deleteAll( clause.target.arguments );
     448                delete clause.statement;
     449                delete clause.condition;
     450        }
     451
     452        delete timeout.time;
     453        delete timeout.statement;
     454        delete timeout.condition;
     455
     456        delete orelse.statement;
     457        delete orelse.condition;
    375458}
    376459
     
    414497        cloneAll( other.exprs, exprs );
    415498}
     499WithStmt::~WithStmt() {
     500        deleteAll( exprs );
     501        delete stmt;
     502}
    416503
    417504void WithStmt::print( std::ostream & os, Indenter indent ) const {
     
    439526}
    440527
     528ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
     529        delete callStmt;
     530}
     531
    441532void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
    442533        os << "Implicit Ctor Dtor Statement" << endl;
  • src/SynTree/Statement.h

    reba74ba r58e822a  
    3838
    3939        Statement( const std::list<Label> & labels = {} );
     40        virtual ~Statement();
    4041
    4142        std::list<Label> & get_labels() { return labels; }
     
    5556        CompoundStmt( std::list<Statement *> stmts );
    5657        CompoundStmt( const CompoundStmt &other );
     58        virtual ~CompoundStmt();
    5759
    5860        std::list<Statement*>& get_kids() { return kids; }
     
    8284        ExprStmt( Expression *expr );
    8385        ExprStmt( const ExprStmt &other );
     86        virtual ~ExprStmt();
    8487
    8588        Expression *get_expr() { return expr; }
     
    102105        AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    103106        AsmStmt( const AsmStmt &other );
     107        virtual ~AsmStmt();
    104108
    105109        bool get_voltile() { return voltile; }
     
    145149                        std::list<Statement *> initialization = std::list<Statement *>() );
    146150        IfStmt( const IfStmt &other );
     151        virtual ~IfStmt();
    147152
    148153        std::list<Statement *> &get_initialization() { return initialization; }
     
    167172        SwitchStmt( Expression *condition, const std::list<Statement *> &statements );
    168173        SwitchStmt( const SwitchStmt &other );
     174        virtual ~SwitchStmt();
    169175
    170176        Expression *get_condition() { return condition; }
     
    188194        CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);
    189195        CaseStmt( const CaseStmt &other );
     196        virtual ~CaseStmt();
    190197
    191198        static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );
     
    218225               Statement *body, bool isDoWhile = false );
    219226        WhileStmt( const WhileStmt &other );
     227        virtual ~WhileStmt();
    220228
    221229        Expression *get_condition() { return condition; }
     
    242250             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    243251        ForStmt( const ForStmt &other );
     252        virtual ~ForStmt();
    244253
    245254        std::list<Statement *> &get_initialization() { return initialization; }
     
    294303        ReturnStmt( Expression *expr );
    295304        ReturnStmt( const ReturnStmt &other );
     305        virtual ~ReturnStmt();
    296306
    297307        Expression *get_expr() { return expr; }
     
    314324        ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
    315325        ThrowStmt( const ThrowStmt &other );
     326        virtual ~ThrowStmt();
    316327
    317328        Kind get_kind() { return kind; }
     
    335346        TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
    336347        TryStmt( const TryStmt &other );
     348        virtual ~TryStmt();
    337349
    338350        CompoundStmt *get_block() const { return block; }
     
    361373                   Expression *cond, Statement *body );
    362374        CatchStmt( const CatchStmt &other );
     375        virtual ~CatchStmt();
    363376
    364377        Kind get_kind() { return kind; }
     
    382395        FinallyStmt( CompoundStmt *block );
    383396        FinallyStmt( const FinallyStmt &other );
     397        virtual ~FinallyStmt();
    384398
    385399        CompoundStmt *get_block() const { return block; }
     
    408422        WaitForStmt();
    409423        WaitForStmt( const WaitForStmt & );
     424        virtual ~WaitForStmt();
    410425
    411426        std::vector<Clause> clauses;
     
    436451        WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
    437452        WithStmt( const WithStmt & other );
     453        virtual ~WithStmt();
    438454
    439455        virtual WithStmt * clone() const override { return new WithStmt( *this ); }
     
    451467        DeclStmt( Declaration *decl );
    452468        DeclStmt( const DeclStmt &other );
     469        virtual ~DeclStmt();
    453470
    454471        Declaration *get_decl() const { return decl; }
     
    472489        ImplicitCtorDtorStmt( Statement * callStmt );
    473490        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
     491        virtual ~ImplicitCtorDtorStmt();
    474492
    475493        Statement *get_callStmt() const { return callStmt; }
  • src/SynTree/TupleExpr.cc

    reba74ba r58e822a  
    3535}
    3636
     37UntypedTupleExpr::~UntypedTupleExpr() {
     38        deleteAll( exprs );
     39}
     40
    3741void UntypedTupleExpr::print( std::ostream &os, Indenter indent ) const {
    3842        os << "Untyped Tuple:" << std::endl;
     
    4751TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
    4852        cloneAll( other.exprs, exprs );
     53}
     54
     55TupleExpr::~TupleExpr() {
     56        deleteAll( exprs );
    4957}
    5058
     
    6472
    6573TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
     74}
     75
     76TupleIndexExpr::~TupleIndexExpr() {
     77        delete tuple;
    6678}
    6779
     
    93105}
    94106
     107TupleAssignExpr::~TupleAssignExpr() {
     108        delete stmtExpr;
     109}
     110
    95111void TupleAssignExpr::print( std::ostream &os, Indenter indent ) const {
    96112        os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
  • src/SynTree/TupleType.cc

    reba74ba r58e822a  
    4343}
    4444
     45TupleType::~TupleType() {
     46        deleteAll( types );
     47        deleteAll( members );
     48}
     49
    4550void TupleType::print( std::ostream &os, Indenter indent ) const {
    4651        Type::print( os, indent );
  • src/SynTree/Type.cc

    reba74ba r58e822a  
    5757}
    5858
     59Type::~Type() {
     60        deleteAll( forall );
     61        deleteAll( attributes );
     62}
     63
    5964// These must remain in the same order as the corresponding bit fields.
    6065const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" };
  • src/SynTree/Type.h

    reba74ba r58e822a  
    141141        Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
    142142        Type( const Type & other );
     143        virtual ~Type();
    143144
    144145        Qualifiers & get_qualifiers() { return tq; }
     
    260261        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    261262        PointerType( const PointerType& );
     263        virtual ~PointerType();
    262264
    263265        Type *get_base() { return base; }
     
    289291        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    290292        ArrayType( const ArrayType& );
     293        virtual ~ArrayType();
    291294
    292295        Type *get_base() { return base; }
     
    316319        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    317320        ReferenceType( const ReferenceType & );
     321        virtual ~ReferenceType();
    318322
    319323        Type *get_base() { return base; }
     
    348352        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    349353        FunctionType( const FunctionType& );
     354        virtual ~FunctionType();
    350355
    351356        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
     
    371376        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
    372377        ReferenceToType( const ReferenceToType & other );
     378        virtual ~ReferenceToType();
    373379
    374380        const std::string & get_name() const { return name; }
     
    497503        TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    498504        TraitInstType( const TraitInstType & other );
     505        ~TraitInstType();
    499506
    500507        virtual bool isComplete() const override;
     
    518525        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    519526        TypeInstType( const TypeInstType & other );
     527        ~TypeInstType();
    520528
    521529        TypeDecl *get_baseType() const { return baseType; }
     
    541549        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    542550        TupleType( const TupleType& );
     551        virtual ~TupleType();
    543552
    544553        typedef std::list<Type*> value_type;
     
    574583        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    575584        TypeofType( const TypeofType& );
     585        virtual ~TypeofType();
    576586
    577587        Expression *get_expr() const { return expr; }
     
    596606        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    597607        AttrType( const AttrType& );
     608        virtual ~AttrType();
    598609
    599610        const std::string & get_name() const { return name; }
  • src/SynTree/TypeDecl.cc

    reba74ba r58e822a  
    2525
    2626TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) {
     27}
     28
     29TypeDecl::~TypeDecl() {
     30  delete init;
    2731}
    2832
  • src/SynTree/TypeExpr.cc

    reba74ba r58e822a  
    2626}
    2727
     28TypeExpr::~TypeExpr() {
     29        delete type;
     30}
     31
    2832void TypeExpr::print( std::ostream &os, Indenter indent ) const {
    2933        if ( type ) type->print( os, indent );
  • src/SynTree/TypeSubstitution.cc

    reba74ba r58e822a  
    2626}
    2727
     28TypeSubstitution::~TypeSubstitution() {
     29        for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     30                delete( i->second );
     31        }
     32        for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
     33                delete( i->second );
     34        }
     35}
     36
    2837TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) {
    2938        if ( this == &other ) return *this;
     
    4857
    4958void TypeSubstitution::add( std::string formalType, Type *actualType ) {
     59        TypeEnvType::iterator i = typeEnv.find( formalType );
     60        if ( i != typeEnv.end() ) {
     61                delete i->second;
     62        } // if
    5063        typeEnv[ formalType ] = actualType->clone();
    5164}
    5265
    5366void TypeSubstitution::remove( std::string formalType ) {
    54         typeEnv.erase( formalType );
     67        TypeEnvType::iterator i = typeEnv.find( formalType );
     68        if ( i != typeEnv.end() ) {
     69                delete i->second;
     70                typeEnv.erase( formalType );
     71        } // if
    5572}
    5673
     
    144161                Type * newtype = i->second->clone();
    145162                newtype->get_qualifiers() |= inst->get_qualifiers();
     163                delete inst;
    146164                // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode.
    147165                return newtype->acceptMutator( *visitor );
     
    155173        } else {
    156174                subCount++;
     175                delete nameExpr;
    157176                return i->second->clone();
    158177        } // if
  • src/SynTree/TypeSubstitution.h

    reba74ba r58e822a  
    3535        TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
    3636        TypeSubstitution( const TypeSubstitution &other );
     37        virtual ~TypeSubstitution();
    3738
    3839        TypeSubstitution &operator=( const TypeSubstitution &other );
     
    5960        void normalize();
    6061
    61         void accept( Visitor& v ) { v.visit( this ); }
    6262        TypeSubstitution * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    6363
     
    101101                        if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) {
    102102                                if ( formal->get_name() != "" ) {
     103                                        TypeEnvType::iterator i = typeEnv.find( formal->get_name() );
     104                                        if ( i != typeEnv.end() ) {
     105                                                delete i->second;
     106                                        } // if
    103107                                        typeEnv[ formal->get_name() ] = actual->get_type()->clone();
    104108                                } // if
  • src/SynTree/TypeofType.cc

    reba74ba r58e822a  
    2929}
    3030
     31TypeofType::~TypeofType() {
     32        delete expr;
     33}
     34
    3135void TypeofType::print( std::ostream &os, Indenter indent ) const {
    3236        Type::print( os, indent );
  • src/SynTree/Visitor.h

    reba74ba r58e822a  
    124124
    125125        virtual void visit( Attribute * attribute ) = 0;
    126 
    127         virtual void visit( TypeSubstitution * sub ) = 0;
    128126};
    129127
  • src/SynTree/module.mk

    reba74ba r58e822a  
    4848       SynTree/TypeSubstitution.cc \
    4949       SynTree/Attribute.cc \
    50        SynTree/BaseSyntaxNode.cc \
    5150       SynTree/DeclReplacer.cc
    5251
  • src/Tuples/Explode.cc

    reba74ba r58e822a  
    7070                                // should now be a tuple of references rather than a reference to a tuple.
    7171                                // Still, this code is a bit awkward, and could use some improvement.
    72                                 UniqueExpr * newUniqueExpr = new UniqueExpr{ applyCast( uniqueExpr->get_expr() ), uniqueExpr->get_id() };
     72                                UniqueExpr * newUniqueExpr = new UniqueExpr( applyCast( uniqueExpr->get_expr() ), uniqueExpr->get_id() );
     73                                delete uniqueExpr;
    7374                                if ( castAdded ) {
    7475                                        // if a cast was added by applyCast, then unique expr now has one more layer of reference
     
    8788                                // field is consistent with the type of the tuple expr, since the field
    8889                                // may have changed from type T to T&.
    89                                 return new TupleIndexExpr( tupleExpr->get_tuple(), tupleExpr->get_index() );
     90                                Expression * expr = tupleExpr->get_tuple();
     91                                tupleExpr->set_tuple( nullptr );
     92                                TupleIndexExpr * ret = new TupleIndexExpr( expr, tupleExpr->get_index() );
     93                                delete tupleExpr;
     94                                return ret;
    9095                        }
    9196                };
  • src/Tuples/Explode.h

    reba74ba r58e822a  
    2727namespace SymTab {
    2828class Indexer;
    29 }  // namespace SymTabf
     29}  // namespace SymTab
    3030
    3131namespace Tuples {
     
    6767                                for ( ResolvExpr::Alternative & alt : alts ) {
    6868                                        // distribute reference cast over all components
    69                                         append( std::forward<Output>(out), distributeReference( alt.expr ),
     69                                        append( std::forward<Output>(out), distributeReference( alt.release_expr() ),
    7070                                                alt.env, alt.cost, alt.cvtCost );
    7171                                }
     
    9696                                        TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), i );
    9797                                        explodeUnique( idx, alt, indexer, std::forward<Output>(out), isTupleAssign );
     98                                        delete idx;
    9899                                }
     100                                delete arg;
    99101                        }
    100102                } else {
  • src/Tuples/TupleExpansion.cc

    reba74ba r58e822a  
    4646
    4747                        std::map< int, Expression * > decls; // not vector, because order added may not be increasing order
     48
     49                        ~UniqueExprExpander() {
     50                                for ( std::pair<const int, Expression *> & p : decls ) {
     51                                        delete p.second;
     52                                }
     53                        }
    4854                };
    4955
     
    106112                                UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->member, inner );
    107113                                inner->location = newMemberExpr->location = loc;
     114                                memberExpr->member = nullptr;
     115                                memberExpr->aggregate = nullptr;
     116                                delete memberExpr;
    108117                                return newMemberExpr->acceptMutator( expander );
    109118                        } else {
     
    125134                                expr->location = memberExpr->location;
    126135                        }
     136                        delete aggr;
    127137                        tupleExpr->location = memberExpr->location;
    128138                        return tupleExpr;
     
    170180                        decls[id] = condExpr;
    171181                }
     182                delete unqExpr;
    172183                return decls[id]->clone();
    173184        }
     
    179190                ret->set_env( assnExpr->get_env() );
    180191                assnExpr->set_env( nullptr );
     192                delete assnExpr;
    181193                return ret;
    182194        }
     
    209221                        newType->get_parameters().push_back( new TypeExpr( t->clone() ) );
    210222                }
     223                delete tupleType;
    211224                return newType;
    212225        }
     
    229242                                ret->env = env;
    230243                                expr = nullptr; // remove from list so it can safely be deleted
     244                                delete tupleExpr;
    231245                                return ret;
    232246                        }
     
    273287                TypeSubstitution * env = tupleExpr->get_env();
    274288
    275                 // remove data from shell
     289                // remove data from shell and delete it
    276290                tupleExpr->set_result( nullptr );
    277291                tupleExpr->get_exprs().clear();
    278292                tupleExpr->set_env( nullptr );
     293                delete tupleExpr;
    279294
    280295                return replaceTupleExpr( result, exprs, env );
  • src/Virtual/ExpandCasts.cc

    reba74ba r58e822a  
    139139                ObjectDecl * table = found->second;
    140140
    141                 return new CastExpr{
     141                Expression * result = new CastExpr(
    142142                        //new ApplicationExpr(
    143143                                //new AddressExpr( new VariableExpr( vcast_decl ) ),
     
    158158                                } ),
    159159                        castExpr->get_result()->clone()
    160                 };
     160                        );
     161
     162                castExpr->set_arg( nullptr );
     163                castExpr->set_result( nullptr );
     164                delete castExpr;
     165                return result;
    161166        }
    162167
  • src/main.cc

    reba74ba r58e822a  
    1 
    21//
    32// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     
    3635#include "CodeTools/TrackLoc.h"             // for fillLocations
    3736#include "Common/CompilerError.h"           // for CompilerError
    38 #include "Common/GC.h"                      // for GC
    3937#include "Common/Heap.h"
    4038#include "Common/PassVisitor.h"
     
    5957#include "SymTab/Validate.h"                // for validate
    6058#include "SynTree/Declaration.h"            // for Declaration
    61 #include "SynTree/GcTracer.h"               // for GC << TranslationUnit
    6259#include "SynTree/Visitor.h"                // for acceptAll
    6360#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
     
    180177        signal( SIGABRT, sigAbortHandler );
    181178
     179        // std::cout << "main" << std::endl;
     180        // for ( int i = 0; i < argc; i += 1 ) {
     181        //      std::cout << '\t' << argv[i] << std::endl;
     182        // } // for
     183
    182184        parse_cmdline( argc, argv, filename );                          // process command-line arguments
    183185        CodeGen::FixMain::setReplaceMain( !nomainp );
     
    238240                delete parseTree;
    239241                parseTree = nullptr;
    240                 collect( translationUnit );
    241242
    242243                if ( astp ) {
     
    247248                // add the assignment statement after the initialization of a type parameter
    248249                PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
    249                 if ( symtabp ) return 0;
    250                 collect( translationUnit );
     250                if ( symtabp ) {
     251                        deleteAll( translationUnit );
     252                        return 0;
     253                } // if
    251254
    252255                if ( expraltp ) {
     
    265268                PASS( "genInit", InitTweak::genInit( translationUnit ) );
    266269                PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
    267                 collect( translationUnit );
    268270                if ( libcfap ) {
    269271                        // generate the bodies of cfa library functions
     
    273275                if ( declstatsp ) {
    274276                        CodeTools::printDeclStats( translationUnit );
     277                        deleteAll( translationUnit );
    275278                        return 0;
    276279                }
     
    284287
    285288                PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
    286                 collect( translationUnit );
    287289                if ( exprp ) {
    288290                        dump( translationUnit );
     
    292294                // fix ObjectDecl - replaces ConstructorInit nodes
    293295                PASS( "fixInit", InitTweak::fix( translationUnit, filename, libcfap || treep ) );
    294                 collect( translationUnit );
    295296                if ( ctorinitp ) {
    296297                        dump ( translationUnit );
     
    307308
    308309                PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
    309                 collect( translationUnit );
     310
    310311                if ( tuplep ) {
    311312                        dump( translationUnit );
     
    316317
    317318                PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
    318                 collect( translationUnit );
    319319                if ( genericsp ) {
    320320                        dump( translationUnit );
     
    322322                }
    323323                PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
    324                 collect( translationUnit );
     324
     325
    325326                if ( bboxp ) {
    326327                        dump( translationUnit );
     
    328329                } // if
    329330                PASS( "box", GenPoly::box( translationUnit ) );
    330                 collect( translationUnit );
     331
    331332                if ( bcodegenp ) {
    332333                        dump( translationUnit );
     
    384385        }// try
    385386
     387        deleteAll( translationUnit );
    386388        if(!libcfap && !treep) HeapStats::printStats();
    387389        return 0;
     
    599601                printAll( decls, out );
    600602        }
     603        deleteAll( translationUnit );
    601604} // dump
    602605
Note: See TracChangeset for help on using the changeset viewer.