Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r3ed994e r35718a9  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 22 08:41:57 2018
    13 // Update Count     : 3353
     12// Last Modified On : Wed May 30 20:29:03 2018
     13// Update Count     : 3432
    1414//
    1515
     
    175175        bool flag;
    176176        CatchStmt::Kind catch_kind;
    177         GenericExpr * genexpr;
    178177}
    179178
     
    260259%type<flag> asm_volatile_opt
    261260%type<en> handler_predicate_opt
    262 %type<genexpr> generic_association generic_assoc_list
    263261
    264262// statements
     
    326324%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    327325
    328 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list_opt
     326%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
    329327
    330328%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
     
    332330%type<decl> c_declaration static_assert
    333331%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    334 %type<decl> KR_declaration_list KR_declaration_list_opt
     332%type<decl> KR_parameter_list KR_parameter_list_opt
    335333
    336334%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    503501                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    504502        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    505                 {
    506                         // add the missing control expression to the GenericExpr and return it
    507                         $5->control = maybeMoveBuild<Expression>( $3 );
    508                         $$ = new ExpressionNode( $5 );
    509                 }
     503                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
    510504        ;
    511505
    512506generic_assoc_list:                                                                             // C11
    513         generic_association
     507        | generic_association
    514508        | generic_assoc_list ',' generic_association
    515                 {
    516                         // steal the association node from the singleton and delete the wrapper
    517                         $1->associations.splice($1->associations.end(), $3->associations);
    518                         delete $3;
    519                         $$ = $1;
    520                 }
    521509        ;
    522510
    523511generic_association:                                                                    // C11
    524512        type_no_function ':' assignment_expression
    525                 {
    526                         // create a GenericExpr wrapper with one association pair
    527                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
    528                 }
    529513        | DEFAULT ':' assignment_expression
    530                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
    531514        ;
    532515
     
    852835//      '[' ']'
    853836//              { $$ = new ExpressionNode( build_tuple() ); }
    854 //      '[' push assignment_expression pop ']'
     837//      | '[' push assignment_expression pop ']'
    855838//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    856839        '[' ',' tuple_expression_list ']'
    857840                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    858         | '[' assignment_expression ',' tuple_expression_list ']'
    859                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$2->set_last( $4 ) ) ); }
     841        | '[' push assignment_expression pop ',' tuple_expression_list ']'
     842                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
    860843        ;
    861844
     
    883866        labeled_statement
    884867        | compound_statement
    885         | expression_statement                                          { $$ = $1; }
     868        | expression_statement
    886869        | selection_statement
    887870        | iteration_statement
     
    909892        '{' '}'
    910893                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    911         | '{'
    912                 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
    913                 // requires its own scope.
    914           push push
     894        | '{' push
    915895          local_label_declaration_opt                                           // GCC, local labels
    916896          statement_decl_list                                                           // C99, intermix declarations and statements
    917897          pop '}'
    918                 { $$ = new StatementNode( build_compound( $5 ) ); }
     898                { $$ = new StatementNode( build_compound( $4 ) ); }
    919899        ;
    920900
    921901statement_decl_list:                                                                    // C99
    922902        statement_decl
    923         | statement_decl_list push statement_decl
    924                 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
     903        | statement_decl_list statement_decl
     904                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    925905        ;
    926906
     
    940920                        $$ = new StatementNode( $2 );
    941921                }
    942         | statement pop
     922        | statement
    943923        ;
    944924
     
    955935
    956936selection_statement:
    957         IF '(' push if_control_expression ')' statement         %prec THEN
     937        IF '(' push if_control_expression ')' statement pop             %prec THEN
    958938                // explicitly deal with the shift/reduce conflict on if/else
    959939                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
    960         | IF '(' push if_control_expression ')' statement ELSE statement
     940        | IF '(' push if_control_expression ')' statement ELSE statement pop
    961941                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    962942        | SWITCH '(' comma_expression ')' case_clause
    963943                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    964         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     944        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    965945                {
    966946                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
     
    974954        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    975955                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
    976         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     956        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    977957                {
    978958                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    982962
    983963if_control_expression:
    984         comma_expression pop
     964        comma_expression
    985965                { $$ = new IfCtl( nullptr, $1 ); }
    986         | c_declaration pop                                                                     // no semi-colon
     966        | c_declaration                                                                         // no semi-colon
    987967                { $$ = new IfCtl( $1, nullptr ); }
    988         | cfa_declaration pop                                                           // no semi-colon
     968        | cfa_declaration                                                                       // no semi-colon
    989969                { $$ = new IfCtl( $1, nullptr ); }
    990970        | declaration comma_expression                                          // semi-colon separated
     
    10471027        | DO statement WHILE '(' comma_expression ')' ';'
    10481028                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1049         | FOR '(' push for_control_expression ')' statement
     1029        | FOR '(' push for_control_expression ')' statement pop
    10501030                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10511031        ;
    10521032
    10531033for_control_expression:
    1054         comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    1055                 { $$ = new ForCtl( $1, $4, $6 ); }
     1034        comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
     1035                { $$ = new ForCtl( $1, $3, $5 ); }
    10561036        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10571037                { $$ = new ForCtl( $1, $2, $4 ); }
     
    12001180        type_specifier_nobody
    12011181        | type_specifier_nobody declarator
    1202                 {
    1203                         $$ = $2->addType( $1 );
    1204                 }
     1182                { $$ = $2->addType( $1 ); }
    12051183        | type_specifier_nobody variable_abstract_declarator
    12061184                { $$ = $2->addType( $1 ); }
    12071185        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    1208                 {
    1209                         $$ = $1->addName( $2 );
    1210                 }
     1186                { $$ = $1->addName( $2 ); }
    12111187        | cfa_abstract_declarator_tuple                                         // CFA
    12121188        ;
     
    12861262
    12871263declaration_list_opt:                                                                   // used at beginning of switch statement
    1288         pop
     1264        // empty
    12891265                { $$ = nullptr; }
    12901266        | declaration_list
     
    12931269declaration_list:
    12941270        declaration
    1295         | declaration_list push declaration
    1296                 { $$ = $1->appendList( $3 ); }
    1297         ;
    1298 
    1299 KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
     1271        | declaration_list declaration
     1272                { $$ = $1->appendList( $2 ); }
     1273        ;
     1274
     1275KR_parameter_list_opt:                                                          // used to declare parameter types in K&R style functions
    13001276        // empty
    13011277                { $$ = nullptr; }
    1302         | KR_declaration_list
    1303         ;
    1304 
    1305 KR_declaration_list:
     1278        | KR_parameter_list
     1279        ;
     1280
     1281KR_parameter_list:
    13061282        push c_declaration pop ';'
    13071283                { $$ = $2; }
    1308         | KR_declaration_list push c_declaration pop ';'
     1284        | KR_parameter_list push c_declaration pop ';'
    13091285                { $$ = $1->appendList( $3 ); }
    13101286        ;
     
    13211297
    13221298local_label_list:                                                                               // GCC, local label
    1323         no_attr_identifier_or_type_name                         {}
    1324         | local_label_list ',' no_attr_identifier_or_type_name {}
     1299        no_attr_identifier_or_type_name
     1300        | local_label_list ',' no_attr_identifier_or_type_name
    13251301        ;
    13261302
    13271303declaration:                                                                                    // old & new style declarations
    1328         c_declaration pop ';'
    1329         | cfa_declaration pop ';'                                                       // CFA
     1304        c_declaration ';'
     1305        | cfa_declaration ';'                                                           // CFA
    13301306        | static_assert
    13311307        ;
     
    13851361        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    13861362                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1387         | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1363        | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13881364                {
    13891365                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    13901366                        DeclarationNode * ret = new DeclarationNode;
    13911367                        ret->type = maybeClone( $1->type->base );
    1392                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) );
     1368                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
    13931369                }
    13941370        ;
    13951371
    13961372cfa_function_specifier:                                                                 // CFA
    1397 //      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
     1373//      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
    13981374//              {
    13991375//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    14001376//              }
    1401 //      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
     1377//      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
    14021378//              {
    14031379//                      typedefTable.setNextIdentifier( *$5 );
    14041380//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    14051381//              }
    1406 //      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
     1382//      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
    14071383//              {
    14081384//                      typedefTable.setNextIdentifier( *$5 );
     
    14121388                // identifier_or_type_name must be broken apart because of the sequence:
    14131389                //
    1414                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1390                //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    14151391                //   '[' ']' type_specifier
    14161392                //
    14171393                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    14181394                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1419         cfa_abstract_tuple identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1395        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    14201396                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1421                 { $$ = DeclarationNode::newFunction( $2, $1, $4, 0 ); }
    1422         | cfa_function_return identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    1423                 { $$ = DeclarationNode::newFunction( $2, $1, $4, 0 ); }
     1397                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1398        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1399                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    14241400        ;
    14251401
    14261402cfa_function_return:                                                                    // CFA
    1427         '[' cfa_parameter_list ']'
    1428                 { $$ = DeclarationNode::newTuple( $2 ); }
    1429         | '[' cfa_parameter_list ',' cfa_abstract_parameter_list ']'
    1430                 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
    1431                 // ']'.
    1432                 { $$ = DeclarationNode::newTuple( $2->appendList( $4 ) ); }
     1403        '[' push cfa_parameter_list pop ']'
     1404                { $$ = DeclarationNode::newTuple( $3 ); }
     1405        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
     1406                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
     1407                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    14331408        ;
    14341409
     
    14361411        TYPEDEF cfa_variable_specifier
    14371412                {
    1438                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1413                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
    14391414                        $$ = $2->addTypedef();
    14401415                }
    14411416        | TYPEDEF cfa_function_specifier
    14421417                {
    1443                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1418                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
    14441419                        $$ = $2->addTypedef();
    14451420                }
    14461421        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14471422                {
    1448                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
     1423                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
    14491424                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14501425                }
     
    14571432        TYPEDEF type_specifier declarator
    14581433                {
    1459                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1434                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
    14601435                        $$ = $3->addType( $2 )->addTypedef();
    14611436                }
    14621437        | typedef_declaration pop ',' push declarator
    14631438                {
    1464                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
     1439                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
    14651440                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14661441                }
    14671442        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14681443                {
    1469                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1444                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
    14701445                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14711446                }
    14721447        | type_specifier TYPEDEF declarator
    14731448                {
    1474                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1449                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
    14751450                        $$ = $3->addType( $1 )->addTypedef();
    14761451                }
    14771452        | type_specifier TYPEDEF type_qualifier_list declarator
    14781453                {
    1479                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1454                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
    14801455                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14811456                }
     
    16041579
    16051580forall:
    1606         FORALL '('
    1607                 {
    1608                         typedefTable.enterScope();
    1609                 }
    1610           type_parameter_list ')'                                                       // CFA
    1611                 {
    1612                         typedefTable.leaveScope();
    1613                         $$ = DeclarationNode::newForall( $4 );
    1614                 }
     1581        FORALL '(' type_parameter_list ')'                                      // CFA
     1582                { $$ = DeclarationNode::newForall( $3 ); }
    16151583        ;
    16161584
     
    19801948        ;
    19811949
    1982 cfa_parameter_type_list_opt:                                                    // CFA, abstract + real
     1950cfa_parameter_ellipsis_list_opt:                                                        // CFA, abstract + real
    19831951        // empty
    19841952                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    19871955        | cfa_abstract_parameter_list
    19881956        | cfa_parameter_list
    1989         | cfa_parameter_list ',' cfa_abstract_parameter_list
    1990                 { $$ = $1->appendList( $3 ); }
    1991         | cfa_abstract_parameter_list ',' ELLIPSIS
     1957        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
     1958                { $$ = $1->appendList( $5 ); }
     1959        | cfa_abstract_parameter_list pop ',' push ELLIPSIS
    19921960                { $$ = $1->addVarArgs(); }
    1993         | cfa_parameter_list ',' ELLIPSIS
     1961        | cfa_parameter_list pop ',' push ELLIPSIS
    19941962                { $$ = $1->addVarArgs(); }
    19951963        ;
     
    19991967                // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
    20001968        cfa_parameter_declaration
    2001         | cfa_abstract_parameter_list ',' cfa_parameter_declaration
    2002                 { $$ = $1->appendList( $3 ); }
    2003         | cfa_parameter_list ',' cfa_parameter_declaration
    2004                 { $$ = $1->appendList( $3 ); }
    2005         | cfa_parameter_list ',' cfa_abstract_parameter_list ',' cfa_parameter_declaration
    2006                 { $$ = $1->appendList( $3 )->appendList( $5 ); }
     1969        | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
     1970                { $$ = $1->appendList( $5 ); }
     1971        | cfa_parameter_list pop ',' push cfa_parameter_declaration
     1972                { $$ = $1->appendList( $5 ); }
     1973        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
     1974                { $$ = $1->appendList( $5 )->appendList( $9 ); }
    20071975        ;
    20081976
    20091977cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
    20101978        cfa_abstract_parameter_declaration
    2011         | cfa_abstract_parameter_list ',' cfa_abstract_parameter_declaration
    2012                 { $$ = $1->appendList( $3 ); }
     1979        | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
     1980                { $$ = $1->appendList( $5 ); }
    20131981        ;
    20141982
     
    21132081                { $$ = $2; }
    21142082        | '=' VOID
    2115                 { $$ = new InitializerNode( true ); }
     2083                { $$ = nullptr; }
    21162084        | ATassign initializer
    21172085                { $$ = $2->set_maybeConstructed( false ); }
     
    21592127        '.' no_attr_identifier                                                          // C99, field name
    21602128                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    2161         | '[' assignment_expression ']'                                         // C99, single array element
     2129        | '[' push assignment_expression pop ']'                        // C99, single array element
    21622130                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
    2163                 { $$ = $2; }
    2164         | '[' subrange ']'                                                                      // CFA, multiple array elements
    2165                 { $$ = $2; }
    2166         | '[' constant_expression ELLIPSIS constant_expression ']' // GCC, multiple array elements
    2167                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $2 ), maybeMoveBuild< Expression >( $4 ) ) ); }
    2168         | '.' '[' field_list ']'                                                        // CFA, tuple field selector
    21692131                { $$ = $3; }
     2132        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
     2133                { $$ = $3; }
     2134        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
     2135                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
     2136        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
     2137                { $$ = $4; }
    21702138        ;
    21712139
     
    22042172type_parameter:                                                                                 // CFA
    22052173        type_class no_attr_identifier_or_type_name
    2206                 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
     2174                { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
    22072175          type_initializer_opt assertion_list_opt
    22082176                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22382206        '|' no_attr_identifier_or_type_name '(' type_list ')'
    22392207                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    2240         | '|' '{' push trait_declaration_list '}'
     2208        | '|' '{' push trait_declaration_list pop '}'
    22412209                { $$ = $4; }
    2242         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    2243                 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2210        // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2211        //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22442212        ;
    22452213
     
    22732241        no_attr_identifier_or_type_name
    22742242                {
    2275                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
     2243                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
    22762244                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22772245                }
    2278         | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    2279                 {
    2280                         typedefTable.addToEnclosingScope( *$1, TYPEGENname );
    2281                         $$ = DeclarationNode::newTypeDecl( $1, $4 );
     2246        | no_attr_identifier_or_type_name '(' type_parameter_list ')'
     2247                {
     2248                        typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
     2249                        $$ = DeclarationNode::newTypeDecl( $1, $3 );
    22822250                }
    22832251        ;
    22842252
    22852253trait_specifier:                                                                                // CFA
    2286         TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    2287                 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
    2288         | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
    2289                 { typedefTable.enterScope(); }
    2290           trait_declaration_list '}'
    2291                 { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
     2254        TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
     2255                { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
     2256        | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
     2257                { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
    22922258        ;
    22932259
    22942260trait_declaration_list:                                                                 // CFA
    22952261        trait_declaration
    2296         | trait_declaration_list push trait_declaration
    2297                 { $$ = $1->appendList( $3 ); }
     2262        | trait_declaration_list pop push trait_declaration
     2263                { $$ = $1->appendList( $4 ); }
    22982264        ;
    22992265
    23002266trait_declaration:                                                                              // CFA
    2301         cfa_trait_declaring_list pop ';'
    2302         | trait_declaring_list pop ';'
     2267        cfa_trait_declaring_list ';'
     2268        | trait_declaring_list ';'
    23032269        ;
    23042270
    23052271cfa_trait_declaring_list:                                                               // CFA
    23062272        cfa_variable_specifier
    2307                 { $$ = $1; }
    23082273        | cfa_function_specifier
    2309                 { $$ = $1; }
    23102274        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    23112275                { $$ = $1->appendList( $1->cloneType( $5 ) ); }
     
    23292293
    23302294external_definition_list:
    2331         external_definition
     2295        push external_definition pop
     2296                { $$ = $2; }
    23322297        | external_definition_list
    23332298                { forall = xxx; }
    2334           push external_definition
     2299          push external_definition pop
    23352300                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23362301        ;
     
    23542319                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23552320                }
    2356           '{' external_definition_list_opt '}'
     2321                        // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope.  However,
     2322                        // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The
     2323                        // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt.  This
     2324                        // trick works for nested extern "X"s, as each one undoes itself in the nesting.
     2325          '{' pop external_definition_list_opt push '}'
    23572326                {
    23582327                        linkage = linkageStack.top();
    23592328                        linkageStack.pop();
    2360                         $$ = $5;
     2329                        $$ = $6;
    23612330                }
    23622331        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     
    23662335                }
    23672336        | type_qualifier_list
    2368                 {
    2369                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2370                 }
    2371           push '{' external_definition_list '}'                         // CFA, namespace
    2372                 {
    2373                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2337                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2338          '{' external_definition_list push '}'                  // CFA, namespace
     2339                {
     2340                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23742341                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23752342                                        iter->addQualifiers( $1->clone() );
     
    23782345                        xxx = false;
    23792346                        delete $1;
    2380                         $$ = $5;
     2347                        $$ = $4;
    23812348                }
    23822349        | declaration_qualifier_list
    2383                 {
    2384                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2385                 }
    2386           push '{' external_definition_list '}'                         // CFA, namespace
    2387                 {
    2388                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2350                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2351          '{' external_definition_list '}'                                       // CFA, namespace
     2352                {
     2353                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23892354                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23902355                                        iter->addQualifiers( $1->clone() );
     
    23932358                        xxx = false;
    23942359                        delete $1;
    2395                         $$ = $5;
     2360                        $$ = $4;
    23962361                }
    23972362        | declaration_qualifier_list type_qualifier_list
     
    24002365                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
    24012366                }
    2402           push '{' external_definition_list '}'                         // CFA, namespace
    2403                 {
    2404                         for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2367          '{' external_definition_list '}'                                      // CFA, namespace
     2368                {
     2369                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    24052370                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    24062371                                        iter->addQualifiers( $1->clone() );
     
    24112376                        delete $1;
    24122377                        delete $2;
    2413                         $$ = $6;
     2378                        $$ = $5;
    24142379                }
    24152380        ;
     
    24232388                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
    24242389        | function_declarator compound_statement
    2425                 {
    2426                         typedefTable.leaveScope();
    2427                         $$ = $1->addFunctionBody( $2 );
    2428                 }
    2429         | KR_function_declarator KR_declaration_list_opt compound_statement
    2430                 {
    2431                         typedefTable.leaveScope();
    2432                         $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
    2433                 }
     2390                { $$ = $1->addFunctionBody( $2 ); }
     2391        | KR_function_declarator KR_parameter_list_opt compound_statement
     2392                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24342393        ;
    24352394
     
    24442403        cfa_function_declaration with_clause_opt compound_statement     // CFA
    24452404                {
    2446                         typedefTable.leaveScope();
    24472405                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    24482406                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
     
    24532411                {
    24542412                        rebindForall( $1, $2 );
    2455                         typedefTable.leaveScope();
    24562413                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24572414                }
     
    24592416                {
    24602417                        rebindForall( $1, $2 );
    2461                         typedefTable.leaveScope();
    24622418                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24632419                }
    24642420                // handles default int return type, OBSOLESCENT (see 1)
    24652421        | type_qualifier_list function_declarator with_clause_opt compound_statement
    2466                 {
    2467                         typedefTable.leaveScope();
    2468                         $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    2469                 }
     2422                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
    24702423                // handles default int return type, OBSOLESCENT (see 1)
    24712424        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    2472                 {
    2473                         typedefTable.leaveScope();
    2474                         $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    2475                 }
     2425                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
    24762426                // handles default int return type, OBSOLESCENT (see 1)
    24772427        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    2478                 {
    2479                         typedefTable.leaveScope();
    2480                         $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    2481                 }
     2428                { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24822429
    24832430                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2484         | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2431        | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24852432                {
    24862433                        rebindForall( $1, $2 );
    2487                         typedefTable.leaveScope();
    24882434                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    24892435                }
    24902436                // handles default int return type, OBSOLESCENT (see 1)
    2491         | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2492                 {
    2493                         typedefTable.leaveScope();
    2494                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    2495                 }
     2437        | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2438                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24962439                // handles default int return type, OBSOLESCENT (see 1)
    2497         | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2498                 {
    2499                         typedefTable.leaveScope();
    2500                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    2501                 }
     2440        | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2441                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    25022442                // handles default int return type, OBSOLESCENT (see 1)
    2503         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2504                 {
    2505                         typedefTable.leaveScope();
    2506                         $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    2507                 }
     2443        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2444                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    25082445        ;
    25092446
     
    27022639        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
    27032640                { $$ = $1->addIdList( $3 ); }
    2704         | '(' KR_function_ptr ')' '(' parameter_type_list_opt ')'
    2705                 { $$ = $2->addParamList( $5 ); }
     2641        | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')'
     2642                { $$ = $2->addParamList( $6 ); }
    27062643        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
    27072644                { $$ = $2; }
     
    27492686        typedef
    27502687                // hide type name in enclosing scope by variable name
    2751                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
     2688                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
    27522689        | '(' paren_type ')'
    27532690                { $$ = $2; }
     
    28212758
    28222759identifier_parameter_function:
    2823         paren_identifier '(' parameter_type_list_opt ')'        // empty parameter list OBSOLESCENT (see 3)
    2824                 { $$ = $1->addParamList( $3 ); }
    2825         | '(' identifier_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    2826                 { $$ = $2->addParamList( $5 ); }
     2760        paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2761                { $$ = $1->addParamList( $4 ); }
     2762        | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2763                { $$ = $2->addParamList( $6 ); }
    28272764        | '(' identifier_parameter_function ')'                         // redundant parenthesis
    28282765                { $$ = $2; }
     
    28742811
    28752812type_parameter_function:
    2876         typedef '(' parameter_type_list_opt ')'                         // empty parameter list OBSOLESCENT (see 3)
    2877                 { $$ = $1->addParamList( $3 ); }
    2878         | '(' type_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    2879                 { $$ = $2->addParamList( $5 ); }
     2813        typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3)
     2814                { $$ = $1->addParamList( $4 ); }
     2815        | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2816                { $$ = $2->addParamList( $6 ); }
    28802817        ;
    28812818
     
    29242861
    29252862abstract_function:
    2926         '(' parameter_type_list_opt ')'                                         // empty parameter list OBSOLESCENT (see 3)
    2927                 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    2928         | '(' abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    2929                 { $$ = $2->addParamList( $5 ); }
     2863        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
     2864                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
     2865        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2866                { $$ = $2->addParamList( $6 ); }
    29302867        | '(' abstract_function ')'                                                     // redundant parenthesis
    29312868                { $$ = $2; }
     
    29422879
    29432880multi_array_dimension:
    2944         '[' assignment_expression ']'
    2945                 { $$ = DeclarationNode::newArray( $2, 0, false ); }
    2946         | '[' '*' ']'                                                                           // C99
     2881        '[' push assignment_expression pop ']'
     2882                { $$ = DeclarationNode::newArray( $3, 0, false ); }
     2883        | '[' push '*' pop ']'                                                          // C99
    29472884                { $$ = DeclarationNode::newVarArray( 0 ); }
    2948         | multi_array_dimension '[' assignment_expression ']'
    2949                 { $$ = $1->addArray( DeclarationNode::newArray( $3, 0, false ) ); }
    2950         | multi_array_dimension '[' '*' ']'                                     // C99
     2885        | multi_array_dimension '[' push assignment_expression pop ']'
     2886                { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
     2887        | multi_array_dimension '[' push '*' pop ']'            // C99
    29512888                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
    29522889        ;
     
    30152952
    30162953abstract_parameter_function:
    3017         '(' parameter_type_list_opt ')'                                         // empty parameter list OBSOLESCENT (see 3)
    3018                 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    3019         | '(' abstract_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    3020                 { $$ = $2->addParamList( $5 ); }
     2954        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
     2955                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
     2956        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2957                { $$ = $2->addParamList( $6 ); }
    30212958        | '(' abstract_parameter_function ')'                           // redundant parenthesis
    30222959                { $$ = $2; }
     
    30392976        '[' ']'
    30402977                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    3041         // multi_array_dimension handles the '[' '*' ']' case
    3042         | '[' type_qualifier_list '*' ']'                                       // remaining C99
    3043                 { $$ = DeclarationNode::newVarArray( $2 ); }
    3044         | '[' type_qualifier_list ']'
    3045                 { $$ = DeclarationNode::newArray( 0, $2, false ); }
    3046         // multi_array_dimension handles the '[' assignment_expression ']' case
    3047         | '[' type_qualifier_list assignment_expression ']'
    3048                 { $$ = DeclarationNode::newArray( $3, $2, false ); }
    3049         | '[' STATIC type_qualifier_list_opt assignment_expression ']'
    3050                 { $$ = DeclarationNode::newArray( $4, $3, true ); }
    3051         | '[' type_qualifier_list STATIC assignment_expression ']'
    3052                 { $$ = DeclarationNode::newArray( $4, $2, true ); }
     2978                // multi_array_dimension handles the '[' '*' ']' case
     2979        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
     2980                { $$ = DeclarationNode::newVarArray( $3 ); }
     2981        | '[' push type_qualifier_list pop ']'
     2982                { $$ = DeclarationNode::newArray( 0, $3, false ); }
     2983                // multi_array_dimension handles the '[' assignment_expression ']' case
     2984        | '[' push type_qualifier_list assignment_expression pop ']'
     2985                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     2986        | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
     2987                { $$ = DeclarationNode::newArray( $5, $4, true ); }
     2988        | '[' push type_qualifier_list STATIC assignment_expression pop ']'
     2989                { $$ = DeclarationNode::newArray( $5, $3, true ); }
    30532990        ;
    30542991
     
    30943031
    30953032variable_abstract_function:
    3096         '(' variable_abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    3097                 { $$ = $2->addParamList( $5 ); }
     3033        '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3034                { $$ = $2->addParamList( $6 ); }
    30983035        | '(' variable_abstract_function ')'                            // redundant parenthesis
    30993036                { $$ = $2; }
     
    31583095
    31593096cfa_array_parameter_1st_dimension:
    3160         '[' type_qualifier_list '*' ']'                                         // remaining C99
    3161                 { $$ = DeclarationNode::newVarArray( $2 ); }
    3162         | '[' type_qualifier_list assignment_expression ']'
    3163                 { $$ = DeclarationNode::newArray( $3, $2, false ); }
    3164         | '[' declaration_qualifier_list assignment_expression ']'
     3097        '[' push type_qualifier_list '*' pop ']'                        // remaining C99
     3098                { $$ = DeclarationNode::newVarArray( $3 ); }
     3099        | '[' push type_qualifier_list assignment_expression pop ']'
     3100                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     3101        | '[' push declaration_qualifier_list assignment_expression pop ']'
    31653102                // declaration_qualifier_list must be used because of shift/reduce conflict with
    31663103                // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot
    31673104                // appear in this context.
    3168                 { $$ = DeclarationNode::newArray( $3, $2, true ); }
    3169         | '[' declaration_qualifier_list type_qualifier_list assignment_expression ']'
    3170                 { $$ = DeclarationNode::newArray( $4, $3->addQualifiers( $3 ), true ); }
     3105                { $$ = DeclarationNode::newArray( $4, $3, true ); }
     3106        | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']'
     3107                { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); }
    31713108        ;
    31723109
     
    31803117//
    31813118//              cfa_abstract_tuple identifier_or_type_name
    3182 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     3119//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    31833120//
    31843121// since a function return type can be syntactically identical to a tuple type:
     
    32373174
    32383175cfa_abstract_tuple:                                                                             // CFA
    3239         '[' cfa_abstract_parameter_list ']'
    3240                 { $$ = DeclarationNode::newTuple( $2 ); }
     3176        '[' push cfa_abstract_parameter_list pop ']'
     3177                { $$ = DeclarationNode::newTuple( $3 ); }
     3178        | '[' push type_specifier_nobody ELLIPSIS pop ']'
     3179                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
     3180        | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
     3181                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    32413182        ;
    32423183
    32433184cfa_abstract_function:                                                                  // CFA
    3244 //      '[' ']' '(' cfa_parameter_type_list_opt ')'
     3185//      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
    32453186//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    3246         cfa_abstract_tuple '(' cfa_parameter_type_list_opt ')'
    3247                 { $$ = DeclarationNode::newFunction( nullptr, $1, $3, nullptr ); }
    3248         | cfa_function_return '(' cfa_parameter_type_list_opt ')'
    3249                 { $$ = DeclarationNode::newFunction( nullptr, $1, $3, nullptr ); }
     3187        cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
     3188                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
     3189        | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
     3190                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    32503191        ;
    32513192
Note: See TracChangeset for help on using the changeset viewer.