Ignore:
Timestamp:
May 25, 2018, 2:51:06 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
cdc4d43
Parents:
3ef35bd (diff), 58e822a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/master' into with_gc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r3ef35bd reba74ba  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri May 11 17:51:38 2018
    13 // Update Count     : 3261
     12// Last Modified On : Thu May 24 18:11:59 2018
     13// Update Count     : 3369
    1414//
    1515
     
    119119// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
    120120//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
     121// Currently, the forall is associated with the routine, and the generic type has to be separately defined:
     122//   forall( otype T ) struct S { int T; };
     123//   forall( otype W ) bar( W ) {}
    121124
    122125void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
    123         if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
     126        if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition
    124127                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
    125128                declSpec->type->aggregate.params = nullptr;
     
    301304%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
    302305
    303 %type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
     306%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
    304307%type<en> field field_list field_name fraction_constants_opt
    305308
     
    361364
    362365// initializers
    363 %type<in>  initializer initializer_list initializer_opt
     366%type<in>  initializer initializer_list_opt initializer_opt
    364367
    365368// designators
     
    412415// actions during the parser update this data structure when the class of identifiers change.
    413416//
    414 // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a
    415 // local scope; it must revert to its original class at the end of the block.  Since type names can be local to a
    416 // particular declaration, each declaration is itself a scope.  This requires distinguishing between type names that are
    417 // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in
    418 // "typedef" or "otype" declarations).
    419 //
    420 // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of
    421 // scopes.  Every push must have a matching pop, although it is regrettable the matching pairs do not always occur
    422 // within the same rule.  These non-terminals may appear in more contexts than strictly necessary from a semantic point
    423 // of view.  Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have
    424 // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra
    425 // rules is to open a new scope unconditionally.  As the grammar evolves, it may be neccesary to add or move around
    426 // "push" and "pop" nonterminals to resolve conflicts of this sort.
     417// Because the Cforall language is block-scoped, an identifier can change its class in a local scope; it must revert to
     418// its original class at the end of the block.  Since type names can be local to a particular declaration, each
     419// declaration is itself a scope.  This requires distinguishing between type names that are local to the current
     420// declaration scope and those that persist past the end of the declaration (i.e., names defined in "typedef" or "otype"
     421// declarations).
     422//
     423// The non-terminals "push" and "pop" denote the opening and closing of scopes.  Every push must have a matching pop,
     424// although it is regrettable the matching pairs do not always occur within the same rule.  These non-terminals may
     425// appear in more contexts than strictly necessary from a semantic point of view.
    427426
    428427push:
     
    498497                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    499498        | type_name '.' no_attr_identifier                                      // CFA, nested type
    500                 { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; }
    501 //              { $$ = nullptr; }
    502         | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    503                 { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; }
    504 //              { $$ = nullptr; }
     499                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     500        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
     501                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    505502        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    506503                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
     
    519516postfix_expression:
    520517        primary_expression
    521         | postfix_expression '[' push assignment_expression pop ']'
     518        | postfix_expression '[' assignment_expression ']'
    522519                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    523520                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    524521                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    525522                // equivalent to the old x[i,j].
    526                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
     523                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    527524        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    528525                {
     
    539536        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    540537                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    541         | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    542                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
     538        | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
     539                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    543540        | postfix_expression ARROW no_attr_identifier
    544541                {
     
    547544        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    548545                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    549         | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
    550                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
     546        | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
     547                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    551548        | postfix_expression ICR
    552549                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
    553550        | postfix_expression DECR
    554551                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    555         | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
     552        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
    556553                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    557         | '(' type_no_function ')' '@' '{' initializer_list comma_opt '}' // CFA, explicit C compound-literal
     554        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    558555                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    559556        | '^' primary_expression '{' argument_expression_list '}' // CFA
     
    588585        | FLOATING_DECIMALconstant field
    589586                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    590         | FLOATING_DECIMALconstant '[' push field_list pop ']'
    591                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
     587        | FLOATING_DECIMALconstant '[' field_list ']'
     588                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    592589        | field_name '.' field
    593590                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    594         | field_name '.' '[' push field_list pop ']'
    595                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
     591        | field_name '.' '[' field_list ']'
     592                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    596593        | field_name ARROW field
    597594                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    598         | field_name ARROW '[' push field_list pop ']'
    599                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
     595        | field_name ARROW '[' field_list ']'
     596                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    600597        ;
    601598
     
    807804        | unary_expression assignment_operator assignment_expression
    808805                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
    809         | unary_expression '=' '{' initializer_list comma_opt '}'
     806        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
    810807                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
    811808        ;
     
    869866        labeled_statement
    870867        | compound_statement
    871         | expression_statement                                          { $$ = $1; }
     868        | expression_statement
    872869        | selection_statement
    873870        | iteration_statement
     
    10741071        | RETURN comma_expression_opt ';'
    10751072                { $$ = new StatementNode( build_return( $2 ) ); }
    1076         | RETURN '{' initializer_list comma_opt '}'
     1073        | RETURN '{' initializer_list_opt comma_opt '}'
    10771074                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    10781075        | THROW assignment_expression_opt ';'                           // handles rethrow
     
    11681165
    11691166handler_predicate_opt:
    1170         //empty
     1167        // empty
    11711168                { $$ = nullptr; }
    11721169        | ';' conditional_expression                            { $$ = $2; }
     
    11861183        type_specifier_nobody
    11871184        | type_specifier_nobody declarator
    1188                 {
    1189                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1190                         $$ = $2->addType( $1 );
    1191                 }
     1185                { $$ = $2->addType( $1 ); }
    11921186        | type_specifier_nobody variable_abstract_declarator
    11931187                { $$ = $2->addType( $1 ); }
    11941188        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    1195                 {
    1196                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1197                         $$ = $1->addName( $2 );
    1198                 }
     1189                { $$ = $1->addName( $2 ); }
    11991190        | cfa_abstract_declarator_tuple                                         // CFA
    12001191        ;
     
    12741265
    12751266declaration_list_opt:                                                                   // used at beginning of switch statement
    1276         pop
     1267        pop     // empty
    12771268                { $$ = nullptr; }
    12781269        | declaration_list
     
    13091300
    13101301local_label_list:                                                                               // GCC, local label
    1311         no_attr_identifier_or_type_name                         {}
    1312         | local_label_list ',' no_attr_identifier_or_type_name {}
     1302        no_attr_identifier_or_type_name
     1303        | local_label_list ',' no_attr_identifier_or_type_name
    13131304        ;
    13141305
     
    13441335cfa_variable_declaration:                                                               // CFA
    13451336        cfa_variable_specifier initializer_opt
    1346                 {
    1347                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1348                         $$ = $1->addInitializer( $2 );
    1349                 }
     1337                { $$ = $1->addInitializer( $2 ); }
    13501338        | declaration_qualifier_list cfa_variable_specifier initializer_opt
    13511339                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
    13521340                // them as a type_qualifier cannot appear in that context.
    1353                 {
    1354                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1355                         $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
    1356                 }
     1341                { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
    13571342        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1358                 {
    1359                         typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
    1360                         $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
    1361                 }
     1343                { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
    13621344        ;
    13631345
     
    13661348                // storage-class
    13671349        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
    1368                 {
    1369                         typedefTable.setNextIdentifier( *$2 );
    1370                         $$ = $1->addName( $2 )->addAsmName( $3 );
    1371                 }
     1350                { $$ = $1->addName( $2 )->addAsmName( $3 ); }
    13721351        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1373                 {
    1374                         typedefTable.setNextIdentifier( *$2 );
    1375                         $$ = $1->addName( $2 )->addAsmName( $3 );
    1376                 }
     1352                { $$ = $1->addName( $2 )->addAsmName( $3 ); }
    13771353        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1378                 {
    1379                         typedefTable.setNextIdentifier( *$3 );
    1380                         $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
    1381                 }
     1354                { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); }
    13821355        ;
    13831356
    13841357cfa_function_declaration:                                                               // CFA
    13851358        cfa_function_specifier
    1386                 {
    1387                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1388                         $$ = $1;
    1389                 }
     1359                { $$ = $1; }
    13901360        | type_qualifier_list cfa_function_specifier
    1391                 {
    1392                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1393                         $$ = $2->addQualifiers( $1 );
    1394                 }
     1361                { $$ = $2->addQualifiers( $1 ); }
    13951362        | declaration_qualifier_list cfa_function_specifier
    1396                 {
    1397                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1398                         $$ = $2->addQualifiers( $1 );
    1399                 }
     1363                { $$ = $2->addQualifiers( $1 ); }
    14001364        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    1401                 {
    1402                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1403                         $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
    1404                 }
    1405         | cfa_function_declaration pop ',' push identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1365                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
     1366        | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    14061367                {
    14071368                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    14081369                        DeclarationNode * ret = new DeclarationNode;
    14091370                        ret->type = maybeClone( $1->type->base );
    1410                         $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr ) );
     1371                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) );
    14111372                }
    14121373        ;
     
    14371398        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    14381399                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1439                 {
    1440                         $$ = DeclarationNode::newFunction( $2, $1, $5, 0 );
    1441                 }
     1400                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    14421401        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    1443                 {
    1444                         $$ = DeclarationNode::newFunction( $2, $1, $5, 0 );
    1445                 }
     1402                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    14461403        ;
    14471404
     
    14501407                { $$ = DeclarationNode::newTuple( $3 ); }
    14511408        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
    1452                 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
    1453                 // ']'.
     1409                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
    14541410                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    14551411        ;
     
    14581414        TYPEDEF cfa_variable_specifier
    14591415                {
    1460                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1416                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14611417                        $$ = $2->addTypedef();
    14621418                }
    14631419        | TYPEDEF cfa_function_specifier
    14641420                {
    1465                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1421                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14661422                        $$ = $2->addTypedef();
    14671423                }
    14681424        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14691425                {
    1470                         typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
     1426                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
    14711427                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14721428                }
     
    14791435        TYPEDEF type_specifier declarator
    14801436                {
    1481                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1437                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14821438                        $$ = $3->addType( $2 )->addTypedef();
    14831439                }
    14841440        | typedef_declaration pop ',' push declarator
    14851441                {
    1486                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1442                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
    14871443                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14881444                }
    14891445        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14901446                {
    1491                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1447                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14921448                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14931449                }
    14941450        | type_specifier TYPEDEF declarator
    14951451                {
    1496                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1452                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14971453                        $$ = $3->addType( $1 )->addTypedef();
    14981454                }
    14991455        | type_specifier TYPEDEF type_qualifier_list declarator
    15001456                {
    1501                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1457                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    15021458                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    15031459                }
     
    15081464        TYPEDEF no_attr_identifier '=' assignment_expression
    15091465                {
    1510                         typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
    1511                         $$ = DeclarationNode::newName( 0 );                     // unimplemented
     1466                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     1467                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    15121468                }
    15131469        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    15141470                {
    1515                         typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
    1516                         $$ = DeclarationNode::newName( 0 );                     // unimplemented
     1471                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     1472                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    15171473                }
    15181474        ;
     
    15301486//       declarator asm_name_opt initializer_opt
    15311487//              {
    1532 //                      typedefTable.addToEnclosingScope( TypedefTable::ID );
     1488//                      typedefTable.addToEnclosingScope( IDENTIFIER );
    15331489//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
    15341490//              }
    15351491//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    15361492//              {
    1537 //                      typedefTable.addToEnclosingScope( TypedefTable::ID );
     1493//                      typedefTable.addToEnclosingScope( IDENTIFIER );
    15381494//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
    15391495//              }
     
    15421498c_declaration:
    15431499        declaration_specifier declaring_list
    1544                 {
    1545                         $$ = distAttr( $1, $2 );
    1546                 }
     1500                { $$ = distAttr( $1, $2 ); }
    15471501        | typedef_declaration
    15481502        | typedef_expression                                                            // GCC, naming expression type
     
    15541508                // storage-class
    15551509        declarator asm_name_opt initializer_opt
    1556                 {
    1557                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1558                         $$ = $1->addAsmName( $2 )->addInitializer( $3 );
    1559                 }
     1510                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
    15601511        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    1561                 {
    1562                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1563                         $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
    1564                 }
     1512                { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
    15651513        ;
    15661514
     
    16341582
    16351583forall:
    1636         FORALL '('
    1637                 {
    1638                         typedefTable.enterScope();
    1639                 }
    1640           type_parameter_list ')'                                                       // CFA
    1641                 {
    1642                         typedefTable.leaveScope();
    1643                         $$ = DeclarationNode::newForall( $4 );
    1644                 }
     1584        FORALL '(' push type_parameter_list pop ')'                                     // CFA
     1585                { $$ = DeclarationNode::newForall( $4 ); }
    16451586        ;
    16461587
     
    18541795
    18551796aggregate_type:                                                                                 // struct, union
    1856         aggregate_key attribute_list_opt '{' field_declaration_list '}'
     1797        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18571798                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    18581799        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    18591800                {
    18601801                        typedefTable.makeTypedef( *$3 );                        // create typedef
    1861                         if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
     1802                        if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18621803                        forall = false;                                                         // reset
    18631804                }
    1864           '{' field_declaration_list '}'
     1805          '{' field_declaration_list_opt '}'
    18651806                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1866         | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
     1807        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18671808                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    18681809        | aggregate_type_nobody
     
    18731814                {
    18741815                        typedefTable.makeTypedef( *$3 );
    1875                         if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
     1816                        if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18761817                        forall = false;                                                         // reset
    18771818                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     
    19091850        ;
    19101851
    1911 field_declaration_list:
     1852field_declaration_list_opt:
    19121853        // empty
    19131854                { $$ = nullptr; }
    1914         | field_declaration_list field_declaration
     1855        | field_declaration_list_opt field_declaration
    19151856                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    19161857        ;
     
    19451886
    19461887field_declaring_list:
    1947         field_declarator
    1948         | field_declaring_list ',' attribute_list_opt field_declarator
     1888        field_declarator_opt
     1889        | field_declaring_list ',' attribute_list_opt field_declarator_opt
    19491890                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    19501891        ;
    19511892
    1952 field_declarator:
     1893field_declarator_opt:
    19531894        // empty
    19541895                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
     
    20902031                // No SUE declaration in parameter list.
    20912032        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    2092                 {
    2093                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2094                         $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    2095                 }
     2033                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    20962034        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    2097                 {
    2098                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2099                         $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    2100                 }
     2035                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    21012036        ;
    21022037
     
    21562091initializer:
    21572092        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
    2158         | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
    2159         ;
    2160 
    2161 initializer_list:
     2093        | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
     2094        ;
     2095
     2096initializer_list_opt:
    21622097        // empty
    21632098                { $$ = nullptr; }
    21642099        | initializer
    21652100        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    2166         | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    2167         | initializer_list ',' designation initializer
     2101        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
     2102        | initializer_list_opt ',' designation initializer
    21682103                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    21692104        ;
     
    22402175type_parameter:                                                                                 // CFA
    22412176        type_class no_attr_identifier_or_type_name
    2242                 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
     2177                { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
    22432178          type_initializer_opt assertion_list_opt
    22442179                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22732208assertion:                                                                                              // CFA
    22742209        '|' no_attr_identifier_or_type_name '(' type_list ')'
    2275                 {
    2276                         typedefTable.openTrait( *$2 );
    2277                         $$ = DeclarationNode::newTraitUse( $2, $4 );
    2278                 }
     2210                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    22792211        | '|' '{' push trait_declaration_list '}'
    22802212                { $$ = $4; }
    22812213        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    2282                 { $$ = nullptr; }
     2214                { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22832215        ;
    22842216
     
    23122244        no_attr_identifier_or_type_name
    23132245                {
    2314                         typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
     2246                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
    23152247                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    23162248                }
    23172249        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    23182250                {
    2319                         typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
     2251                        typedefTable.addToEnclosingScope( *$1, TYPEGENname );
    23202252                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
    23212253                }
     
    23242256trait_specifier:                                                                                // CFA
    23252257        TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    2326                 {
    2327                         typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    2328                         $$ = DeclarationNode::newTrait( $2, $5, 0 );
    2329                 }
    2330         | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
    2331                 {
    2332                         typedefTable.enterTrait( *$2 );
    2333                         typedefTable.enterScope();
    2334                 }
    2335           trait_declaration_list '}'
    2336                 {
    2337                         typedefTable.leaveTrait();
    2338                         typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    2339                         $$ = DeclarationNode::newTrait( $2, $5, $10 );
    2340                 }
     2258                { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
     2259        | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}'
     2260                { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
    23412261        ;
    23422262
     
    23542274cfa_trait_declaring_list:                                                               // CFA
    23552275        cfa_variable_specifier
    2356                 {
    2357                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2358                         $$ = $1;
    2359                 }
    23602276        | cfa_function_specifier
    2361                 {
    2362                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2363                         $$ = $1;
    2364                 }
    23652277        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    2366                 {
    2367                         typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
    2368                         $$ = $1->appendList( $1->cloneType( $5 ) );
    2369                 }
     2278                { $$ = $1->appendList( $1->cloneType( $5 ) ); }
    23702279        ;
    23712280
    23722281trait_declaring_list:                                                                   // CFA
    23732282        type_specifier declarator
    2374                 {
    2375                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2376                         $$ = $2->addType( $1 );
    2377                 }
     2283                { $$ = $2->addType( $1 ); }
    23782284        | trait_declaring_list pop ',' push declarator
    2379                 {
    2380                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2381                         $$ = $1->appendList( $1->cloneBaseType( $5 ) );
    2382                 }
     2285                { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
    23832286        ;
    23842287
     
    24302333                }
    24312334        | type_qualifier_list
    2432                 {
    2433                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2434                 }
     2335                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    24352336          push '{' external_definition_list '}'                         // CFA, namespace
    24362337                {
     
    24452346                }
    24462347        | declaration_qualifier_list
    2447                 {
    2448                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2449                 }
     2348                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    24502349          push '{' external_definition_list '}'                         // CFA, namespace
    24512350                {
     
    24872386                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
    24882387        | function_declarator compound_statement
    2489                 {
    2490                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2491                         typedefTable.leaveScope();
    2492                         $$ = $1->addFunctionBody( $2 );
    2493                 }
     2388                { $$ = $1->addFunctionBody( $2 ); }
    24942389        | KR_function_declarator KR_declaration_list_opt compound_statement
    2495                 {
    2496                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2497                         typedefTable.leaveScope();
    2498                         $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
    2499                 }
     2390                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    25002391        ;
    25012392
     
    25102401        cfa_function_declaration with_clause_opt compound_statement     // CFA
    25112402                {
    2512                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2513                         typedefTable.leaveScope();
    25142403                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    25152404                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
     
    25202409                {
    25212410                        rebindForall( $1, $2 );
    2522                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2523                         typedefTable.leaveScope();
     2411                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
     2412                }
     2413        | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
     2414                {
     2415                        rebindForall( $1, $2 );
    25242416                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    25252417                }
    25262418                // handles default int return type, OBSOLESCENT (see 1)
    25272419        | type_qualifier_list function_declarator with_clause_opt compound_statement
    2528                 {
    2529                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2530                         typedefTable.leaveScope();
    2531                         $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    2532                 }
     2420                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
    25332421                // handles default int return type, OBSOLESCENT (see 1)
    25342422        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    2535                 {
    2536                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2537                         typedefTable.leaveScope();
    2538                         $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    2539                 }
     2423                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
    25402424                // handles default int return type, OBSOLESCENT (see 1)
    25412425        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    2542                 {
    2543                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2544                         typedefTable.leaveScope();
    2545                         $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    2546                 }
     2426                { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    25472427
    25482428                // Old-style K&R function definition, OBSOLESCENT (see 4)
     
    25502430                {
    25512431                        rebindForall( $1, $2 );
    2552                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2553                         typedefTable.leaveScope();
    25542432                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    25552433                }
    25562434                // handles default int return type, OBSOLESCENT (see 1)
    25572435        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2558                 {
    2559                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2560                         typedefTable.leaveScope();
    2561                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    2562                 }
     2436                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    25632437                // handles default int return type, OBSOLESCENT (see 1)
    25642438        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2565                 {
    2566                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2567                         typedefTable.leaveScope();
    2568                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    2569                 }
     2439                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    25702440                // handles default int return type, OBSOLESCENT (see 1)
    25712441        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2572                 {
    2573                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2574                         typedefTable.leaveScope();
    2575                         $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    2576                 }
     2442                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    25772443        ;
    25782444
     
    26842550paren_identifier:
    26852551        identifier
    2686                 {
    2687                         typedefTable.setNextIdentifier( *$1 );
    2688                         $$ = DeclarationNode::newName( $1 );
    2689                 }
     2552                { $$ = DeclarationNode::newName( $1 ); }
    26902553        | '(' paren_identifier ')'                                                      // redundant parenthesis
    26912554                { $$ = $2; }
     
    28202683paren_type:
    28212684        typedef
     2685                // hide type name in enclosing scope by variable name
     2686                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
    28222687        | '(' paren_type ')'
    28232688                { $$ = $2; }
     
    29222787typedef:
    29232788        TYPEDEFname
    2924                 {
    2925                         typedefTable.setNextIdentifier( *$1 );
    2926                         $$ = DeclarationNode::newName( $1 );
    2927                 }
     2789                { $$ = DeclarationNode::newName( $1 ); }
    29282790        | TYPEGENname
    2929                 {
    2930                         typedefTable.setNextIdentifier( *$1 );
    2931                         $$ = DeclarationNode::newName( $1 );
    2932                 }
     2791                { $$ = DeclarationNode::newName( $1 ); }
    29332792        ;
    29342793
Note: See TracChangeset for help on using the changeset viewer.