Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r0522ebe r44adf1b  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Nov 26 13:18:06 2023
    13 // Update Count     : 6398
     12// Last Modified On : Mon Mar  4 08:44:25 2024
     13// Update Count     : 6562
    1414//
    1515
     
    102102
    103103DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
    104         // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
     104        // Distribute type specifier across all declared variables, e.g., static, const, __attribute__.
    105105        assert( declList );
    106         // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
    107         DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
    108         // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
    109         // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
    110 
    111         for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    112                 cl->cloneBaseType( cur );
     106
     107        // Do not distribute attributes for aggregates because the attributes surrounding the aggregate belong it not the
     108        // variables in the declaration list, e.g.,
     109        //
     110        //   struct __attribute__(( aligned(128) )) S { ...
     111        //   } v1 __attribute__(( aligned(64) )), v2 __attribute__(( aligned(32) )), v3;
     112        //   struct S v4;
     113        //
     114        // v1 => 64, v2 =>32, v3 => 128, v2 => 128
     115        //
     116        // Anonymous aggregates are a special case because there is no aggregate to bind the attribute to; hence it floats
     117        // to the declaration list.
     118        //
     119        //   struct __attribute__(( aligned(128) )) /*anonymous */ { ... } v1;
     120        //
     121        // v1 => 128
     122
     123        bool copyattr = ! (typeSpec->type && typeSpec->type->kind == TypeData::Aggregate && ! typeSpec->type->aggregate.anon );
     124
     125        // addType copies the type information for the aggregate instances from typeSpec into cl's aggInst.aggregate.
     126        DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); // typeSpec IS DELETED!!!
     127
     128        // Start at second variable in declaration list and clone the type specifiers for each variable.
     129        for ( DeclarationNode * cur = declList->next ; cur != nullptr; cur = cur->next ) {
     130                cl->cloneBaseType( cur, copyattr );                             // cur is modified
    113131        } // for
    114         declList->addType( cl );
    115         // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
     132
     133        // Add first variable in declaration list with hidden type information in aggInst.aggregate, which is used by
     134        // extractType to recover the type for the aggregate instances.
     135        declList->addType( cl, copyattr );                                      // cl IS DELETED!!!
    116136        return declList;
    117137} // distAttr
     
    119139void distExt( DeclarationNode * declaration ) {
    120140        // distribute EXTENSION across all declarations
    121         for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     141        for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next ) {
    122142                iter->set_extension( true );
    123143        } // for
     
    126146void distInl( DeclarationNode * declaration ) {
    127147        // distribute INLINE across all declarations
    128         for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     148        for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next ) {
    129149                iter->set_inLine( true );
    130150        } // for
     
    133153void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
    134154        // distribute qualifiers across all non-variable declarations in a distribution statemement
    135         for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     155        for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next ) {
    136156                // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since
    137157                // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To
     
    192212                fieldList = DeclarationNode::newName( nullptr );
    193213        } // if
    194 //      return distAttr( typeSpec, fieldList );                         // mark all fields in list
    195214
    196215        // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
    197         DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
     216        DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list
    198217        // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
    199218        return temp;
     
    370389%token LE GE EQ NE                                                                              // <=   >=      ==      !=
    371390%token ANDAND OROR                                                                              // &&   ||
    372 %token ELLIPSIS                                                                                 // ...
     391%token ATTR ELLIPSIS                                                                    // @@   ...
    373392
    374393%token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
     
    414433%type<stmt> statement                                   labeled_statement                       compound_statement
    415434%type<stmt> statement_decl                              statement_decl_list                     statement_list_nodecl
    416 %type<stmt> selection_statement                 if_statement
     435%type<stmt> selection_statement
    417436%type<clause> switch_clause_list_opt    switch_clause_list
    418437%type<expr> case_value
     
    481500%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    482501
    483 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
     502%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_list_ellipsis_opt
    484503
    485504%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
     
    489508%type<decl> KR_parameter_list KR_parameter_list_opt
    490509
    491 %type<decl> parameter_declaration parameter_list parameter_type_list_opt
     510%type<decl> parameter_declaration parameter_list parameter_list_ellipsis_opt
    492511
    493512%type<decl> paren_identifier paren_type
     
    511530%type<decl> type_parameter type_parameter_list type_initializer_opt
    512531
    513 %type<expr> type_parameters_opt type_list array_type_list
     532%type<expr> type_parameters_opt type_list array_type_list // array_dimension_list
    514533
    515534%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    761780        | string_literal '`' identifier                                         // CFA, postfix call
    762781                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
     782
     783                // SKULLDUGGERY: The typedef table used for parsing does not store fields in structures. To parse a qualified
     784                // name, it is assumed all name-tokens after the first are identifiers, regardless of how the lexer identifies
     785        // them. For example:
     786                //   
     787                //   struct S;
     788                //   forall(T) struct T;
     789                //   union U;
     790                //   enum E { S, T, E };
     791                //   struct Z { int S, T, Z, E, U; };
     792                //   void fred () {
     793                //       Z z;
     794                //       z.S;  // lexer returns S is TYPEDEFname
     795                //       z.T;  // lexer returns T is TYPEGENname
     796                //       z.Z;  // lexer returns Z is TYPEDEFname
     797                //       z.U;  // lexer returns U is TYPEDEFname
     798                //       z.E;  // lexer returns E is TYPEDEFname
     799                //   }
    763800        | postfix_expression '.' identifier
    764801                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     802        | postfix_expression '.' TYPEDEFname                            // CFA, SKULLDUGGERY
     803                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     804        | postfix_expression '.' TYPEGENname                            // CFA, SKULLDUGGERY
     805                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     806
    765807        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
    766808                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); }
     
    10391081        | logical_OR_expression '?' comma_expression ':' conditional_expression
    10401082                { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); }
    1041                 // FIX ME: computes $1 twice
    10421083        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    1043                 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }
     1084                { $$ = new ExpressionNode( build_cond( yylloc, $1, nullptr, $4 ) ); }
    10441085        ;
    10451086
     
    12051246        ;
    12061247
     1248// if, switch, and choose require parenthesis around the conditional because it can be followed by a statement.
     1249// For example, without parenthesis:
     1250//
     1251//    if x + y + z; => "if ( x + y ) + z" or "if ( x ) + y + z"
     1252//    switch ( S ) { ... } => switch ( S ) { compound literal... } ... or
     1253
    12071254selection_statement:
    1208                         // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
    1209                         // the inherent S/R conflict with THEN/ELSE.
    1210         push if_statement pop
    1211                 { $$ = $2; }
     1255        IF '(' conditional_declaration ')' statement            %prec THEN
     1256                // explicitly deal with the shift/reduce conflict on if/else
     1257                { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); }
     1258        | IF '(' conditional_declaration ')' statement ELSE statement
     1259                { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); }
    12121260        | SWITCH '(' comma_expression ')' case_clause
    12131261                { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); }
     
    12331281        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule
    12341282                { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
    1235         ;
    1236 
    1237 if_statement:
    1238         IF '(' conditional_declaration ')' statement            %prec THEN
    1239                 // explicitly deal with the shift/reduce conflict on if/else
    1240                 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); }
    1241         | IF '(' conditional_declaration ')' statement ELSE statement
    1242                 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); }
    12431283        ;
    12441284
     
    18571897        declaration
    18581898        | declaration_list declaration
    1859                 { $$ = $1->appendList( $2 ); }
     1899                { $$ = $1->set_last( $2 ); }
    18601900        ;
    18611901
     
    18701910                { $$ = $1; }
    18711911        | KR_parameter_list c_declaration ';'
    1872                 { $$ = $1->appendList( $2 ); }
     1912                { $$ = $1->set_last( $2 ); }
    18731913        ;
    18741914
     
    18901930declaration:                                                                                    // old & new style declarations
    18911931        c_declaration ';'
    1892                 {
    1893                         // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
    1894                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    1895                         //   printf( "\tattr %s\n", attr->name.c_str() );
    1896                         // } // for
    1897                 }
    18981932        | cfa_declaration ';'                                                           // CFA
    18991933        | static_assert                                                                         // C11
     
    19341968                { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
    19351969        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1936                 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
     1970                { $$ = $1->set_last( $1->cloneType( $5 )->addInitializer( $6 ) ); }
    19371971        ;
    19381972
     
    19561990        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    19571991                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1958         | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1992        | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')'
    19591993                {
    19601994                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    19611995                        DeclarationNode * ret = new DeclarationNode;
    19621996                        ret->type = maybeCopy( $1->type->base );
    1963                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
     1997                        $$ = $1->set_last( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
    19641998                }
    19651999        ;
    19662000
    19672001cfa_function_specifier:                                                                 // CFA
    1968 //      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
    1969 //              {
    1970 //                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, nullptr, true );
    1971 //              }
    1972 //      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
    1973 //              {
    1974 //                      typedefTable.setNextIdentifier( *$5 );
    1975 //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true );
    1976 //              }
    1977 //      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
    1978 //              {
    1979 //                      typedefTable.setNextIdentifier( *$5 );
    1980 //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true );
    1981 //              }
    1982 //      | '[' ']' typegen_name
     2002        '[' ']' identifier '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
     2003                { $$ = DeclarationNode::newFunction( $3,  DeclarationNode::newTuple( nullptr ), $6, nullptr )->addQualifiers( $9 ); }
     2004        | '[' ']' TYPEDEFname '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
     2005                { $$ = DeclarationNode::newFunction( $3,  DeclarationNode::newTuple( nullptr ), $6, nullptr )->addQualifiers( $9 ); }
     2006        // | '[' ']' TYPEGENname '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
     2007        //      { $$ = DeclarationNode::newFunction( $3,  DeclarationNode::newTuple( nullptr ), $6, nullptr )->addQualifiers( $9 ); }
     2008
    19832009                // identifier_or_type_name must be broken apart because of the sequence:
    19842010                //
    1985                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
     2011                //   '[' ']' identifier_or_type_name '(' cfa_parameter_list_ellipsis_opt ')'
    19862012                //   '[' ']' type_specifier
    19872013                //
    19882014                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    19892015                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1990         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
     2016        | cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
    19912017                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    19922018                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
    1993         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
     2019        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
    19942020                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
    19952021        ;
     
    19982024        '[' push cfa_parameter_list pop ']'
    19992025                { $$ = DeclarationNode::newTuple( $3 ); }
    2000         | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
     2026        | '[' push cfa_parameter_list ',' cfa_abstract_parameter_list pop ']'
    20012027                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
    2002                 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
     2028                { $$ = DeclarationNode::newTuple( $3->set_last( $5 ) ); }
    20032029        ;
    20042030
     
    20142040                        $$ = $2->addTypedef();
    20152041                }
    2016         | cfa_typedef_declaration pop ',' push identifier
    2017                 {
    2018                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "cfa_typedef_declaration 3" );
    2019                         $$ = $1->appendList( $1->cloneType( $5 ) );
     2042        | cfa_typedef_declaration ',' identifier
     2043                {
     2044                        typedefTable.addToEnclosingScope( *$3, TYPEDEFname, "cfa_typedef_declaration 3" );
     2045                        $$ = $1->set_last( $1->cloneType( $3 ) );
    20202046                }
    20212047        ;
     
    20352061                {
    20362062                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 2" );
    2037                         $$ = $1->appendList( $1->cloneBaseType( $3 )->addTypedef() );
     2063                        $$ = $1->set_last( $1->cloneBaseType( $3 )->addTypedef() );
    20382064                }
    20392065        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
     
    20892115
    20902116        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    2091                 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     2117                { $$ = $1->set_last( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
    20922118        ;
    20932119
     
    23482374sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
    23492375        sue_type_specifier
    2350                 {
    2351                         // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2352                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2353                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2354                         // } // for
    2355                 }
    23562376        | declaration_qualifier_list sue_type_specifier
    23572377                { $$ = $2->addQualifiers( $1 ); }
     
    23642384sue_type_specifier:                                                                             // struct, union, enum + type specifier
    23652385        elaborated_type
    2366                 {
    2367                         // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2368                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2369                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2370                         // } // for
    2371                 }
    23722386        | type_qualifier_list
    23732387                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     
    24422456elaborated_type:                                                                                // struct, union, enum
    24432457        aggregate_type
    2444                 {
    2445                         // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2446                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2447                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2448                         // } // for
    2449                 }
    24502458        | enum_type
    24512459        ;
     
    25712579                { $$ = nullptr; }
    25722580        | field_declaration_list_opt field_declaration
    2573                 { $$ = $1 ? $1->appendList( $2 ) : $2; }
     2581                { $$ = $1 ? $1->set_last( $2 ) : $2; }
    25742582        ;
    25752583
     
    26192627        | field_declarator
    26202628        | field_declaring_list_opt ',' attribute_list_opt field_declarator
    2621                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     2629                { $$ = $1->set_last( $4->addQualifiers( $3 ) ); }
    26222630        ;
    26232631
     
    26412649        | field_abstract
    26422650        | field_abstract_list_opt ',' attribute_list_opt field_abstract
    2643                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     2651                { $$ = $1->set_last( $4->addQualifiers( $3 ) ); }
    26442652        ;
    26452653
     
    26542662                { $$ = $1->addName( $2 ); }
    26552663        | cfa_field_declaring_list ',' identifier_or_type_name
    2656                 { $$ = $1->appendList( $1->cloneType( $3 ) ); }
     2664                { $$ = $1->set_last( $1->cloneType( $3 ) ); }
    26572665        ;
    26582666
     
    26612669        cfa_abstract_declarator_tuple
    26622670        | cfa_field_abstract_list ','
    2663                 { $$ = $1->appendList( $1->cloneType( 0 ) ); }
     2671                { $$ = $1->set_last( $1->cloneType( 0 ) ); }
    26642672        ;
    26652673
     
    26752683        ;
    26762684
     2685// ***********
     2686// Enumeration
     2687// ***********
     2688
    26772689enum_type:
    26782690        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    26792691                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    26802692        | ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
    2681                 { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2693                { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    26822694        | ENUM attribute_list_opt identifier
    26832695                { typedefTable.makeTypedef( *$3, "enum_type 1" ); }
     
    26942706                }
    26952707        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name
    2696                 { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2708                { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    26972709        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    26982710                {
     
    27002712                }
    27012713        | ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
    2702                 { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2714                { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    27032715        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    27042716                {
    2705                         if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) {
     2717                        if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0) ) {
    27062718                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    27072719                        }
     
    27532765                { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); }
    27542766        | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt
    2755                 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }
     2767                { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }
    27562768        | enumerator_list ',' INLINE type_name enumerator_value_opt
    2757                 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }
     2769                { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }
    27582770        ;
    27592771
     
    27732785        ;
    27742786
    2775 cfa_parameter_ellipsis_list_opt:                                                // CFA, abstract + real
    2776         // empty
    2777                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
    2778         | ELLIPSIS
    2779                 { $$ = nullptr; }
    2780         | cfa_abstract_parameter_list
    2781         | cfa_parameter_list
    2782         | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
    2783                 { $$ = $1->appendList( $5 ); }
    2784         | cfa_abstract_parameter_list pop ',' push ELLIPSIS
    2785                 { $$ = $1->addVarArgs(); }
    2786         | cfa_parameter_list pop ',' push ELLIPSIS
    2787                 { $$ = $1->addVarArgs(); }
    2788         ;
    2789 
    2790 cfa_parameter_list:                                                                             // CFA
    2791                 // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is
    2792                 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
    2793         cfa_parameter_declaration
    2794         | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
    2795                 { $$ = $1->appendList( $5 ); }
    2796         | cfa_parameter_list pop ',' push cfa_parameter_declaration
    2797                 { $$ = $1->appendList( $5 ); }
    2798         | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
    2799                 { $$ = $1->appendList( $5 )->appendList( $9 ); }
    2800         ;
    2801 
    2802 cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
    2803         cfa_abstract_parameter_declaration
    2804         | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
    2805                 { $$ = $1->appendList( $5 ); }
    2806         ;
    2807 
    2808 parameter_type_list_opt:
     2787// *******************
     2788// Function parameters
     2789// *******************
     2790
     2791parameter_list_ellipsis_opt:
    28092792        // empty
    28102793                { $$ = nullptr; }
     
    28172800
    28182801parameter_list:                                                                                 // abstract + real
    2819         abstract_parameter_declaration
    2820         | parameter_declaration
     2802        parameter_declaration
     2803        | abstract_parameter_declaration
     2804        | parameter_list ',' parameter_declaration
     2805                { $$ = $1->set_last( $3 ); }
    28212806        | parameter_list ',' abstract_parameter_declaration
    2822                 { $$ = $1->appendList( $3 ); }
    2823         | parameter_list ',' parameter_declaration
    2824                 { $$ = $1->appendList( $3 ); }
     2807                { $$ = $1->set_last( $3 ); }
     2808        ;
     2809
     2810cfa_parameter_list_ellipsis_opt:                                                // CFA, abstract + real
     2811        // empty
     2812                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     2813        | ELLIPSIS
     2814                { $$ = nullptr; }
     2815        | cfa_parameter_list
     2816        | cfa_abstract_parameter_list
     2817        | cfa_parameter_list ',' cfa_abstract_parameter_list
     2818                { $$ = $1->set_last( $3 ); }
     2819        | cfa_parameter_list ',' ELLIPSIS
     2820                { $$ = $1->addVarArgs(); }
     2821        | cfa_abstract_parameter_list ',' ELLIPSIS
     2822                { $$ = $1->addVarArgs(); }
     2823        ;
     2824
     2825cfa_parameter_list:                                                                             // CFA
     2826                // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is
     2827                // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
     2828        cfa_parameter_declaration
     2829        | cfa_abstract_parameter_list ',' cfa_parameter_declaration
     2830                { $$ = $1->set_last( $3 ); }
     2831        | cfa_parameter_list ',' cfa_parameter_declaration
     2832                { $$ = $1->set_last( $3 ); }
     2833        | cfa_parameter_list ',' cfa_abstract_parameter_list ',' cfa_parameter_declaration
     2834                { $$ = $1->set_last( $3 )->set_last( $5 ); }
     2835        ;
     2836
     2837cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
     2838        cfa_abstract_parameter_declaration
     2839        | cfa_abstract_parameter_list ',' cfa_abstract_parameter_declaration
     2840                { $$ = $1->set_last( $3 ); }
    28252841        ;
    28262842
    28272843// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
    28282844// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
     2845
     2846parameter_declaration:
     2847                // No SUE declaration in parameter list.
     2848        declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt
     2849                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2850        | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt
     2851                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2852        ;
     2853
     2854abstract_parameter_declaration:
     2855        declaration_specifier_nobody default_initializer_opt
     2856                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
     2857        | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt
     2858                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2859        ;
    28292860
    28302861cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
     
    28502881        ;
    28512882
    2852 parameter_declaration:
    2853                 // No SUE declaration in parameter list.
    2854         declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt
    2855                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    2856         | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt
    2857                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    2858         ;
    2859 
    2860 abstract_parameter_declaration:
    2861         declaration_specifier_nobody default_initializer_opt
    2862                 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
    2863         | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt
    2864                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    2865         ;
    2866 
    28672883// ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a
    28682884// parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on
     
    28732889                { $$ = DeclarationNode::newName( $1 ); }
    28742890        | identifier_list ',' identifier
    2875                 { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
     2891                { $$ = $1->set_last( DeclarationNode::newName( $3 ) ); }
    28762892        ;
    28772893
     
    29742990        type_parameter
    29752991        | type_parameter_list ',' type_parameter
    2976                 { $$ = $1->appendList( $3 ); }
     2992                { $$ = $1->set_last( $3 ); }
    29772993        ;
    29782994
     
    30473063        assertion
    30483064        | assertion_list assertion
    3049                 { $$ = $1->appendList( $2 ); }
     3065                { $$ = $1->set_last( $2 ); }
    30503066        ;
    30513067
     
    30753091                { $$ = $3->addQualifiers( $1 ); }
    30763092        | type_declaring_list ',' type_declarator
    3077                 { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); }
     3093                { $$ = $1->set_last( $3->copySpecifiers( $1 ) ); }
    30783094        ;
    30793095
     
    31183134        trait_declaration
    31193135        | trait_declaration_list pop push trait_declaration
    3120                 { $$ = $1->appendList( $4 ); }
     3136                { $$ = $1->set_last( $4 ); }
    31213137        ;
    31223138
     
    31303146        | cfa_function_specifier
    31313147        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    3132                 { $$ = $1->appendList( $1->cloneType( $5 ) ); }
     3148                { $$ = $1->set_last( $1->cloneType( $5 ) ); }
    31333149        ;
    31343150
     
    31373153                { $$ = $2->addType( $1 ); }
    31383154        | trait_declaring_list pop ',' push declarator
    3139                 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
     3155                { $$ = $1->set_last( $1->cloneBaseType( $5 ) ); }
    31403156        ;
    31413157
     
    31453161        // empty, input file
    31463162        | external_definition_list
    3147                 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     3163                { parseTree = parseTree ? parseTree->set_last( $1 ) : $1;       }
    31483164        ;
    31493165
     
    31523168                { $$ = $2; }
    31533169        | external_definition_list push external_definition pop
    3154                 { $$ = $1 ? $1->appendList( $3 ) : $3; }
     3170                { $$ = $1 ? $1->set_last( $3 ) : $3; }
    31553171        ;
    31563172
     
    31773193                        // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is
    31783194                        // disallowed at the moment.
    3179                         if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {
     3195                        if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static &&
     3196                                 $1->type && $1->type->kind == TypeData::AggregateInst ) {
    31803197                                if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) {
    31813198                                        SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr;
     
    33783395        ATTRIBUTE '(' '(' attribute_name_list ')' ')'
    33793396                { $$ = $4; }
     3397        | ATTRIBUTE '(' attribute_name_list ')'                         // CFA
     3398                { $$ = $3; }
     3399        | ATTR '(' attribute_name_list ')'                                      // CFA
     3400                { $$ = $3; }
    33803401        ;
    33813402
     
    34823503
    34833504variable_function:
    3484         '(' variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3505        '(' variable_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    34853506                { $$ = $2->addParamList( $5 ); }
    3486         | '(' attribute_list variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3507        | '(' attribute_list variable_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    34873508                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    34883509        | '(' variable_function ')'                                                     // redundant parenthesis
     
    35053526
    35063527function_no_ptr:
    3507         paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3528        paren_identifier '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    35083529                { $$ = $1->addParamList( $3 ); }
    3509         | '(' function_ptr ')' '(' parameter_type_list_opt ')'
     3530        | '(' function_ptr ')' '(' parameter_list_ellipsis_opt ')'
    35103531                { $$ = $2->addParamList( $5 ); }
    3511         | '(' attribute_list function_ptr ')' '(' parameter_type_list_opt ')'
     3532        | '(' attribute_list function_ptr ')' '(' parameter_list_ellipsis_opt ')'
    35123533                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    35133534        | '(' function_no_ptr ')'                                                       // redundant parenthesis
     
    35593580        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
    35603581                { $$ = $1->addIdList( $3 ); }
    3561         | '(' KR_function_ptr ')' '(' parameter_type_list_opt ')'
     3582        | '(' KR_function_ptr ')' '(' parameter_list_ellipsis_opt ')'
    35623583                { $$ = $2->addParamList( $5 ); }
    3563         | '(' attribute_list KR_function_ptr ')' '(' parameter_type_list_opt ')'
     3584        | '(' attribute_list KR_function_ptr ')' '(' parameter_list_ellipsis_opt ')'
    35643585                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    35653586        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
     
    36513672
    36523673variable_type_function:
    3653         '(' variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3674        '(' variable_type_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    36543675                { $$ = $2->addParamList( $5 ); }
    3655         | '(' attribute_list variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3676        | '(' attribute_list variable_type_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    36563677                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    36573678        | '(' variable_type_function ')'                                        // redundant parenthesis
     
    36743695
    36753696function_type_no_ptr:
    3676         paren_type '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3697        paren_type '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    36773698                { $$ = $1->addParamList( $3 ); }
    3678         | '(' function_type_ptr ')' '(' parameter_type_list_opt ')'
     3699        | '(' function_type_ptr ')' '(' parameter_list_ellipsis_opt ')'
    36793700                { $$ = $2->addParamList( $5 ); }
    3680         | '(' attribute_list function_type_ptr ')' '(' parameter_type_list_opt ')'
     3701        | '(' attribute_list function_type_ptr ')' '(' parameter_list_ellipsis_opt ')'
    36813702                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    36823703        | '(' function_type_no_ptr ')'                                          // redundant parenthesis
     
    37213742                { $$ = $1->addQualifiers( $2 ); }
    37223743        | '&' MUTEX paren_identifier attribute_list_opt
    3723                 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
     3744                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ),
     3745                                                                                                                        OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    37243746        | identifier_parameter_ptr
    37253747        | identifier_parameter_array attribute_list_opt
     
    37503772
    37513773identifier_parameter_function:
    3752         paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3774        paren_identifier '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    37533775                { $$ = $1->addParamList( $3 ); }
    3754         | '(' identifier_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3776        | '(' identifier_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    37553777                { $$ = $2->addParamList( $5 ); }
    37563778        | '(' identifier_parameter_function ')'                         // redundant parenthesis
     
    37713793                { $$ = $1->addQualifiers( $2 ); }
    37723794        | '&' MUTEX typedef_name attribute_list_opt
    3773                 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
     3795                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ),
     3796                                                                                                                        OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    37743797        | type_parameter_ptr
    37753798        | type_parameter_array attribute_list_opt
     
    38033826
    38043827type_parameter_function:
    3805         typedef_name '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3828        typedef_name '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    38063829                { $$ = $1->addParamList( $3 ); }
    3807         | '(' type_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3830        | '(' type_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    38083831                { $$ = $2->addParamList( $5 ); }
    38093832        ;
     
    38533876
    38543877abstract_function:
    3855         '(' parameter_type_list_opt ')'                 // empty parameter list OBSOLESCENT (see 3)
     3878        '(' parameter_list_ellipsis_opt ')'                     // empty parameter list OBSOLESCENT (see 3)
    38563879                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    3857         | '(' abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3880        | '(' abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    38583881                { $$ = $2->addParamList( $5 ); }
    38593882        | '(' abstract_function ')'                                                     // redundant parenthesis
     
    38713894                { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); }
    38723895                // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
     3896
     3897                // If needed, the following parses and does not use comma_expression, so the array structure can be built.
     3898        // | '[' push assignment_expression pop ',' push array_dimension_list pop ']' // CFA
     3899
    38733900        | '[' push array_type_list pop ']'                                      // CFA
    38743901                { $$ = DeclarationNode::newArray( $3, nullptr, false ); }
    38753902        | multi_array_dimension
    38763903        ;
     3904
     3905// array_dimension_list:
     3906//      assignment_expression
     3907//      | array_dimension_list ',' assignment_expression
     3908//      ;
    38773909
    38783910array_type_list:
     
    39764008
    39774009abstract_parameter_function:
    3978         '(' parameter_type_list_opt ')'                 // empty parameter list OBSOLESCENT (see 3)
     4010        '(' parameter_list_ellipsis_opt ')'                     // empty parameter list OBSOLESCENT (see 3)
    39794011                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    3980         | '(' abstract_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     4012        | '(' abstract_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    39814013                { $$ = $2->addParamList( $5 ); }
    39824014        | '(' abstract_parameter_function ')'                           // redundant parenthesis
     
    40554087
    40564088variable_abstract_function:
    4057         '(' variable_abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
     4089        '(' variable_abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
    40584090                { $$ = $2->addParamList( $5 ); }
    40594091        | '(' variable_abstract_function ')'                            // redundant parenthesis
     
    41414173//
    41424174//              cfa_abstract_tuple identifier_or_type_name
    4143 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
     4175//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_list_ellipsis_opt ')'
    41444176//
    41454177// since a function return type can be syntactically identical to a tuple type:
     
    42074239
    42084240cfa_abstract_function:                                                                  // CFA
    4209 //      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
    4210 //              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    4211         cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
     4241        '[' ']' '(' cfa_parameter_list_ellipsis_opt ')'
     4242                { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
     4243        | cfa_abstract_tuple '(' push cfa_parameter_list_ellipsis_opt pop ')'
    42124244                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    4213         | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
     4245        | cfa_function_return '(' push cfa_parameter_list_ellipsis_opt pop ')'
    42144246                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    42154247        ;
Note: See TracChangeset for help on using the changeset viewer.