Ignore:
Timestamp:
Mar 21, 2023, 7:18:07 PM (13 months ago)
Author:
Mugilan Ganesan <mganesan@…>
Branches:
ADT, ast-experimental, master
Children:
5d9c4bb
Parents:
1205b3e
Message:

Removed list initialization and simple assignment expression rules for functions. Split variable_type_redeclarator rule into variable_type_redeclarator and function_type_redeclarator rules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r1205b3e r1f771fc  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 14 09:37:58 2023
     12// Last Modified On : Tue Mar 21 19:01:00 2023
    1313// Update Count     : 5990
    1414//
     
    496496%type<decl> typedef_name typedef_declaration typedef_expression
    497497
    498 %type<decl> variable_type_redeclarator type_ptr type_array type_function
     498%type<decl> variable_type_redeclarator variable_type_ptr variable_type_array variable_type_function
     499%type<decl> general_function_declarator function_type_redeclarator function_type_array function_type_no_ptr function_type_ptr
    499500
    500501%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
     
    20162017                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
    20172018                // storage-class
    2018         declarator asm_name_opt initializer_opt
     2019        variable_declarator asm_name_opt initializer_opt
    20192020                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     2021        | variable_type_redeclarator asm_name_opt initializer_opt
     2022                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     2023
     2024        | general_function_declarator asm_name_opt
     2025                { $$ = $1->addAsmName( $2 )->addInitializer( nullptr ); }
     2026        | general_function_declarator asm_name_opt '=' VOID
     2027                { $$ = $1->addAsmName( $2 )->addInitializer( new InitializerNode( true ) ); }
     2028
    20202029        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    20212030                { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     2031        ;
     2032
     2033general_function_declarator:
     2034        function_type_redeclarator
     2035        | function_declarator
    20222036        ;
    20232037
     
    25432557                // A semantic check is required to ensure bit_subrange only appears on integral types.
    25442558                { $$ = $1->addBitfield( $2 ); }
     2559        | function_type_redeclarator bit_subrange_size_opt
     2560                // A semantic check is required to ensure bit_subrange only appears on integral types.
     2561                { $$ = $1->addBitfield( $2 ); }
    25452562        ;
    25462563
     
    31953212                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    31963213                }
    3197         | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
     3214        | declaration_specifier function_type_redeclarator with_clause_opt compound_statement
    31983215                {
    31993216                        rebindForall( $1, $2 );
     
    32313248        | variable_type_redeclarator
    32323249        | function_declarator
     3250        | function_type_redeclarator
    32333251        ;
    32343252
     
    34813499        ;
    34823500
    3483 // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:
     3501// This pattern parses a declaration for a variable that redefines a type name, e.g.:
    34843502//
    34853503//              typedef int foo;
     
    34873505//                 int foo; // redefine typedef name in new scope
    34883506//              }
    3489 //
    3490 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
    3491 // and functions versus pointers to arrays and functions.
    34923507
    34933508paren_type:
     
    35043519        paren_type attribute_list_opt
    35053520                { $$ = $1->addQualifiers( $2 ); }
    3506         | type_ptr
    3507         | type_array attribute_list_opt
     3521        | variable_type_ptr
     3522        | variable_type_array attribute_list_opt
    35083523                { $$ = $1->addQualifiers( $2 ); }
    3509         | type_function attribute_list_opt
     3524        | variable_type_function attribute_list_opt
    35103525                { $$ = $1->addQualifiers( $2 ); }
    35113526        ;
    35123527
    3513 type_ptr:
     3528variable_type_ptr:
    35143529        ptrref_operator variable_type_redeclarator
    35153530                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    35163531        | ptrref_operator type_qualifier_list variable_type_redeclarator
    35173532                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    3518         | '(' type_ptr ')' attribute_list_opt                           // redundant parenthesis
     3533        | '(' variable_type_ptr ')' attribute_list_opt          // redundant parenthesis
    35193534                { $$ = $2->addQualifiers( $4 ); }
    3520         | '(' attribute_list type_ptr ')' attribute_list_opt // redundant parenthesis
     3535        | '(' attribute_list variable_type_ptr ')' attribute_list_opt // redundant parenthesis
    35213536                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
    35223537        ;
    35233538
    3524 type_array:
     3539variable_type_array:
    35253540        paren_type array_dimension
    35263541                { $$ = $1->addArray( $2 ); }
    3527         | '(' type_ptr ')' array_dimension
     3542        | '(' variable_type_ptr ')' array_dimension
    35283543                { $$ = $2->addArray( $4 ); }
    3529         | '(' attribute_list type_ptr ')' array_dimension
     3544        | '(' attribute_list variable_type_ptr ')' array_dimension
    35303545                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
    3531         | '(' type_array ')' multi_array_dimension                      // redundant parenthesis
     3546        | '(' variable_type_array ')' multi_array_dimension     // redundant parenthesis
    35323547                { $$ = $2->addArray( $4 ); }
    3533         | '(' attribute_list type_array ')' multi_array_dimension // redundant parenthesis
     3548        | '(' attribute_list variable_type_array ')' multi_array_dimension // redundant parenthesis
    35343549                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
    3535         | '(' type_array ')'                                                            // redundant parenthesis
     3550        | '(' variable_type_array ')'                                           // redundant parenthesis
    35363551                { $$ = $2; }
    3537         | '(' attribute_list type_array ')'                                     // redundant parenthesis
     3552        | '(' attribute_list variable_type_array ')'            // redundant parenthesis
    35383553                { $$ = $3->addQualifiers( $2 ); }
    35393554        ;
    35403555
    3541 type_function:
     3556variable_type_function:
     3557        '(' variable_type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3558                { $$ = $2->addParamList( $6 ); }
     3559        | '(' attribute_list variable_type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3560                { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); }
     3561        | '(' variable_type_function ')'                                        // redundant parenthesis
     3562                { $$ = $2; }
     3563        | '(' attribute_list variable_type_function ')'         // redundant parenthesis
     3564                { $$ = $3->addQualifiers( $2 ); }
     3565        ;
     3566
     3567// This pattern parses a declaration for a function prototype that redefines a type name.  It precludes declaring an
     3568// array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to
     3569// arrays and functions.
     3570
     3571function_type_redeclarator:
     3572        function_type_no_ptr attribute_list_opt
     3573                { $$ = $1->addQualifiers( $2 ); }
     3574        | function_type_ptr
     3575        | function_type_array attribute_list_opt
     3576                { $$ = $1->addQualifiers( $2 ); }
     3577        ;
     3578
     3579function_type_no_ptr:
    35423580        paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    35433581                { $$ = $1->addParamList( $4 ); }
    3544         | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3582        | '(' function_type_ptr ')' '(' push parameter_type_list_opt pop ')'
    35453583                { $$ = $2->addParamList( $6 ); }
    3546         | '(' attribute_list type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3584        | '(' attribute_list function_type_ptr ')' '(' push parameter_type_list_opt pop ')'
    35473585                { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); }
    3548         | '(' type_function ')'                                                         // redundant parenthesis
     3586        | '(' function_type_no_ptr ')'                                          // redundant parenthesis
    35493587                { $$ = $2; }
    3550         | '(' attribute_list type_function ')'                          // redundant parenthesis
     3588        | '(' attribute_list function_type_no_ptr ')'           // redundant parenthesis
     3589                { $$ = $3->addQualifiers( $2 ); }
     3590        ;
     3591
     3592function_type_ptr:
     3593        ptrref_operator function_type_redeclarator
     3594                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
     3595        | ptrref_operator type_qualifier_list function_type_redeclarator
     3596                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     3597        | '(' function_type_ptr ')' attribute_list_opt
     3598                { $$ = $2->addQualifiers( $4 ); }
     3599        | '(' attribute_list function_type_ptr ')' attribute_list_opt
     3600                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
     3601        ;
     3602
     3603function_type_array:
     3604        '(' function_type_ptr ')' array_dimension
     3605                { $$ = $2->addArray( $4 ); }
     3606        | '(' attribute_list function_type_ptr ')' array_dimension
     3607                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
     3608        | '(' function_type_array ')' multi_array_dimension     // redundant parenthesis
     3609                { $$ = $2->addArray( $4 ); }
     3610        | '(' attribute_list function_type_array ')' multi_array_dimension // redundant parenthesis
     3611                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
     3612        | '(' function_type_array ')'                                           // redundant parenthesis
     3613                { $$ = $2; }
     3614        | '(' attribute_list function_type_array ')'            // redundant parenthesis
    35513615                { $$ = $3->addQualifiers( $2 ); }
    35523616        ;
Note: See TracChangeset for help on using the changeset viewer.