Changeset 65197c2 for src/Parser
- Timestamp:
- Dec 5, 2017, 2:17:17 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, stuck-waitfor-destruct, with_gc
- Children:
- 971d9f2, a85e44c, c13e8dc8
- Parents:
- 12d2dc8 (diff), 866f560 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 4 edited
-
DeclarationNode.cc (modified) (1 diff)
-
ParseNode.h (modified) (5 diffs)
-
StatementNode.cc (modified) (1 diff)
-
parser.yy (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r12d2dc8 r65197c2 717 717 } 718 718 719 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) {719 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, StatementNode * with ) { 720 720 assert( type ); 721 721 assert( type->kind == TypeData::Function ); 722 722 assert( ! type->function.body ); 723 if ( with ) { 724 // convert 725 // void f(S s) with (s) { x = 0; } 726 // to 727 // void f(S s) { with(s) { x = 0; } } 728 WithStmt * withStmt = strict_dynamic_cast< WithStmt * >( with->build() ); 729 withStmt->stmt = body->build(); 730 delete body; 731 delete with; 732 body = new StatementNode( new CompoundStmt( { withStmt } ) ); 733 } 723 734 type->function.body = body; 724 735 return this; -
src/Parser/ParseNode.h
r12d2dc8 r65197c2 69 69 70 70 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 71 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 71 virtual void printList( std::ostream &os, int indent = 0 ) const { 72 print( os, indent ); 73 if ( next ) next->print( os, indent ); 74 } 72 75 73 76 static int indent_by; … … 120 123 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; } 121 124 122 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 125 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 126 os << expr.get() << std::endl; 127 } 123 128 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 124 129 … … 257 262 DeclarationNode * addBitfield( ExpressionNode * size ); 258 263 DeclarationNode * addVarArgs(); 259 DeclarationNode * addFunctionBody( StatementNode * body );264 DeclarationNode * addFunctionBody( StatementNode * body, StatementNode * with = nullptr ); 260 265 DeclarationNode * addOldDeclList( DeclarationNode * list ); 261 266 DeclarationNode * setBase( TypeData * newType ); … … 359 364 virtual StatementNode * append_last_case( StatementNode * ); 360 365 361 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 362 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 366 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 367 os << stmt.get() << std::endl; 368 } 363 369 private: 364 370 std::unique_ptr<Statement> stmt; … … 408 414 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ); 409 415 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ); 416 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ); 410 417 411 418 //############################################################################## -
src/Parser/StatementNode.cc
r12d2dc8 r65197c2 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 ); 288 295 } 289 296 -
src/Parser/parser.yy
r12d2dc8 r65197c2 1058 1058 with_statement: 1059 1059 WITH '(' tuple_expression_list ')' statement 1060 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME 1060 { 1061 $$ = new StatementNode( build_with( $3, $5 ) ); 1062 } 1061 1063 ; 1062 1064 … … 2410 2412 { $$ = nullptr; } 2411 2413 | WITH '(' tuple_expression_list ')' 2412 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME2414 { $$ = new StatementNode( build_with( $3, nullptr ) ); } 2413 2415 ; 2414 2416 … … 2420 2422 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2421 2423 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } 2422 $1->get_last()->addFunctionBody( $3 );2424 $1->get_last()->addFunctionBody( $3, $2 ); 2423 2425 $$ = $1; 2424 2426 } … … 2428 2430 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2429 2431 typedefTable.leaveScope(); 2430 $$ = $2->addFunctionBody( $4 )->addType( $1 );2432 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2431 2433 } 2432 2434 // handles default int return type, OBSOLESCENT (see 1) … … 2435 2437 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2436 2438 typedefTable.leaveScope(); 2437 $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );2439 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2438 2440 } 2439 2441 // handles default int return type, OBSOLESCENT (see 1) … … 2442 2444 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2443 2445 typedefTable.leaveScope(); 2444 $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );2446 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2445 2447 } 2446 2448 // handles default int return type, OBSOLESCENT (see 1) … … 2449 2451 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2450 2452 typedefTable.leaveScope(); 2451 $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );2453 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); 2452 2454 } 2453 2455 … … 2458 2460 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2459 2461 typedefTable.leaveScope(); 2460 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );2462 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); 2461 2463 } 2462 2464 // handles default int return type, OBSOLESCENT (see 1) … … 2465 2467 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2466 2468 typedefTable.leaveScope(); 2467 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );2469 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2468 2470 } 2469 2471 // handles default int return type, OBSOLESCENT (see 1) … … 2472 2474 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2473 2475 typedefTable.leaveScope(); 2474 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );2476 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2475 2477 } 2476 2478 // handles default int return type, OBSOLESCENT (see 1) … … 2479 2481 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2480 2482 typedefTable.leaveScope(); 2481 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );2483 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); 2482 2484 } 2483 2485 ;
Note:
See TracChangeset
for help on using the changeset viewer.