Changeset d800676 for src


Ignore:
Timestamp:
Mar 23, 2023, 12:18:39 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
c94b1f0
Parents:
1afd9ccb (diff), 18ea270 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslateNew.cpp

    r1afd9ccb rd800676  
    314314                nullptr,
    315315                ast::Storage::Classes{},
    316                 ast::Linkage::Cforall
     316                ast::Linkage::Cforall,
     317                {},
     318                { ast::Function::Inline }
    317319        );
    318320}
  • src/Parser/ExpressionNode.cc

    r1afd9ccb rd800676  
    164164        } else {
    165165                // At least one digit in integer constant, so safe to backup while looking for suffix.
     166                // This declaration and the comma expressions in the conditions mimic
     167                // the declare and check pattern allowed in later compiler versions.
     168                // (Only some early compilers/C++ standards do not support it.)
    166169                string::size_type posn;
    167170                // pointer value
    168                 if ( posn = str.find_last_of( "pP" ); posn != string::npos ) {
     171                if ( posn = str.find_last_of( "pP" ), posn != string::npos ) {
    169172                        ltype = 5; str.erase( posn, 1 );
    170173                // size_t
    171                 } else if ( posn = str.find_last_of( "zZ" ); posn != string::npos ) {
     174                } else if ( posn = str.find_last_of( "zZ" ), posn != string::npos ) {
    172175                        Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 );
    173176                // signed char
    174                 } else if ( posn = str.rfind( "hh" ); posn != string::npos ) {
     177                } else if ( posn = str.rfind( "hh" ), posn != string::npos ) {
    175178                        type = 1; str.erase( posn, 2 );
    176179                // signed char
    177                 } else if ( posn = str.rfind( "HH" ); posn != string::npos ) {
     180                } else if ( posn = str.rfind( "HH" ), posn != string::npos ) {
    178181                        type = 1; str.erase( posn, 2 );
    179182                // short
    180                 } else if ( posn = str.find_last_of( "hH" ); posn != string::npos ) {
     183                } else if ( posn = str.find_last_of( "hH" ), posn != string::npos ) {
    181184                        type = 0; str.erase( posn, 1 );
    182185                // int (natural number)
    183                 } else if ( posn = str.find_last_of( "nN" ); posn != string::npos ) {
     186                } else if ( posn = str.find_last_of( "nN" ), posn != string::npos ) {
    184187                        type = 2; str.erase( posn, 1 );
    185188                } else if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) {
  • src/Parser/parser.yy

    r1afd9ccb rd800676  
    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
    13 // Update Count     : 5990
     12// Last Modified On : Wed Mar 22 21:26:01 2023
     13// Update Count     : 6002
    1414//
    1515
     
    270270        SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
    271271                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
     272} // IdentifierBeforeType
     273
     274static 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        } // if
     279        return false;
    272280} // IdentifierBeforeType
    273281
     
    496504%type<decl> typedef_name typedef_declaration typedef_expression
    497505
    498 %type<decl> variable_type_redeclarator type_ptr type_array type_function
     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
    499508
    500509%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
     
    19571966        TYPEDEF type_specifier declarator
    19581967                {
    1959                         // if type_specifier is an anon aggregate => name
    19601968                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
    1961                         $$ = $3->addType( $2 )->addTypedef();           // watchout frees $2 and $3
     1969                        if ( TypedefForall( $2 ) ) $$ = nullptr;
     1970                        else $$ = $3->addType( $2 )->addTypedef();              // watchout frees $2 and $3
    19621971                }
    19631972        | typedef_declaration pop ',' push declarator
     
    19691978                {
    19701979                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
    1971                         $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef();
     1980                        if ( TypedefForall( $1 ) ) $$ = nullptr;
     1981                        else $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef();
    19721982                }
    19731983        | type_specifier TYPEDEF declarator
    19741984                {
    19751985                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
    1976                         $$ = $3->addType( $1 )->addTypedef();
     1986                        if ( TypedefForall( $1 ) ) $$ = nullptr;
     1987                        else $$ = $3->addType( $1 )->addTypedef();
    19771988                }
    19781989        | type_specifier TYPEDEF type_qualifier_list declarator
    19791990                {
    19801991                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
    1981                         $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef();
     1992                        if ( TypedefForall( $3 ) ) $$ = nullptr;
     1993                        else $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef();
    19821994                }
    19831995        ;
     
    20162028                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
    20172029                // storage-class
    2018         declarator asm_name_opt initializer_opt
     2030        variable_declarator asm_name_opt initializer_opt
    20192031                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     2032        | variable_type_redeclarator asm_name_opt initializer_opt
     2033                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     2034
     2035        | general_function_declarator asm_name_opt
     2036                { $$ = $1->addAsmName( $2 )->addInitializer( nullptr ); }
     2037        | general_function_declarator asm_name_opt '=' VOID
     2038                { $$ = $1->addAsmName( $2 )->addInitializer( new InitializerNode( true ) ); }
     2039
    20202040        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    20212041                { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     2042        ;
     2043
     2044general_function_declarator:
     2045        function_type_redeclarator
     2046        | function_declarator
    20222047        ;
    20232048
     
    25432568                // A semantic check is required to ensure bit_subrange only appears on integral types.
    25442569                { $$ = $1->addBitfield( $2 ); }
     2570        | function_type_redeclarator bit_subrange_size_opt
     2571                // A semantic check is required to ensure bit_subrange only appears on integral types.
     2572                { $$ = $1->addBitfield( $2 ); }
    25452573        ;
    25462574
     
    31953223                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    31963224                }
    3197         | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
     3225        | declaration_specifier function_type_redeclarator with_clause_opt compound_statement
    31983226                {
    31993227                        rebindForall( $1, $2 );
     
    32313259        | variable_type_redeclarator
    32323260        | function_declarator
     3261        | function_type_redeclarator
    32333262        ;
    32343263
     
    34813510        ;
    34823511
    3483 // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:
     3512// This pattern parses a declaration for a variable that redefines a type name, e.g.:
    34843513//
    34853514//              typedef int foo;
     
    34873516//                 int foo; // redefine typedef name in new scope
    34883517//              }
    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.
    34923518
    34933519paren_type:
     
    35043530        paren_type attribute_list_opt
    35053531                { $$ = $1->addQualifiers( $2 ); }
    3506         | type_ptr
    3507         | type_array attribute_list_opt
     3532        | variable_type_ptr
     3533        | variable_type_array attribute_list_opt
    35083534                { $$ = $1->addQualifiers( $2 ); }
    3509         | type_function attribute_list_opt
     3535        | variable_type_function attribute_list_opt
    35103536                { $$ = $1->addQualifiers( $2 ); }
    35113537        ;
    35123538
    3513 type_ptr:
     3539variable_type_ptr:
    35143540        ptrref_operator variable_type_redeclarator
    35153541                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    35163542        | ptrref_operator type_qualifier_list variable_type_redeclarator
    35173543                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    3518         | '(' type_ptr ')' attribute_list_opt                           // redundant parenthesis
     3544        | '(' variable_type_ptr ')' attribute_list_opt          // redundant parenthesis
    35193545                { $$ = $2->addQualifiers( $4 ); }
    3520         | '(' attribute_list type_ptr ')' attribute_list_opt // redundant parenthesis
     3546        | '(' attribute_list variable_type_ptr ')' attribute_list_opt // redundant parenthesis
    35213547                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
    35223548        ;
    35233549
    3524 type_array:
     3550variable_type_array:
    35253551        paren_type array_dimension
    35263552                { $$ = $1->addArray( $2 ); }
    3527         | '(' type_ptr ')' array_dimension
     3553        | '(' variable_type_ptr ')' array_dimension
    35283554                { $$ = $2->addArray( $4 ); }
    3529         | '(' attribute_list type_ptr ')' array_dimension
     3555        | '(' attribute_list variable_type_ptr ')' array_dimension
    35303556                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
    3531         | '(' type_array ')' multi_array_dimension                      // redundant parenthesis
     3557        | '(' variable_type_array ')' multi_array_dimension     // redundant parenthesis
    35323558                { $$ = $2->addArray( $4 ); }
    3533         | '(' attribute_list type_array ')' multi_array_dimension // redundant parenthesis
     3559        | '(' attribute_list variable_type_array ')' multi_array_dimension // redundant parenthesis
    35343560                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
    3535         | '(' type_array ')'                                                            // redundant parenthesis
     3561        | '(' variable_type_array ')'                                           // redundant parenthesis
    35363562                { $$ = $2; }
    3537         | '(' attribute_list type_array ')'                                     // redundant parenthesis
     3563        | '(' attribute_list variable_type_array ')'            // redundant parenthesis
    35383564                { $$ = $3->addQualifiers( $2 ); }
    35393565        ;
    35403566
    3541 type_function:
     3567variable_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
     3582function_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
     3590function_type_no_ptr:
    35423591        paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    35433592                { $$ = $1->addParamList( $4 ); }
    3544         | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3593        | '(' function_type_ptr ')' '(' push parameter_type_list_opt pop ')'
    35453594                { $$ = $2->addParamList( $6 ); }
    3546         | '(' attribute_list type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3595        | '(' attribute_list function_type_ptr ')' '(' push parameter_type_list_opt pop ')'
    35473596                { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); }
    3548         | '(' type_function ')'                                                         // redundant parenthesis
     3597        | '(' function_type_no_ptr ')'                                          // redundant parenthesis
    35493598                { $$ = $2; }
    3550         | '(' attribute_list type_function ')'                          // redundant parenthesis
     3599        | '(' attribute_list function_type_no_ptr ')'           // redundant parenthesis
     3600                { $$ = $3->addQualifiers( $2 ); }
     3601        ;
     3602
     3603function_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
     3614function_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
    35513626                { $$ = $3->addQualifiers( $2 ); }
    35523627        ;
Note: See TracChangeset for help on using the changeset viewer.