Changes in src/ResolvExpr/Resolver.cc [bd87b138:2efe4b8]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
rbd87b138 r2efe4b8 22 22 #include "Alternative.h" // for Alternative, AltList 23 23 #include "AlternativeFinder.h" // for AlternativeFinder, resolveIn... 24 #include "Common/GC.h" // for new_generation, collect_young 24 25 #include "Common/PassVisitor.h" // for PassVisitor 25 26 #include "Common/SemanticError.h" // for SemanticError … … 59 60 void previsit( TypeDecl *typeDecl ); 60 61 void previsit( EnumDecl * enumDecl ); 61 void previsit( StaticAssertDecl * assertDecl );62 62 63 63 void previsit( ArrayType * at ); … … 139 139 castExpr->arg = nullptr; 140 140 std::swap( expr->env, castExpr->env ); 141 delete castExpr;142 141 } 143 142 } … … 148 147 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) { 149 148 assertf( untyped, "expected a non-null expression." ); 149 150 auto guard = new_generation(); // set up GC generation for this top-level expression 151 150 152 TypeEnvironment env; 151 153 AlternativeFinder finder( indexer, env ); … … 175 177 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 176 178 if ( winners.size() == 0 ) { 177 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") ); 179 SemanticError( untyped, toString( 180 "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), 181 "expression: ") ); 178 182 } else if ( winners.size() != 1 ) { 179 183 std::ostringstream stream; 180 stream << "Cannot choose between " << winners.size() << " alternatives for " << kindStr << (kindStr != "" ? " " : "") << "expression\n"; 184 stream << "Cannot choose between " << winners.size() << " alternatives for " 185 << kindStr << (kindStr != "" ? " " : "") << "expression\n"; 181 186 untyped->print( stream ); 182 187 stream << " Alternatives are:\n"; 183 188 printAlts( winners, stream, 1 ); 189 184 190 SemanticError( untyped->location, stream.str() ); 185 191 } … … 188 194 Alternative & choice = winners.front(); 189 195 if ( findDeletedExpr( choice.expr ) ) { 190 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 196 trace( choice.expr ); 197 SemanticError( choice.expr, 198 "Unique best alternative includes deleted identifier in " ); 191 199 } 192 200 alt = std::move( choice ); 201 trace( alt ); 193 202 } 194 203 … … 199 208 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast ); 200 209 finishExpr( choice.expr, choice.env, untyped->env ); 201 delete untyped;202 210 untyped = choice.expr; 203 211 choice.expr = nullptr; … … 222 230 assertf( expr, "expected a non-null expression." ); 223 231 224 static CastExpr untyped( nullptr ); // cast to void232 auto untyped = new CastExpr{ expr }; // cast to void 225 233 226 234 // set up and resolve expression cast to void 227 untyped.arg = expr;228 235 Alternative choice; 229 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );236 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true ); 230 237 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 231 238 env = std::move( choice.env ); 232 239 233 240 // clean up resolved expression 234 Expression * ret = castExpr->arg; 235 castExpr->arg = nullptr; 236 237 // unlink the arg so that it isn't deleted twice at the end of the program 238 untyped.arg = nullptr; 239 return ret; 241 return castExpr->arg; 240 242 } 241 243 … … 245 247 Expression * newExpr = resolveInVoidContext( untyped, indexer, env ); 246 248 finishExpr( newExpr, env, untyped->env ); 247 delete untyped;248 249 untyped = newExpr; 249 250 } … … 364 365 } 365 366 366 void Resolver::previsit( StaticAssertDecl * assertDecl ) {367 findIntegralExpression( assertDecl->condition, indexer );368 }369 370 367 void Resolver::previsit( ExprStmt *exprStmt ) { 371 368 visit_children = false; … … 423 420 caseStmt->condition = castExpr->arg; 424 421 castExpr->arg = nullptr; 425 delete castExpr;426 422 } 427 423 } … … 705 701 std::swap( initExpr->env, newExpr->env ); 706 702 std::swap( initExpr->inferParams, newExpr->inferParams ) ; 707 delete initExpr;708 703 709 704 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) … … 723 718 ce->set_arg( nullptr ); 724 719 std::swap( ce->env, newExpr->env ); 725 delete ce;726 720 } 727 721 } … … 774 768 // could not find valid constructor, or found an intrinsic constructor 775 769 // fall back on C-style initializer 776 delete ctorInit->get_ctor(); 777 ctorInit->set_ctor( NULL ); 778 delete ctorInit->get_dtor(); 779 ctorInit->set_dtor( NULL ); 770 ctorInit->set_ctor( nullptr ); 771 ctorInit->set_dtor( nullptr ); 780 772 maybeAccept( ctorInit->get_init(), *visitor ); 781 773 } … … 803 795 804 796 // found a constructor - can get rid of C-style initializer 805 delete ctorInit->init;806 797 ctorInit->init = nullptr; 807 798 … … 810 801 // to clean up generated code. 811 802 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) { 812 delete ctorInit->ctor;813 803 ctorInit->ctor = nullptr; 814 804 } 815 805 816 806 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) { 817 delete ctorInit->dtor;818 807 ctorInit->dtor = nullptr; 819 808 }
Note:
See TracChangeset
for help on using the changeset viewer.