Changeset 8f98b78 for src/ResolvExpr
- Timestamp:
- Sep 19, 2017, 3:55:54 PM (7 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:
- 764e009
- Parents:
- 695e00d
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r695e00d r8f98b78 118 118 } 119 119 120 Expression * findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 121 TypeEnvironment env; 122 AlternativeFinder finder( indexer, env ); 123 finder.find( untyped ); 124 #if 0 125 if ( finder.get_alternatives().size() != 1 ) { 126 std::cout << "untyped expr is "; 127 untyped->print( std::cout ); 128 std::cout << std::endl << "alternatives are:"; 129 for ( std::list< Alternative >::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) { 130 i->print( std::cout ); 131 } // for 132 } // if 133 #endif 134 assertf( finder.get_alternatives().size() == 1, "findSingleExpression: must have exactly one alternative at the end." ); 135 Alternative &choice = finder.get_alternatives().front(); 136 Expression *newExpr = choice.expr->clone(); 137 finishExpr( newExpr, choice.env ); 138 return newExpr; 139 } 140 120 141 namespace { 121 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {122 TypeEnvironment env;123 AlternativeFinder finder( indexer, env );124 finder.find( untyped );125 #if 0126 if ( finder.get_alternatives().size() != 1 ) {127 std::cout << "untyped expr is ";128 untyped->print( std::cout );129 std::cout << std::endl << "alternatives are:";130 for ( std::list< Alternative >::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {131 i->print( std::cout );132 } // for133 } // if134 #endif135 assertf( finder.get_alternatives().size() == 1, "findSingleExpression: must have exactly one alternative at the end." );136 Alternative &choice = finder.get_alternatives().front();137 Expression *newExpr = choice.expr->clone();138 finishExpr( newExpr, choice.env );139 return newExpr;140 }141 142 142 bool isIntegralType( Type *type ) { 143 143 if ( dynamic_cast< EnumInstType * >( type ) ) { … … 393 393 } 394 394 395 inline void resolveAsIf( Expression *& expr, Resolver & resolver ) {395 inline void resolveAsIf( Expression *& expr, SymTab::Indexer & indexer ) { 396 396 if( !expr ) return; 397 Expression * newExpr = findSingleExpression( expr, resolver );397 Expression * newExpr = findSingleExpression( expr, indexer ); 398 398 delete expr; 399 399 expr = newExpr; 400 400 } 401 401 402 inline void resolveAsType( Expression *& expr, Type * type, Resolver & resolver ) {402 inline void resolveAsType( Expression *& expr, Type * type, SymTab::Indexer & indexer ) { 403 403 if( !expr ) return; 404 Expression * newExpr = findSingleExpression( new CastExpr( expr, type ), resolver );404 Expression * newExpr = findSingleExpression( new CastExpr( expr, type ), indexer ); 405 405 delete expr; 406 406 expr = newExpr; … … 417 417 418 418 void Resolver::previsit( WaitForStmt * stmt ) { 419 visit_children = false; 419 420 420 421 // Resolve all clauses first … … 422 423 423 424 TypeEnvironment env; 424 AlternativeFinder funcFinder( *this, env );425 AlternativeFinder funcFinder( indexer, env ); 425 426 426 427 // Find all alternatives for a function in canonical form … … 511 512 512 513 // Check if the argument matches the parameter type in the current scope 513 if( ! unify( (*param)->get_type(), arg.expr->get_result(), resultEnv, resultNeed, resultHave, openVars, *this) ) {514 if( ! unify( (*param)->get_type(), arg.expr->get_result(), resultEnv, resultNeed, resultHave, openVars, this->indexer ) ) { 514 515 // Type doesn't match 515 516 stringstream ss; … … 573 574 // Resolve the conditions as if it were an IfStmt 574 575 // Resolve the statments normally 575 resolveAsIf( clause.condition, *this);576 clause.statement->accept( * this);576 resolveAsIf( clause.condition, this->indexer ); 577 clause.statement->accept( *visitor ); 577 578 } 578 579 … … 582 583 // Resolve the conditions as if it were an IfStmt 583 584 // Resolve the statments normally 584 resolveAsType( stmt->timeout.time, new BasicType( noQualifiers, BasicType::LongLongUnsignedInt ), *this);585 resolveAsIf ( stmt->timeout.condition, *this);586 stmt->timeout.statement->accept( * this);585 resolveAsType( stmt->timeout.time, new BasicType( noQualifiers, BasicType::LongLongUnsignedInt ), this->indexer ); 586 resolveAsIf ( stmt->timeout.condition, this->indexer ); 587 stmt->timeout.statement->accept( *visitor ); 587 588 } 588 589 … … 590 591 // Resolve the conditions as if it were an IfStmt 591 592 // Resolve the statments normally 592 resolveAsIf( stmt->orelse.condition, *this);593 stmt->orelse.statement->accept( * this);593 resolveAsIf( stmt->orelse.condition, this->indexer ); 594 stmt->orelse.statement->accept( *visitor ); 594 595 } 595 596 } -
src/ResolvExpr/Resolver.h
r695e00d r8f98b78 29 29 /// Checks types and binds syntactic constructs to typed representations 30 30 void resolve( std::list< Declaration * > translationUnit ); 31 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer ); 32 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ); 31 Expression * resolveInVoidContext( Expression *expr , const SymTab::Indexer &indexer ); 32 Expression * findVoidExpression ( Expression *untyped, const SymTab::Indexer &indexer ); 33 Expression * findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ); 33 34 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ); 34 35 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer );
Note: See TracChangeset
for help on using the changeset viewer.