Changes in / [ae32d96:94b1022a]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rae32d96 r94b1022a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 28 17:01:36 2018
    13 // Update Count     : 3383
     12// Last Modified On : Wed May 30 20:29:03 2018
     13// Update Count     : 3432
    1414//
    1515
     
    332332%type<decl> c_declaration static_assert
    333333%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    334 %type<decl> KR_declaration_list KR_declaration_list_opt
     334%type<decl> KR_parameter_list KR_parameter_list_opt
    335335
    336336%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    854854//      | '[' push assignment_expression pop ']'
    855855//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    856         '[' push ',' tuple_expression_list pop ']'
    857                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
    858         | '[' push assignment_expression ',' tuple_expression_list pop ']'
    859                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
     856        '[' ',' tuple_expression_list ']'
     857                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
     858        | '[' push assignment_expression pop ',' tuple_expression_list ']'
     859                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
    860860        ;
    861861
     
    909909        '{' '}'
    910910                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    911         | '{'
    912                 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
    913                 // requires its own scope.
    914           push push
     911        | '{' push
    915912          local_label_declaration_opt                                           // GCC, local labels
    916913          statement_decl_list                                                           // C99, intermix declarations and statements
    917914          pop '}'
    918                 { $$ = new StatementNode( build_compound( $5 ) ); }
     915                { $$ = new StatementNode( build_compound( $4 ) ); }
    919916        ;
    920917
    921918statement_decl_list:                                                                    // C99
    922919        statement_decl
    923         | statement_decl_list push statement_decl
    924                 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
     920        | statement_decl_list statement_decl
     921                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    925922        ;
    926923
     
    940937                        $$ = new StatementNode( $2 );
    941938                }
    942         | statement pop
     939        | statement
    943940        ;
    944941
     
    955952
    956953selection_statement:
    957         IF '(' push if_control_expression ')' statement         %prec THEN
     954        IF '(' push if_control_expression ')' statement pop             %prec THEN
    958955                // explicitly deal with the shift/reduce conflict on if/else
    959956                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
    960         | IF '(' push if_control_expression ')' statement ELSE statement
     957        | IF '(' push if_control_expression ')' statement ELSE statement pop
    961958                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    962959        | SWITCH '(' comma_expression ')' case_clause
    963960                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    964         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     961        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    965962                {
    966963                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
     
    974971        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    975972                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
    976         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     973        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    977974                {
    978975                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    982979
    983980if_control_expression:
    984         comma_expression pop
     981        comma_expression
    985982                { $$ = new IfCtl( nullptr, $1 ); }
    986         | c_declaration pop                                                                     // no semi-colon
     983        | c_declaration                                                                         // no semi-colon
    987984                { $$ = new IfCtl( $1, nullptr ); }
    988         | cfa_declaration pop                                                           // no semi-colon
     985        | cfa_declaration                                                                       // no semi-colon
    989986                { $$ = new IfCtl( $1, nullptr ); }
    990987        | declaration comma_expression                                          // semi-colon separated
     
    10471044        | DO statement WHILE '(' comma_expression ')' ';'
    10481045                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1049         | FOR '(' push for_control_expression ')' statement
     1046        | FOR '(' push for_control_expression ')' statement pop
    10501047                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10511048        ;
    10521049
    10531050for_control_expression:
    1054         comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    1055                 { $$ = new ForCtl( $1, $4, $6 ); }
     1051        comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
     1052                { $$ = new ForCtl( $1, $3, $5 ); }
    10561053        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10571054                { $$ = new ForCtl( $1, $2, $4 ); }
     
    12821279
    12831280declaration_list_opt:                                                                   // used at beginning of switch statement
    1284         pop     // empty
     1281        // empty
    12851282                { $$ = nullptr; }
    12861283        | declaration_list
     
    12891286declaration_list:
    12901287        declaration
    1291         | declaration_list push declaration
    1292                 { $$ = $1->appendList( $3 ); }
    1293         ;
    1294 
    1295 KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
     1288        | declaration_list declaration
     1289                { $$ = $1->appendList( $2 ); }
     1290        ;
     1291
     1292KR_parameter_list_opt:                                                          // used to declare parameter types in K&R style functions
    12961293        // empty
    12971294                { $$ = nullptr; }
    1298         | KR_declaration_list
    1299         ;
    1300 
    1301 KR_declaration_list:
     1295        | KR_parameter_list
     1296        ;
     1297
     1298KR_parameter_list:
    13021299        push c_declaration pop ';'
    13031300                { $$ = $2; }
    1304         | KR_declaration_list push c_declaration pop ';'
     1301        | KR_parameter_list push c_declaration pop ';'
    13051302                { $$ = $1->appendList( $3 ); }
    13061303        ;
     
    13221319
    13231320declaration:                                                                                    // old & new style declarations
    1324         c_declaration pop ';'
    1325         | cfa_declaration pop ';'                                                       // CFA
     1321        c_declaration ';'
     1322        | cfa_declaration ';'                                                           // CFA
    13261323        | static_assert
    13271324        ;
     
    14311428        TYPEDEF cfa_variable_specifier
    14321429                {
    1433                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1430                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
    14341431                        $$ = $2->addTypedef();
    14351432                }
    14361433        | TYPEDEF cfa_function_specifier
    14371434                {
    1438                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1435                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
    14391436                        $$ = $2->addTypedef();
    14401437                }
    14411438        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14421439                {
    1443                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
     1440                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
    14441441                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14451442                }
     
    14521449        TYPEDEF type_specifier declarator
    14531450                {
    1454                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1451                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
    14551452                        $$ = $3->addType( $2 )->addTypedef();
    14561453                }
    14571454        | typedef_declaration pop ',' push declarator
    14581455                {
    1459                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
     1456                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
    14601457                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14611458                }
    14621459        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14631460                {
    1464                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1461                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
    14651462                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14661463                }
    14671464        | type_specifier TYPEDEF declarator
    14681465                {
    1469                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1466                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
    14701467                        $$ = $3->addType( $1 )->addTypedef();
    14711468                }
    14721469        | type_specifier TYPEDEF type_qualifier_list declarator
    14731470                {
    1474                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1471                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
    14751472                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14761473                }
     
    15991596
    16001597forall:
    1601         FORALL '(' push type_parameter_list pop ')'                                     // CFA
    1602                 { $$ = DeclarationNode::newForall( $4 ); }
     1598        FORALL '(' type_parameter_list ')'                                      // CFA
     1599                { $$ = DeclarationNode::newForall( $3 ); }
    16031600        ;
    16041601
     
    21922189type_parameter:                                                                                 // CFA
    21932190        type_class no_attr_identifier_or_type_name
    2194                 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
     2191                { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
    21952192          type_initializer_opt assertion_list_opt
    21962193                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22282225        | '|' '{' push trait_declaration_list pop '}'
    22292226                { $$ = $4; }
    2230         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
    2231                 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2227        // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2228        //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22322229        ;
    22332230
     
    22612258        no_attr_identifier_or_type_name
    22622259                {
    2263                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
     2260                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
    22642261                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22652262                }
    2266         | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    2267                 {
    2268                         typedefTable.addToEnclosingScope( *$1, TYPEGENname );
    2269                         $$ = DeclarationNode::newTypeDecl( $1, $4 );
     2263        | no_attr_identifier_or_type_name '(' type_parameter_list ')'
     2264                {
     2265                        typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
     2266                        $$ = DeclarationNode::newTypeDecl( $1, $3 );
    22702267                }
    22712268        ;
    22722269
    22732270trait_specifier:                                                                                // CFA
    2274         TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    2275                 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
    2276         | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}'
    2277                 { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
     2271        TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
     2272                { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
     2273        | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
     2274                { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
    22782275        ;
    22792276
     
    23132310
    23142311external_definition_list:
    2315         external_definition
     2312        push external_definition pop
     2313                { $$ = $2; }
    23162314        | external_definition_list
    23172315                { forall = xxx; }
    2318           push external_definition
     2316          push external_definition pop
    23192317                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23202318        ;
     
    23382336                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23392337                }
    2340           '{' external_definition_list_opt '}'
     2338                        // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope.  However,
     2339                        // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The
     2340                        // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt.  This
     2341                        // trick works for nested extern "X"s, as each one undoes itself in the nesting.
     2342          '{' pop external_definition_list_opt push '}'
    23412343                {
    23422344                        linkage = linkageStack.top();
    23432345                        linkageStack.pop();
    2344                         $$ = $5;
     2346                        $$ = $6;
    23452347                }
    23462348        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     
    23512353        | type_qualifier_list
    23522354                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2353           push '{' external_definition_list '}'                         // CFA, namespace
    2354                 {
    2355                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2355          '{' external_definition_list push '}'                  // CFA, namespace
     2356                {
     2357                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23562358                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23572359                                        iter->addQualifiers( $1->clone() );
     
    23602362                        xxx = false;
    23612363                        delete $1;
    2362                         $$ = $5;
     2364                        $$ = $4;
    23632365                }
    23642366        | declaration_qualifier_list
    23652367                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2366           push '{' external_definition_list '}'                         // CFA, namespace
    2367                 {
    2368                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2368          '{' external_definition_list '}'                                       // CFA, namespace
     2369                {
     2370                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23692371                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23702372                                        iter->addQualifiers( $1->clone() );
     
    23732375                        xxx = false;
    23742376                        delete $1;
    2375                         $$ = $5;
     2377                        $$ = $4;
    23762378                }
    23772379        | declaration_qualifier_list type_qualifier_list
     
    23802382                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
    23812383                }
    2382           push '{' external_definition_list '}'                         // CFA, namespace
    2383                 {
    2384                         for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2384          '{' external_definition_list '}'                                      // CFA, namespace
     2385                {
     2386                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23852387                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    23862388                                        iter->addQualifiers( $1->clone() );
     
    23912393                        delete $1;
    23922394                        delete $2;
    2393                         $$ = $6;
     2395                        $$ = $5;
    23942396                }
    23952397        ;
     
    24042406        | function_declarator compound_statement
    24052407                { $$ = $1->addFunctionBody( $2 ); }
    2406         | KR_function_declarator KR_declaration_list_opt compound_statement
     2408        | KR_function_declarator KR_parameter_list_opt compound_statement
    24072409                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24082410        ;
     
    24442446
    24452447                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2446         | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2448        | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24472449                {
    24482450                        rebindForall( $1, $2 );
     
    24502452                }
    24512453                // handles default int return type, OBSOLESCENT (see 1)
    2452         | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2454        | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24532455                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24542456                // handles default int return type, OBSOLESCENT (see 1)
    2455         | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2457        | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24562458                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24572459                // handles default int return type, OBSOLESCENT (see 1)
    2458         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2460        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24592461                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24602462        ;
     
    27012703        typedef
    27022704                // hide type name in enclosing scope by variable name
    2703                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
     2705                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
    27042706        | '(' paren_type ')'
    27052707                { $$ = $2; }
     
    31913193        '[' push cfa_abstract_parameter_list pop ']'
    31923194                { $$ = DeclarationNode::newTuple( $3 ); }
    3193         | '[' push type_specifier_nobody ELLIPSIS ']'
     3195        | '[' push type_specifier_nobody ELLIPSIS pop ']'
    31943196                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    3195         | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'
     3197        | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
    31963198                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    31973199        ;
Note: See TracChangeset for help on using the changeset viewer.