Changeset 1d2b64f
- Timestamp:
- Dec 13, 2016, 5:20:54 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d5556a3
- Parents:
- 722617d
- git-author:
- Rob Schluntz <rschlunt@…> (12/13/16 17:16:27)
- git-committer:
- Rob Schluntz <rschlunt@…> (12/13/16 17:20:54)
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r722617d r1d2b64f 36 36 public: 37 37 Resolver() : SymTab::Indexer( false ) {} 38 39 using SymTab::Indexer::visit; 38 Resolver( const SymTab:: Indexer & other ) : SymTab::Indexer( other ) { 39 if ( const Resolver * res = dynamic_cast< const Resolver * >( &other ) ) { 40 functionReturn = res->functionReturn; 41 initContext = res->initContext; 42 inEnumDecl = res->inEnumDecl; 43 } 44 } 45 46 typedef SymTab::Indexer Parent; 47 using Parent::visit; 40 48 virtual void visit( FunctionDecl *functionDecl ) override; 41 49 virtual void visit( ObjectDecl *functionDecl ) override; … … 192 200 initContext = new BasicType( Type::Qualifiers(), BasicType::SignedInt ); 193 201 } 194 SymTab::Indexer::visit( objectDecl );202 Parent::visit( objectDecl ); 195 203 if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) { 196 204 // delete newly created signed int type … … 212 220 void Resolver::visit( ArrayType * at ) { 213 221 handlePtrType( at ); 214 Visitor::visit( at );222 Parent::visit( at ); 215 223 } 216 224 217 225 void Resolver::visit( PointerType * pt ) { 218 226 handlePtrType( pt ); 219 Visitor::visit( pt );227 Parent::visit( pt ); 220 228 } 221 229 … … 225 233 typeDecl->set_base( new_type ); 226 234 } // if 227 SymTab::Indexer::visit( typeDecl );235 Parent::visit( typeDecl ); 228 236 } 229 237 … … 238 246 ValueGuard< Type * > oldFunctionReturn( functionReturn ); 239 247 functionReturn = ResolvExpr::extractResultType( functionDecl->get_functionType() ); 240 SymTab::Indexer::visit( functionDecl );248 Parent::visit( functionDecl ); 241 249 } 242 250 243 251 void Resolver::visit( EnumDecl * enumDecl ) { 244 252 // in case we decide to allow nested enums 245 bool oldInEnumDecl = inEnumDecl;253 ValueGuard< bool > oldInEnumDecl( inEnumDecl ); 246 254 inEnumDecl = true; 247 SymTab::Indexer::visit( enumDecl ); 248 inEnumDecl = oldInEnumDecl; 255 Parent::visit( enumDecl ); 249 256 } 250 257 251 258 void Resolver::visit( ExprStmt *exprStmt ) { 252 if ( exprStmt->get_expr() ) { 253 Expression *newExpr = findVoidExpression( exprStmt->get_expr(), *this ); 254 delete exprStmt->get_expr(); 255 exprStmt->set_expr( newExpr ); 256 } // if 259 assertf( exprStmt->get_expr(), "ExprStmt has null Expression in resolver" ); 260 Expression *newExpr = findVoidExpression( exprStmt->get_expr(), *this ); 261 delete exprStmt->get_expr(); 262 exprStmt->set_expr( newExpr ); 257 263 } 258 264 … … 277 283 delete ifStmt->get_condition(); 278 284 ifStmt->set_condition( newExpr ); 279 Visitor::visit( ifStmt );285 Parent::visit( ifStmt ); 280 286 } 281 287 … … 284 290 delete whileStmt->get_condition(); 285 291 whileStmt->set_condition( newExpr ); 286 Visitor::visit( whileStmt );292 Parent::visit( whileStmt ); 287 293 } 288 294 289 295 void Resolver::visit( ForStmt *forStmt ) { 290 SymTab::Indexer::visit( forStmt );296 Parent::visit( forStmt ); 291 297 292 298 if ( forStmt->get_condition() ) { … … 318 324 319 325 void Resolver::visit( CaseStmt *caseStmt ) { 320 Visitor::visit( caseStmt );326 Parent::visit( caseStmt ); 321 327 } 322 328 … … 482 488 } else { 483 489 // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context 484 Visitor::visit( listInit );490 Parent::visit( listInit ); 485 491 } 486 492 } else { 487 493 assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) 488 || dynamic_cast< ZeroType * >( initContext ) || dynamic_cast< OneType * >( initContext ) );494 || dynamic_cast< ZeroType * >( initContext ) || dynamic_cast< OneType * >( initContext ) || dynamic_cast < EnumInstType * > ( initContext ) ); 489 495 // basic types are handled here 490 Visitor::visit( listInit );496 Parent::visit( listInit ); 491 497 } 492 498 … … 554 560 } 555 561 562 // needs to be callable from outside the resolver, so this is a standalone function 563 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) { 564 assert( ctorInit ); 565 Resolver resolver( indexer ); 566 ctorInit->accept( resolver ); 567 } 568 569 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) { 570 assert( stmtExpr ); 571 Resolver resolver( indexer ); 572 stmtExpr->accept( resolver ); 573 } 574 556 575 void Resolver::visit( ConstructorInit *ctorInit ) { 557 576 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit -
src/ResolvExpr/Resolver.h
r722617d r1d2b64f 25 25 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer ); 26 26 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ); 27 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ); 28 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ); 27 29 } // namespace ResolvExpr 28 30 -
src/Tuples/TupleAssignment.cc
r722617d r1d2b64f 23 23 #include "Common/SemanticError.h" 24 24 #include "InitTweak/InitTweak.h" 25 #include "InitTweak/GenInit.h" 25 26 26 27 #include <functional> … … 47 48 virtual ~Matcher() {} 48 49 virtual void match( std::list< Expression * > &out ) = 0; 50 ObjectDecl * newObject( UniqueName & namer, Expression * expr ); 49 51 ResolvExpr::AltList lhs, rhs; 50 52 TupleAssignSpotter &spotter; 53 ResolvExpr::Cost baseCost; 51 54 std::list< ObjectDecl * > tmpDecls; 55 ResolvExpr::TypeEnvironment compositeEnv; 52 56 }; 53 57 … … 146 150 finder.findWithAdjustment(*i); 147 151 } catch (...) { 148 return; // xxx -no match should not mean failure, it just means this particular tuple assignment isn't valid152 return; // no match should not mean failure, it just means this particular tuple assignment isn't valid 149 153 } 150 154 // prune expressions that don't coincide with … … 161 165 solved_assigns.push_back( alt.expr->clone() ); 162 166 } 163 // xxx - need to do this?? 164 ResolvExpr::TypeEnvironment compositeEnv; 165 simpleCombineEnvironments( current.begin(), current.end(), compositeEnv ); 166 currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new TupleAssignExpr(solved_assigns, matcher->tmpDecls), compositeEnv, ResolvExpr::sumCost( current ) ) ); 167 } 168 169 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList &alts ) : spotter(spotter) { 167 // combine assignment environments into combined expression environment 168 simpleCombineEnvironments( current.begin(), current.end(), matcher->compositeEnv ); 169 currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, ResolvExpr::sumCost( current ) + matcher->baseCost ) ); 170 } 171 172 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList &alts ) : spotter(spotter), baseCost( ResolvExpr::sumCost( alts ) ) { 170 173 assert( ! alts.empty() ); 174 // combine argument environments into combined expression environment 175 simpleCombineEnvironments( alts.begin(), alts.end(), compositeEnv ); 176 171 177 ResolvExpr::Alternative lhsAlt = alts.front(); 172 178 // peel off the cast that exists on ctor/dtor expressions … … 217 223 } 218 224 219 ObjectDecl * newObject( UniqueName & namer, Expression * expr ) { 225 // removes environments from subexpressions within statement exprs, which could throw off later passes like those in Box which rely on PolyMutator. 226 // xxx - maybe this should happen in alternative finder for every StmtExpr? 227 // xxx - it's possible that these environments could contain some useful information. Maybe the right thing to do is aggregate the environments and pass the aggregate back to be added into the compositeEnv 228 struct EnvRemover : public Visitor { 229 virtual void visit( ExprStmt * stmt ) { 230 delete stmt->get_expr()->get_env(); 231 stmt->get_expr()->set_env( nullptr ); 232 Visitor::visit( stmt ); 233 } 234 }; 235 236 ObjectDecl * TupleAssignSpotter::Matcher::newObject( UniqueName & namer, Expression * expr ) { 220 237 assert( expr->has_result() && ! expr->get_result()->isVoid() ); 221 return new ObjectDecl( namer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 238 ObjectDecl * ret = new ObjectDecl( namer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 239 ConstructorInit * ctorInit = InitTweak::genCtorInit( ret ); 240 ret->set_init( ctorInit ); 241 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 242 EnvRemover rm; // remove environments from subexpressions of StmtExprs 243 ctorInit->accept( rm ); 244 return ret; 222 245 } 223 246 … … 244 267 std::list< ObjectDecl * > ltmp; 245 268 std::list< ObjectDecl * > rtmp; 246 std::transform( lhs.begin(), lhs.end(), back_inserter( ltmp ), [ ]( ResolvExpr::Alternative & alt ){269 std::transform( lhs.begin(), lhs.end(), back_inserter( ltmp ), [&]( ResolvExpr::Alternative & alt ){ 247 270 return newObject( lhsNamer, alt.expr ); 248 271 }); 249 std::transform( rhs.begin(), rhs.end(), back_inserter( rtmp ), [ ]( ResolvExpr::Alternative & alt ){272 std::transform( rhs.begin(), rhs.end(), back_inserter( rtmp ), [&]( ResolvExpr::Alternative & alt ){ 250 273 return newObject( rhsNamer, alt.expr ); 251 274 });
Note: See TracChangeset
for help on using the changeset viewer.