Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rac235a8 rd63aeba  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 29 17:56:42 2023
    13 // Update Count     : 6325
     12// Last Modified On : Wed Mar 22 21:26:01 2023
     13// Update Count     : 6002
    1414//
    1515
     
    4444
    4545#include <cstdio>
    46 #include <sstream>
    4746#include <stack>
    4847using namespace std;
     
    271270        SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
    272271                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
     272} // IdentifierBeforeType
     273
     274static bool TypedefForall( DeclarationNode * decl ) {
     275        if ( decl->type->forall || (decl->type->kind == TypeData::Aggregate && decl->type->aggregate.params) ) {
     276                SemanticError( yylloc, "forall qualifier in typedef is currently unimplemented." );
     277                return true;
     278        } // if
     279        return false;
    273280} // IdentifierBeforeType
    274281
     
    352359
    353360// names and constants: lexer differentiates between identifier and typedef names
    354 %token<tok> IDENTIFIER          TYPEDIMname             TYPEDEFname             TYPEGENname
    355 %token<tok> TIMEOUT                     WAND    WOR                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
     361%token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDIMname             TYPEDEFname             TYPEGENname
     362%token<tok> TIMEOUT                     WOR                                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
    356363%token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
    357364%token<tok> DIRECTIVE
     
    422429%type<catch_kind> handler_key
    423430%type<sn> mutex_statement
    424 %type<en> when_clause                                   when_clause_opt                         waitfor         waituntil               timeout
    425 %type<sn> waitfor_statement                             waituntil_statement
    426 %type<wfs> wor_waitfor_clause                   waituntil_clause                        wand_waituntil_clause   wor_waituntil_clause
     431%type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
     432%type<sn> waitfor_statement
     433%type<wfs> waitfor_clause
    427434
    428435// declarations
     
    528535// Similar issues exit with the waitfor statement.
    529536
    530 // Order of these lines matters (low-to-high precedence). THEN is left associative over WAND/WOR/TIMEOUT/ELSE, WAND/WOR
    531 // is left associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
     537// Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left
     538// associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
    532539%precedence THEN                // rule precedence for IF/WAITFOR statement
    533 %precedence ANDAND              // token precedence for start of WAND in WAITFOR statement
    534 %precedence WAND                // token precedence for start of WAND in WAITFOR statement
    535 %precedence OROR                // token precedence for start of WOR in WAITFOR statement
    536540%precedence WOR                 // token precedence for start of WOR in WAITFOR statement
    537541%precedence TIMEOUT             // token precedence for start of TIMEOUT in WAITFOR statement
     
    620624quasi_keyword:                                                                                  // CFA
    621625        TIMEOUT
    622         | WAND
    623626        | WOR
    624627        | CATCH
     
    771774                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    772775        | postfix_expression ICR
    773                 { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }
     776                { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }
    774777        | postfix_expression DECR
    775                 { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }
     778                { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }
    776779        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
    777780                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
     
    801804        '@'                                                                                                     // CFA, default parameter
    802805                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    803                 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     806                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    804807        | assignment_expression
    805808        ;
     
    876879                }
    877880        | unary_operator cast_expression
    878                 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
     881                { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
    879882        | ICR unary_expression
    880                 { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }
     883                { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }
    881884        | DECR unary_expression
    882                 { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }
     885                { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }
    883886        | SIZEOF unary_expression
    884887                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); }
     
    11331136        | mutex_statement
    11341137        | waitfor_statement
    1135         | waituntil_statement
    11361138        | exception_statement
    11371139        | enable_disable_statement
     
    12431245        | declaration comma_expression                                          // semi-colon separated
    12441246                { $$ = new CondCtl( $1, $2 ); }
    1245         ;
     1247        ;
    12461248
    12471249// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
     
    13261328                }
    13271329        | FOR '(' for_control_expression_list ')' statement     %prec THEN
    1328                 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
     1330                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
    13291331        | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
    13301332                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); }
     
    15181520                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    15191521                }
    1520         ;
     1522        ;
    15211523
    15221524downupdowneq:
     
    15271529        | ErangeDownEq
    15281530                { $$ = OperKinds::GEThan; }
    1529         ;
     1531        ;
    15301532
    15311533updown:
     
    15341536        | ErangeDown
    15351537                { $$ = OperKinds::GThan; }
    1536         ;
     1538        ;
    15371539
    15381540updowneq:
     
    15421544        | ErangeDownEq
    15431545                { $$ = OperKinds::GEThan; }
    1544         ;
     1546        ;
    15451547
    15461548jump_statement:
     
    16251627        ;
    16261628
     1629waitfor:
     1630        WAITFOR '(' cast_expression ')'
     1631                { $$ = $3; }
     1632//      | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'
     1633//              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     1634        | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
     1635                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
     1636        ;
     1637
    16271638cast_expression_list:
    16281639        cast_expression
     
    16331644
    16341645timeout:
    1635         TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
    1636         ;
    1637 
    1638 wor:
    1639         OROR
    1640         | WOR
    1641 
    1642 waitfor:
    1643         WAITFOR '(' cast_expression ')'
    1644                 { $$ = $3; }
    1645         | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
    1646                 { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    1647         ;
    1648 
    1649 wor_waitfor_clause:
     1646        TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
     1647        ;
     1648
     1649waitfor_clause:
    16501650        when_clause_opt waitfor statement                                       %prec THEN
    1651                 // Called first: create header for WaitForStmt.
    1652                 { $$ = build_waitfor( new WaitForStmt(), $1, $2, maybe_build_compound( $3 ) ); }
    1653         | wor_waitfor_clause wor when_clause_opt waitfor statement      %prec THEN
    1654                 { $$ = build_waitfor( $1, $3, $4, maybe_build_compound( $5 ) ); }
    1655         | wor_waitfor_clause wor when_clause_opt ELSE statement
    1656                 { $$ = build_waitfor_else( $1, $3, maybe_build_compound( $5 ) ); }
    1657         | wor_waitfor_clause wor when_clause_opt timeout statement      %prec THEN
    1658                 { $$ = build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ); }
     1651                { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); }
     1652        | when_clause_opt waitfor statement WOR waitfor_clause
     1653                { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); }
     1654        | when_clause_opt timeout statement                                     %prec THEN
     1655                { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); }
     1656        | when_clause_opt ELSE statement
     1657                { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }
    16591658        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1660         | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
     1659        | when_clause_opt timeout statement WOR ELSE statement // syntax error
    16611660                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    1662         | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    1663                 { $$ = build_waitfor_else( build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ), $7, maybe_build_compound( $9 ) ); }
     1661        | when_clause_opt timeout statement WOR when_clause ELSE statement
     1662                { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); }
     1663        ;
    16641664
    16651665waitfor_statement:
    1666         wor_waitfor_clause                                                                      %prec THEN
    1667                 { $$ = new StatementNode( $1 ); }
    1668         ;
    1669 
    1670 wand:
    1671         ANDAND
    1672         | WAND
    1673         ;
    1674 
    1675 waituntil:
    1676         WAITUNTIL '(' cast_expression ')'
    1677                 { $$ = $3; }
    1678         ;
    1679 
    1680 waituntil_clause:
    1681         when_clause_opt waituntil statement
    1682                 { printf( "waituntil_clause 1\n" ); $$ = nullptr; }
    1683         | '(' wor_waituntil_clause ')'
    1684                 { printf( "waituntil_clause 2\n" ); $$ = nullptr; }
    1685         ;
    1686 
    1687 wand_waituntil_clause:
    1688         waituntil_clause                                                                        %prec THEN
    1689                 { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; }
    1690         | waituntil_clause wand wand_waituntil_clause
    1691                 { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; }
    1692         ;
    1693 
    1694 wor_waituntil_clause:
    1695         wand_waituntil_clause
    1696                 { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; }
    1697         | wor_waituntil_clause wor wor_waituntil_clause         %prec THEN
    1698                 { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; }
    1699         | wor_waituntil_clause wor when_clause_opt ELSE statement
    1700                 { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; }
    1701         | wor_waituntil_clause wor when_clause_opt timeout statement    %prec THEN
    1702                 { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; }
    1703         // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1704         | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    1705                 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    1706         | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    1707                 { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; }
    1708         ;
    1709 
    1710 waituntil_statement:
    1711         wor_waituntil_clause                                                            %prec THEN
    1712                 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement.
    1713                 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
     1666        when_clause_opt waitfor statement                                       %prec THEN
     1667                { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
     1668        | when_clause_opt waitfor statement WOR waitfor_clause
     1669                { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); }
    17141670        ;
    17151671
    17161672exception_statement:
    1717         TRY compound_statement handler_clause                           %prec THEN
     1673        TRY compound_statement handler_clause                                   %prec THEN
    17181674                { $$ = new StatementNode( build_try( $2, $3, nullptr ) ); }
    17191675        | TRY compound_statement finally_clause
     
    18751831                {
    18761832                        // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
    1877                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1833                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    18781834                        //   printf( "\tattr %s\n", attr->name.c_str() );
    18791835                        // } // for
     
    20111967                {
    20121968                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
    2013                         if ( $2->type->forall || ($2->type->kind == TypeData::Aggregate && $2->type->aggregate.params) ) {
    2014                                 SemanticError( yylloc, "forall qualifier in typedef is currently unimplemented." ); $$ = nullptr;
    2015                         } else $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3
     1969                        if ( TypedefForall( $2 ) ) $$ = nullptr;
     1970                        else $$ = $3->addType( $2 )->addTypedef();              // watchout frees $2 and $3
    20161971                }
    20171972        | typedef_declaration pop ',' push declarator
     
    20211976                }
    20221977        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    2023                 { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; }
     1978                {
     1979                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
     1980                        if ( TypedefForall( $1 ) ) $$ = nullptr;
     1981                        else $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef();
     1982                }
    20241983        | type_specifier TYPEDEF declarator
    2025                 { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; }
     1984                {
     1985                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
     1986                        if ( TypedefForall( $1 ) ) $$ = nullptr;
     1987                        else $$ = $3->addType( $1 )->addTypedef();
     1988                }
    20261989        | type_specifier TYPEDEF type_qualifier_list declarator
    2027                 { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; }
     1990                {
     1991                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
     1992                        if ( TypedefForall( $3 ) ) $$ = nullptr;
     1993                        else $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef();
     1994                }
    20281995        ;
    20291996
     
    20321999        TYPEDEF identifier '=' assignment_expression
    20332000                {
    2034                         SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
     2001                        SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
    20352002                }
    20362003        | typedef_expression pop ',' push identifier '=' assignment_expression
    20372004                {
    2038                         SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
     2005                        SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
    20392006                }
    20402007        ;
     
    23342301                {
    23352302                        // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2336                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2303                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    23372304                        //   printf( "\tattr %s\n", attr->name.c_str() );
    23382305                        // } // for
     
    23502317                {
    23512318                        // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2352                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2319                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    23532320                        //   printf( "\tattr %s\n", attr->name.c_str() );
    23542321                        // } // for
     
    24282395                {
    24292396                        // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2430                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2397                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    24312398                        //   printf( "\tattr %s\n", attr->name.c_str() );
    24322399                        // } // for
     
    25552522                        $$ = fieldDecl( $1, $2 );
    25562523                        // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2557                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2524                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    25582525                        //   printf( "\tattr %s\n", attr->name.c_str() );
    25592526                        // } // for
     
    25622529                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
    25632530        | STATIC type_specifier field_declaring_list_opt ';' // CFA
    2564                 { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; }
     2531                { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; }
    25652532        | INLINE type_specifier field_abstract_list_opt ';'     // CFA
    25662533                {
     
    25732540                }
    25742541        | INLINE aggregate_control ';'                                          // CFA
    2575                 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
     2542                { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
    25762543        | typedef_declaration ';'                                                       // CFA
    25772544        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
     
    26562623                { $$ = DeclarationNode::newEnum( $3->name, $6, true, false, nullptr, $4 )->addQualifiers( $2 ); }
    26572624        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    2658                 {
     2625                {
    26592626                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() )
    26602627                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    31903157                {
    31913158                        distQual( $5, $1 );
    3192                         forall = false;
     3159                        forall = false;
    31933160                        $$ = $5;
    31943161                }
     
    32013168                {
    32023169                        distQual( $5, $1 );
    3203                         forall = false;
     3170                        forall = false;
    32043171                        $$ = $5;
    32053172                }
     
    32123179                {
    32133180                        distQual( $6, $1->addQualifiers( $2 ) );
    3214                         forall = false;
     3181                        forall = false;
    32153182                        $$ = $6;
    32163183                }
     
    34193386        | '(' attribute_list variable_ptr ')' array_dimension
    34203387                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
    3421         | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
     3388        | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
    34223389                { $$ = $2->addArray( $4 ); }
    34233390        | '(' attribute_list variable_array ')' multi_array_dimension // redundant parenthesis
     
    38423809        | ErangeUpEq
    38433810                { $$ = OperKinds::LEThan; }
    3844         ;
     3811        ;
    38453812
    38463813multi_array_dimension:
Note: See TracChangeset for help on using the changeset viewer.