Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r3d56d15b rb048dc3  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 22 13:59:11 2018
    13 // Update Count     : 3586
     12// Last Modified On : Thu May 24 18:11:59 2018
     13// Update Count     : 3369
    1414//
    1515
     
    136136} // build_postfix_name
    137137
    138 bool forall = false, xxx = false, yyy = false;                  // aggregate have one or more forall qualifiers ?
     138bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
    139139
    140140// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    175175        bool flag;
    176176        CatchStmt::Kind catch_kind;
    177         GenericExpr * genexpr;
    178177}
    179178
     
    260259%type<flag> asm_volatile_opt
    261260%type<en> handler_predicate_opt
    262 %type<genexpr> generic_association generic_assoc_list
    263261
    264262// statements
    265263%type<sn> statement                                             labeled_statement                       compound_statement
    266264%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    267 %type<sn> selection_statement                   if_statement
     265%type<sn> selection_statement
    268266%type<sn> switch_clause_list_opt                switch_clause_list
    269267%type<en> case_value
     
    304302%type<en> enumerator_value_opt
    305303
    306 %type<decl> external_definition external_definition_list external_definition_list_opt
    307 
    308 %type<decl> exception_declaration
     304%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
    309305
    310306%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    328324%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    329325
    330 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
     326%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list_opt
    331327
    332328%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
     
    334330%type<decl> c_declaration static_assert
    335331%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    336 %type<decl> KR_parameter_list KR_parameter_list_opt
     332%type<decl> KR_declaration_list KR_declaration_list_opt
    337333
    338334%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    406402//************************* Namespace Management ********************************
    407403
    408 // The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",
    409 // which are lexically identical.
    410 //
    411 //   typedef int foo; // identifier foo must now be scanned as TYPEDEFname
    412 //   foo f;           // to allow it to appear in this context
    413 //
    414 // While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship
    415 // between syntactic and semantic constructs.  Cforall compounds this problem by introducing type names local to the
    416 // scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type
    417 // generators" -- parameterized types.  This latter type name creates a third class of identifiers, "TYPEGENname", which
    418 // must be distinguished by the lexical scanner.
    419 //
    420 // Since the scanner cannot distinguish among the different classes of identifiers without some context information,
    421 // there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named
    422 // scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For
    423 // each context that introduces a name scope, a new level is created in the type table and that level is popped on
    424 // exiting the scope.  Since type names can be local to a particular declaration, each declaration is itself a scope.
    425 // This requires distinguishing between type names that are local to the current declaration scope and those that
    426 // persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).
    427 //
    428 // The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in
    429 // the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push
    430 // around the list separator.
    431 //
    432 //  int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) );
    433 //      push               pop   push                   pop
     404// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
     405// "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
     406// context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
     407// Hence, this grammar uses the ANSI style.
     408//
     409// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
     410// introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types.  This latter
     411// type name creates a third class of identifiers that must be distinguished by the scanner.
     412//
     413// Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
     414// accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read.  Semantic
     415// actions during the parser update this data structure when the class of identifiers change.
     416//
     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.
    434426
    435427push:
     
    505497                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    506498        | type_name '.' no_attr_identifier                                      // CFA, nested type
    507                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    508                 { $$ = nullptr; }
     499                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    509500        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    510                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    511                 { $$ = nullptr; }
     501                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    512502        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    513                 {
    514                         // add the missing control expression to the GenericExpr and return it
    515                         $5->control = maybeMoveBuild<Expression>( $3 );
    516                         $$ = new ExpressionNode( $5 );
    517                 }
     503                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
    518504        ;
    519505
    520506generic_assoc_list:                                                                             // C11
    521         generic_association
     507        | generic_association
    522508        | generic_assoc_list ',' generic_association
    523                 {
    524                         // steal the association node from the singleton and delete the wrapper
    525                         $1->associations.splice($1->associations.end(), $3->associations);
    526                         delete $3;
    527                         $$ = $1;
    528                 }
    529509        ;
    530510
    531511generic_association:                                                                    // C11
    532512        type_no_function ':' assignment_expression
    533                 {
    534                         // create a GenericExpr wrapper with one association pair
    535                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
    536                 }
    537513        | DEFAULT ':' assignment_expression
    538                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
    539514        ;
    540515
     
    648623                // semantics checks, e.g., ++3, 3--, *3, &&3
    649624        | constant
     625                { $$ = $1; }
    650626        | string_literal
    651627                { $$ = new ExpressionNode( $1 ); }
     
    859835//      '[' ']'
    860836//              { $$ = new ExpressionNode( build_tuple() ); }
    861 //      | '[' push assignment_expression pop ']'
     837//      '[' push assignment_expression pop ']'
    862838//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    863         '[' ',' tuple_expression_list ']'
    864                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    865         | '[' push assignment_expression pop ',' tuple_expression_list ']'
    866                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
     839        '[' push ',' tuple_expression_list pop ']'
     840                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
     841        | '[' push assignment_expression ',' tuple_expression_list pop ']'
     842                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
    867843        ;
    868844
     
    916892        '{' '}'
    917893                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    918         | '{' push
     894        | '{'
     895                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     896                // requires its own scope.
     897          push push
    919898          local_label_declaration_opt                                           // GCC, local labels
    920899          statement_decl_list                                                           // C99, intermix declarations and statements
    921900          pop '}'
    922                 { $$ = new StatementNode( build_compound( $4 ) ); }
     901                { $$ = new StatementNode( build_compound( $5 ) ); }
    923902        ;
    924903
    925904statement_decl_list:                                                                    // C99
    926905        statement_decl
    927         | statement_decl_list statement_decl
    928                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     906        | statement_decl_list push statement_decl
     907                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    929908        ;
    930909
     
    944923                        $$ = new StatementNode( $2 );
    945924                }
    946         | statement
     925        | statement pop
    947926        ;
    948927
     
    959938
    960939selection_statement:
    961                         // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
    962                         // the inherent S/R conflict with THEN/ELSE.
    963         push if_statement pop
    964                 { $$ = $2; }
     940        IF '(' push if_control_expression ')' statement         %prec THEN
     941                // explicitly deal with the shift/reduce conflict on if/else
     942                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     943        | IF '(' push if_control_expression ')' statement ELSE statement
     944                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    965945        | SWITCH '(' comma_expression ')' case_clause
    966946                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    967         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     947        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    968948                {
    969949                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
     
    977957        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    978958                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
    979         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     959        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    980960                {
    981961                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    984964        ;
    985965
    986 if_statement:
    987         IF '(' if_control_expression ')' statement                      %prec THEN
    988                 // explicitly deal with the shift/reduce conflict on if/else
    989                 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    990         | IF '(' if_control_expression ')' statement ELSE statement
    991                 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    992         ;
    993 
    994966if_control_expression:
    995         comma_expression
     967        comma_expression pop
    996968                { $$ = new IfCtl( nullptr, $1 ); }
    997         | c_declaration                                                                         // no semi-colon
     969        | c_declaration pop                                                                     // no semi-colon
    998970                { $$ = new IfCtl( $1, nullptr ); }
    999         | cfa_declaration                                                                       // no semi-colon
     971        | cfa_declaration pop                                                           // no semi-colon
    1000972                { $$ = new IfCtl( $1, nullptr ); }
    1001973        | declaration comma_expression                                          // semi-colon separated
     
    10541026
    10551027iteration_statement:
    1056         WHILE '(' push if_control_expression ')' statement pop
    1057                 { $$ = new StatementNode( build_while( $4, $6 ) ); }
     1028        WHILE '(' comma_expression ')' statement
     1029                { $$ = new StatementNode( build_while( $3, $5 ) ); }
    10581030        | DO statement WHILE '(' comma_expression ')' ';'
    1059                 { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
    1060         | FOR '(' push for_control_expression ')' statement pop
     1031                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
     1032        | FOR '(' push for_control_expression ')' statement
    10611033                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10621034        ;
    10631035
    10641036for_control_expression:
    1065         comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
    1066                 { $$ = new ForCtl( $1, $3, $5 ); }
     1037        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
     1038                { $$ = new ForCtl( $1, $4, $6 ); }
    10671039        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10681040                { $$ = new ForCtl( $1, $2, $4 ); }
     
    11861158
    11871159handler_clause:
    1188         handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1189                 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
    1190         | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1191                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
     1160        handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1161                { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
     1162        | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1163                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
    11921164        ;
    11931165
     
    12931265
    12941266declaration_list_opt:                                                                   // used at beginning of switch statement
     1267        pop     // empty
     1268                { $$ = nullptr; }
     1269        | declaration_list
     1270        ;
     1271
     1272declaration_list:
     1273        declaration
     1274        | declaration_list push declaration
     1275                { $$ = $1->appendList( $3 ); }
     1276        ;
     1277
     1278KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    12951279        // empty
    12961280                { $$ = nullptr; }
    1297         | declaration_list
    1298         ;
    1299 
    1300 declaration_list:
    1301         declaration
    1302         | declaration_list declaration
    1303                 { $$ = $1->appendList( $2 ); }
    1304         ;
    1305 
    1306 KR_parameter_list_opt:                                                                  // used to declare parameter types in K&R style functions
    1307         // empty
    1308                 { $$ = nullptr; }
    1309         | KR_parameter_list
    1310         ;
    1311 
    1312 KR_parameter_list:
     1281        | KR_declaration_list
     1282        ;
     1283
     1284KR_declaration_list:
    13131285        push c_declaration pop ';'
    13141286                { $$ = $2; }
    1315         | KR_parameter_list push c_declaration pop ';'
     1287        | KR_declaration_list push c_declaration pop ';'
    13161288                { $$ = $1->appendList( $3 ); }
    13171289        ;
     
    13331305
    13341306declaration:                                                                                    // old & new style declarations
    1335         c_declaration ';'
    1336         | cfa_declaration ';'                                                           // CFA
    1337         | static_assert                                                                         // C11
     1307        c_declaration pop ';'
     1308        | cfa_declaration pop ';'                                                       // CFA
     1309        | static_assert
    13381310        ;
    13391311
     
    13411313        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    13421314                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
    1343         | STATICASSERT '(' constant_expression ')' ';'          // CFA
    1344                 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); }
    13451315
    13461316// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
     
    13871357cfa_function_declaration:                                                               // CFA
    13881358        cfa_function_specifier
     1359                { $$ = $1; }
    13891360        | type_qualifier_list cfa_function_specifier
    13901361                { $$ = $2->addQualifiers( $1 ); }
     
    13931364        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    13941365                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1395         | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1366        | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    13961367                {
    13971368                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    13981369                        DeclarationNode * ret = new DeclarationNode;
    13991370                        ret->type = maybeClone( $1->type->base );
    1400                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
     1371                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) );
    14011372                }
    14021373        ;
    14031374
    14041375cfa_function_specifier:                                                                 // CFA
    1405 //      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
     1376//      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
    14061377//              {
    14071378//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    14081379//              }
    1409 //      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1380//      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
    14101381//              {
    14111382//                      typedefTable.setNextIdentifier( *$5 );
    14121383//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    14131384//              }
    1414 //      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1385//      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
    14151386//              {
    14161387//                      typedefTable.setNextIdentifier( *$5 );
     
    14201391                // identifier_or_type_name must be broken apart because of the sequence:
    14211392                //
    1422                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
     1393                //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    14231394                //   '[' ']' type_specifier
    14241395                //
    14251396                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    14261397                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1427         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1398        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    14281399                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    14291400                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    1430         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1401        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    14311402                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    14321403        ;
     
    14431414        TYPEDEF cfa_variable_specifier
    14441415                {
    1445                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1" );
     1416                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14461417                        $$ = $2->addTypedef();
    14471418                }
    14481419        | TYPEDEF cfa_function_specifier
    14491420                {
    1450                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2" );
     1421                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14511422                        $$ = $2->addTypedef();
    14521423                }
    14531424        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14541425                {
    1455                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
     1426                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
    14561427                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14571428                }
     
    14641435        TYPEDEF type_specifier declarator
    14651436                {
    1466                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
     1437                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14671438                        $$ = $3->addType( $2 )->addTypedef();
    14681439                }
    14691440        | typedef_declaration pop ',' push declarator
    14701441                {
    1471                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5" );
     1442                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
    14721443                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14731444                }
    14741445        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14751446                {
    1476                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
     1447                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14771448                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14781449                }
    14791450        | type_specifier TYPEDEF declarator
    14801451                {
    1481                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
     1452                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14821453                        $$ = $3->addType( $1 )->addTypedef();
    14831454                }
    14841455        | type_specifier TYPEDEF type_qualifier_list declarator
    14851456                {
    1486                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
     1457                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14871458                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14881459                }
     
    16111582
    16121583forall:
    1613         FORALL '(' type_parameter_list ')'                                      // CFA
    1614                 { $$ = DeclarationNode::newForall( $3 ); }
     1584        FORALL '(' push type_parameter_list pop ')'                                     // CFA
     1585                { $$ = DeclarationNode::newForall( $4 ); }
    16151586        ;
    16161587
     
    17941765                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17951766        | '.' TYPEDEFname
    1796                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1767                { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
    17971768        | type_name '.' TYPEDEFname
    1798                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1769                { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
    17991770        | typegen_name
    18001771        | '.' typegen_name
    1801                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1772                { $$ = $2; }                                                                    // FIX ME
    18021773        | type_name '.' typegen_name
    1803                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1774                { $$ = $3; }                                                                    // FIX ME
    18041775        ;
    18051776
     
    18231794        ;
    18241795
    1825 fred:
    1826         // empty
    1827                 { yyy = false; }
    1828         ;
    1829 
    18301796aggregate_type:                                                                                 // struct, union
    18311797        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18321798                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1833         | aggregate_key attribute_list_opt no_attr_identifier fred
    1834                 {
    1835                         typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1836                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1799        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
     1800                {
     1801                        typedefTable.makeTypedef( *$3 );                        // create typedef
     1802                        if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18371803                        forall = false;                                                         // reset
    18381804                }
    18391805          '{' field_declaration_list_opt '}'
    1840                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
    1841         | aggregate_key attribute_list_opt type_name fred
    1842                 {
    1843                         typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1844                         //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
    1845                         forall = false;                                                         // reset
    1846                 }
    1847           '{' field_declaration_list_opt '}'
    1848                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); }
     1806                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    18491807        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18501808                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     
    18531811
    18541812aggregate_type_nobody:                                                                  // struct, union - {...}
    1855         aggregate_key attribute_list_opt no_attr_identifier fred
    1856                 {
    1857                         typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
    1858                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1813        aggregate_key attribute_list_opt no_attr_identifier
     1814                {
     1815                        typedefTable.makeTypedef( *$3 );
     1816                        if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18591817                        forall = false;                                                         // reset
    18601818                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18611819                }
    1862         | aggregate_key attribute_list_opt type_name fred
     1820        | aggregate_key attribute_list_opt TYPEDEFname
     1821                {
     1822                        typedefTable.makeTypedef( *$3 );
     1823                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     1824                }
     1825        | aggregate_key attribute_list_opt typegen_name         // CFA
    18631826                {
    18641827                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18741837aggregate_key:
    18751838        STRUCT
    1876                 { yyy = true; $$ = DeclarationNode::Struct; }
     1839                { $$ = DeclarationNode::Struct; }
    18771840        | UNION
    1878                 { yyy = true; $$ = DeclarationNode::Union; }
     1841                { $$ = DeclarationNode::Union; }
    18791842        | EXCEPTION
    1880                 { yyy = true; $$ = DeclarationNode::Exception; }
     1843                { $$ = DeclarationNode::Exception; }
    18811844        | COROUTINE
    1882                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1845                { $$ = DeclarationNode::Coroutine; }
    18831846        | MONITOR
    1884                 { yyy = true; $$ = DeclarationNode::Monitor; }
     1847                { $$ = DeclarationNode::Monitor; }
    18851848        | THREAD
    1886                 { yyy = true; $$ = DeclarationNode::Thread; }
     1849                { $$ = DeclarationNode::Thread; }
    18871850        ;
    18881851
     
    18951858
    18961859field_declaration:
    1897         type_specifier field_declaring_list ';'
    1898                 { $$ = distAttr( $1, $2 ); }
     1860        cfa_field_declaring_list ';'                                            // CFA, new style field declaration
     1861        | EXTENSION cfa_field_declaring_list ';'                        // GCC
     1862                {
     1863                        distExt( $2 );                                                          // mark all fields in list
     1864                        $$ = $2;
     1865                }
     1866        | type_specifier field_declaring_list ';'
     1867                {
     1868                        $$ = distAttr( $1, $2 ); }
    18991869        | EXTENSION type_specifier field_declaring_list ';'     // GCC
    1900                 { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
    1901         | typedef_declaration ';'                                                       // CFA
    1902                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    1903         | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    1904         | EXTENSION cfa_field_declaring_list ';'                        // GCC
    1905                 { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
    1906         | cfa_typedef_declaration ';'                                           // CFA
    1907                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    1908         | static_assert                                                                         // C11
     1870                {
     1871                        distExt( $3 );                                                          // mark all fields in list
     1872                        $$ = distAttr( $2, $3 );
     1873                }
     1874        | static_assert
    19091875        ;
    19101876
     
    19451911                { $$ = nullptr; }
    19461912        | bit_subrange_size
     1913                { $$ = $1; }
    19471914        ;
    19481915
     
    19551922        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    19561923                { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
    1957         | ENUM attribute_list_opt no_attr_identifier
     1924        | ENUM attribute_list_opt no_attr_identifier_or_type_name
    19581925                { typedefTable.makeTypedef( *$3 ); }
    19591926          '{' enumerator_list comma_opt '}'
    19601927                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
    1961         | ENUM attribute_list_opt type_name
    1962           '{' enumerator_list comma_opt '}'
    1963                 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }
    19641928        | enum_type_nobody
    19651929        ;
    19661930
    19671931enum_type_nobody:                                                                               // enum - {...}
    1968         ENUM attribute_list_opt no_attr_identifier
     1932        ENUM attribute_list_opt no_attr_identifier_or_type_name
    19691933                {
    19701934                        typedefTable.makeTypedef( *$3 );
    19711935                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
    1972                 }
    1973         | ENUM attribute_list_opt type_name
    1974                 {
    1975                         typedefTable.makeTypedef( *$3->type->symbolic.name );
    1976                         $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 );
    19771936                }
    19781937        ;
     
    19921951        ;
    19931952
    1994 cfa_parameter_ellipsis_list_opt:                                                        // CFA, abstract + real
     1953cfa_parameter_type_list_opt:                                                    // CFA, abstract + real
    19951954        // empty
    19961955                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    21252084                { $$ = $2; }
    21262085        | '=' VOID
    2127                 { $$ = new InitializerNode( true ); }
     2086                { $$ = nullptr; }
    21282087        | ATassign initializer
    21292088                { $$ = $2->set_maybeConstructed( false ); }
     
    22022161type_parameter_list:                                                                    // CFA
    22032162        type_parameter
     2163                { $$ = $1; }
    22042164        | type_parameter_list ',' type_parameter
    22052165                { $$ = $1->appendList( $3 ); }
     
    22152175type_parameter:                                                                                 // CFA
    22162176        type_class no_attr_identifier_or_type_name
    2217                 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
     2177                { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
    22182178          type_initializer_opt assertion_list_opt
    22192179                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22492209        '|' no_attr_identifier_or_type_name '(' type_list ')'
    22502210                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    2251         | '|' '{' push trait_declaration_list pop '}'
     2211        | '|' '{' push trait_declaration_list '}'
    22522212                { $$ = $4; }
    2253         // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
    2254         //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2213        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
     2214                { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22552215        ;
    22562216
     
    22842244        no_attr_identifier_or_type_name
    22852245                {
    2286                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
     2246                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
    22872247                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22882248                }
    2289         | no_attr_identifier_or_type_name '(' type_parameter_list ')'
    2290                 {
    2291                         typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
    2292                         $$ = DeclarationNode::newTypeDecl( $1, $3 );
     2249        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
     2250                {
     2251                        typedefTable.addToEnclosingScope( *$1, TYPEGENname );
     2252                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
    22932253                }
    22942254        ;
    22952255
    22962256trait_specifier:                                                                                // CFA
    2297         TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
    2298                 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
    2299         | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
    2300                 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
     2257        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 ); }
    23012261        ;
    23022262
    23032263trait_declaration_list:                                                                 // CFA
    23042264        trait_declaration
    2305         | trait_declaration_list pop push trait_declaration
    2306                 { $$ = $1->appendList( $4 ); }
     2265        | trait_declaration_list push trait_declaration
     2266                { $$ = $1->appendList( $3 ); }
    23072267        ;
    23082268
    23092269trait_declaration:                                                                              // CFA
    2310         cfa_trait_declaring_list ';'
    2311         | trait_declaring_list ';'
     2270        cfa_trait_declaring_list pop ';'
     2271        | trait_declaring_list pop ';'
    23122272        ;
    23132273
     
    23292289
    23302290translation_unit:
    2331         // empty, input file
     2291        // empty
     2292                {}                                                                                              // empty input file
    23322293        | external_definition_list
    23332294                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23352296
    23362297external_definition_list:
    2337         push external_definition pop
    2338                 { $$ = $2; }
     2298        external_definition
    23392299        | external_definition_list
    23402300                { forall = xxx; }
    2341           push external_definition pop
     2301          push external_definition
    23422302                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23432303        ;
     
    23492309        ;
    23502310
    2351 up:
    2352                 { typedefTable.up(); }
    2353         ;
    2354 
    2355 down:
    2356                 { typedefTable.down(); }
    2357         ;
    2358 
    23592311external_definition:
    23602312        declaration
    23612313        | external_function_definition
     2314        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
     2315                {
     2316                        $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) );
     2317                }
     2318        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
     2319                {
     2320                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
     2321                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
     2322                }
     2323          '{' external_definition_list_opt '}'
     2324                {
     2325                        linkage = linkageStack.top();
     2326                        linkageStack.pop();
     2327                        $$ = $5;
     2328                }
    23622329        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
    23632330                {
     
    23652332                        $$ = $2;
    23662333                }
    2367         | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    2368                 {
    2369                         $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) );
    2370                 }
    2371         | EXTERN STRINGliteral                                                          // C++-style linkage specifier
    2372                 {
    2373                         linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2374                         linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    2375                 }
    2376           '{' up external_definition_list_opt down '}'
    2377                 {
    2378                         linkage = linkageStack.top();
    2379                         linkageStack.pop();
    2380                         $$ = $6;
    2381                 }
    23822334        | type_qualifier_list
    2383                 {
    2384                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2385                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2386                 }
    2387           '{' up external_definition_list_opt down '}'          // CFA, namespace
     2335                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2336          push '{' external_definition_list '}'                         // CFA, namespace
    23882337                {
    23892338                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     
    23972346                }
    23982347        | declaration_qualifier_list
    2399                 {
    2400                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2401                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2402                 }
    2403           '{' up external_definition_list_opt down '}'          // CFA, namespace
     2348                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2349          push '{' external_definition_list '}'                         // CFA, namespace
    24042350                {
    24052351                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     
    24142360        | declaration_qualifier_list type_qualifier_list
    24152361                {
    2416                         if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2417                         if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type
    2418                 }
    2419           '{' up external_definition_list_opt down '}'          // CFA, namespace
     2362                        // forall must be in the type_qualifier_list
     2363                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
     2364                }
     2365          push '{' external_definition_list '}'                         // CFA, namespace
    24202366                {
    24212367                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     
    24412387        | function_declarator compound_statement
    24422388                { $$ = $1->addFunctionBody( $2 ); }
    2443         | KR_function_declarator KR_parameter_list_opt compound_statement
     2389        | KR_function_declarator KR_declaration_list_opt compound_statement
    24442390                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24452391        ;
     
    24812427
    24822428                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2483         | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2429        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24842430                {
    24852431                        rebindForall( $1, $2 );
     
    24872433                }
    24882434                // handles default int return type, OBSOLESCENT (see 1)
    2489         | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2435        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24902436                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24912437                // handles default int return type, OBSOLESCENT (see 1)
    2492         | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2438        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24932439                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24942440                // handles default int return type, OBSOLESCENT (see 1)
    2495         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2441        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24962442                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24972443        ;
     
    27382684        typedef
    27392685                // hide type name in enclosing scope by variable name
    2740                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); }
     2686                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
    27412687        | '(' paren_type ')'
    27422688                { $$ = $2; }
     
    30282974        '[' ']'
    30292975                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    3030                 // multi_array_dimension handles the '[' '*' ']' case
     2976        // multi_array_dimension handles the '[' '*' ']' case
    30312977        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
    30322978                { $$ = DeclarationNode::newVarArray( $3 ); }
    30332979        | '[' push type_qualifier_list pop ']'
    30342980                { $$ = DeclarationNode::newArray( 0, $3, false ); }
    3035                 // multi_array_dimension handles the '[' assignment_expression ']' case
     2981        // multi_array_dimension handles the '[' assignment_expression ']' case
    30362982        | '[' push type_qualifier_list assignment_expression pop ']'
    30372983                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     
    31693115//
    31703116//              cfa_abstract_tuple identifier_or_type_name
    3171 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
     3117//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    31723118//
    31733119// since a function return type can be syntactically identical to a tuple type:
     
    32283174        '[' push cfa_abstract_parameter_list pop ']'
    32293175                { $$ = DeclarationNode::newTuple( $3 ); }
    3230         | '[' push type_specifier_nobody ELLIPSIS pop ']'
    3231                 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    3232         | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
    3233                 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    32343176        ;
    32353177
    32363178cfa_abstract_function:                                                                  // CFA
    3237 //      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
     3179//      '[' ']' '(' cfa_parameter_type_list_opt ')'
    32383180//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    3239         cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
     3181        cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
    32403182                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    3241         | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
     3183        | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
    32423184                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    32433185        ;
     
    32703212
    32713213%%
    3272 
    32733214// ----end of grammar----
    32743215
Note: See TracChangeset for help on using the changeset viewer.