Changeset 1f771fc
- Timestamp:
- Mar 21, 2023, 7:18:07 PM (18 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 5d9c4bb
- Parents:
- 1205b3e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r1205b3e r1f771fc 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 14 09:37:58202312 // Last Modified On : Tue Mar 21 19:01:00 2023 13 13 // Update Count : 5990 14 14 // … … 496 496 %type<decl> typedef_name typedef_declaration typedef_expression 497 497 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 499 500 500 501 %type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function … … 2016 2017 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 2017 2018 // storage-class 2018 declarator asm_name_opt initializer_opt2019 variable_declarator asm_name_opt initializer_opt 2019 2020 { $$ = $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 2020 2029 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 2021 2030 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 2031 ; 2032 2033 general_function_declarator: 2034 function_type_redeclarator 2035 | function_declarator 2022 2036 ; 2023 2037 … … 2543 2557 // A semantic check is required to ensure bit_subrange only appears on integral types. 2544 2558 { $$ = $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 ); } 2545 2562 ; 2546 2563 … … 3195 3212 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 3196 3213 } 3197 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement3214 | declaration_specifier function_type_redeclarator with_clause_opt compound_statement 3198 3215 { 3199 3216 rebindForall( $1, $2 ); … … 3231 3248 | variable_type_redeclarator 3232 3249 | function_declarator 3250 | function_type_redeclarator 3233 3251 ; 3234 3252 … … 3481 3499 ; 3482 3500 3483 // This pattern parses a declaration for a variable or function prototypethat redefines a type name, e.g.:3501 // This pattern parses a declaration for a variable that redefines a type name, e.g.: 3484 3502 // 3485 3503 // typedef int foo; … … 3487 3505 // int foo; // redefine typedef name in new scope 3488 3506 // } 3489 //3490 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays3491 // and functions versus pointers to arrays and functions.3492 3507 3493 3508 paren_type: … … 3504 3519 paren_type attribute_list_opt 3505 3520 { $$ = $1->addQualifiers( $2 ); } 3506 | type_ptr3507 | type_array attribute_list_opt3521 | variable_type_ptr 3522 | variable_type_array attribute_list_opt 3508 3523 { $$ = $1->addQualifiers( $2 ); } 3509 | type_function attribute_list_opt3524 | variable_type_function attribute_list_opt 3510 3525 { $$ = $1->addQualifiers( $2 ); } 3511 3526 ; 3512 3527 3513 type_ptr:3528 variable_type_ptr: 3514 3529 ptrref_operator variable_type_redeclarator 3515 3530 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3516 3531 | ptrref_operator type_qualifier_list variable_type_redeclarator 3517 3532 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 3518 | '(' type_ptr ')' attribute_list_opt// redundant parenthesis3533 | '(' variable_type_ptr ')' attribute_list_opt // redundant parenthesis 3519 3534 { $$ = $2->addQualifiers( $4 ); } 3520 | '(' attribute_list type_ptr ')' attribute_list_opt // redundant parenthesis3535 | '(' attribute_list variable_type_ptr ')' attribute_list_opt // redundant parenthesis 3521 3536 { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); } 3522 3537 ; 3523 3538 3524 type_array:3539 variable_type_array: 3525 3540 paren_type array_dimension 3526 3541 { $$ = $1->addArray( $2 ); } 3527 | '(' type_ptr ')' array_dimension3542 | '(' variable_type_ptr ')' array_dimension 3528 3543 { $$ = $2->addArray( $4 ); } 3529 | '(' attribute_list type_ptr ')' array_dimension3544 | '(' attribute_list variable_type_ptr ')' array_dimension 3530 3545 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3531 | '(' type_array ')' multi_array_dimension// redundant parenthesis3546 | '(' variable_type_array ')' multi_array_dimension // redundant parenthesis 3532 3547 { $$ = $2->addArray( $4 ); } 3533 | '(' attribute_list type_array ')' multi_array_dimension // redundant parenthesis3548 | '(' attribute_list variable_type_array ')' multi_array_dimension // redundant parenthesis 3534 3549 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3535 | '(' type_array ')'// redundant parenthesis3550 | '(' variable_type_array ')' // redundant parenthesis 3536 3551 { $$ = $2; } 3537 | '(' attribute_list type_array ')'// redundant parenthesis3552 | '(' attribute_list variable_type_array ')' // redundant parenthesis 3538 3553 { $$ = $3->addQualifiers( $2 ); } 3539 3554 ; 3540 3555 3541 type_function: 3556 variable_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 3571 function_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 3579 function_type_no_ptr: 3542 3580 paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3543 3581 { $$ = $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 ')' 3545 3583 { $$ = $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 ')' 3547 3585 { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); } 3548 | '(' type_function ')'// redundant parenthesis3586 | '(' function_type_no_ptr ')' // redundant parenthesis 3549 3587 { $$ = $2; } 3550 | '(' attribute_list type_function ')' // redundant parenthesis 3588 | '(' attribute_list function_type_no_ptr ')' // redundant parenthesis 3589 { $$ = $3->addQualifiers( $2 ); } 3590 ; 3591 3592 function_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 3603 function_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 3551 3615 { $$ = $3->addQualifiers( $2 ); } 3552 3616 ;
Note: See TracChangeset
for help on using the changeset viewer.