Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rb048dc3 r1dbc8590  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 24 18:11:59 2018
    13 // Update Count     : 3369
     12// Last Modified On : Fri May 11 17:51:38 2018
     13// Update Count     : 3261
    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 ) {}
    124121
    125122void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
    126         if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition
     123        if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
    127124                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
    128125                declSpec->type->aggregate.params = nullptr;
     
    304301%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
    305302
    306 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     303%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
    307304%type<en> field field_list field_name fraction_constants_opt
    308305
     
    364361
    365362// initializers
    366 %type<in>  initializer initializer_list_opt initializer_opt
     363%type<in>  initializer initializer_list initializer_opt
    367364
    368365// designators
     
    415412// actions during the parser update this data structure when the class of identifiers change.
    416413//
    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.
     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.
    426427
    427428push:
     
    497498                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    498499        | type_name '.' no_attr_identifier                                      // CFA, nested type
    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; }
     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; }
    502505        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    503506                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
     
    516519postfix_expression:
    517520        primary_expression
    518         | postfix_expression '[' assignment_expression ']'
     521        | postfix_expression '[' push assignment_expression pop ']'
    519522                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    520523                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    521524                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    522525                // equivalent to the old x[i,j].
    523                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
     526                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
    524527        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    525528                {
     
    536539        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    537540                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    538         | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
    539                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     541        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
     542                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    540543        | postfix_expression ARROW no_attr_identifier
    541544                {
     
    544547        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    545548                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    546         | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
    547                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     549        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
     550                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    548551        | postfix_expression ICR
    549552                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
    550553        | postfix_expression DECR
    551554                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    552         | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
     555        | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    553556                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    554         | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
     557        | '(' type_no_function ')' '@' '{' initializer_list comma_opt '}' // CFA, explicit C compound-literal
    555558                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    556559        | '^' primary_expression '{' argument_expression_list '}' // CFA
     
    585588        | FLOATING_DECIMALconstant field
    586589                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    587         | FLOATING_DECIMALconstant '[' field_list ']'
    588                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
     590        | FLOATING_DECIMALconstant '[' push field_list pop ']'
     591                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
    589592        | field_name '.' field
    590593                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    591         | field_name '.' '[' field_list ']'
    592                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     594        | field_name '.' '[' push field_list pop ']'
     595                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    593596        | field_name ARROW field
    594597                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    595         | field_name ARROW '[' field_list ']'
    596                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     598        | field_name ARROW '[' push field_list pop ']'
     599                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    597600        ;
    598601
     
    804807        | unary_expression assignment_operator assignment_expression
    805808                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
    806         | unary_expression '=' '{' initializer_list_opt comma_opt '}'
     809        | unary_expression '=' '{' initializer_list comma_opt '}'
    807810                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
    808811        ;
     
    866869        labeled_statement
    867870        | compound_statement
    868         | expression_statement
     871        | expression_statement                                          { $$ = $1; }
    869872        | selection_statement
    870873        | iteration_statement
     
    10711074        | RETURN comma_expression_opt ';'
    10721075                { $$ = new StatementNode( build_return( $2 ) ); }
    1073         | RETURN '{' initializer_list_opt comma_opt '}'
     1076        | RETURN '{' initializer_list comma_opt '}'
    10741077                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    10751078        | THROW assignment_expression_opt ';'                           // handles rethrow
     
    11651168
    11661169handler_predicate_opt:
    1167         // empty
     1170        //empty
    11681171                { $$ = nullptr; }
    11691172        | ';' conditional_expression                            { $$ = $2; }
     
    11831186        type_specifier_nobody
    11841187        | type_specifier_nobody declarator
    1185                 { $$ = $2->addType( $1 ); }
     1188                {
     1189                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1190                        $$ = $2->addType( $1 );
     1191                }
    11861192        | type_specifier_nobody variable_abstract_declarator
    11871193                { $$ = $2->addType( $1 ); }
    11881194        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    1189                 { $$ = $1->addName( $2 ); }
     1195                {
     1196                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1197                        $$ = $1->addName( $2 );
     1198                }
    11901199        | cfa_abstract_declarator_tuple                                         // CFA
    11911200        ;
     
    12651274
    12661275declaration_list_opt:                                                                   // used at beginning of switch statement
    1267         pop     // empty
     1276        pop
    12681277                { $$ = nullptr; }
    12691278        | declaration_list
     
    13001309
    13011310local_label_list:                                                                               // GCC, local label
    1302         no_attr_identifier_or_type_name
    1303         | local_label_list ',' no_attr_identifier_or_type_name
     1311        no_attr_identifier_or_type_name                         {}
     1312        | local_label_list ',' no_attr_identifier_or_type_name {}
    13041313        ;
    13051314
     
    13351344cfa_variable_declaration:                                                               // CFA
    13361345        cfa_variable_specifier initializer_opt
    1337                 { $$ = $1->addInitializer( $2 ); }
     1346                {
     1347                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1348                        $$ = $1->addInitializer( $2 );
     1349                }
    13381350        | declaration_qualifier_list cfa_variable_specifier initializer_opt
    13391351                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
    13401352                // them as a type_qualifier cannot appear in that context.
    1341                 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
     1353                {
     1354                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1355                        $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
     1356                }
    13421357        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1343                 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
     1358                {
     1359                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     1360                        $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
     1361                }
    13441362        ;
    13451363
     
    13481366                // storage-class
    13491367        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
    1350                 { $$ = $1->addName( $2 )->addAsmName( $3 ); }
     1368                {
     1369                        typedefTable.setNextIdentifier( *$2 );
     1370                        $$ = $1->addName( $2 )->addAsmName( $3 );
     1371                }
    13511372        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1352                 { $$ = $1->addName( $2 )->addAsmName( $3 ); }
     1373                {
     1374                        typedefTable.setNextIdentifier( *$2 );
     1375                        $$ = $1->addName( $2 )->addAsmName( $3 );
     1376                }
    13531377        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1354                 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); }
     1378                {
     1379                        typedefTable.setNextIdentifier( *$3 );
     1380                        $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
     1381                }
    13551382        ;
    13561383
    13571384cfa_function_declaration:                                                               // CFA
    13581385        cfa_function_specifier
    1359                 { $$ = $1; }
     1386                {
     1387                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1388                        $$ = $1;
     1389                }
    13601390        | type_qualifier_list cfa_function_specifier
    1361                 { $$ = $2->addQualifiers( $1 ); }
     1391                {
     1392                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1393                        $$ = $2->addQualifiers( $1 );
     1394                }
    13621395        | declaration_qualifier_list cfa_function_specifier
    1363                 { $$ = $2->addQualifiers( $1 ); }
     1396                {
     1397                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1398                        $$ = $2->addQualifiers( $1 );
     1399                }
    13641400        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    1365                 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1366         | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     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 ')'
    13671406                {
    13681407                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    13691408                        DeclarationNode * ret = new DeclarationNode;
    13701409                        ret->type = maybeClone( $1->type->base );
    1371                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) );
     1410                        $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr ) );
    13721411                }
    13731412        ;
     
    13981437        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    13991438                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1400                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1439                {
     1440                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0 );
     1441                }
    14011442        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    1402                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1443                {
     1444                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0 );
     1445                }
    14031446        ;
    14041447
     
    14071450                { $$ = DeclarationNode::newTuple( $3 ); }
    14081451        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
    1409                 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
     1452                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
     1453                // ']'.
    14101454                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    14111455        ;
     
    14141458        TYPEDEF cfa_variable_specifier
    14151459                {
    1416                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1460                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14171461                        $$ = $2->addTypedef();
    14181462                }
    14191463        | TYPEDEF cfa_function_specifier
    14201464                {
    1421                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1465                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14221466                        $$ = $2->addTypedef();
    14231467                }
    14241468        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14251469                {
    1426                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
     1470                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
    14271471                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14281472                }
     
    14351479        TYPEDEF type_specifier declarator
    14361480                {
    1437                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1481                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14381482                        $$ = $3->addType( $2 )->addTypedef();
    14391483                }
    14401484        | typedef_declaration pop ',' push declarator
    14411485                {
    1442                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
     1486                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14431487                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14441488                }
    14451489        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14461490                {
    1447                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1491                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14481492                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14491493                }
    14501494        | type_specifier TYPEDEF declarator
    14511495                {
    1452                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1496                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14531497                        $$ = $3->addType( $1 )->addTypedef();
    14541498                }
    14551499        | type_specifier TYPEDEF type_qualifier_list declarator
    14561500                {
    1457                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1501                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14581502                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14591503                }
     
    14641508        TYPEDEF no_attr_identifier '=' assignment_expression
    14651509                {
    1466                         // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    1467                         SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1510                        typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
     1511                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    14681512                }
    14691513        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    14701514                {
    1471                         // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    1472                         SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1515                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
     1516                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    14731517                }
    14741518        ;
     
    14861530//       declarator asm_name_opt initializer_opt
    14871531//              {
    1488 //                      typedefTable.addToEnclosingScope( IDENTIFIER );
     1532//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
    14891533//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
    14901534//              }
    14911535//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    14921536//              {
    1493 //                      typedefTable.addToEnclosingScope( IDENTIFIER );
     1537//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
    14941538//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
    14951539//              }
     
    14981542c_declaration:
    14991543        declaration_specifier declaring_list
    1500                 { $$ = distAttr( $1, $2 ); }
     1544                {
     1545                        $$ = distAttr( $1, $2 );
     1546                }
    15011547        | typedef_declaration
    15021548        | typedef_expression                                                            // GCC, naming expression type
     
    15081554                // storage-class
    15091555        declarator asm_name_opt initializer_opt
    1510                 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     1556                {
     1557                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1558                        $$ = $1->addAsmName( $2 )->addInitializer( $3 );
     1559                }
    15111560        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    1512                 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     1561                {
     1562                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1563                        $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
     1564                }
    15131565        ;
    15141566
     
    15821634
    15831635forall:
    1584         FORALL '(' push type_parameter_list pop ')'                                     // CFA
    1585                 { $$ = DeclarationNode::newForall( $4 ); }
     1636        FORALL '('
     1637                {
     1638                        typedefTable.enterScope();
     1639                }
     1640          type_parameter_list ')'                                                       // CFA
     1641                {
     1642                        typedefTable.leaveScope();
     1643                        $$ = DeclarationNode::newForall( $4 );
     1644                }
    15861645        ;
    15871646
     
    17951854
    17961855aggregate_type:                                                                                 // struct, union
    1797         aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
     1856        aggregate_key attribute_list_opt '{' field_declaration_list '}'
    17981857                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    17991858        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    18001859                {
    18011860                        typedefTable.makeTypedef( *$3 );                        // create typedef
    1802                         if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1861                        if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
    18031862                        forall = false;                                                         // reset
    18041863                }
    1805           '{' field_declaration_list_opt '}'
     1864          '{' field_declaration_list '}'
    18061865                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1807         | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
     1866        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
    18081867                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    18091868        | aggregate_type_nobody
     
    18141873                {
    18151874                        typedefTable.makeTypedef( *$3 );
    1816                         if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1875                        if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
    18171876                        forall = false;                                                         // reset
    18181877                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     
    18501909        ;
    18511910
    1852 field_declaration_list_opt:
     1911field_declaration_list:
    18531912        // empty
    18541913                { $$ = nullptr; }
    1855         | field_declaration_list_opt field_declaration
     1914        | field_declaration_list field_declaration
    18561915                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    18571916        ;
     
    18861945
    18871946field_declaring_list:
    1888         field_declarator_opt
    1889         | field_declaring_list ',' attribute_list_opt field_declarator_opt
     1947        field_declarator
     1948        | field_declaring_list ',' attribute_list_opt field_declarator
    18901949                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    18911950        ;
    18921951
    1893 field_declarator_opt:
     1952field_declarator:
    18941953        // empty
    18951954                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
     
    20312090                // No SUE declaration in parameter list.
    20322091        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    2033                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2092                {
     2093                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2094                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
     2095                }
    20342096        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    2035                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2097                {
     2098                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2099                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
     2100                }
    20362101        ;
    20372102
     
    20912156initializer:
    20922157        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
    2093         | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
    2094         ;
    2095 
    2096 initializer_list_opt:
     2158        | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
     2159        ;
     2160
     2161initializer_list:
    20972162        // empty
    20982163                { $$ = nullptr; }
    20992164        | initializer
    21002165        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    2101         | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    2102         | initializer_list_opt ',' designation initializer
     2166        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
     2167        | initializer_list ',' designation initializer
    21032168                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    21042169        ;
     
    21752240type_parameter:                                                                                 // CFA
    21762241        type_class no_attr_identifier_or_type_name
    2177                 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
     2242                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
    21782243          type_initializer_opt assertion_list_opt
    21792244                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22082273assertion:                                                                                              // CFA
    22092274        '|' no_attr_identifier_or_type_name '(' type_list ')'
    2210                 { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
     2275                {
     2276                        typedefTable.openTrait( *$2 );
     2277                        $$ = DeclarationNode::newTraitUse( $2, $4 );
     2278                }
    22112279        | '|' '{' push trait_declaration_list '}'
    22122280                { $$ = $4; }
    22132281        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    2214                 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2282                { $$ = nullptr; }
    22152283        ;
    22162284
     
    22442312        no_attr_identifier_or_type_name
    22452313                {
    2246                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
     2314                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
    22472315                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22482316                }
    22492317        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    22502318                {
    2251                         typedefTable.addToEnclosingScope( *$1, TYPEGENname );
     2319                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
    22522320                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
    22532321                }
     
    22562324trait_specifier:                                                                                // CFA
    22572325        TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    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 ); }
     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                }
    22612341        ;
    22622342
     
    22742354cfa_trait_declaring_list:                                                               // CFA
    22752355        cfa_variable_specifier
     2356                {
     2357                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2358                        $$ = $1;
     2359                }
    22762360        | cfa_function_specifier
     2361                {
     2362                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2363                        $$ = $1;
     2364                }
    22772365        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    2278                 { $$ = $1->appendList( $1->cloneType( $5 ) ); }
     2366                {
     2367                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
     2368                        $$ = $1->appendList( $1->cloneType( $5 ) );
     2369                }
    22792370        ;
    22802371
    22812372trait_declaring_list:                                                                   // CFA
    22822373        type_specifier declarator
    2283                 { $$ = $2->addType( $1 ); }
     2374                {
     2375                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2376                        $$ = $2->addType( $1 );
     2377                }
    22842378        | trait_declaring_list pop ',' push declarator
    2285                 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
     2379                {
     2380                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2381                        $$ = $1->appendList( $1->cloneBaseType( $5 ) );
     2382                }
    22862383        ;
    22872384
     
    23332430                }
    23342431        | type_qualifier_list
    2335                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2432                {
     2433                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2434                }
    23362435          push '{' external_definition_list '}'                         // CFA, namespace
    23372436                {
     
    23462445                }
    23472446        | declaration_qualifier_list
    2348                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2447                {
     2448                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2449                }
    23492450          push '{' external_definition_list '}'                         // CFA, namespace
    23502451                {
     
    23862487                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
    23872488        | function_declarator compound_statement
    2388                 { $$ = $1->addFunctionBody( $2 ); }
     2489                {
     2490                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2491                        typedefTable.leaveScope();
     2492                        $$ = $1->addFunctionBody( $2 );
     2493                }
    23892494        | KR_function_declarator KR_declaration_list_opt compound_statement
    2390                 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
     2495                {
     2496                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2497                        typedefTable.leaveScope();
     2498                        $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
     2499                }
    23912500        ;
    23922501
     
    24012510        cfa_function_declaration with_clause_opt compound_statement     // CFA
    24022511                {
     2512                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2513                        typedefTable.leaveScope();
    24032514                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    24042515                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
     
    24092520                {
    24102521                        rebindForall( $1, $2 );
    2411                         $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    2412                 }
    2413         | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
    2414                 {
    2415                         rebindForall( $1, $2 );
     2522                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2523                        typedefTable.leaveScope();
    24162524                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24172525                }
    24182526                // handles default int return type, OBSOLESCENT (see 1)
    24192527        | type_qualifier_list function_declarator with_clause_opt compound_statement
    2420                 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
     2528                {
     2529                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2530                        typedefTable.leaveScope();
     2531                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
     2532                }
    24212533                // handles default int return type, OBSOLESCENT (see 1)
    24222534        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    2423                 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
     2535                {
     2536                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2537                        typedefTable.leaveScope();
     2538                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
     2539                }
    24242540                // handles default int return type, OBSOLESCENT (see 1)
    24252541        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    2426                 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); }
     2542                {
     2543                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2544                        typedefTable.leaveScope();
     2545                        $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
     2546                }
    24272547
    24282548                // Old-style K&R function definition, OBSOLESCENT (see 4)
     
    24302550                {
    24312551                        rebindForall( $1, $2 );
     2552                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2553                        typedefTable.leaveScope();
    24322554                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    24332555                }
    24342556                // handles default int return type, OBSOLESCENT (see 1)
    24352557        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2436                 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
     2558                {
     2559                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2560                        typedefTable.leaveScope();
     2561                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
     2562                }
    24372563                // handles default int return type, OBSOLESCENT (see 1)
    24382564        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2439                 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
     2565                {
     2566                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2567                        typedefTable.leaveScope();
     2568                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
     2569                }
    24402570                // handles default int return type, OBSOLESCENT (see 1)
    24412571        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2442                 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
     2572                {
     2573                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2574                        typedefTable.leaveScope();
     2575                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
     2576                }
    24432577        ;
    24442578
     
    25502684paren_identifier:
    25512685        identifier
    2552                 { $$ = DeclarationNode::newName( $1 ); }
     2686                {
     2687                        typedefTable.setNextIdentifier( *$1 );
     2688                        $$ = DeclarationNode::newName( $1 );
     2689                }
    25532690        | '(' paren_identifier ')'                                                      // redundant parenthesis
    25542691                { $$ = $2; }
     
    26832820paren_type:
    26842821        typedef
    2685                 // hide type name in enclosing scope by variable name
    2686                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
    26872822        | '(' paren_type ')'
    26882823                { $$ = $2; }
     
    27872922typedef:
    27882923        TYPEDEFname
    2789                 { $$ = DeclarationNode::newName( $1 ); }
     2924                {
     2925                        typedefTable.setNextIdentifier( *$1 );
     2926                        $$ = DeclarationNode::newName( $1 );
     2927                }
    27902928        | TYPEGENname
    2791                 { $$ = DeclarationNode::newName( $1 ); }
     2929                {
     2930                        typedefTable.setNextIdentifier( *$1 );
     2931                        $$ = DeclarationNode::newName( $1 );
     2932                }
    27922933        ;
    27932934
Note: See TracChangeset for help on using the changeset viewer.