Changes in / [3ca540f:5da9d6a]
- Location:
- src
- Files:
-
- 23 edited
-
CodeGen/CodeGenerator.cc (modified) (1 diff)
-
CodeGen/CodeGenerator.h (modified) (1 diff)
-
Common/PassVisitor.h (modified) (3 diffs)
-
Common/PassVisitor.impl.h (modified) (1 diff)
-
Common/PassVisitor.proto.h (modified) (1 diff)
-
GenPoly/InstantiateGeneric.cc (modified) (3 diffs)
-
Parser/ParseNode.h (modified) (1 diff)
-
Parser/StatementNode.cc (modified) (1 diff)
-
Parser/parser.yy (modified) (1 diff)
-
ResolvExpr/AlternativeFinder.cc (modified) (1 diff)
-
ResolvExpr/AlternativeFinder.h (modified) (2 diffs)
-
ResolvExpr/Resolver.cc (modified) (2 diffs)
-
SymTab/Indexer.cc (modified) (1 diff)
-
SymTab/Indexer.h (modified) (1 diff)
-
SynTree/Mutator.cc (modified) (1 diff)
-
SynTree/Mutator.h (modified) (1 diff)
-
SynTree/ReferenceToType.cc (modified) (2 diffs)
-
SynTree/Statement.cc (modified) (1 diff)
-
SynTree/Statement.h (modified) (1 diff)
-
SynTree/SynTree.h (modified) (1 diff)
-
SynTree/Type.h (modified) (3 diffs)
-
SynTree/Visitor.cc (modified) (1 diff)
-
SynTree/Visitor.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r3ca540f r5da9d6a 1012 1012 } 1013 1013 1014 void CodeGenerator::postvisit( WithStmt * with ) {1015 if ( ! genC ) {1016 output << "with ( ";1017 genCommaList( with->exprs.begin(), with->exprs.end() );1018 output << " ) ";1019 }1020 with->stmt->accept( *visitor );1021 }1022 1014 1023 1015 void CodeGenerator::postvisit( WhileStmt * whileStmt ) { -
src/CodeGen/CodeGenerator.h
r3ca540f r5da9d6a 102 102 void postvisit( CatchStmt * ); 103 103 void postvisit( WaitForStmt * ); 104 void postvisit( WithStmt * );105 104 void postvisit( WhileStmt * ); 106 105 void postvisit( ForStmt * ); -
src/Common/PassVisitor.h
r3ca540f r5da9d6a 81 81 virtual void visit( FinallyStmt * finallyStmt ) override final; 82 82 virtual void visit( WaitForStmt * waitforStmt ) override final; 83 virtual void visit( WithStmt * withStmt ) override final;84 83 virtual void visit( NullStmt * nullStmt ) override final; 85 84 virtual void visit( DeclStmt * declStmt ) override final; … … 173 172 virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; 174 173 virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; 175 virtual Statement * mutate( WithStmt * withStmt ) override final;176 174 virtual NullStmt * mutate( NullStmt * nullStmt ) override final; 177 175 virtual Statement * mutate( DeclStmt * declStmt ) override final; … … 298 296 void indexerAddUnionFwd ( UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); } 299 297 void indexerAddTrait ( TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); } 300 void indexerAddWith ( WithStmt * node ) { indexer_impl_addWith ( pass, 0, node ); }301 302 298 303 299 template< typename TreeType, typename VisitorType > -
src/Common/PassVisitor.impl.h
r3ca540f r5da9d6a 985 985 } 986 986 987 988 989 //--------------------------------------------------------------------------990 // NullStmt991 template< typename pass_type >992 void PassVisitor< pass_type >::visit( WithStmt * node ) {993 VISIT_START( node );994 maybeAccept_impl( node->exprs, *this );995 {996 // catch statements introduce a level of scope (for the caught exception)997 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );998 indexerAddWith( node );999 maybeAccept_impl( node->stmt, *this );1000 }1001 VISIT_END( node );1002 }1003 1004 template< typename pass_type >1005 Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {1006 MUTATE_START( node );1007 maybeMutate_impl( node->exprs, *this );1008 {1009 // catch statements introduce a level of scope (for the caught exception)1010 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );1011 indexerAddWith( node );1012 maybeMutate_impl( node->stmt, *this );1013 }1014 MUTATE_END( Statement, node );1015 }1016 1017 987 //-------------------------------------------------------------------------- 1018 988 // NullStmt -
src/Common/PassVisitor.proto.h
r3ca540f r5da9d6a 208 208 INDEXER_FUNC( addUnion , UnionDecl * ); 209 209 INDEXER_FUNC( addTrait , TraitDecl * ); 210 INDEXER_FUNC( addWith , WithStmt * );211 210 212 211 -
src/GenPoly/InstantiateGeneric.cc
r3ca540f r5da9d6a 453 453 return false; 454 454 } 455 456 AggregateDecl * getAggr( Type * t ) { 457 if ( StructInstType * inst = dynamic_cast< StructInstType * >( t ) ) { 458 return inst->baseStruct; 459 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( t ) ) { 460 return inst->baseUnion; 461 } 462 assertf( false, "Non-aggregate type: %s", toString( t ).c_str() ); 463 } 455 464 } 456 465 … … 460 469 if ( isGenericType( memberExpr->aggregate->result ) ) { 461 470 // find the location of the member 462 AggregateDecl * aggr = memberExpr->aggregate->result->getAggr();471 AggregateDecl * aggr = getAggr( memberExpr->aggregate->result ); 463 472 std::list< Declaration * > & members = aggr->members; 464 473 memberIndex = std::distance( members.begin(), std::find( members.begin(), members.end(), memberExpr->member ) ); … … 470 479 if ( memberIndex != -1 ) { 471 480 // using the location from the generic type, find the member in the instantiation and rebuild the member expression 472 AggregateDecl * aggr = memberExpr->aggregate->result->getAggr();481 AggregateDecl * aggr = getAggr( memberExpr->aggregate->result ); 473 482 assertf( memberIndex < (int)aggr->members.size(), "Instantiation somehow has fewer members than the generic type." ); 474 483 Declaration * member = *std::next( aggr->members.begin(), memberIndex ); -
src/Parser/ParseNode.h
r3ca540f r5da9d6a 408 408 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ); 409 409 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ); 410 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt );411 410 412 411 //############################################################################## -
src/Parser/StatementNode.cc
r3ca540f r5da9d6a 282 282 node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 283 283 284 node->orelse.statement = maybeMoveBuild<Statement >( else_stmt );284 node->orelse.statement = maybeMoveBuild<Statement >( else_stmt ); 285 285 node->orelse.condition = notZeroExpr( maybeMoveBuild<Expression>( else_when ) ); 286 286 287 287 return node; 288 }289 290 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {291 std::list< Expression * > e;292 buildMoveList( exprs, e );293 Statement * s = maybeMoveBuild<Statement>( stmt );294 return new WithStmt( e, s );295 288 } 296 289 -
src/Parser/parser.yy
r3ca540f r5da9d6a 1058 1058 with_statement: 1059 1059 WITH '(' tuple_expression_list ')' statement 1060 { 1061 $$ = new StatementNode( build_with( $3, $5 ) ); 1062 } 1060 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME 1063 1061 ; 1064 1062 -
src/ResolvExpr/AlternativeFinder.cc
r3ca540f r5da9d6a 83 83 } 84 84 85 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt ) {86 Indenter indent = { Indenter::tabsize, indentAmt };87 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) {88 i->print( os, indent );89 os << std::endl;90 }91 }92 93 85 namespace { 86 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 ) { 87 Indenter indent = { Indenter::tabsize, indentAmt }; 88 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { 89 i->print( os, indent ); 90 os << std::endl; 91 } 92 } 93 94 94 void makeExprList( const AltList &in, std::list< Expression* > &out ) { 95 95 for ( AltList::const_iterator i = in.begin(); i != in.end(); ++i ) { -
src/ResolvExpr/AlternativeFinder.h
r3ca540f r5da9d6a 174 174 175 175 Cost sumCost( const AltList &in ); 176 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 );177 176 178 177 template< typename InputIterator > … … 182 181 } 183 182 } 184 185 183 } // namespace ResolvExpr 186 184 -
src/ResolvExpr/Resolver.cc
r3ca540f r5da9d6a 74 74 void previsit( CatchStmt *catchStmt ); 75 75 void previsit( WaitForStmt * stmt ); 76 void previsit( WithStmt * withStmt );77 76 78 77 void previsit( SingleInit *singleInit ); … … 572 571 } 573 572 574 bool isStructOrUnion( Type * t ) {575 t = t->stripReferences();576 return dynamic_cast< StructInstType * >( t ) || dynamic_cast< UnionInstType * >( t );577 }578 579 void Resolver::previsit( WithStmt * withStmt ) {580 for ( Expression *& expr : withStmt->exprs ) {581 TypeEnvironment env;582 AlternativeFinder finder( indexer, env );583 finder.findWithAdjustment( expr );584 585 // only struct- and union-typed expressions are viable candidates586 AltList candidates;587 for ( Alternative & alt : finder.get_alternatives() ) {588 if ( isStructOrUnion( alt.expr->result ) ) {589 candidates.push_back( std::move( alt ) );590 }591 }592 593 // choose the lowest cost expression among the candidates594 AltList winners;595 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );596 if ( winners.size() == 0 ) {597 throw SemanticError( "No reasonable alternatives for with statement expression: ", expr );598 } else if ( winners.size() != 1 ) {599 std::ostringstream stream;600 stream << "Cannot choose between " << winners.size() << " alternatives for with statement expression\n";601 expr->print( stream );602 stream << "Alternatives are:\n";603 printAlts( winners, stream, 1 );604 throw SemanticError( stream.str() );605 }606 607 // there is one unambiguous interpretation - move the expression into the with statement608 Alternative & alt = winners.front();609 finishExpr( alt.expr, alt.env, expr->env );610 delete expr;611 expr = alt.expr;612 alt.expr = nullptr;613 }614 }615 616 573 template< typename T > 617 574 bool isCharType( T t ) { -
src/SymTab/Indexer.cc
r3ca540f r5da9d6a 567 567 } 568 568 569 void Indexer::addWith( WithStmt * stmt ) {570 for ( Expression * expr : stmt->exprs ) {571 if ( expr->result ) {572 AggregateDecl * aggr = expr->result->getAggr();573 assertf( aggr, "WithStmt expr has non-aggregate type: %s", toString( expr->result ).c_str() );574 575 // xxx - this is wrong, needs to somehow hook up chain of objects576 for ( Declaration * decl : aggr->members ) {577 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {578 addId( dwt );579 }580 }581 }582 }583 }584 585 569 void Indexer::addIds( const std::list< DeclarationWithType * > & decls ) { 586 570 for ( auto d : decls ) { -
src/SymTab/Indexer.h
r3ca540f r5da9d6a 76 76 void addTrait( TraitDecl *decl ); 77 77 78 /// adds all of the IDs from WithStmt exprs79 void addWith( WithStmt * );80 81 78 /// convenience function for adding a list of Ids to the indexer 82 79 void addIds( const std::list< DeclarationWithType * > & decls ); -
src/SynTree/Mutator.cc
r3ca540f r5da9d6a 203 203 } 204 204 205 Statement * Mutator::mutate( WithStmt * withStmt ) {206 mutateAll( withStmt->exprs, *this );207 withStmt->stmt = maybeMutate( withStmt->stmt, *this );208 return withStmt;209 }210 211 205 NullStmt * Mutator::mutate( NullStmt *nullStmt ) { 212 206 return nullStmt; -
src/SynTree/Mutator.h
r3ca540f r5da9d6a 50 50 virtual Statement * mutate( FinallyStmt * catchStmt ); 51 51 virtual Statement * mutate( WaitForStmt * waitforStmt ); 52 virtual Statement * mutate( WithStmt * withStmt );53 52 virtual NullStmt * mutate( NullStmt * nullStmt ); 54 53 virtual Statement * mutate( DeclStmt * declStmt ); -
src/SynTree/ReferenceToType.cc
r3ca540f r5da9d6a 70 70 bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; } 71 71 72 AggregateDecl * StructInstType::getAggr() { return baseStruct; }73 74 72 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 75 73 assert( baseStruct ); … … 103 101 104 102 bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; } 105 106 AggregateDecl * UnionInstType::getAggr() { return baseUnion; }107 103 108 104 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { -
src/SynTree/Statement.cc
r3ca540f r5da9d6a 456 456 } 457 457 458 459 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {}460 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {461 cloneAll( other.exprs, exprs );462 }463 WithStmt::~WithStmt() {464 deleteAll( exprs );465 delete stmt;466 }467 468 void WithStmt::print( std::ostream & os, Indenter indent ) const {469 os << "With statement" << endl;470 os << indent << "... with statement:" << endl << indent+1;471 stmt->print( os, indent+1 );472 }473 474 475 458 NullStmt::NullStmt( const std::list<Label> & labels ) : Statement( labels ) { 476 459 } -
src/SynTree/Statement.h
r3ca540f r5da9d6a 431 431 }; 432 432 433 class WithStmt : public Statement {434 public:435 std::list< Expression * > exprs;436 Statement * stmt;437 438 WithStmt( const std::list< Expression * > & exprs, Statement * stmt );439 WithStmt( const WithStmt & other );440 virtual ~WithStmt();441 442 virtual WithStmt * clone() const override { return new WithStmt( *this ); }443 virtual void accept( Visitor & v ) override { v.visit( this ); }444 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }445 virtual void print( std::ostream & os, Indenter indent = {} ) const override;446 };447 448 433 449 434 // represents a declaration that occurs as part of a compound statement -
src/SynTree/SynTree.h
r3ca540f r5da9d6a 55 55 class FinallyStmt; 56 56 class WaitForStmt; 57 class WithStmt;58 57 class NullStmt; 59 58 class DeclStmt; -
src/SynTree/Type.h
r3ca540f r5da9d6a 178 178 virtual bool isComplete() const { return true; } 179 179 180 virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toString( this ).c_str() ); }181 182 180 virtual Type *clone() const = 0; 183 181 virtual void accept( Visitor & v ) = 0; … … 407 405 virtual bool isComplete() const override; 408 406 409 virtual AggregateDecl * getAggr() override;410 411 407 /// Looks up the members of this struct named "name" and places them into "foundDecls". 412 408 /// Clones declarations into "foundDecls", caller responsible for freeing … … 440 436 441 437 virtual bool isComplete() const override; 442 443 virtual AggregateDecl * getAggr() override;444 438 445 439 /// looks up the members of this union named "name" and places them into "foundDecls" -
src/SynTree/Visitor.cc
r3ca540f r5da9d6a 174 174 } 175 175 176 void Visitor::visit( WithStmt * withStmt ) { 177 acceptAll( withStmt->exprs, *this ); 178 maybeAccept( withStmt->stmt, *this ); 179 } 180 181 void Visitor::visit( NullStmt * ) { 176 void Visitor::visit( __attribute__((unused)) NullStmt *nullStmt ) { 182 177 } 183 178 -
src/SynTree/Visitor.h
r3ca540f r5da9d6a 52 52 virtual void visit( FinallyStmt * finallyStmt ); 53 53 virtual void visit( WaitForStmt * waitforStmt ); 54 virtual void visit( WithStmt * withStmt );55 54 virtual void visit( NullStmt * nullStmt ); 56 55 virtual void visit( DeclStmt * declStmt );
Note:
See TracChangeset
for help on using the changeset viewer.