Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r44adf1b r0522ebe  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  4 08:44:25 2024
    13 // Update Count     : 6562
     12// Last Modified On : Sun Nov 26 13:18:06 2023
     13// Update Count     : 6398
    1414//
    1515
     
    102102
    103103DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
    104         // Distribute type specifier across all declared variables, e.g., static, const, __attribute__.
     104        // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
    105105        assert( declList );
    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
     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 );
    131113        } // for
    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!!!
     114        declList->addType( cl );
     115        // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
    136116        return declList;
    137117} // distAttr
     
    139119void distExt( DeclarationNode * declaration ) {
    140120        // distribute EXTENSION across all declarations
    141         for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next ) {
     121        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    142122                iter->set_extension( true );
    143123        } // for
     
    146126void distInl( DeclarationNode * declaration ) {
    147127        // distribute INLINE across all declarations
    148         for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next ) {
     128        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    149129                iter->set_inLine( true );
    150130        } // for
     
    153133void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
    154134        // distribute qualifiers across all non-variable declarations in a distribution statemement
    155         for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next ) {
     135        for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    156136                // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since
    157137                // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To
     
    212192                fieldList = DeclarationNode::newName( nullptr );
    213193        } // if
     194//      return distAttr( typeSpec, fieldList );                         // mark all fields in list
    214195
    215196        // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
    216         DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list
     197        DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
    217198        // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
    218199        return temp;
     
    389370%token LE GE EQ NE                                                                              // <=   >=      ==      !=
    390371%token ANDAND OROR                                                                              // &&   ||
    391 %token ATTR ELLIPSIS                                                                    // @@   ...
     372%token ELLIPSIS                                                                                 // ...
    392373
    393374%token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
     
    433414%type<stmt> statement                                   labeled_statement                       compound_statement
    434415%type<stmt> statement_decl                              statement_decl_list                     statement_list_nodecl
    435 %type<stmt> selection_statement
     416%type<stmt> selection_statement                 if_statement
    436417%type<clause> switch_clause_list_opt    switch_clause_list
    437418%type<expr> case_value
     
    500481%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    501482
    502 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_list_ellipsis_opt
     483%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
    503484
    504485%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
     
    508489%type<decl> KR_parameter_list KR_parameter_list_opt
    509490
    510 %type<decl> parameter_declaration parameter_list parameter_list_ellipsis_opt
     491%type<decl> parameter_declaration parameter_list parameter_type_list_opt
    511492
    512493%type<decl> paren_identifier paren_type
     
    530511%type<decl> type_parameter type_parameter_list type_initializer_opt
    531512
    532 %type<expr> type_parameters_opt type_list array_type_list // array_dimension_list
     513%type<expr> type_parameters_opt type_list array_type_list
    533514
    534515%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    780761        | string_literal '`' identifier                                         // CFA, postfix call
    781762                { $$ = 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                 //   }
    800763        | postfix_expression '.' identifier
    801764                { $$ = 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 
    807765        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
    808766                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); }
     
    10811039        | logical_OR_expression '?' comma_expression ':' conditional_expression
    10821040                { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); }
     1041                // FIX ME: computes $1 twice
    10831042        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    1084                 { $$ = new ExpressionNode( build_cond( yylloc, $1, nullptr, $4 ) ); }
     1043                { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }
    10851044        ;
    10861045
     
    12461205        ;
    12471206
    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 
    12541207selection_statement:
    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 ) ) ); }
     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; }
    12601212        | SWITCH '(' comma_expression ')' case_clause
    12611213                { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); }
     
    12811233        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule
    12821234                { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
     1235        ;
     1236
     1237if_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 ) ) ); }
    12831243        ;
    12841244
     
    18971857        declaration
    18981858        | declaration_list declaration
    1899                 { $$ = $1->set_last( $2 ); }
     1859                { $$ = $1->appendList( $2 ); }
    19001860        ;
    19011861
     
    19101870                { $$ = $1; }
    19111871        | KR_parameter_list c_declaration ';'
    1912                 { $$ = $1->set_last( $2 ); }
     1872                { $$ = $1->appendList( $2 ); }
    19131873        ;
    19141874
     
    19301890declaration:                                                                                    // old & new style declarations
    19311891        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                }
    19321898        | cfa_declaration ';'                                                           // CFA
    19331899        | static_assert                                                                         // C11
     
    19681934                { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
    19691935        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1970                 { $$ = $1->set_last( $1->cloneType( $5 )->addInitializer( $6 ) ); }
     1936                { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
    19711937        ;
    19721938
     
    19901956        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    19911957                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1992         | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')'
     1958        | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    19931959                {
    19941960                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    19951961                        DeclarationNode * ret = new DeclarationNode;
    19961962                        ret->type = maybeCopy( $1->type->base );
    1997                         $$ = $1->set_last( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
     1963                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
    19981964                }
    19991965        ;
    20001966
    20011967cfa_function_specifier:                                                                 // CFA
    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 
     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
    20091983                // identifier_or_type_name must be broken apart because of the sequence:
    20101984                //
    2011                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_list_ellipsis_opt ')'
     1985                //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    20121986                //   '[' ']' type_specifier
    20131987                //
    20141988                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    20151989                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    2016         | cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
     1990        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    20171991                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    20181992                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
    2019         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt
     1993        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    20201994                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
    20211995        ;
     
    20241998        '[' push cfa_parameter_list pop ']'
    20251999                { $$ = DeclarationNode::newTuple( $3 ); }
    2026         | '[' push cfa_parameter_list ',' cfa_abstract_parameter_list pop ']'
     2000        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
    20272001                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
    2028                 { $$ = DeclarationNode::newTuple( $3->set_last( $5 ) ); }
     2002                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    20292003        ;
    20302004
     
    20402014                        $$ = $2->addTypedef();
    20412015                }
    2042         | cfa_typedef_declaration ',' identifier
    2043                 {
    2044                         typedefTable.addToEnclosingScope( *$3, TYPEDEFname, "cfa_typedef_declaration 3" );
    2045                         $$ = $1->set_last( $1->cloneType( $3 ) );
     2016        | cfa_typedef_declaration pop ',' push identifier
     2017                {
     2018                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "cfa_typedef_declaration 3" );
     2019                        $$ = $1->appendList( $1->cloneType( $5 ) );
    20462020                }
    20472021        ;
     
    20612035                {
    20622036                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 2" );
    2063                         $$ = $1->set_last( $1->cloneBaseType( $3 )->addTypedef() );
     2037                        $$ = $1->appendList( $1->cloneBaseType( $3 )->addTypedef() );
    20642038                }
    20652039        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
     
    21152089
    21162090        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    2117                 { $$ = $1->set_last( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     2091                { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
    21182092        ;
    21192093
     
    23742348sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
    23752349        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                }
    23762356        | declaration_qualifier_list sue_type_specifier
    23772357                { $$ = $2->addQualifiers( $1 ); }
     
    23842364sue_type_specifier:                                                                             // struct, union, enum + type specifier
    23852365        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                }
    23862372        | type_qualifier_list
    23872373                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     
    24562442elaborated_type:                                                                                // struct, union, enum
    24572443        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                }
    24582450        | enum_type
    24592451        ;
     
    25792571                { $$ = nullptr; }
    25802572        | field_declaration_list_opt field_declaration
    2581                 { $$ = $1 ? $1->set_last( $2 ) : $2; }
     2573                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    25822574        ;
    25832575
     
    26272619        | field_declarator
    26282620        | field_declaring_list_opt ',' attribute_list_opt field_declarator
    2629                 { $$ = $1->set_last( $4->addQualifiers( $3 ) ); }
     2621                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    26302622        ;
    26312623
     
    26492641        | field_abstract
    26502642        | field_abstract_list_opt ',' attribute_list_opt field_abstract
    2651                 { $$ = $1->set_last( $4->addQualifiers( $3 ) ); }
     2643                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    26522644        ;
    26532645
     
    26622654                { $$ = $1->addName( $2 ); }
    26632655        | cfa_field_declaring_list ',' identifier_or_type_name
    2664                 { $$ = $1->set_last( $1->cloneType( $3 ) ); }
     2656                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    26652657        ;
    26662658
     
    26692661        cfa_abstract_declarator_tuple
    26702662        | cfa_field_abstract_list ','
    2671                 { $$ = $1->set_last( $1->cloneType( 0 ) ); }
     2663                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
    26722664        ;
    26732665
     
    26832675        ;
    26842676
    2685 // ***********
    2686 // Enumeration
    2687 // ***********
    2688 
    26892677enum_type:
    26902678        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    26912679                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    26922680        | ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
    2693                 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2681                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    26942682        | ENUM attribute_list_opt identifier
    26952683                { typedefTable.makeTypedef( *$3, "enum_type 1" ); }
     
    27062694                }
    27072695        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name
    2708                 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2696                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    27092697        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    27102698                {
     
    27122700                }
    27132701        | ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
    2714                 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2702                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    27152703        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    27162704                {
    2717                         if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0) ) {
     2705                        if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) {
    27182706                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    27192707                        }
     
    27652753                { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); }
    27662754        | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt
    2767                 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }
     2755                { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }
    27682756        | enumerator_list ',' INLINE type_name enumerator_value_opt
    2769                 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }
     2757                { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }
    27702758        ;
    27712759
     
    27852773        ;
    27862774
    2787 // *******************
    2788 // Function parameters
    2789 // *******************
    2790 
    2791 parameter_list_ellipsis_opt:
     2775cfa_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
     2790cfa_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
     2802cfa_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
     2808parameter_type_list_opt:
    27922809        // empty
    27932810                { $$ = nullptr; }
     
    28002817
    28012818parameter_list:                                                                                 // abstract + real
    2802         parameter_declaration
    2803         | abstract_parameter_declaration
     2819        abstract_parameter_declaration
     2820        | parameter_declaration
     2821        | parameter_list ',' abstract_parameter_declaration
     2822                { $$ = $1->appendList( $3 ); }
    28042823        | parameter_list ',' parameter_declaration
    2805                 { $$ = $1->set_last( $3 ); }
    2806         | parameter_list ',' abstract_parameter_declaration
    2807                 { $$ = $1->set_last( $3 ); }
    2808         ;
    2809 
    2810 cfa_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 
    2825 cfa_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 
    2837 cfa_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 ); }
     2824                { $$ = $1->appendList( $3 ); }
    28412825        ;
    28422826
    28432827// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
    28442828// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
    2845 
    2846 parameter_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 
    2854 abstract_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         ;
    28602829
    28612830cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
     
    28812850        ;
    28822851
     2852parameter_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
     2860abstract_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
    28832867// ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a
    28842868// parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on
     
    28892873                { $$ = DeclarationNode::newName( $1 ); }
    28902874        | identifier_list ',' identifier
    2891                 { $$ = $1->set_last( DeclarationNode::newName( $3 ) ); }
     2875                { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
    28922876        ;
    28932877
     
    29902974        type_parameter
    29912975        | type_parameter_list ',' type_parameter
    2992                 { $$ = $1->set_last( $3 ); }
     2976                { $$ = $1->appendList( $3 ); }
    29932977        ;
    29942978
     
    30633047        assertion
    30643048        | assertion_list assertion
    3065                 { $$ = $1->set_last( $2 ); }
     3049                { $$ = $1->appendList( $2 ); }
    30663050        ;
    30673051
     
    30913075                { $$ = $3->addQualifiers( $1 ); }
    30923076        | type_declaring_list ',' type_declarator
    3093                 { $$ = $1->set_last( $3->copySpecifiers( $1 ) ); }
     3077                { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); }
    30943078        ;
    30953079
     
    31343118        trait_declaration
    31353119        | trait_declaration_list pop push trait_declaration
    3136                 { $$ = $1->set_last( $4 ); }
     3120                { $$ = $1->appendList( $4 ); }
    31373121        ;
    31383122
     
    31463130        | cfa_function_specifier
    31473131        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    3148                 { $$ = $1->set_last( $1->cloneType( $5 ) ); }
     3132                { $$ = $1->appendList( $1->cloneType( $5 ) ); }
    31493133        ;
    31503134
     
    31533137                { $$ = $2->addType( $1 ); }
    31543138        | trait_declaring_list pop ',' push declarator
    3155                 { $$ = $1->set_last( $1->cloneBaseType( $5 ) ); }
     3139                { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
    31563140        ;
    31573141
     
    31613145        // empty, input file
    31623146        | external_definition_list
    3163                 { parseTree = parseTree ? parseTree->set_last( $1 ) : $1;       }
     3147                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
    31643148        ;
    31653149
     
    31683152                { $$ = $2; }
    31693153        | external_definition_list push external_definition pop
    3170                 { $$ = $1 ? $1->set_last( $3 ) : $3; }
     3154                { $$ = $1 ? $1->appendList( $3 ) : $3; }
    31713155        ;
    31723156
     
    31933177                        // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is
    31943178                        // disallowed at the moment.
    3195                         if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static &&
    3196                                  $1->type && $1->type->kind == TypeData::AggregateInst ) {
     3179                        if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {
    31973180                                if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) {
    31983181                                        SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr;
     
    33953378        ATTRIBUTE '(' '(' attribute_name_list ')' ')'
    33963379                { $$ = $4; }
    3397         | ATTRIBUTE '(' attribute_name_list ')'                         // CFA
    3398                 { $$ = $3; }
    3399         | ATTR '(' attribute_name_list ')'                                      // CFA
    3400                 { $$ = $3; }
    34013380        ;
    34023381
     
    35033482
    35043483variable_function:
    3505         '(' variable_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3484        '(' variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    35063485                { $$ = $2->addParamList( $5 ); }
    3507         | '(' attribute_list variable_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3486        | '(' attribute_list variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    35083487                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    35093488        | '(' variable_function ')'                                                     // redundant parenthesis
     
    35263505
    35273506function_no_ptr:
    3528         paren_identifier '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3507        paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    35293508                { $$ = $1->addParamList( $3 ); }
    3530         | '(' function_ptr ')' '(' parameter_list_ellipsis_opt ')'
     3509        | '(' function_ptr ')' '(' parameter_type_list_opt ')'
    35313510                { $$ = $2->addParamList( $5 ); }
    3532         | '(' attribute_list function_ptr ')' '(' parameter_list_ellipsis_opt ')'
     3511        | '(' attribute_list function_ptr ')' '(' parameter_type_list_opt ')'
    35333512                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    35343513        | '(' function_no_ptr ')'                                                       // redundant parenthesis
     
    35803559        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
    35813560                { $$ = $1->addIdList( $3 ); }
    3582         | '(' KR_function_ptr ')' '(' parameter_list_ellipsis_opt ')'
     3561        | '(' KR_function_ptr ')' '(' parameter_type_list_opt ')'
    35833562                { $$ = $2->addParamList( $5 ); }
    3584         | '(' attribute_list KR_function_ptr ')' '(' parameter_list_ellipsis_opt ')'
     3563        | '(' attribute_list KR_function_ptr ')' '(' parameter_type_list_opt ')'
    35853564                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    35863565        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
     
    36723651
    36733652variable_type_function:
    3674         '(' variable_type_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3653        '(' variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    36753654                { $$ = $2->addParamList( $5 ); }
    3676         | '(' attribute_list variable_type_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3655        | '(' attribute_list variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    36773656                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    36783657        | '(' variable_type_function ')'                                        // redundant parenthesis
     
    36953674
    36963675function_type_no_ptr:
    3697         paren_type '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3676        paren_type '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    36983677                { $$ = $1->addParamList( $3 ); }
    3699         | '(' function_type_ptr ')' '(' parameter_list_ellipsis_opt ')'
     3678        | '(' function_type_ptr ')' '(' parameter_type_list_opt ')'
    37003679                { $$ = $2->addParamList( $5 ); }
    3701         | '(' attribute_list function_type_ptr ')' '(' parameter_list_ellipsis_opt ')'
     3680        | '(' attribute_list function_type_ptr ')' '(' parameter_type_list_opt ')'
    37023681                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
    37033682        | '(' function_type_no_ptr ')'                                          // redundant parenthesis
     
    37423721                { $$ = $1->addQualifiers( $2 ); }
    37433722        | '&' MUTEX paren_identifier attribute_list_opt
    3744                 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ),
    3745                                                                                                                         OperKinds::AddressOf ) )->addQualifiers( $4 ); }
     3723                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    37463724        | identifier_parameter_ptr
    37473725        | identifier_parameter_array attribute_list_opt
     
    37723750
    37733751identifier_parameter_function:
    3774         paren_identifier '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3752        paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    37753753                { $$ = $1->addParamList( $3 ); }
    3776         | '(' identifier_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3754        | '(' identifier_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    37773755                { $$ = $2->addParamList( $5 ); }
    37783756        | '(' identifier_parameter_function ')'                         // redundant parenthesis
     
    37933771                { $$ = $1->addQualifiers( $2 ); }
    37943772        | '&' MUTEX typedef_name attribute_list_opt
    3795                 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ),
    3796                                                                                                                         OperKinds::AddressOf ) )->addQualifiers( $4 ); }
     3773                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    37973774        | type_parameter_ptr
    37983775        | type_parameter_array attribute_list_opt
     
    38263803
    38273804type_parameter_function:
    3828         typedef_name '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3805        typedef_name '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    38293806                { $$ = $1->addParamList( $3 ); }
    3830         | '(' type_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3807        | '(' type_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    38313808                { $$ = $2->addParamList( $5 ); }
    38323809        ;
     
    38763853
    38773854abstract_function:
    3878         '(' parameter_list_ellipsis_opt ')'                     // empty parameter list OBSOLESCENT (see 3)
     3855        '(' parameter_type_list_opt ')'                 // empty parameter list OBSOLESCENT (see 3)
    38793856                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    3880         | '(' abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3857        | '(' abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    38813858                { $$ = $2->addParamList( $5 ); }
    38823859        | '(' abstract_function ')'                                                     // redundant parenthesis
     
    38943871                { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); }
    38953872                // { 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 
    39003873        | '[' push array_type_list pop ']'                                      // CFA
    39013874                { $$ = DeclarationNode::newArray( $3, nullptr, false ); }
    39023875        | multi_array_dimension
    39033876        ;
    3904 
    3905 // array_dimension_list:
    3906 //      assignment_expression
    3907 //      | array_dimension_list ',' assignment_expression
    3908 //      ;
    39093877
    39103878array_type_list:
     
    40083976
    40093977abstract_parameter_function:
    4010         '(' parameter_list_ellipsis_opt ')'                     // empty parameter list OBSOLESCENT (see 3)
     3978        '(' parameter_type_list_opt ')'                 // empty parameter list OBSOLESCENT (see 3)
    40113979                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    4012         | '(' abstract_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3980        | '(' abstract_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    40133981                { $$ = $2->addParamList( $5 ); }
    40143982        | '(' abstract_parameter_function ')'                           // redundant parenthesis
     
    40874055
    40884056variable_abstract_function:
    4089         '(' variable_abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     4057        '(' variable_abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    40904058                { $$ = $2->addParamList( $5 ); }
    40914059        | '(' variable_abstract_function ')'                            // redundant parenthesis
     
    41734141//
    41744142//              cfa_abstract_tuple identifier_or_type_name
    4175 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_list_ellipsis_opt ')'
     4143//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    41764144//
    41774145// since a function return type can be syntactically identical to a tuple type:
     
    42394207
    42404208cfa_abstract_function:                                                                  // CFA
    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 ')'
     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 ')'
    42444212                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    4245         | cfa_function_return '(' push cfa_parameter_list_ellipsis_opt pop ')'
     4213        | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
    42464214                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    42474215        ;
Note: See TracChangeset for help on using the changeset viewer.