Changeset 044ae62 for src/Parser
- Timestamp:
- May 29, 2023, 11:44:29 AM (2 years ago)
- Branches:
- ADT
- Children:
- fa2c005
- Parents:
- 3a513d89 (diff), 2b78949 (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
-
StatementNode.cc (modified) (2 diffs)
-
StatementNode.h (modified) (1 diff)
-
lex.ll (modified) (2 diffs)
-
parser.yy (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r3a513d89 r044ae62 328 328 ast::WaitForStmt * build_waitfor( const CodeLocation & location, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ) { 329 329 auto clause = new ast::WaitForClause( location ); 330 clause->target _func= maybeBuild( targetExpr );330 clause->target = maybeBuild( targetExpr ); 331 331 clause->stmt = maybeMoveBuild( stmt ); 332 clause-> cond = notZeroExpr( maybeMoveBuild( when ) );332 clause->when_cond = notZeroExpr( maybeMoveBuild( when ) ); 333 333 334 334 ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() ); … … 359 359 return existing; 360 360 } // build_waitfor_timeout 361 362 ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation & loc, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ) { 363 ast::WhenClause * clause = new ast::WhenClause( loc ); 364 clause->when_cond = notZeroExpr( maybeMoveBuild( when ) ); 365 clause->stmt = maybeMoveBuild( stmt ); 366 clause->target = maybeMoveBuild( targetExpr ); 367 return new ast::WaitUntilStmt::ClauseNode( clause ); 368 } 369 ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation & loc, ExpressionNode * when, StatementNode * stmt ) { 370 ast::WhenClause * clause = new ast::WhenClause( loc ); 371 clause->when_cond = notZeroExpr( maybeMoveBuild( when ) ); 372 clause->stmt = maybeMoveBuild( stmt ); 373 return new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::ELSE, clause ); 374 } 375 ast::WaitUntilStmt::ClauseNode * build_waituntil_timeout( const CodeLocation & loc, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ) { 376 ast::WhenClause * clause = new ast::WhenClause( loc ); 377 clause->when_cond = notZeroExpr( maybeMoveBuild( when ) ); 378 clause->stmt = maybeMoveBuild( stmt ); 379 clause->target = maybeMoveBuild( timeout ); 380 return new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::TIMEOUT, clause ); 381 } 382 383 ast::WaitUntilStmt * build_waituntil_stmt( const CodeLocation & loc, ast::WaitUntilStmt::ClauseNode * root ) { 384 ast::WaitUntilStmt * retStmt = new ast::WaitUntilStmt( loc ); 385 retStmt->predicateTree = root; 386 387 // iterative tree traversal 388 std::vector<ast::WaitUntilStmt::ClauseNode *> nodeStack; // stack needed for iterative traversal 389 ast::WaitUntilStmt::ClauseNode * currNode = nullptr; 390 ast::WaitUntilStmt::ClauseNode * lastInternalNode = nullptr; 391 ast::WaitUntilStmt::ClauseNode * cleanup = nullptr; // used to cleanup removed else/timeout 392 nodeStack.push_back(root); 393 394 do { 395 currNode = nodeStack.back(); 396 nodeStack.pop_back(); // remove node since it will be processed 397 398 switch (currNode->op) { 399 case ast::WaitUntilStmt::ClauseNode::LEAF: 400 retStmt->clauses.push_back(currNode->leaf); 401 break; 402 case ast::WaitUntilStmt::ClauseNode::ELSE: 403 retStmt->else_stmt = currNode->leaf->stmt 404 ? ast::deepCopy( currNode->leaf->stmt ) 405 : nullptr; 406 407 retStmt->else_cond = currNode->leaf->when_cond 408 ? ast::deepCopy( currNode->leaf->when_cond ) 409 : nullptr; 410 411 delete currNode->leaf; 412 break; 413 case ast::WaitUntilStmt::ClauseNode::TIMEOUT: 414 retStmt->timeout_time = currNode->leaf->target 415 ? ast::deepCopy( currNode->leaf->target ) 416 : nullptr; 417 retStmt->timeout_stmt = currNode->leaf->stmt 418 ? ast::deepCopy( currNode->leaf->stmt ) 419 : nullptr; 420 retStmt->timeout_cond = currNode->leaf->when_cond 421 ? ast::deepCopy( currNode->leaf->when_cond ) 422 : nullptr; 423 424 delete currNode->leaf; 425 break; 426 default: 427 nodeStack.push_back( currNode->right ); // process right after left 428 nodeStack.push_back( currNode->left ); 429 430 // Cut else/timeout out of the tree 431 if ( currNode->op == ast::WaitUntilStmt::ClauseNode::LEFT_OR ) { 432 if ( lastInternalNode ) 433 lastInternalNode->right = currNode->left; 434 else // if not set then root is LEFT_OR 435 retStmt->predicateTree = currNode->left; 436 437 currNode->left = nullptr; 438 cleanup = currNode; 439 } 440 441 lastInternalNode = currNode; 442 break; 443 } 444 } while ( !nodeStack.empty() ); 445 446 if ( cleanup ) delete cleanup; 447 448 return retStmt; 449 } 361 450 362 451 ast::Stmt * build_with( const CodeLocation & location, ExpressionNode * exprs, StatementNode * stmt ) { -
src/Parser/StatementNode.h
r3a513d89 r044ae62 100 100 ast::WaitForStmt * build_waitfor_else( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt ); 101 101 ast::WaitForStmt * build_waitfor_timeout( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ); 102 ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation &, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ); 103 ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation &, ExpressionNode * when, StatementNode * stmt ); 104 ast::WaitUntilStmt::ClauseNode * build_waituntil_timeout( const CodeLocation &, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ); 105 ast::WaitUntilStmt * build_waituntil_stmt( const CodeLocation &, ast::WaitUntilStmt::ClauseNode * root ); 102 106 ast::Stmt * build_with( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt ); 103 107 ast::Stmt * build_mutex( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt ); -
src/Parser/lex.ll
r3a513d89 r044ae62 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sat Mar 25 08:09:03202313 * Update Count : 76 812 * Last Modified On : Tue May 2 08:45:21 2023 13 * Update Count : 769 14 14 */ 15 15 … … 258 258 enable { KEYWORD_RETURN(ENABLE); } // CFA 259 259 enum { KEYWORD_RETURN(ENUM); } 260 exception { KEYWORD_RETURN(EXCEPTION); } // CFA 260 261 __extension__ { KEYWORD_RETURN(EXTENSION); } // GCC 261 exception { KEYWORD_RETURN(EXCEPTION); } // CFA262 262 extern { KEYWORD_RETURN(EXTERN); } 263 263 fallthrough { KEYWORD_RETURN(FALLTHROUGH); } // CFA -
src/Parser/parser.yy
r3a513d89 r044ae62 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue Apr 4 14:02:00202313 // Update Count : 63 2911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 26 16:45:37 2023 13 // Update Count : 6330 14 14 // 15 15 … … 307 307 ClauseNode * clause; 308 308 ast::WaitForStmt * wfs; 309 ast::WaitUntilStmt::ClauseNode * wucn; 309 310 CondCtl * ifctl; 310 311 ForCtrl * forctl; … … 427 428 %type<expr> when_clause when_clause_opt waitfor waituntil timeout 428 429 %type<stmt> waitfor_statement waituntil_statement 429 %type<wfs> wor_waitfor_clause waituntil_clause wand_waituntil_clause wor_waituntil_clause 430 %type<wfs> wor_waitfor_clause 431 %type<wucn> waituntil_clause wand_waituntil_clause wor_waituntil_clause 430 432 431 433 // declarations … … 1682 1684 1683 1685 waituntil: 1684 WAITUNTIL '(' c ast_expression ')'1686 WAITUNTIL '(' comma_expression ')' 1685 1687 { $$ = $3; } 1686 1688 ; … … 1688 1690 waituntil_clause: 1689 1691 when_clause_opt waituntil statement 1690 { printf( "waituntil_clause 1\n" ); $$ = nullptr; }1692 { $$ = build_waituntil_clause( yylloc, $1, $2, maybe_build_compound( yylloc, $3 ) ); } 1691 1693 | '(' wor_waituntil_clause ')' 1692 { printf( "waituntil_clause 2\n" ); $$ = nullptr; }1694 { $$ = $2; } 1693 1695 ; 1694 1696 1695 1697 wand_waituntil_clause: 1696 1698 waituntil_clause %prec THEN 1697 { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; }1699 { $$ = $1; } 1698 1700 | waituntil_clause wand wand_waituntil_clause 1699 { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; }1701 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::AND, $1, $3 ); } 1700 1702 ; 1701 1703 1702 1704 wor_waituntil_clause: 1703 1705 wand_waituntil_clause 1704 { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; }1706 { $$ = $1; } 1705 1707 | wor_waituntil_clause wor wand_waituntil_clause 1706 { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; }1708 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, $1, $3 ); } 1707 1709 | wor_waituntil_clause wor when_clause_opt ELSE statement 1708 { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; }1710 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); } 1709 1711 | wor_waituntil_clause wor when_clause_opt timeout statement %prec THEN 1710 { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; }1712 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); } 1711 1713 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1712 1714 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1713 1715 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1714 1716 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1715 { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; } 1717 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, 1718 new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, 1719 build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ), 1720 build_waituntil_else( yylloc, $7, maybe_build_compound( yylloc, $9 ) ) ) ); } 1716 1721 ; 1717 1722 … … 1719 1724 wor_waituntil_clause %prec THEN 1720 1725 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement. 1721 { $$ = new StatementNode( build_compound( yylloc, nullptr ) ); } 1726 { 1727 $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) ); 1728 // $$ = new StatementNode( build_compound( yylloc, nullptr ) ); 1729 } 1722 1730 ; 1723 1731
Note:
See TracChangeset
for help on using the changeset viewer.