Changes in src/ResolvExpr/Resolver.cc [d286cf68:b60f9d9]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
rd286cf68 rb60f9d9 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 … … 32 33 #include "ResolveTypeof.h" // for resolveTypeof 33 34 #include "Resolver.h" 35 #include "ResolvMode.h" // for ResolvMode 34 36 #include "SymTab/Autogen.h" // for SizeType 35 37 #include "SymTab/Indexer.h" // for Indexer … … 49 51 namespace ResolvExpr { 50 52 struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting, public WithStmtsToAdd { 53 54 friend void resolve( std::list<Declaration*> ); 55 51 56 Resolver() {} 52 57 Resolver( const SymTab::Indexer & other ) { … … 94 99 CurrentObject currentObject = nullptr; 95 100 bool inEnumDecl = false; 101 bool atTopLevel = false; ///< Was this resolver set up at the top level of resolution 96 102 }; 97 103 98 104 void resolve( std::list< Declaration * > translationUnit ) { 99 105 PassVisitor<Resolver> resolver; 106 resolver.pass.atTopLevel = true; // mark resolver as top-level 100 107 acceptAll( translationUnit, resolver ); 101 108 } … … 158 165 castExpr->arg = nullptr; 159 166 std::swap( expr->env, castExpr->env ); 160 delete castExpr;161 167 } 162 168 } … … 165 171 166 172 namespace { 167 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) {173 void findUnfinishedKindExpression( Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, ResolvMode mode = ResolvMode{} ) { 168 174 assertf( untyped, "expected a non-null expression." ); 175 176 auto guard = new_generation(); // set up GC generation for this top-level expression 177 169 178 TypeEnvironment env; 170 179 AlternativeFinder finder( indexer, env ); 171 finder.find( untyped, adjust, prune, failFast);180 finder.find( untyped, mode ); 172 181 173 182 #if 0 … … 207 216 Alternative & choice = winners.front(); 208 217 if ( findDeletedExpr( choice.expr ) ) { 209 SemanticError( untyped->location, choice.expr, "Unique best alternative includes deleted identifier in " ); 218 trace( choice.expr ); 219 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 210 220 } 211 221 alt = std::move( choice ); 222 trace( alt ); 212 223 } 213 224 214 225 /// resolve `untyped` to the expression whose alternative satisfies `pred` with the lowest cost; kindStr is used for providing better error messages 215 void findKindExpression(Expression *& untyped, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {226 void findKindExpression(Expression *& untyped, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, ResolvMode mode = ResolvMode{}) { 216 227 if ( ! untyped ) return; 217 228 Alternative choice; 218 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast);229 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, mode ); 219 230 finishExpr( choice.expr, choice.env, untyped->env ); 220 delete untyped;221 231 untyped = choice.expr; 222 232 choice.expr = nullptr; … … 241 251 assertf( expr, "expected a non-null expression." ); 242 252 243 static CastExpr untyped( nullptr ); // cast to void 244 untyped.location = expr->location; 253 auto untyped = new CastExpr{ expr }; // cast to void 245 254 246 255 // set up and resolve expression cast to void 247 untyped.arg = expr;248 256 Alternative choice; 249 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true);257 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() ); 250 258 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 251 259 env = std::move( choice.env ); 252 260 253 261 // clean up resolved expression 254 Expression * ret = castExpr->arg; 255 castExpr->arg = nullptr; 256 257 // unlink the arg so that it isn't deleted twice at the end of the program 258 untyped.arg = nullptr; 259 return ret; 262 return castExpr->arg; 260 263 } 261 264 … … 265 268 Expression * newExpr = resolveInVoidContext( untyped, indexer, env ); 266 269 finishExpr( newExpr, env, untyped->env ); 267 delete untyped;268 270 untyped = newExpr; 269 271 } … … 275 277 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer ) { 276 278 assert( untyped && type ); 277 // transfer location to generated cast for error purposes278 CodeLocation location = untyped->location;279 279 untyped = new CastExpr( untyped, type ); 280 untyped->location = location;281 280 findSingleExpression( untyped, indexer ); 282 281 removeExtraneousCast( untyped, indexer ); … … 449 448 castExpr->arg = nullptr; 450 449 std::swap( newExpr->env, castExpr->env ); 451 delete castExpr;452 450 } 453 451 caseStmt->condition = newExpr; … … 582 580 583 581 // Make sure we don't widen any existing bindings 584 resultEnv.forbidWidening(); 585 582 for ( auto & i : resultEnv ) { 583 i.allowWidening = false; 584 } 585 586 586 // Find any unbound type variables 587 587 resultEnv.extractOpenVars( openVars ); … … 747 747 // and newExpr may already have inferParams of its own, so a simple swap is not sufficient. 748 748 newExpr->spliceInferParams( initExpr ); 749 delete initExpr;750 749 751 750 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) … … 765 764 ce->set_arg( nullptr ); 766 765 std::swap( ce->env, newExpr->env ); 767 delete ce;768 766 } 769 767 } … … 816 814 // could not find valid constructor, or found an intrinsic constructor 817 815 // fall back on C-style initializer 818 delete ctorInit->get_ctor(); 819 ctorInit->set_ctor( NULL ); 820 delete ctorInit->get_dtor(); 821 ctorInit->set_dtor( NULL ); 816 ctorInit->set_ctor( nullptr ); 817 ctorInit->set_dtor( nullptr ); 822 818 maybeAccept( ctorInit->get_init(), *visitor ); 823 819 } … … 845 841 846 842 // found a constructor - can get rid of C-style initializer 847 delete ctorInit->init;848 843 ctorInit->init = nullptr; 849 844 … … 852 847 // to clean up generated code. 853 848 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) { 854 delete ctorInit->ctor;855 849 ctorInit->ctor = nullptr; 856 850 } 857 851 858 852 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) { 859 delete ctorInit->dtor;860 853 ctorInit->dtor = nullptr; 861 854 }
Note:
See TracChangeset
for help on using the changeset viewer.