Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r2871210 rde62360d  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  3 13:53:45 2015
    13 // Update Count     : 1220
     12// Last Modified On : Mon Jun 22 15:19:44 2015
     13// Update Count     : 1082
    1414//
    1515
     
    118118
    119119%type<tok> zero_one  identifier  no_attr_identifier  no_01_identifier
    120 %type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name
     120%type<tok> identifier_or_typedef_name  no_attr_identifier_or_typedef_name  no_01_identifier_or_typedef_name
    121121%type<constant> string_literal_list
    122122
     
    204204%type<decl> parameter_type_list_opt
    205205
    206 %type<decl> paren_identifier paren_type
     206%type<decl> paren_identifier paren_typedef
    207207
    208208%type<decl> storage_class storage_class_name storage_class_list
     
    213213%type<decl> type_declarator type_declarator_name type_declaring_list
    214214
    215 %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression
    216 %type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr
    217 %type<decl> type_parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier
    218 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
     215%type<decl> typedef typedef_array typedef_declaration typedef_declaration_specifier typedef_expression
     216%type<decl> typedef_function typedef_parameter_array typedef_parameter_function typedef_parameter_ptr
     217%type<decl> typedef_parameter_redeclarator typedef_ptr typedef_redeclarator typedef_type_specifier
     218%type<decl> typegen_declaration_specifier typegen_type_specifier
    219219
    220220%type<decl> type_name type_name_no_function
     
    376376        | no_attr_identifier ':' assignment_expression
    377377                { $$ = $3->set_asArgName( $1 ); }
    378                 // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient
     378                // Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there is insufficient
    379379                // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used
    380380                // with an appropriate semantic check.
     
    564564                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
    565565                // comma_expression in new_identifier_parameter_array and new_abstract_array
    566         '[' ']'
     566        '[' push pop ']'
    567567                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); }
    568568        | '[' push assignment_expression pop ']'
     
    924924
    925925label_list:                                                                                             // GCC, local label
    926         no_attr_identifier_or_type_name                 {}
    927         | label_list ',' no_attr_identifier_or_type_name {}
     926        no_attr_identifier_or_typedef_name                      {}
     927        | label_list ',' no_attr_identifier_or_typedef_name {}
    928928        ;
    929929
     
    965965                        $$ = $2->addQualifiers( $1 );
    966966                }
    967         | new_variable_declaration pop ',' push identifier_or_type_name initializer_opt
     967        | new_variable_declaration pop ',' push identifier_or_typedef_name initializer_opt
    968968                {
    969969                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     
    975975                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
    976976                // storage-class
    977         new_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
     977        new_abstract_declarator_no_tuple identifier_or_typedef_name asm_name_opt
    978978                {
    979979                        typedefTable.setNextIdentifier( *$2 );
    980980                        $$ = $1->addName( $2 );
    981981                }
    982         | new_abstract_tuple identifier_or_type_name asm_name_opt
     982        | new_abstract_tuple identifier_or_typedef_name asm_name_opt
    983983                {
    984984                        typedefTable.setNextIdentifier( *$2 );
    985985                        $$ = $1->addName( $2 );
    986986                }
    987         | type_qualifier_list new_abstract_tuple identifier_or_type_name asm_name_opt
     987        | type_qualifier_list new_abstract_tuple identifier_or_typedef_name asm_name_opt
    988988                {
    989989                        typedefTable.setNextIdentifier( *$3 );
     
    10131013                        $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
    10141014                }
    1015         | new_function_declaration pop ',' push identifier_or_type_name
     1015        | new_function_declaration pop ',' push identifier_or_typedef_name
    10161016                {
    10171017                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     
    10211021
    10221022new_function_specifier:                                                                 // CFA
    1023         '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict
    1024                 {
    1025                         $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    1026                 }
    1027 //      '[' ']' identifier '(' push new_parameter_type_list_opt pop ')'
    1028 //              {
    1029 //                      typedefTable.setNextIdentifier( *$5 );
    1030 //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    1031 //              }
    1032 //      | '[' ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')'
    1033 //              {
    1034 //                      typedefTable.setNextIdentifier( *$5 );
    1035 //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    1036 //              }
    1037 //      | '[' ']' typegen_name
    1038                 // identifier_or_type_name must be broken apart because of the sequence:
     1023        '[' push pop ']' identifier '(' push new_parameter_type_list_opt pop ')'
     1024                {
     1025                        typedefTable.setNextIdentifier( *( $5 ) );
     1026                        $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
     1027                }
     1028        | '[' push pop ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')'
     1029                {
     1030                        typedefTable.setNextIdentifier( *( $5 ) );
     1031                        $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
     1032                }
     1033                // identifier_or_typedef_name must be broken apart because of the sequence:
    10391034                //
    1040                 //   '[' ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'
     1035                //   '[' ']' identifier_or_typedef_name '(' new_parameter_type_list_opt ')'
    10411036                //   '[' ']' type_specifier
    10421037                //
    1043                 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    1044                 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1045         | new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
     1038                // type_specifier can resolve to just TYPEDEFname (e.g. typedef int T; int f( T );). Therefore this must be
     1039                // flattened to allow lookahead to the '(' without having to reduce identifier_or_typedef_name.
     1040        | new_abstract_tuple identifier_or_typedef_name '(' push new_parameter_type_list_opt pop ')'
    10461041                // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator).
    10471042                {
    10481043                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
    10491044                }
    1050         | new_function_return identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
     1045        | new_function_return identifier_or_typedef_name '(' push new_parameter_type_list_opt pop ')'
    10511046                {
    10521047                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
     
    11121107        ;
    11131108
    1114 typedef_expression:
    1115                 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
     1109typedef_expression:                                                                             // GCC, naming expression type
    11161110        TYPEDEF no_attr_identifier '=' assignment_expression
    11171111                {
     
    13611355aggregate_name:
    13621356        aggregate_key '{' field_declaration_list '}'
    1363                 { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3 ); }
    1364         | aggregate_key no_attr_identifier_or_type_name
    1365                 { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0 ); }
    1366         | aggregate_key no_attr_identifier_or_type_name '{' field_declaration_list '}'
    1367                 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $4 ); }
    1368         | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    1369                 { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6 ); }
    1370         | aggregate_key typegen_name                                            // CFA, S/R conflict
    1371                 { $$ = $2; }
     1357                { $$ = DeclarationNode::newAggregate( $1, 0, 0, 0, $3 ); }
     1358        | aggregate_key no_attr_identifier_or_typedef_name
     1359                { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, 0 ); }
     1360        | aggregate_key no_attr_identifier_or_typedef_name '{' field_declaration_list '}'
     1361                { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, $4 ); }
     1362        | aggregate_key '(' push type_parameter_list pop ')' '{' field_declaration_list '}' // CFA
     1363                { $$ = DeclarationNode::newAggregate( $1, 0, $4, 0, $8 ); }
     1364        | aggregate_key '(' push type_parameter_list pop ')' no_attr_identifier_or_typedef_name // CFA
     1365                { $$ = DeclarationNode::newAggregate( $1, $7, $4, 0, 0 ); }
     1366        | aggregate_key '(' push type_parameter_list pop ')' no_attr_identifier_or_typedef_name '{' field_declaration_list '}' // CFA
     1367                { $$ = DeclarationNode::newAggregate( $1, $7, $4, 0, $9 ); }
     1368        | aggregate_key '(' push type_parameter_list pop ')' '(' type_name_list ')' '{' field_declaration_list '}' // CFA
     1369                { $$ = DeclarationNode::newAggregate( $1, 0, $4, $8, $11 ); }
     1370        | aggregate_key TYPEGENname '(' type_name_list ')' // CFA
     1371                {}
     1372        | aggregate_key '(' push type_name_list pop ')' no_attr_identifier_or_typedef_name // CFA
     1373                // push and pop are only to prevent S/R conflicts
     1374                { $$ = DeclarationNode::newAggregate( $1, $7, 0, $4, 0 ); }
     1375        | aggregate_key '(' push type_parameter_list pop ')' '(' type_name_list ')' no_attr_identifier_or_typedef_name '{' field_declaration_list '}' // CFA
     1376                { $$ = DeclarationNode::newAggregate( $1, $10, $4, $8, $12 ); }
    13721377        ;
    13731378
     
    13971402new_field_declaring_list:                                                               // CFA, new style field declaration
    13981403        new_abstract_declarator_tuple                                           // CFA, no field name
    1399         | new_abstract_declarator_tuple no_attr_identifier_or_type_name
     1404        | new_abstract_declarator_tuple no_attr_identifier_or_typedef_name
    14001405                { $$ = $1->addName( $2 ); }
    1401         | new_field_declaring_list ',' no_attr_identifier_or_type_name
     1406        | new_field_declaring_list ',' no_attr_identifier_or_typedef_name
    14021407                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    14031408        | new_field_declaring_list ','                                          // CFA, no field name
     
    14201425                // A semantic check is required to ensure bit_subrange only appears on base type int.
    14211426                { $$ = $1->addBitfield( $2 ); }
    1422         | type_redeclarator bit_subrange_size_opt
     1427        | typedef_redeclarator bit_subrange_size_opt
    14231428                // A semantic check is required to ensure bit_subrange only appears on base type int.
    14241429                { $$ = $1->addBitfield( $2 ); }
     
    14451450        enum_key '{' enumerator_list comma_opt '}'
    14461451                { $$ = DeclarationNode::newEnum( 0, $3 ); }
    1447         | enum_key no_attr_identifier_or_type_name '{' enumerator_list comma_opt '}'
     1452        | enum_key no_attr_identifier_or_typedef_name '{' enumerator_list comma_opt '}'
    14481453                { $$ = DeclarationNode::newEnum( $2, $4 ); }
    1449         | enum_key no_attr_identifier_or_type_name
     1454        | enum_key no_attr_identifier_or_typedef_name
    14501455                { $$ = DeclarationNode::newEnum( $2, 0 ); }
    14511456        ;
    14521457
    14531458enumerator_list:
    1454         no_attr_identifier_or_type_name enumerator_value_opt
     1459        no_attr_identifier_or_typedef_name enumerator_value_opt
    14551460                { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
    1456         | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt
     1461        | enumerator_list ',' no_attr_identifier_or_typedef_name enumerator_value_opt
    14571462                { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
    14581463        ;
     
    15241529
    15251530// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
    1526 // for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
     1531// for typedef name by using typedef_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
    15271532
    15281533new_parameter_declaration:                                                              // CFA, new & old style parameter declaration
    15291534        parameter_declaration
    1530         | new_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
     1535        | new_identifier_parameter_declarator_no_tuple identifier_or_typedef_name assignment_opt
    15311536                { $$ = $1->addName( $2 ); }
    1532         | new_abstract_tuple identifier_or_type_name assignment_opt
     1537        | new_abstract_tuple identifier_or_typedef_name assignment_opt
    15331538                // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).
    15341539                { $$ = $1->addName( $2 ); }
    1535         | type_qualifier_list new_abstract_tuple identifier_or_type_name assignment_opt
     1540        | type_qualifier_list new_abstract_tuple identifier_or_typedef_name assignment_opt
    15361541                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    15371542        | new_function_specifier
     
    15541559                        $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) );
    15551560                }
    1556         | declaration_specifier type_parameter_redeclarator assignment_opt
     1561        | declaration_specifier typedef_parameter_redeclarator assignment_opt
    15571562                {
    15581563                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    15781583        ;
    15791584
    1580 identifier_or_type_name:
     1585identifier_or_typedef_name:
    15811586        identifier
    15821587        | TYPEDEFname
     
    15841589        ;
    15851590
    1586 no_01_identifier_or_type_name:
     1591no_01_identifier_or_typedef_name:
    15871592        no_01_identifier
    15881593        | TYPEDEFname
     
    15901595        ;
    15911596
    1592 no_attr_identifier_or_type_name:
     1597no_attr_identifier_or_typedef_name:
    15931598        no_attr_identifier
    15941599        | TYPEDEFname
    1595         | TYPEGENname
     1600        //      | TYPEGENname
    15961601        ;
    15971602
     
    16141619        // empty
    16151620                { $$ = 0; }
    1616         | '=' initializer
    1617                 { $$ = $2; }
     1621        | '=' initializer                                                       { $$ = $2; }
    16181622        ;
    16191623
     
    16431647designation:
    16441648        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    1645         | no_attr_identifier_or_type_name ':'                           // GCC, field name
    1646                 { $$ = new VarRefNode( $1 ); }
     1649        | no_attr_identifier_or_typedef_name ':'                        // GCC, field name
     1650                                { $$ = new VarRefNode( $1 ); }
    16471651        ;
    16481652
    16491653designator_list:                                                                                // C99
    16501654        designator
    1651         | designator_list designator
    1652                 { $$ = (ExpressionNode *)( $1->set_link( $2 )); }
     1655        | designator_list designator                                    { $$ = (ExpressionNode *)( $1->set_link( $2 )); }
    16531656        //| designator_list designator                                          { $$ = new CompositeExprNode( $1, $2 ); }
    16541657        ;
    16551658
    16561659designator:
    1657         '.' no_attr_identifier_or_type_name                                     // C99, field name
     1660        '.' no_attr_identifier_or_typedef_name                          // C99, field name
    16581661                { $$ = new VarRefNode( $2 ); }
    16591662        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    16971700
    16981701typegen_type_specifier:                                                                 // CFA
    1699         typegen_name
    1700         | type_qualifier_list typegen_name
    1701                 { $$ = $2->addQualifiers( $1 ); }
     1702        TYPEGENname '(' type_name_list ')'
     1703                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
     1704        | type_qualifier_list TYPEGENname '(' type_name_list ')'
     1705                { $$ = DeclarationNode::newFromTypeGen( $2, $4 )->addQualifiers( $1 ); }
    17021706        | typegen_type_specifier type_qualifier
    17031707                { $$ = $1->addQualifiers( $2 ); }
    1704         ;
    1705 
    1706 typegen_name:                                                                                   // CFA
    1707         TYPEGENname '(' type_name_list ')'
    1708                 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    17091708        ;
    17101709
     
    17161715
    17171716type_parameter:                                                                                 // CFA
    1718         type_class no_attr_identifier_or_type_name
    1719                 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
     1717        type_class no_attr_identifier_or_typedef_name
     1718                { typedefTable.addToEnclosingScope(*( $2 ), TypedefTable::TD ); }
    17201719          assertion_list_opt
    17211720                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); }
     
    17401739
    17411740assertion:                                                                                              // CFA
    1742         '|' no_attr_identifier_or_type_name '(' type_name_list ')'
    1743                 {
    1744                         typedefTable.openContext( *$2 );
     1741        '|' no_attr_identifier_or_typedef_name '(' type_name_list ')'
     1742                {
     1743                        typedefTable.openContext( *( $2 ) );
    17451744                        $$ = DeclarationNode::newContextUse( $2, $4 );
    17461745                }
     
    17781777
    17791778type_declarator_name:                                                                   // CFA
    1780         no_attr_identifier_or_type_name
     1779        no_attr_identifier_or_typedef_name
    17811780                {
    17821781                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
    17831782                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    17841783                }
    1785         | no_01_identifier_or_type_name '(' push type_parameter_list pop ')'
     1784        | no_01_identifier_or_typedef_name '(' push type_parameter_list pop ')'
    17861785                {
    17871786                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
     
    17911790
    17921791context_specifier:                                                                              // CFA
    1793         CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
     1792        CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' '}'
    17941793                {
    17951794                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    17961795                        $$ = DeclarationNode::newContext( $2, $5, 0 );
    17971796                }
    1798         | CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
     1797        | CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{'
    17991798                {
    18001799                        typedefTable.enterContext( *$2 );
     
    18311830                        $$ = $1;
    18321831                }
    1833         | new_context_declaring_list pop ',' push identifier_or_type_name
     1832        | new_context_declaring_list pop ',' push identifier_or_typedef_name
    18341833                {
    18351834                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
     
    19001899external_function_definition:
    19011900        function_definition
     1901
    19021902                // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of
    19031903                // code with functions missing a type-specifier on the return type.  Parsing is possible because
     
    19821982        variable_declarator
    19831983        | function_declarator
    1984         | type_redeclarator
     1984        | typedef_redeclarator
    19851985        ;
    19861986
     
    20212021
    20222022any_word:                                                                                               // GCC
    2023         identifier_or_type_name {}
     2023        identifier_or_typedef_name {}
    20242024        | storage_class_name {}
    20252025        | basic_type_name {}
     
    21032103// This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot be nested,
    21042104// there is no context where a function definition can redefine a typedef name. To allow nested functions requires
    2105 // further separation of variable and function declarators in type_redeclarator.  The pattern precludes returning
     2105// further separation of variable and function declarators in typedef_redeclarator.  The pattern precludes returning
    21062106// arrays and functions versus pointers to arrays and functions.
    21072107
     
    21762176        ;
    21772177
    2178 // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:
     2178// This pattern parses a declaration for a variable or function prototype that redefines a typedef name, e.g.:
    21792179//
    21802180//              typedef int foo;
     
    21862186// and functions versus pointers to arrays and functions.
    21872187
    2188 type_redeclarator:
    2189         paren_type attribute_list_opt
    2190         | type_ptr
    2191         | type_array attribute_list_opt
    2192         | type_function attribute_list_opt
    2193         ;
    2194 
    2195 paren_type:
    2196         typedef
    2197         | '(' paren_type ')'
    2198                 { $$ = $2; }
    2199         ;
    2200 
    2201 type_ptr:
    2202         '*' type_redeclarator
     2188typedef_redeclarator:
     2189        paren_typedef attribute_list_opt
     2190        | typedef_ptr
     2191        | typedef_array attribute_list_opt
     2192        | typedef_function attribute_list_opt
     2193        ;
     2194
     2195paren_typedef:
     2196        TYPEDEFname
     2197                {
     2198                        typedefTable.setNextIdentifier( *( $1 ) );
     2199                        $$ = DeclarationNode::newName( $1 );
     2200                }
     2201        | '(' paren_typedef ')'
     2202                { $$ = $2; }
     2203        ;
     2204
     2205typedef_ptr:
     2206        '*' typedef_redeclarator
    22032207                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2204         | '*' type_qualifier_list type_redeclarator
     2208        | '*' type_qualifier_list typedef_redeclarator
    22052209                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2206         | '(' type_ptr ')'
    2207                 { $$ = $2; }
    2208         ;
    2209 
    2210 type_array:
    2211         paren_type array_dimension
     2210        | '(' typedef_ptr ')'
     2211                { $$ = $2; }
     2212        ;
     2213
     2214typedef_array:
     2215        paren_typedef array_dimension
    22122216                { $$ = $1->addArray( $2 ); }
    2213         | '(' type_ptr ')' array_dimension
     2217        | '(' typedef_ptr ')' array_dimension
    22142218                { $$ = $2->addArray( $4 ); }
    2215         | '(' type_array ')' multi_array_dimension                      // redundant parenthesis
     2219        | '(' typedef_array ')' multi_array_dimension           // redundant parenthesis
    22162220                { $$ = $2->addArray( $4 ); }
    2217         | '(' type_array ')'                                                            // redundant parenthesis
    2218                 { $$ = $2; }
    2219         ;
    2220 
    2221 type_function:
    2222         paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2221        | '(' typedef_array ')'                                                         // redundant parenthesis
     2222                { $$ = $2; }
     2223        ;
     2224
     2225typedef_function:
     2226        paren_typedef '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    22232227                { $$ = $1->addParamList( $4 ); }
    2224         | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2228        | '(' typedef_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    22252229                { $$ = $2->addParamList( $6 ); }
    2226         | '(' type_function ')'                                                         // redundant parenthesis
     2230        | '(' typedef_function ')'                                                      // redundant parenthesis
    22272231                { $$ = $2; }
    22282232        ;
     
    22952299// functions.
    22962300
    2297 type_parameter_redeclarator:
     2301typedef_parameter_redeclarator:
    22982302        typedef attribute_list_opt
    2299         | type_parameter_ptr
    2300         | type_parameter_array attribute_list_opt
    2301         | type_parameter_function attribute_list_opt
     2303        | typedef_parameter_ptr
     2304        | typedef_parameter_array attribute_list_opt
     2305        | typedef_parameter_function attribute_list_opt
    23022306        ;
    23032307
     
    23082312                        $$ = DeclarationNode::newName( $1 );
    23092313                }
    2310         | TYPEGENname
    2311                 {
    2312                         typedefTable.setNextIdentifier( *$1 );
    2313                         $$ = DeclarationNode::newName( $1 );
    2314                 }
    2315         ;
    2316 
    2317 type_parameter_ptr:
    2318         '*' type_parameter_redeclarator
     2314        ;
     2315
     2316typedef_parameter_ptr:
     2317        '*' typedef_parameter_redeclarator
    23192318                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2320         | '*' type_qualifier_list type_parameter_redeclarator
     2319        | '*' type_qualifier_list typedef_parameter_redeclarator
    23212320                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2322         | '(' type_parameter_ptr ')'
    2323                 { $$ = $2; }
    2324         ;
    2325 
    2326 type_parameter_array:
     2321        | '(' typedef_parameter_ptr ')'
     2322                { $$ = $2; }
     2323        ;
     2324
     2325typedef_parameter_array:
    23272326        typedef array_parameter_dimension
    23282327                { $$ = $1->addArray( $2 ); }
    2329         | '(' type_parameter_ptr ')' array_parameter_dimension
     2328        | '(' typedef_parameter_ptr ')' array_parameter_dimension
    23302329                { $$ = $2->addArray( $4 ); }
    23312330        ;
    23322331
    2333 type_parameter_function:
     2332typedef_parameter_function:
    23342333        typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3)
    23352334                { $$ = $1->addParamList( $4 ); }
    2336         | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2335        | '(' typedef_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    23372336                { $$ = $2->addParamList( $6 ); }
    23382337        ;
     
    23872386array_dimension:
    23882387                // Only the first dimension can be empty.
    2389         '[' ']'
     2388        '[' push pop ']'
    23902389                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    2391         | '[' ']' multi_array_dimension
    2392                 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
     2390        | '[' push pop ']' multi_array_dimension
     2391                { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $5 ); }
    23932392        | multi_array_dimension
    23942393        ;
     
    24662465
    24672466array_parameter_1st_dimension:
    2468         '[' ']'
     2467        '[' push pop ']'
    24692468                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    24702469        // multi_array_dimension handles the '[' '*' ']' case
     
    25592558                // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to
    25602559                // shift/reduce conflict with new-style empty (void) function return type.
    2561         '[' ']' type_specifier
    2562                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2560        '[' push pop ']' type_specifier
     2561                { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    25632562        | new_array_parameter_1st_dimension type_specifier
    25642563                { $$ = $2->addNewArray( $1 ); }
    2565         | '[' ']' multi_array_dimension type_specifier
    2566                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2564        | '[' push pop ']' multi_array_dimension type_specifier
     2565                { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    25672566        | new_array_parameter_1st_dimension multi_array_dimension type_specifier
    25682567                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
    25692568        | multi_array_dimension type_specifier
    25702569                { $$ = $2->addNewArray( $1 ); }
    2571         | '[' ']' new_identifier_parameter_ptr
    2572                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2570        | '[' push pop ']' new_identifier_parameter_ptr
     2571                { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    25732572        | new_array_parameter_1st_dimension new_identifier_parameter_ptr
    25742573                { $$ = $2->addNewArray( $1 ); }
    2575         | '[' ']' multi_array_dimension new_identifier_parameter_ptr
    2576                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2574        | '[' push pop ']' multi_array_dimension new_identifier_parameter_ptr
     2575                { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    25772576        | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr
    25782577                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
     
    26032602// These rules need LR(3):
    26042603//
    2605 //              new_abstract_tuple identifier_or_type_name
    2606 //              '[' new_parameter_list ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'
     2604//              new_abstract_tuple identifier_or_typedef_name
     2605//              '[' new_parameter_list ']' identifier_or_typedef_name '(' new_parameter_type_list_opt ')'
    26072606//
    26082607// since a function return type can be syntactically identical to a tuple type:
     
    26112610//              [int, int] f( int );
    26122611//
    2613 // Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce
     2612// Therefore, it is necessary to look at the token after identifier_or_typedef_name to know when to reduce
    26142613// new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
    26152614// lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are
     
    26462645                // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with
    26472646                // empty (void) function return type.
    2648         '[' ']' type_specifier
    2649                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    2650         | '[' ']' multi_array_dimension type_specifier
    2651                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2647        '[' push pop ']' type_specifier
     2648                { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2649        | '[' push pop ']' multi_array_dimension type_specifier
     2650                { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    26522651        | multi_array_dimension type_specifier
    26532652                { $$ = $2->addNewArray( $1 ); }
    2654         | '[' ']' new_abstract_ptr
    2655                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    2656         | '[' ']' multi_array_dimension new_abstract_ptr
    2657                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2653        | '[' push pop ']' new_abstract_ptr
     2654                { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2655        | '[' push pop ']' multi_array_dimension new_abstract_ptr
     2656                { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    26582657        | multi_array_dimension new_abstract_ptr
    26592658                { $$ = $2->addNewArray( $1 ); }
     
    26662665
    26672666new_abstract_function:                                                                  // CFA
    2668         '[' ']' '(' new_parameter_type_list_opt ')'
    2669                 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0 ); }
     2667        '[' push pop ']' '(' new_parameter_type_list_opt ')'
     2668                { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $6, 0 ); }
    26702669        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
    26712670                { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
Note: See TracChangeset for help on using the changeset viewer.