Changeset 9fd9d015 for src/Parser
- Timestamp:
- Mar 29, 2023, 5:34:51 PM (17 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- ac235a8
- Parents:
- afdb74b
- Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rafdb74b r9fd9d015 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 19 09:02:37 202313 // Update Count : 94 012 // Last Modified On : Wed Mar 29 08:40:27 2023 13 // Update Count : 948 14 14 // 15 15 … … 425 425 Statement * build_directive( std::string * directive ); 426 426 SuspendStmt * build_suspend( StatementNode *, SuspendStmt::Type = SuspendStmt::None); 427 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 428 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); 429 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ); 430 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ); 427 WaitForStmt * build_waitfor( WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ); 428 WaitForStmt * build_waitfor_else( WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt ); 429 WaitForStmt * build_waitfor_timeout( WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ); 431 430 Statement * build_with( ExpressionNode * exprs, StatementNode * stmt ); 432 431 Statement * build_mutex( ExpressionNode * exprs, StatementNode * stmt ); -
src/Parser/StatementNode.cc
rafdb74b r9fd9d015 11 11 // Created On : Sat May 16 14:59:41 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Wed Feb 2 20:29:30 202214 // Update Count : 4 2513 // Last Modified On : Wed Mar 29 08:51:23 2023 14 // Update Count : 454 15 15 // 16 16 … … 268 268 269 269 return node; 270 } 271 272 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) { 273 auto node = new WaitForStmt(); 274 270 } // build_suspend 271 272 WaitForStmt * build_waitfor( WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ) { 275 273 WaitForStmt::Target target; 276 274 target.function = maybeBuild( targetExpr ); … … 282 280 delete targetExpr; 283 281 284 node->clauses.push_back( WaitForStmt::Clause{ 285 target, 286 maybeMoveBuild( stmt ), 287 notZeroExpr( maybeMoveBuild( when ) ) 288 }); 289 290 return node; 291 } // build_waitfor 292 293 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) { 294 WaitForStmt::Target target; 295 target.function = maybeBuild( targetExpr ); 296 297 ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() ); 298 targetExpr->set_next( nullptr ); 299 buildMoveList< Expression >( next, target.arguments ); 300 301 delete targetExpr; 302 303 node->clauses.insert( node->clauses.begin(), WaitForStmt::Clause{ 282 existing->clauses.insert( existing->clauses.begin(), WaitForStmt::Clause{ 304 283 std::move( target ), 305 284 maybeMoveBuild( stmt ), … … 307 286 }); 308 287 309 return node;288 return existing; 310 289 } // build_waitfor 311 290 312 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) { 313 auto node = new WaitForStmt(); 314 315 if( timeout ) { 316 node->timeout.time = maybeMoveBuild( timeout ); 317 node->timeout.statement = maybeMoveBuild( stmt ); 318 node->timeout.condition = notZeroExpr( maybeMoveBuild( when ) ); 319 } else { 320 node->orelse.statement = maybeMoveBuild( stmt ); 321 node->orelse.condition = notZeroExpr( maybeMoveBuild( when ) ); 322 } // if 323 324 return node; 325 } // build_waitfor_timeout 326 327 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_, ExpressionNode * else_when ) { 328 auto node = new WaitForStmt(); 329 330 node->timeout.time = maybeMoveBuild( timeout ); 331 node->timeout.statement = maybeMoveBuild( stmt ); 332 node->timeout.condition = notZeroExpr( maybeMoveBuild( when ) ); 333 334 node->orelse.statement = maybeMoveBuild( else_ ); 335 node->orelse.condition = notZeroExpr( maybeMoveBuild( else_when ) ); 336 337 return node; 291 WaitForStmt * build_waitfor_else( WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt ) { 292 existing->orelse.statement = maybeMoveBuild( stmt ); 293 existing->orelse.condition = notZeroExpr( maybeMoveBuild( when ) ); 294 295 return existing; 296 } // build_waitfor_else 297 298 WaitForStmt * build_waitfor_timeout( WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ) { 299 existing->timeout.time = maybeMoveBuild( timeout ); 300 existing->timeout.statement = maybeMoveBuild( stmt ); 301 existing->timeout.condition = notZeroExpr( maybeMoveBuild( when ) ); 302 303 return existing; 338 304 } // build_waitfor_timeout 339 305 -
src/Parser/lex.ll
rafdb74b r9fd9d015 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Mon Jan 30 19:03:34202313 * Update Count : 76 712 * Last Modified On : Sat Mar 25 08:09:03 2023 13 * Update Count : 768 14 14 */ 15 15 … … 214 214 __alignof { KEYWORD_RETURN(ALIGNOF); } // GCC 215 215 __alignof__ { KEYWORD_RETURN(ALIGNOF); } // GCC 216 and { QKEYWORD_RETURN(WAND); } // CFA 216 217 asm { KEYWORD_RETURN(ASM); } 217 218 __asm { KEYWORD_RETURN(ASM); } // GCC -
src/Parser/parser.yy
rafdb74b r9fd9d015 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 2 21:26:01202313 // Update Count : 6 00212 // Last Modified On : Wed Mar 29 11:21:38 2023 13 // Update Count : 6321 14 14 // 15 15 … … 360 360 361 361 // names and constants: lexer differentiates between identifier and typedef names 362 %token<tok> IDENTIFIER QUOTED_IDENTIFIERTYPEDIMname TYPEDEFname TYPEGENname363 %token<tok> TIMEOUT W ORCATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA362 %token<tok> IDENTIFIER TYPEDIMname TYPEDEFname TYPEGENname 363 %token<tok> TIMEOUT WAND WOR CATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA 364 364 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 365 365 %token<tok> DIRECTIVE … … 430 430 %type<catch_kind> handler_key 431 431 %type<sn> mutex_statement 432 %type<en> when_clause when_clause_opt waitfor 433 %type<sn> waitfor_statement 434 %type<wfs> w aitfor_clause432 %type<en> when_clause when_clause_opt waitfor waituntil timeout 433 %type<sn> waitfor_statement waituntil_statement 434 %type<wfs> wor_waitfor_clause waituntil_clause wand_waituntil_clause wor_waituntil_clause 435 435 436 436 // declarations … … 536 536 // Similar issues exit with the waitfor statement. 537 537 538 // Order of these lines matters (low-to-high precedence). THEN is left associative over W OR/TIMEOUT/ELSE, WOR is left539 // associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.538 // Order of these lines matters (low-to-high precedence). THEN is left associative over WAND/WOR/TIMEOUT/ELSE, WAND/WOR 539 // is left associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE. 540 540 %precedence THEN // rule precedence for IF/WAITFOR statement 541 %precedence ANDAND // token precedence for start of WAND in WAITFOR statement 542 %precedence WAND // token precedence for start of WAND in WAITFOR statement 543 %precedence OROR // token precedence for start of WOR in WAITFOR statement 541 544 %precedence WOR // token precedence for start of WOR in WAITFOR statement 542 545 %precedence TIMEOUT // token precedence for start of TIMEOUT in WAITFOR statement … … 625 628 quasi_keyword: // CFA 626 629 TIMEOUT 630 | WAND 627 631 | WOR 628 632 | CATCH … … 775 779 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 776 780 | postfix_expression ICR 777 781 { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); } 778 782 | postfix_expression DECR 779 783 { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); } 780 784 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 781 785 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } … … 805 809 '@' // CFA, default parameter 806 810 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 807 811 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 808 812 | assignment_expression 809 813 ; … … 880 884 } 881 885 | unary_operator cast_expression 882 886 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); } 883 887 | ICR unary_expression 884 888 { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); } 885 889 | DECR unary_expression 886 890 { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); } 887 891 | SIZEOF unary_expression 888 892 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); } … … 1137 1141 | mutex_statement 1138 1142 | waitfor_statement 1143 | waituntil_statement 1139 1144 | exception_statement 1140 1145 | enable_disable_statement … … 1246 1251 | declaration comma_expression // semi-colon separated 1247 1252 { $$ = new CondCtl( $1, $2 ); } 1248 1253 ; 1249 1254 1250 1255 // CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case … … 1329 1334 } 1330 1335 | FOR '(' for_control_expression_list ')' statement %prec THEN 1331 1336 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); } 1332 1337 | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA 1333 1338 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); } … … 1521 1526 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1522 1527 } 1523 1528 ; 1524 1529 1525 1530 downupdowneq: … … 1530 1535 | ErangeDownEq 1531 1536 { $$ = OperKinds::GEThan; } 1532 1537 ; 1533 1538 1534 1539 updown: … … 1537 1542 | ErangeDown 1538 1543 { $$ = OperKinds::GThan; } 1539 1544 ; 1540 1545 1541 1546 updowneq: … … 1545 1550 | ErangeDownEq 1546 1551 { $$ = OperKinds::GEThan; } 1547 1552 ; 1548 1553 1549 1554 jump_statement: … … 1628 1633 ; 1629 1634 1630 waitfor:1631 WAITFOR '(' cast_expression ')'1632 { $$ = $3; }1633 // | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'1634 // { $$ = (ExpressionNode *)$3->set_last( $5 ); }1635 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'1636 { $$ = (ExpressionNode *)($3->set_last( $5 )); }1637 ;1638 1639 1635 cast_expression_list: 1640 1636 cast_expression … … 1645 1641 1646 1642 timeout: 1647 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1648 ; 1649 1650 waitfor_clause: 1643 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1644 ; 1645 1646 wor: 1647 OROR 1648 | WOR 1649 1650 waitfor: 1651 WAITFOR '(' cast_expression ')' 1652 { $$ = $3; } 1653 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')' 1654 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1655 ; 1656 1657 wor_waitfor_clause: 1651 1658 when_clause_opt waitfor statement %prec THEN 1652 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); } 1653 | when_clause_opt waitfor statement WOR waitfor_clause 1654 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); } 1655 | when_clause_opt timeout statement %prec THEN 1656 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); } 1657 | when_clause_opt ELSE statement 1658 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); } 1659 // Called first: create header for WaitForStmt. 1660 { $$ = build_waitfor( new WaitForStmt(), $1, $2, maybe_build_compound( $3 ) ); } 1661 | wor_waitfor_clause wor when_clause_opt waitfor statement %prec THEN 1662 { $$ = build_waitfor( $1, $3, $4, maybe_build_compound( $5 ) ); } 1663 | wor_waitfor_clause wor when_clause_opt ELSE statement 1664 { $$ = build_waitfor_else( $1, $3, maybe_build_compound( $5 ) ); } 1665 | wor_waitfor_clause wor when_clause_opt timeout statement %prec THEN 1666 { $$ = build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ); } 1659 1667 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1660 | w hen_clause_opt timeout statement WORELSE statement // syntax error1668 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1661 1669 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1662 | when_clause_opt timeout statement WOR when_clause ELSE statement 1663 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); } 1664 ; 1670 | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1671 { $$ = build_waitfor_else( build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ), $7, maybe_build_compound( $9 ) ); } 1665 1672 1666 1673 waitfor_statement: 1667 when_clause_opt waitfor statement %prec THEN 1668 { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); } 1669 | when_clause_opt waitfor statement WOR waitfor_clause 1670 { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); } 1674 wor_waitfor_clause %prec THEN 1675 { $$ = new StatementNode( $1 ); } 1676 ; 1677 1678 wand: 1679 ANDAND 1680 | WAND 1681 ; 1682 1683 waituntil: 1684 WAITUNTIL '(' cast_expression ')' 1685 { $$ = $3; } 1686 ; 1687 1688 waituntil_clause: 1689 when_clause_opt waituntil statement 1690 { printf( "waituntil_clause 1\n" ); $$ = nullptr; } 1691 | '(' wor_waituntil_clause ')' 1692 { printf( "waituntil_clause 2\n" ); $$ = nullptr; } 1693 ; 1694 1695 wand_waituntil_clause: 1696 waituntil_clause %prec THEN 1697 { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; } 1698 | waituntil_clause wand wand_waituntil_clause 1699 { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; } 1700 ; 1701 1702 wor_waituntil_clause: 1703 wand_waituntil_clause 1704 { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; } 1705 | wor_waituntil_clause wor wor_waituntil_clause %prec THEN 1706 { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; } 1707 | wor_waituntil_clause wor when_clause_opt ELSE statement 1708 { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; } 1709 | wor_waituntil_clause wor when_clause_opt timeout statement %prec THEN 1710 { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; } 1711 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1712 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1713 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1714 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1715 { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; } 1716 ; 1717 1718 waituntil_statement: 1719 wor_waituntil_clause %prec THEN 1720 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement. 1721 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 1671 1722 ; 1672 1723 1673 1724 exception_statement: 1674 TRY compound_statement handler_clause 1725 TRY compound_statement handler_clause %prec THEN 1675 1726 { $$ = new StatementNode( build_try( $2, $3, nullptr ) ); } 1676 1727 | TRY compound_statement finally_clause … … 1832 1883 { 1833 1884 // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" ); 1834 1885 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 1835 1886 // printf( "\tattr %s\n", attr->name.c_str() ); 1836 1887 // } // for … … 2302 2353 { 2303 2354 // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2304 2355 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2305 2356 // printf( "\tattr %s\n", attr->name.c_str() ); 2306 2357 // } // for … … 2318 2369 { 2319 2370 // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2320 2371 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2321 2372 // printf( "\tattr %s\n", attr->name.c_str() ); 2322 2373 // } // for … … 2396 2447 { 2397 2448 // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2398 2449 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2399 2450 // printf( "\tattr %s\n", attr->name.c_str() ); 2400 2451 // } // for … … 2523 2574 $$ = fieldDecl( $1, $2 ); 2524 2575 // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2525 2576 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2526 2577 // printf( "\tattr %s\n", attr->name.c_str() ); 2527 2578 // } // for … … 2530 2581 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } 2531 2582 | STATIC type_specifier field_declaring_list_opt ';' // CFA 2532 2583 { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; } 2533 2584 | INLINE type_specifier field_abstract_list_opt ';' // CFA 2534 2585 { … … 2541 2592 } 2542 2593 | INLINE aggregate_control ';' // CFA 2543 2594 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; } 2544 2595 | typedef_declaration ';' // CFA 2545 2596 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2624 2675 { $$ = DeclarationNode::newEnum( $3->name, $6, true, false, nullptr, $4 )->addQualifiers( $2 ); } 2625 2676 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2626 2677 { 2627 2678 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) 2628 2679 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } … … 3158 3209 { 3159 3210 distQual( $5, $1 ); 3160 3211 forall = false; 3161 3212 $$ = $5; 3162 3213 } … … 3169 3220 { 3170 3221 distQual( $5, $1 ); 3171 3222 forall = false; 3172 3223 $$ = $5; 3173 3224 } … … 3180 3231 { 3181 3232 distQual( $6, $1->addQualifiers( $2 ) ); 3182 3233 forall = false; 3183 3234 $$ = $6; 3184 3235 } … … 3387 3438 | '(' attribute_list variable_ptr ')' array_dimension 3388 3439 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3389 | '(' variable_array ')' multi_array_dimension 3440 | '(' variable_array ')' multi_array_dimension // redundant parenthesis 3390 3441 { $$ = $2->addArray( $4 ); } 3391 3442 | '(' attribute_list variable_array ')' multi_array_dimension // redundant parenthesis … … 3810 3861 | ErangeUpEq 3811 3862 { $$ = OperKinds::LEThan; } 3812 3863 ; 3813 3864 3814 3865 multi_array_dimension:
Note: See TracChangeset
for help on using the changeset viewer.