Changeset 68f9c43 for src/ResolvExpr


Ignore:
Timestamp:
Mar 16, 2018, 5:15:02 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
8d7bef2
Parents:
6171841
git-author:
Aaron Moss <a3moss@…> (03/16/18 17:04:24)
git-committer:
Aaron Moss <a3moss@…> (03/16/18 17:15:02)
Message:

First pass at delete removal

Location:
src/ResolvExpr
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AdjustExprType.cc

    r6171841 r68f9c43  
    6666
    6767        Type * AdjustExprType::postmutate( ArrayType * arrayType ) {
    68                 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base );
    69                 arrayType->base = nullptr;
    70                 delete arrayType;
    71                 return pointerType;
     68                return new PointerType{ arrayType->get_qualifiers(), arrayType->base };
    7269        }
    7370
    7471        Type * AdjustExprType::postmutate( FunctionType * functionType ) {
    75                 return new PointerType( Type::Qualifiers(), functionType );
     72                return new PointerType{ Type::Qualifiers(), functionType };
    7673        }
    7774
     
    8077                if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
    8178                        if ( eqvClass.data.kind == TypeDecl::Ftype ) {
    82                                 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
    83                                 return pointerType;
     79                                return new PointerType{ Type::Qualifiers(), typeInst };
    8480                        }
    8581                } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
    8682                        if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
    8783                                if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
    88                                         PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
    89                                         return pointerType;
     84                                        return new PointerType{ Type::Qualifiers(), typeInst };
    9085                                } // if
    9186                        } // if
  • src/ResolvExpr/Alternative.cc

    r6171841 r68f9c43  
    3434        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
    3535                : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( 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;
    47                 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;
    67         }
    6836
    6937        void Alternative::print( std::ostream &os, Indenter indent ) const {
  • src/ResolvExpr/Alternative.h

    r6171841 r68f9c43  
    2929                Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost );
    3030                Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost, const Cost &cvtCost );
    31                 Alternative( const Alternative &other );
    32                 Alternative &operator=( const Alternative &other );
    33                 Alternative( Alternative && other );
    34                 Alternative &operator=( Alternative && other );
    35                 ~Alternative();
     31                Alternative( const Alternative &other ) = default;
     32                Alternative &operator=( const Alternative &other ) = default;
    3633
    3734                void print( std::ostream &os, Indenter indent = {} ) const;
    3835
    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 
    4636                Cost cost;
    4737                Cost cvtCost;
    48                 Expression *expr;
     38                Expression * expr;
    4939                TypeEnvironment env;
    5040        };
  • src/ResolvExpr/AlternativeFinder.cc

    r6171841 r68f9c43  
    165165                                        candidate->env.apply( newType );
    166166                                        mangleName = SymTab::Mangler::mangle( newType );
    167                                         delete newType;
    168167                                }
    169168                                std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName );
     
    568567
    569568                                Expression *varExpr = data.combine( newerAlt.cvtCost );
    570                                 delete varExpr->get_result();
    571569                                varExpr->set_result( adjType->clone() );
    572570                                PRINT(
     
    585583                                (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr );
    586584                                inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out );
    587                         } else {
    588                                 delete adjType;
    589585                        }
    590586                }
     
    12641260                                componentExprs.push_back( restructureCast( idx, toType->getComponent( i ) ) );
    12651261                        }
    1266                         delete argExpr;
    12671262                        assert( componentExprs.size() > 0 );
    12681263                        // produce the tuple of casts
     
    16001595                        alternatives.push_back( Alternative( new CommaExpr( newFirstArg->clone(), alt.expr->clone() ), alt.env, alt.cost ) );
    16011596                } // for
    1602                 delete newFirstArg;
    16031597        }
    16041598
  • src/ResolvExpr/ResolveTypeof.cc

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

    r6171841 r68f9c43  
    138138                                        castExpr->arg = nullptr;
    139139                                        std::swap( expr->env, castExpr->env );
    140                                         delete castExpr;
    141140                                }
    142141                        }
     
    198197                        findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast );
    199198                        finishExpr( choice.expr, choice.env, untyped->env );
    200                         delete untyped;
    201199                        untyped = choice.expr;
    202200                        choice.expr = nullptr;
     
    244242                Expression * newExpr = resolveInVoidContext( untyped, indexer, env );
    245243                finishExpr( newExpr, env, untyped->env );
    246                 delete untyped;
    247244                untyped = newExpr;
    248245        }
     
    418415                        caseStmt->condition = castExpr->arg;
    419416                        castExpr->arg = nullptr;
    420                         delete castExpr;
    421417                }
    422418        }
     
    700696                std::swap( initExpr->env, newExpr->env );
    701697                std::swap( initExpr->inferParams, newExpr->inferParams ) ;
    702                 delete initExpr;
    703698
    704699                // get the actual object's type (may not exactly match what comes back from the resolver due to conversions)
     
    718713                                                        ce->set_arg( nullptr );
    719714                                                        std::swap( ce->env, newExpr->env );
    720                                                         delete ce;
    721715                                                }
    722716                                        }
     
    769763                // could not find valid constructor, or found an intrinsic constructor
    770764                // fall back on C-style initializer
    771                 delete ctorInit->get_ctor();
    772                 ctorInit->set_ctor( NULL );
    773                 delete ctorInit->get_dtor();
    774                 ctorInit->set_dtor( NULL );
     765                ctorInit->set_ctor( nullptr );
     766                ctorInit->set_dtor( nullptr );
    775767                maybeAccept( ctorInit->get_init(), *visitor );
    776768        }
     
    798790
    799791                // found a constructor - can get rid of C-style initializer
    800                 delete ctorInit->init;
    801792                ctorInit->init = nullptr;
    802793
     
    805796                // to clean up generated code.
    806797                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
    807                         delete ctorInit->ctor;
    808798                        ctorInit->ctor = nullptr;
    809799                }
    810800
    811801                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
    812                         delete ctorInit->dtor;
    813802                        ctorInit->dtor = nullptr;
    814803                }
  • src/ResolvExpr/TypeEnvironment.cc

    r6171841 r68f9c43  
    5959        EqvClass &EqvClass::operator=( const EqvClass &other ) {
    6060                if ( this == &other ) return *this;
    61                 delete type;
    6261                initialize( other, *this );
    6362                return *this;
    64         }
    65 
    66         EqvClass::~EqvClass() {
    67                 delete type;
    6863        }
    6964
     
    147142///         std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl;
    148143                                        sub.add( *theVar, newTypeInst );
    149                                         delete newTypeInst;
    150144                                } // if
    151145                        } // for
     
    188182                                        if ( secondClass->type ) {
    189183                                                if ( newClass.type ) {
    190                                                         Type *newType = combineFunc( newClass.type, secondClass->type );
    191                                                         delete newClass.type;
    192                                                         newClass.type = newType;
     184                                                        newClass.type = combineFunc( newClass.type, secondClass->type );
    193185                                                        newClass.allowWidening = newClass.allowWidening && secondClass->allowWidening;
    194186                                                } else {
  • src/ResolvExpr/TypeEnvironment.h

    r6171841 r68f9c43  
    6767                EqvClass( const EqvClass &other );
    6868                EqvClass &operator=( const EqvClass &other );
    69                 ~EqvClass();
    7069                void print( std::ostream &os, Indenter indent = {} ) const;
    7170        };
  • src/ResolvExpr/Unify.cc

    r6171841 r68f9c43  
    9999                findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );
    100100
    101                 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    102                 delete newFirst;
    103                 delete newSecond;
    104                 return result;
     101                return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    105102        }
    106103
     
    123120///   newSecond->print( std::cerr );
    124121///   std::cerr << std::endl;
    125                 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    126                 delete newFirst;
    127                 delete newSecond;
    128                 return result;
     122                return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    129123        }
    130124
     
    176170                                        if ( common ) {
    177171                                                common->get_qualifiers() = Type::Qualifiers();
    178                                                 delete curClass.type;
    179172                                                curClass.type = common;
    180173                                                env.add( curClass );
     
    239232                                if ( common ) {
    240233                                        common->get_qualifiers() = Type::Qualifiers();
    241                                         delete class1.type;
    242234                                        class1.type = common;
    243235                                } // if
     
    272264                        env.add( newClass );
    273265                } // if
    274                 delete type1;
    275                 delete type2;
    276266                return result;
    277267        }
     
    282272                findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true );
    283273                Type *commonType = 0;
    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
     274                return unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType );
    292275        }
    293276
     
    544527                                        // expand ttype parameter into its actual type
    545528                                        if ( eqvClass.type ) {
    546                                                 delete typeInst;
    547529                                                return eqvClass.type->clone();
    548530                                        }
     
    569551                                dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) );
    570552                        }
    571                         delete dcl;
    572553                }
    573554        }
  • src/ResolvExpr/Unify.h

    r6171841 r68f9c43  
    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                 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
     66                return unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes );
    7267        }
    7368
Note: See TracChangeset for help on using the changeset viewer.