Changeset 8573729 for src/ResolvExpr
- Timestamp:
- Mar 12, 2018, 5:28:11 PM (6 years ago)
- Branches:
- resolv-new
- Children:
- 4edf753
- Parents:
- 6171841
- Location:
- src/ResolvExpr
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r6171841 r8573729 15 15 16 16 #include <stddef.h> // for NULL 17 #include <algorithm> // for sort 17 18 #include <cassert> // for strict_dynamic_cast, assert 18 19 #include <memory> // for allocator, allocator_traits<... … … 29 30 #include "InitTweak/InitTweak.h" // for isIntrinsicSingleArgCallStmt 30 31 #include "RenameVars.h" // for RenameVars, global_renamer 32 #include "ResolveAssertions.h" // for resolveAssertions 31 33 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 32 34 #include "ResolveTypeof.h" // for resolveTypeof … … 169 171 } 170 172 171 // xxx - if > 1 alternative with same cost, ignore deleted and pick from remaining 172 // choose the lowest cost expression among the candidates 173 // sort candidates by cost 174 std::sort( candidates.begin(), candidates.end(), 175 [](const Alternative& a, const Alternative& b) { return a.cost < b.cost; } ); 176 // search for cheapest resolvable candidate 173 177 AltList winners; 174 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 178 for ( const Alternative& r : candidates ) { 179 if ( ! winners.empty() ) { 180 // break if already have a cheaper candidate 181 if ( winners[0].cost < r.cost ) break; 182 183 // ignore min-cost deleted alternatives if already found one alternative 184 if ( findDeletedExpr( r.expr ) ) continue; 185 } 186 187 // check candidate assertion resolution 188 if ( resolveAssertions( r.expr ) ) { 189 winners.push_back( r ); 190 } 191 } 192 175 193 if ( winners.size() == 0 ) { 176 194 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") ); … … 281 299 Type *new_type = resolveTypeof( objectDecl->get_type(), indexer ); 282 300 objectDecl->set_type( new_type ); 283 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable284 // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes285 // initContext because of a function type can contain object declarations in the return and parameter types. So286 // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting287 // the RHS.301 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 302 // class-variable initContext is changed multiple time because the LHS is analysed twice. 303 // The second analysis changes initContext because of a function type can contain object 304 // declarations in the return and parameter types. So each value of initContext is retained, 305 // so the type on the first analysis is preserved and used for selecting the RHS. 288 306 GuardValue( currentObject ); 289 307 currentObject = CurrentObject( objectDecl->get_type() ); … … 329 347 330 348 { 331 // resolve with-exprs with parameters in scope and add any newly generated declarations to the 332 // front of the function body. 333 auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this](){ indexer.leaveScope(); } ); 349 // resolve with-exprs with parameters in scope and add any newly generated declarations 350 // to the front of the function body. 351 auto guard = makeFuncGuard( 352 [this]() { indexer.enterScope(); }, [this](){ indexer.leaveScope(); } ); 334 353 indexer.addFunctionType( functionDecl->type ); 335 354 std::list< Statement * > newStmts; … … 344 363 345 364 void Resolver::postvisit( FunctionDecl *functionDecl ) { 346 // default value expressions have an environment which shouldn't be there and trips up later passes. 347 // xxx - it might be necessary to somehow keep the information from this environment, but I can't currently 348 // see how it's useful. 365 // default value expressions have an environment which shouldn't be there and trips up 366 // later passes. 367 // xxx - it might be necessary to somehow keep the information from this environment, but I 368 // can't currently see how it's useful. 349 369 for ( Declaration * d : functionDecl->type->parameters ) { 350 370 if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( d ) ) { -
src/ResolvExpr/module.mk
r6171841 r8573729 33 33 ResolvExpr/TypeEnvironment.cc \ 34 34 ResolvExpr/CurrentObject.cc \ 35 ResolvExpr/ExplodedActual.cc 35 ResolvExpr/ExplodedActual.cc \ 36 ResolvExpr/ResolveAssertions.cc
Note: See TracChangeset
for help on using the changeset viewer.