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