Changeset 1a73dbb


Ignore:
Timestamp:
Feb 24, 2023, 3:26:01 PM (14 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
f2a1cd2
Parents:
dc3c9b1
Message:

parser rejects useless type qualifier in empty declaration, and extern anonymous SUE declarations, switch from bitset val to any(), reset()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rdc3c9b1 r1a73dbb  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb 20 11:31:26 2023
    13 // Update Count     : 5896
     12// Last Modified On : Fri Feb 24 14:46:55 2023
     13// Update Count     : 5983
    1414//
    1515
     
    19411941                        // if type_specifier is an anon aggregate => name
    19421942                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
    1943                         $$ = $3->addType( $2 )->addTypedef();
     1943                        $$ = $3->addType( $2 )->addTypedef();           // watchout frees $2 and $3
    19441944                }
    19451945        | typedef_declaration pop ',' push declarator
     
    19851985                {
    19861986                        assert( $1->type );
    1987                         if ( $1->type->qualifiers.val != 0 ) {
    1988                                 SemanticError( yylloc, "Useless type qualifier in empty declaration." ); $$ = nullptr;
     1987                        if ( $1->type->qualifiers.any() ) {                     // CV qualifiers ?
     1988                                SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr;
     1989                        }
     1990                        // enums are never empty declarations because there must have at least one enumeration.
     1991                        if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ?
     1992                                SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
    19891993                        }
    19901994                }
     
    20062010        | sue_declaration_specifier invalid_types
    20072011                {
    2008                         SemanticError( yylloc,
    2009                                                   ::toString( "Missing ';' after end of ",
    2010                                                                           $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ),
    2011                                                                           " declaration" ) );
     2012                        SemanticError( yylloc, ::toString( "Missing ';' after end of ",
     2013                                $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ),
     2014                                " declaration" ) );
    20122015                        $$ = nullptr;
    20132016                }
     
    25882591        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    25892592                {
    2590                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 )
     2593                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() )
    25912594                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    25922595
     
    25992602        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    26002603                {
    2601                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2604                        if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    26022605                        typedefTable.makeTypedef( *$6 );
    26032606                }
     
    30583061                { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); }
    30593062        | declaration
     3063                {
     3064                        // Variable declarations of anonymous types requires creating a unique type-name across multiple translation
     3065                        // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is
     3066                        // disallowed at the moment.
     3067                        if ( $1->linkage == LinkageSpec::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {
     3068                                if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) {
     3069                                        SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr;
     3070                                } else if ( $1->type->aggInst.aggregate->aggregate.anon ) { // handles struct or union
     3071                                        SemanticError( yylloc, "extern anonymous struct/union is currently unimplemented." ); $$ = nullptr;
     3072                                }
     3073                        }
     3074                }
    30603075        | IDENTIFIER IDENTIFIER
    30613076                { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; }
     
    31033118        | type_qualifier_list
    31043119                {
    3105                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3120                        if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    31063121                        if ( $1->type->forall ) forall = true;          // remember generic type
    31073122                }
     
    31143129        | declaration_qualifier_list
    31153130                {
    3116                         if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3131                        if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    31173132                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
    31183133                }
     
    31253140        | declaration_qualifier_list type_qualifier_list
    31263141                {
    3127                         if ( ($1->type && $1->type->qualifiers.val) || ($2->type && $2->type->qualifiers.val) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3142                        if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    31283143                        if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type
    31293144                }
Note: See TracChangeset for help on using the changeset viewer.