Changeset 68f9c43 for src/ResolvExpr
- Timestamp:
- Mar 16, 2018, 5:15:02 PM (8 years ago)
- 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)
- Location:
- src/ResolvExpr
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
r6171841 r68f9c43 66 66 67 67 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 }; 72 69 } 73 70 74 71 Type * AdjustExprType::postmutate( FunctionType * functionType ) { 75 return new PointerType ( Type::Qualifiers(), functionType );72 return new PointerType{ Type::Qualifiers(), functionType }; 76 73 } 77 74 … … 80 77 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 81 78 if ( eqvClass.data.kind == TypeDecl::Ftype ) { 82 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 83 return pointerType; 79 return new PointerType{ Type::Qualifiers(), typeInst }; 84 80 } 85 81 } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 86 82 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { 87 83 if ( tyDecl->get_kind() == TypeDecl::Ftype ) { 88 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 89 return pointerType; 84 return new PointerType{ Type::Qualifiers(), typeInst }; 90 85 } // if 91 86 } // if -
src/ResolvExpr/Alternative.cc
r6171841 r68f9c43 34 34 Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost ) 35 35 : 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 }68 36 69 37 void Alternative::print( std::ostream &os, Indenter indent ) const { -
src/ResolvExpr/Alternative.h
r6171841 r68f9c43 29 29 Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost ); 30 30 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; 36 33 37 34 void print( std::ostream &os, Indenter indent = {} ) const; 38 35 39 /// Returns the stored expression, but released from management of this Alternative40 Expression* release_expr() {41 Expression* tmp = expr;42 expr = nullptr;43 return tmp;44 }45 46 36 Cost cost; 47 37 Cost cvtCost; 48 Expression * expr;38 Expression * expr; 49 39 TypeEnvironment env; 50 40 }; -
src/ResolvExpr/AlternativeFinder.cc
r6171841 r68f9c43 165 165 candidate->env.apply( newType ); 166 166 mangleName = SymTab::Mangler::mangle( newType ); 167 delete newType;168 167 } 169 168 std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName ); … … 568 567 569 568 Expression *varExpr = data.combine( newerAlt.cvtCost ); 570 delete varExpr->get_result();571 569 varExpr->set_result( adjType->clone() ); 572 570 PRINT( … … 585 583 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 586 584 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out ); 587 } else {588 delete adjType;589 585 } 590 586 } … … 1264 1260 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ) ) ); 1265 1261 } 1266 delete argExpr;1267 1262 assert( componentExprs.size() > 0 ); 1268 1263 // produce the tuple of casts … … 1600 1595 alternatives.push_back( Alternative( new CommaExpr( newFirstArg->clone(), alt.expr->clone() ), alt.env, alt.cost ) ); 1601 1596 } // for 1602 delete newFirstArg;1603 1597 } 1604 1598 -
src/ResolvExpr/ResolveTypeof.cc
r6171841 r68f9c43 70 70 Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer ); 71 71 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; 77 73 } // if 78 74 return typeofType; -
src/ResolvExpr/Resolver.cc
r6171841 r68f9c43 138 138 castExpr->arg = nullptr; 139 139 std::swap( expr->env, castExpr->env ); 140 delete castExpr;141 140 } 142 141 } … … 198 197 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast ); 199 198 finishExpr( choice.expr, choice.env, untyped->env ); 200 delete untyped;201 199 untyped = choice.expr; 202 200 choice.expr = nullptr; … … 244 242 Expression * newExpr = resolveInVoidContext( untyped, indexer, env ); 245 243 finishExpr( newExpr, env, untyped->env ); 246 delete untyped;247 244 untyped = newExpr; 248 245 } … … 418 415 caseStmt->condition = castExpr->arg; 419 416 castExpr->arg = nullptr; 420 delete castExpr;421 417 } 422 418 } … … 700 696 std::swap( initExpr->env, newExpr->env ); 701 697 std::swap( initExpr->inferParams, newExpr->inferParams ) ; 702 delete initExpr;703 698 704 699 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) … … 718 713 ce->set_arg( nullptr ); 719 714 std::swap( ce->env, newExpr->env ); 720 delete ce;721 715 } 722 716 } … … 769 763 // could not find valid constructor, or found an intrinsic constructor 770 764 // 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 ); 775 767 maybeAccept( ctorInit->get_init(), *visitor ); 776 768 } … … 798 790 799 791 // found a constructor - can get rid of C-style initializer 800 delete ctorInit->init;801 792 ctorInit->init = nullptr; 802 793 … … 805 796 // to clean up generated code. 806 797 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) { 807 delete ctorInit->ctor;808 798 ctorInit->ctor = nullptr; 809 799 } 810 800 811 801 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) { 812 delete ctorInit->dtor;813 802 ctorInit->dtor = nullptr; 814 803 } -
src/ResolvExpr/TypeEnvironment.cc
r6171841 r68f9c43 59 59 EqvClass &EqvClass::operator=( const EqvClass &other ) { 60 60 if ( this == &other ) return *this; 61 delete type;62 61 initialize( other, *this ); 63 62 return *this; 64 }65 66 EqvClass::~EqvClass() {67 delete type;68 63 } 69 64 … … 147 142 /// std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl; 148 143 sub.add( *theVar, newTypeInst ); 149 delete newTypeInst;150 144 } // if 151 145 } // for … … 188 182 if ( secondClass->type ) { 189 183 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 ); 193 185 newClass.allowWidening = newClass.allowWidening && secondClass->allowWidening; 194 186 } else { -
src/ResolvExpr/TypeEnvironment.h
r6171841 r68f9c43 67 67 EqvClass( const EqvClass &other ); 68 68 EqvClass &operator=( const EqvClass &other ); 69 ~EqvClass();70 69 void print( std::ostream &os, Indenter indent = {} ) const; 71 70 }; -
src/ResolvExpr/Unify.cc
r6171841 r68f9c43 99 99 findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true ); 100 100 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 ); 105 102 } 106 103 … … 123 120 /// newSecond->print( std::cerr ); 124 121 /// 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 ); 129 123 } 130 124 … … 176 170 if ( common ) { 177 171 common->get_qualifiers() = Type::Qualifiers(); 178 delete curClass.type;179 172 curClass.type = common; 180 173 env.add( curClass ); … … 239 232 if ( common ) { 240 233 common->get_qualifiers() = Type::Qualifiers(); 241 delete class1.type;242 234 class1.type = common; 243 235 } // if … … 272 264 env.add( newClass ); 273 265 } // if 274 delete type1;275 delete type2;276 266 return result; 277 267 } … … 282 272 findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true ); 283 273 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 ); 292 275 } 293 276 … … 544 527 // expand ttype parameter into its actual type 545 528 if ( eqvClass.type ) { 546 delete typeInst;547 529 return eqvClass.type->clone(); 548 530 } … … 569 551 dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) ); 570 552 } 571 delete dcl;572 553 } 573 554 } -
src/ResolvExpr/Unify.h
r6171841 r68f9c43 64 64 bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 65 65 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 ); 72 67 } 73 68
Note:
See TracChangeset
for help on using the changeset viewer.