Changes in src/Parser/parser.yy [d63aeba:9fa61f5]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rd63aeba r9fa61f5 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 22 21:26:01202313 // Update Count : 600212 // Last Modified On : Tue Mar 14 09:37:58 2023 13 // Update Count : 5990 14 14 // 15 15 … … 270 270 SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n" 271 271 "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) ); 272 } // IdentifierBeforeType273 274 static 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 } // if279 return false;280 272 } // IdentifierBeforeType 281 273 … … 504 496 %type<decl> typedef_name typedef_declaration typedef_expression 505 497 506 %type<decl> variable_type_redeclarator variable_type_ptr variable_type_array variable_type_function 507 %type<decl> general_function_declarator function_type_redeclarator function_type_array function_type_no_ptr function_type_ptr 498 %type<decl> variable_type_redeclarator type_ptr type_array type_function 508 499 509 500 %type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function … … 1966 1957 TYPEDEF type_specifier declarator 1967 1958 { 1959 // if type_specifier is an anon aggregate => name 1968 1960 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" ); 1969 if ( TypedefForall( $2 ) ) $$ = nullptr; 1970 else $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 1961 $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 1971 1962 } 1972 1963 | typedef_declaration pop ',' push declarator … … 1978 1969 { 1979 1970 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" ); 1980 if ( TypedefForall( $1 ) ) $$ = nullptr; 1981 else $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef(); 1971 $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef(); 1982 1972 } 1983 1973 | type_specifier TYPEDEF declarator 1984 1974 { 1985 1975 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" ); 1986 if ( TypedefForall( $1 ) ) $$ = nullptr; 1987 else $$ = $3->addType( $1 )->addTypedef(); 1976 $$ = $3->addType( $1 )->addTypedef(); 1988 1977 } 1989 1978 | type_specifier TYPEDEF type_qualifier_list declarator 1990 1979 { 1991 1980 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" ); 1992 if ( TypedefForall( $3 ) ) $$ = nullptr; 1993 else $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef(); 1981 $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef(); 1994 1982 } 1995 1983 ; … … 2028 2016 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 2029 2017 // storage-class 2030 variable_declarator asm_name_opt initializer_opt2018 declarator asm_name_opt initializer_opt 2031 2019 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 2032 | variable_type_redeclarator asm_name_opt initializer_opt2033 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }2034 2035 | general_function_declarator asm_name_opt2036 { $$ = $1->addAsmName( $2 )->addInitializer( nullptr ); }2037 | general_function_declarator asm_name_opt '=' VOID2038 { $$ = $1->addAsmName( $2 )->addInitializer( new InitializerNode( true ) ); }2039 2040 2020 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 2041 2021 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 2042 ;2043 2044 general_function_declarator:2045 function_type_redeclarator2046 | function_declarator2047 2022 ; 2048 2023 … … 2568 2543 // A semantic check is required to ensure bit_subrange only appears on integral types. 2569 2544 { $$ = $1->addBitfield( $2 ); } 2570 | function_type_redeclarator bit_subrange_size_opt2571 // A semantic check is required to ensure bit_subrange only appears on integral types.2572 { $$ = $1->addBitfield( $2 ); }2573 2545 ; 2574 2546 … … 3223 3195 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 3224 3196 } 3225 | declaration_specifier function_type_redeclarator with_clause_opt compound_statement3197 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement 3226 3198 { 3227 3199 rebindForall( $1, $2 ); … … 3259 3231 | variable_type_redeclarator 3260 3232 | function_declarator 3261 | function_type_redeclarator3262 3233 ; 3263 3234 … … 3510 3481 ; 3511 3482 3512 // This pattern parses a declaration for a variable that redefines a type name, e.g.:3483 // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.: 3513 3484 // 3514 3485 // typedef int foo; … … 3516 3487 // int foo; // redefine typedef name in new scope 3517 3488 // } 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. 3518 3492 3519 3493 paren_type: … … 3530 3504 paren_type attribute_list_opt 3531 3505 { $$ = $1->addQualifiers( $2 ); } 3532 | variable_type_ptr3533 | variable_type_array attribute_list_opt3506 | type_ptr 3507 | type_array attribute_list_opt 3534 3508 { $$ = $1->addQualifiers( $2 ); } 3535 | variable_type_function attribute_list_opt3509 | type_function attribute_list_opt 3536 3510 { $$ = $1->addQualifiers( $2 ); } 3537 3511 ; 3538 3512 3539 variable_type_ptr:3513 type_ptr: 3540 3514 ptrref_operator variable_type_redeclarator 3541 3515 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3542 3516 | ptrref_operator type_qualifier_list variable_type_redeclarator 3543 3517 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 3544 | '(' variable_type_ptr ')' attribute_list_opt// redundant parenthesis3518 | '(' type_ptr ')' attribute_list_opt // redundant parenthesis 3545 3519 { $$ = $2->addQualifiers( $4 ); } 3546 | '(' attribute_list variable_type_ptr ')' attribute_list_opt // redundant parenthesis3520 | '(' attribute_list type_ptr ')' attribute_list_opt // redundant parenthesis 3547 3521 { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); } 3548 3522 ; 3549 3523 3550 variable_type_array:3524 type_array: 3551 3525 paren_type array_dimension 3552 3526 { $$ = $1->addArray( $2 ); } 3553 | '(' variable_type_ptr ')' array_dimension3527 | '(' type_ptr ')' array_dimension 3554 3528 { $$ = $2->addArray( $4 ); } 3555 | '(' attribute_list variable_type_ptr ')' array_dimension3529 | '(' attribute_list type_ptr ')' array_dimension 3556 3530 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3557 | '(' variable_type_array ')' multi_array_dimension// redundant parenthesis3531 | '(' type_array ')' multi_array_dimension // redundant parenthesis 3558 3532 { $$ = $2->addArray( $4 ); } 3559 | '(' attribute_list variable_type_array ')' multi_array_dimension // redundant parenthesis3533 | '(' attribute_list type_array ')' multi_array_dimension // redundant parenthesis 3560 3534 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3561 | '(' variable_type_array ')'// redundant parenthesis3535 | '(' type_array ')' // redundant parenthesis 3562 3536 { $$ = $2; } 3563 | '(' attribute_list variable_type_array ')'// redundant parenthesis3537 | '(' attribute_list type_array ')' // redundant parenthesis 3564 3538 { $$ = $3->addQualifiers( $2 ); } 3565 3539 ; 3566 3540 3567 variable_type_function: 3568 '(' variable_type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3569 { $$ = $2->addParamList( $6 ); } 3570 | '(' attribute_list variable_type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3571 { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); } 3572 | '(' variable_type_function ')' // redundant parenthesis 3573 { $$ = $2; } 3574 | '(' attribute_list variable_type_function ')' // redundant parenthesis 3575 { $$ = $3->addQualifiers( $2 ); } 3576 ; 3577 3578 // This pattern parses a declaration for a function prototype that redefines a type name. It precludes declaring an 3579 // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to 3580 // arrays and functions. 3581 3582 function_type_redeclarator: 3583 function_type_no_ptr attribute_list_opt 3584 { $$ = $1->addQualifiers( $2 ); } 3585 | function_type_ptr 3586 | function_type_array attribute_list_opt 3587 { $$ = $1->addQualifiers( $2 ); } 3588 ; 3589 3590 function_type_no_ptr: 3541 type_function: 3591 3542 paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3592 3543 { $$ = $1->addParamList( $4 ); } 3593 | '(' function_type_ptr ')' '(' push parameter_type_list_opt pop ')'3544 | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3594 3545 { $$ = $2->addParamList( $6 ); } 3595 | '(' attribute_list function_type_ptr ')' '(' push parameter_type_list_opt pop ')'3546 | '(' attribute_list type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3596 3547 { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); } 3597 | '(' function_type_no_ptr ')'// redundant parenthesis3548 | '(' type_function ')' // redundant parenthesis 3598 3549 { $$ = $2; } 3599 | '(' attribute_list function_type_no_ptr ')' // redundant parenthesis 3600 { $$ = $3->addQualifiers( $2 ); } 3601 ; 3602 3603 function_type_ptr: 3604 ptrref_operator function_type_redeclarator 3605 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3606 | ptrref_operator type_qualifier_list function_type_redeclarator 3607 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 3608 | '(' function_type_ptr ')' attribute_list_opt 3609 { $$ = $2->addQualifiers( $4 ); } 3610 | '(' attribute_list function_type_ptr ')' attribute_list_opt 3611 { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); } 3612 ; 3613 3614 function_type_array: 3615 '(' function_type_ptr ')' array_dimension 3616 { $$ = $2->addArray( $4 ); } 3617 | '(' attribute_list function_type_ptr ')' array_dimension 3618 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3619 | '(' function_type_array ')' multi_array_dimension // redundant parenthesis 3620 { $$ = $2->addArray( $4 ); } 3621 | '(' attribute_list function_type_array ')' multi_array_dimension // redundant parenthesis 3622 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3623 | '(' function_type_array ')' // redundant parenthesis 3624 { $$ = $2; } 3625 | '(' attribute_list function_type_array ')' // redundant parenthesis 3550 | '(' attribute_list type_function ')' // redundant parenthesis 3626 3551 { $$ = $3->addQualifiers( $2 ); } 3627 3552 ;
Note:
See TracChangeset
for help on using the changeset viewer.