Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r7951100 rb067d9b  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 10:07:12 2018
    13 // Update Count     : 3527
     12// Last Modified On : Sun Aug  4 21:48:23 2019
     13// Update Count     : 4364
    1414//
    1515
     
    9999        // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
    100100        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
    101         //cur->addType( specifier );
    102         for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
     101        for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    103102                cl->cloneBaseType( cur );
    104103        } // for
    105104        declList->addType( cl );
    106 //      delete cl;
    107105        return declList;
    108106} // distAttr
     
    114112        } // for
    115113} // distExt
     114
     115void distInl( DeclarationNode * declaration ) {
     116        // distribute EXTENSION across all declarations
     117        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     118                iter->set_inLine( true );
     119        } // for
     120} // distInl
     121
     122void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
     123        // distribute qualifiers across all non-variable declarations in a distribution statemement
     124        for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     125                // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since
     126                // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To
     127                // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to
     128                // be copied to add to front), the appropriate forall pointers are interchanged before calling addQualifiers.
     129                DeclarationNode * clone = qualifiers->clone();
     130                if ( qualifiers->type ) {                                               // forall clause ? (handles SC)
     131                        if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ?
     132                                swap( clone->type->forall, iter->type->aggregate.params );
     133                                iter->addQualifiers( clone );
     134                        } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ?
     135                                // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together.
     136                                DeclarationNode newnode;
     137                                swap( newnode.type, iter->type->aggInst.aggregate );
     138                                swap( clone->type->forall, newnode.type->aggregate.params );
     139                                newnode.addQualifiers( clone );
     140                                swap( newnode.type, iter->type->aggInst.aggregate );
     141                        } else if ( iter->type->kind == TypeData::Function ) { // routines ?
     142                                swap( clone->type->forall, iter->type->forall );
     143                                iter->addQualifiers( clone );
     144                        } // if
     145                } else {                                                                                // just SC qualifiers
     146                        iter->addQualifiers( clone );
     147                } // if
     148        } // for
     149        delete qualifiers;
     150} // distQual
    116151
    117152// There is an ambiguity for inline generic-routine return-types and generic routines.
     
    136171} // build_postfix_name
    137172
    138 bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
     173DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) {
     174        if ( ! fieldList ) {                                                            // field declarator ?
     175                if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) {
     176                        stringstream ss;
     177                        typeSpec->type->print( ss );
     178                        SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
     179                        return nullptr;
     180                } // if
     181                fieldList = DeclarationNode::newName( nullptr );
     182        } // if
     183        return distAttr( typeSpec, fieldList );                         // mark all fields in list
     184} // fieldDecl
     185
     186ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     187        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
     188        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
     189        type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     190        } // if
     191        return new ForCtrl(
     192                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
     193                // NULL comp/inc => leave blank
     194                comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : 0,
     195                inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
     196                                                        OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : 0 );
     197} // forCtrl
     198
     199ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     200        if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->expr.get()) ) {
     201                return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
     202        } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->expr.get()) ) {
     203                if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1 ) ) {
     204                        return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
     205                } else {
     206                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     207                } // if
     208        } else {
     209                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     210        } // if
     211} // forCtrl
     212
     213
     214bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
    139215
    140216// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    156232
    157233// Types declaration for productions
    158 %union
    159 {
     234%union {
    160235        Token tok;
    161236        ParseNode * pn;
     
    167242        WaitForStmt * wfs;
    168243        Expression * constant;
    169         IfCtl * ifctl;
    170         ForCtl * fctl;
     244        IfCtrl * ifctl;
     245        ForCtrl * fctl;
     246        enum OperKinds compop;
    171247        LabelNode * label;
    172248        InitializerNode * in;
     
    189265%token RESTRICT                                                                                 // C99
    190266%token ATOMIC                                                                                   // C11
    191 %token FORALL MUTEX VIRTUAL                                                             // CFA
     267%token FORALL MUTEX VIRTUAL COERCE                                              // CFA
    192268%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    193269%token BOOL COMPLEX IMAGINARY                                                   // C99
    194 %token INT128 FLOAT80 FLOAT128                                                  // GCC
     270%token INT128 UINT128 uuFLOAT80 uuFLOAT128                              // GCC
     271%token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC
    195272%token ZERO_T ONE_T                                                                             // CFA
    196273%token VALIST                                                                                   // GCC
    197 %token TYPEOF LABEL                                                                             // GCC
     274%token AUTO_TYPE                                                                                // GCC
     275%token TYPEOF BASETYPEOF LABEL                                                  // GCC
    198276%token ENUM STRUCT UNION
    199277%token EXCEPTION                                                                                // CFA
    200 %token COROUTINE MONITOR THREAD                                                 // CFA
     278%token GENERATOR COROUTINE MONITOR THREAD                               // CFA
    201279%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    202280%token SIZEOF OFFSETOF
     281// %token SUSPEND RESUME                                                                        // CFA
    203282%token ATTRIBUTE EXTENSION                                                              // GCC
    204283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    210289%token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
    211290%token<tok> TIMEOUT                             WOR
    212 %token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
    213291%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
    214292%token<tok> DIRECTIVE
     
    231309%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
    232310
     311%token ErangeUpEq       ErangeDown      ErangeDownEq                    // ~=   -~      -~=
    233312%token ATassign                                                                                 // @=
    234313
    235 %type<tok> identifier  no_attr_identifier
    236 %type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
     314%type<tok> identifier
     315%type<tok> identifier_or_type_name  attr_name
    237316%type<tok> quasi_keyword
    238317%type<constant> string_literal
     
    252331%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    253332%type<ifctl> if_control_expression
    254 %type<fctl> for_control_expression
     333%type<fctl> for_control_expression              for_control_expression_list
     334%type<compop> inclexcl
    255335%type<en> subrange
    256336%type<decl> asm_name_opt
    257 %type<en> asm_operands_opt asm_operands_list asm_operand
     337%type<en> asm_operands_opt                              asm_operands_list                       asm_operand
    258338%type<label> label_list
    259339%type<en> asm_clobbers_list_opt
    260340%type<flag> asm_volatile_opt
    261341%type<en> handler_predicate_opt
    262 %type<genexpr> generic_association generic_assoc_list
     342%type<genexpr> generic_association              generic_assoc_list
    263343
    264344// statements
     
    304384%type<en> enumerator_value_opt
    305385
    306 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
    307 
    308 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
    309 %type<en> field field_list field_name fraction_constants_opt
     386%type<decl> external_definition external_definition_list external_definition_list_opt
     387
     388%type<decl> exception_declaration
     389
     390%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
     391%type<en> field field_name_list field_name fraction_constants_opt
    310392
    311393%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    320402%type<decl> cfa_array_parameter_1st_dimension
    321403
    322 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
     404%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
    323405%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
    324406
     
    355437%type<decl> type_parameter type_parameter_list type_initializer_opt
    356438
    357 %type<en> type_list
     439%type<en> type_parameters_opt type_list
    358440
    359441%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    390472//   Foo ( *fp )( int );
    391473//   `---'                                              matches start of TYPEGENname '('
    392 // Must be:
     474// must be:
    393475//   Foo( int ) ( *fp )( int );
     476// The same problem occurs here:
     477//   forall( otype T ) struct Foo { T v; } ( *fp )( int );
     478// must be:
     479//   forall( otype T ) struct Foo { T v; } ( int ) ( *fp )( int );
    394480
    395481// Order of these lines matters (low-to-high precedence).
    396482%precedence TYPEGENname
     483%precedence '}'
    397484%precedence '('
     485
     486// %precedence RESUME
     487// %precedence '{'
     488// %precedence ')'
    398489
    399490%locations                                                                                              // support location tracking for error messages
     
    457548identifier:
    458549        IDENTIFIER
    459         | ATTR_IDENTIFIER                                                                       // CFA
    460550        | quasi_keyword
    461         ;
    462 
    463 no_attr_identifier:
    464         IDENTIFIER
    465         | quasi_keyword
     551        | '@'                                                                                           // CFA
     552                { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
    466553        ;
    467554
     
    502589        | '(' comma_expression ')' '`' IDENTIFIER                       // CFA, postfix call
    503590                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    504         | type_name '.' no_attr_identifier                                      // CFA, nested type
    505                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    506                 { $$ = nullptr; }
    507         | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    508                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    509                 { $$ = nullptr; }
     591        | type_name '.' identifier                                                      // CFA, nested type
     592                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     593        | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
     594                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    510595        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    511596                {
     
    514599                        $$ = new ExpressionNode( $5 );
    515600                }
     601        // | RESUME '(' comma_expression ')'
     602        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
     603        // | RESUME '(' comma_expression ')' compound_statement
     604        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
    516605        ;
    517606
     
    553642        | postfix_expression '(' argument_expression_list ')'
    554643                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    555         | postfix_expression '.' no_attr_identifier
     644        | postfix_expression '.' identifier
    556645                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    557646        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
     
    559648        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    560649                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    561         | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
     650        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
    562651                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    563         | postfix_expression ARROW no_attr_identifier
    564                 {
    565                         $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    566                 }
     652        | postfix_expression ARROW identifier
     653                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
    567654        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    568655                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    569         | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
     656        | postfix_expression ARROW '[' field_name_list ']'      // CFA, tuple field selector
    570657                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    571658        | postfix_expression ICR
     
    586673
    587674argument_expression_list:
    588         argument_expression
     675        // empty
     676                { $$ = nullptr; }
     677        | argument_expression
    589678        | argument_expression_list ',' argument_expression
    590679                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     
    592681
    593682argument_expression:
    594         // empty
    595                 { $$ = nullptr; }
    596         // | '@'                                                                                                // use default argument
    597         //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     683        '@'                                                                                                     // CFA, default parameter
     684                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
     685                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    598686        | assignment_expression
    599687        ;
    600688
    601 field_list:                                                                                             // CFA, tuple field selector
     689field_name_list:                                                                                // CFA, tuple field selector
    602690        field
    603         | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     691        | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    604692        ;
    605693
     
    608696        | FLOATING_DECIMALconstant field
    609697                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    610         | FLOATING_DECIMALconstant '[' field_list ']'
     698        | FLOATING_DECIMALconstant '[' field_name_list ']'
    611699                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    612700        | field_name '.' field
    613701                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    614         | field_name '.' '[' field_list ']'
     702        | field_name '.' '[' field_name_list ']'
    615703                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    616704        | field_name ARROW field
    617705                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    618         | field_name ARROW '[' field_list ']'
     706        | field_name ARROW '[' field_name_list ']'
    619707                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    620708        ;
     
    625713        | FLOATINGconstant fraction_constants_opt
    626714                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
    627         | no_attr_identifier fraction_constants_opt
     715        | identifier fraction_constants_opt
    628716                {
    629717                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     
    683771        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    684772                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
    685         | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
     773        | OFFSETOF '(' type_no_function ',' identifier ')'
    686774                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
    687         | ATTR_IDENTIFIER
    688                 { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ) ) ); }
    689         | ATTR_IDENTIFIER '(' argument_expression ')'
    690                 { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    691         | ATTR_IDENTIFIER '(' type ')'
    692                 { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuildType( $3 ) ) ); }
    693775        ;
    694776
     
    711793        | '(' type_no_function ')' cast_expression
    712794                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
     795                // keyword cast cannot be grouped because of reduction in aggregate_key
     796        | '(' GENERATOR '&' ')' cast_expression                         // CFA
     797                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
    713798        | '(' COROUTINE '&' ')' cast_expression                         // CFA
    714799                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     
    722807        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    723808                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
     809        | '(' RETURN type_no_function ')' cast_expression       // CFA
     810                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     811        | '(' COERCE type_no_function ')' cast_expression       // CFA
     812                { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; }
     813        | '(' qualifier_cast_list ')' cast_expression           // CFA
     814                { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; }
    724815//      | '(' type_no_function ')' tuple
    725816//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
     817        ;
     818
     819qualifier_cast_list:
     820        cast_modifier type_qualifier_name
     821        | cast_modifier MUTEX
     822        | qualifier_cast_list cast_modifier type_qualifier_name
     823        | qualifier_cast_list cast_modifier MUTEX
     824        ;
     825
     826cast_modifier:
     827        '-'
     828        | '+'
    726829        ;
    727830
     
    9041007
    9051008labeled_statement:
    906                 // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
     1009                // labels cannot be identifiers 0 or 1
    9071010        identifier_or_type_name ':' attribute_list_opt statement
    908                 {
    909                         $$ = $4->add_label( $1, $3 );
    910                 }
     1011                { $$ = $4->add_label( $1, $3 ); }
    9111012        ;
    9121013
     
    9241025        statement_decl
    9251026        | statement_decl_list statement_decl
    926                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     1027                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    9271028        ;
    9281029
     
    9311032                { $$ = new StatementNode( $1 ); }
    9321033        | EXTENSION declaration                                                         // GCC
    933                 {
    934                         distExt( $2 );
    935                         $$ = new StatementNode( $2 );
    936                 }
     1034                { distExt( $2 ); $$ = new StatementNode( $2 ); }
    9371035        | function_definition
    9381036                { $$ = new StatementNode( $1 ); }
    9391037        | EXTENSION function_definition                                         // GCC
    940                 {
    941                         distExt( $2 );
    942                         $$ = new StatementNode( $2 );
    943                 }
     1038                { distExt( $2 ); $$ = new StatementNode( $2 ); }
    9441039        | statement
    9451040        ;
     
    9481043        statement
    9491044        | statement_list_nodecl statement
    950                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     1045                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    9511046        ;
    9521047
     
    9921087if_control_expression:
    9931088        comma_expression
    994                 { $$ = new IfCtl( nullptr, $1 ); }
     1089                { $$ = new IfCtrl( nullptr, $1 ); }
    9951090        | c_declaration                                                                         // no semi-colon
    996                 { $$ = new IfCtl( $1, nullptr ); }
     1091                { $$ = new IfCtrl( $1, nullptr ); }
    9971092        | cfa_declaration                                                                       // no semi-colon
    998                 { $$ = new IfCtl( $1, nullptr ); }
     1093                { $$ = new IfCtrl( $1, nullptr ); }
    9991094        | declaration comma_expression                                          // semi-colon separated
    1000                 { $$ = new IfCtl( $1, $2 ); }
     1095                { $$ = new IfCtrl( $1, $2 ); }
    10011096        ;
    10021097
     
    10541149        WHILE '(' push if_control_expression ')' statement pop
    10551150                { $$ = new StatementNode( build_while( $4, $6 ) ); }
     1151        | WHILE '(' ')' statement                                                       // CFA => while ( 1 )
     1152                { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); }
    10561153        | DO statement WHILE '(' comma_expression ')' ';'
    10571154                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
    1058         | FOR '(' push for_control_expression ')' statement pop
     1155        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
     1156                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); }
     1157        | FOR '(' push for_control_expression_list ')' statement pop
    10591158                { $$ = new StatementNode( build_for( $4, $6 ) ); }
     1159        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     1160                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4 ) ); }
     1161        ;
     1162
     1163for_control_expression_list:
     1164        for_control_expression
     1165        | for_control_expression_list ':' for_control_expression
     1166                // ForCtrl + ForCtrl:
     1167                //    init + init => multiple declaration statements that are hoisted
     1168                //    condition + condition => (expression) && (expression)
     1169                //    change + change => (expression), (expression)
     1170                {
     1171                        $1->init->set_last( $3->init );
     1172                        if ( $1->condition ) {
     1173                                if ( $3->condition ) {
     1174                                        $1->condition->expr.reset( new LogicalExpr( $1->condition->expr.release(), $3->condition->expr.release(), true ) );
     1175                                } // if
     1176                        } else $1->condition = $3->condition;
     1177                        if ( $1->change ) {
     1178                                if ( $3->change ) {
     1179                                        $1->change->expr.reset( new CommaExpr( $1->change->expr.release(), $3->change->expr.release() ) );
     1180                                } // if
     1181                        } else $1->change = $3->change;
     1182                        $$ = $1;
     1183                }
    10601184        ;
    10611185
    10621186for_control_expression:
    1063         comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
    1064                 { $$ = new ForCtl( $1, $3, $5 ); }
    1065         | declaration comma_expression_opt ';' comma_expression_opt // C99
    1066                 { $$ = new ForCtl( $1, $2, $4 ); }
     1187        ';' comma_expression_opt ';' comma_expression_opt
     1188                { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
     1189        | comma_expression ';' comma_expression_opt ';' comma_expression_opt
     1190                { $$ = new ForCtrl( $1, $3, $5 ); }
     1191        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
     1192                { $$ = new ForCtrl( $1, $2, $4 ); }
     1193
     1194        | comma_expression                                                                      // CFA
     1195                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1196                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1197        | comma_expression inclexcl comma_expression            // CFA
     1198                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1199        | comma_expression inclexcl comma_expression '~' comma_expression // CFA
     1200                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
     1201        | comma_expression ';' comma_expression                         // CFA
     1202                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1203                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1204        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
     1205                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1206        | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA
     1207                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); }
     1208
     1209                // There is a S/R conflicit if ~ and -~ are factored out.
     1210        | comma_expression ';' comma_expression '~' '@'         // CFA
     1211                { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1212        | comma_expression ';' comma_expression ErangeDown '@' // CFA
     1213                { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1214        | comma_expression ';' comma_expression '~' '@' '~' comma_expression // CFA
     1215                { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, $7 ); }
     1216        | comma_expression ';' comma_expression ErangeDown '@' '~' comma_expression // CFA
     1217                { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, $7 ); }
     1218        | comma_expression ';' comma_expression '~' '@' '~' '@' // CFA
     1219                { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, nullptr ); }
     1220        ;
     1221
     1222inclexcl:
     1223        '~'
     1224                { $$ = OperKinds::LThan; }
     1225        | ErangeUpEq
     1226                { $$ = OperKinds::LEThan; }
     1227        | ErangeDown
     1228                { $$ = OperKinds::GThan; }
     1229        | ErangeDownEq
     1230                { $$ = OperKinds::GEThan; }
    10671231        ;
    10681232
     
    10971261        | RETURN comma_expression_opt ';'
    10981262                { $$ = new StatementNode( build_return( $2 ) ); }
    1099         | RETURN '{' initializer_list_opt comma_opt '}'
     1263        | RETURN '{' initializer_list_opt comma_opt '}' ';'
    11001264                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
     1265        // | SUSPEND ';'
     1266        //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1267        // | SUSPEND compound_statement ';'
     1268        //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
    11011269        | THROW assignment_expression_opt ';'                           // handles rethrow
    11021270                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    11361304
    11371305waitfor:
    1138         WAITFOR '(' identifier ')'
    1139                 {
    1140                         $$ = new ExpressionNode( new NameExpr( *$3 ) );
    1141                         delete $3;
    1142                 }
    1143         | WAITFOR '(' identifier ',' argument_expression_list ')'
    1144                 {
    1145                         $$ = new ExpressionNode( new NameExpr( *$3 ) );
    1146                         $$->set_last( $5 );
    1147                         delete $3;
    1148                 }
     1306        WAITFOR '(' cast_expression ')'
     1307                { $$ = $3; }
     1308        | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1309                { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    11491310        ;
    11501311
     
    11631324                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    11641325                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1326        | when_clause_opt timeout statement WOR ELSE statement
     1327                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    11651328        | when_clause_opt timeout statement WOR when_clause ELSE statement
    11661329                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
     
    11841347
    11851348handler_clause:
    1186         handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1349        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    11871350                { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
    1188         | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1351        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    11891352                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
    11901353        ;
     
    12121375        | type_specifier_nobody variable_abstract_declarator
    12131376                { $$ = $2->addType( $1 ); }
    1214         | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
     1377        | cfa_abstract_declarator_tuple identifier                      // CFA
    12151378                { $$ = $1->addName( $2 ); }
    12161379        | cfa_abstract_declarator_tuple                                         // CFA
     
    12761439
    12771440label_list:
    1278         no_attr_identifier
     1441        identifier
    12791442                {
    12801443                        $$ = new LabelNode(); $$->labels.push_back( *$1 );
    12811444                        delete $1;                                                                      // allocated by lexer
    12821445                }
    1283         | label_list ',' no_attr_identifier
     1446        | label_list ',' identifier
    12841447                {
    12851448                        $$ = $1; $1->labels.push_back( *$3 );
     
    13261489
    13271490local_label_list:                                                                               // GCC, local label
    1328         no_attr_identifier_or_type_name
    1329         | local_label_list ',' no_attr_identifier_or_type_name
     1491        identifier_or_type_name
     1492        | local_label_list ',' identifier_or_type_name
    13301493        ;
    13311494
     
    14491612                        $$ = $2->addTypedef();
    14501613                }
    1451         | cfa_typedef_declaration pop ',' push no_attr_identifier
     1614        | cfa_typedef_declaration pop ',' push identifier
    14521615                {
    14531616                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
     
    14891652typedef_expression:
    14901653                // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
    1491         TYPEDEF no_attr_identifier '=' assignment_expression
     1654        TYPEDEF identifier '=' assignment_expression
    14921655                {
    14931656                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    14941657                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    14951658                }
    1496         | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
     1659        | typedef_expression pop ',' push identifier '=' assignment_expression
    14971660                {
    14981661                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     
    16631826        | INT128
    16641827                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); }
     1828        | UINT128
     1829                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ); }
    16651830        | FLOAT
    16661831                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
    1667         | FLOAT80
    1668                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }
    1669         | FLOAT128
    1670                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }
    16711832        | DOUBLE
    16721833                { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
     1834        | uuFLOAT80
     1835                { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat80 ); }
     1836        | uuFLOAT128
     1837                { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat128 ); }
     1838        | uFLOAT16
     1839                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat16 ); }
     1840        | uFLOAT32
     1841                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32 ); }
     1842        | uFLOAT32X
     1843                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32x ); }
     1844        | uFLOAT64
     1845                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64 ); }
     1846        | uFLOAT64X
     1847                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64x ); }
     1848        | uFLOAT128
     1849                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); }
    16731850        | COMPLEX                                                                                       // C99
    16741851                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     
    16851862        | VALIST                                                                                        // GCC, __builtin_va_list
    16861863                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
     1864        | AUTO_TYPE
     1865                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::AutoType ); }
    16871866        ;
    16881867
     
    17181897
    17191898indirect_type:
    1720         TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
     1899        TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
    17211900                { $$ = $3; }
    1722         | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
     1901        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
    17231902                { $$ = DeclarationNode::newTypeof( $3 ); }
    1724         | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
    1725                 { $$ = DeclarationNode::newAttr( $1, $3 ); }
    1726         | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
    1727                 { $$ = DeclarationNode::newAttr( $1, $3 ); }
     1903        | BASETYPEOF '(' type ')'                                                       // CFA: basetypeof( x ) y;
     1904                { $$ = DeclarationNode::newTypeof( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ), true ); }
     1905        | BASETYPEOF '(' comma_expression ')'                           // CFA: basetypeof( a+b ) y;
     1906                { $$ = DeclarationNode::newTypeof( $3, true ); }
    17281907        | ZERO_T                                                                                        // CFA
    17291908                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
     
    17491928                { $$ = $3->addQualifiers( $1 ); }
    17501929        | sue_type_specifier type_qualifier
    1751                 { $$ = $1->addQualifiers( $2 ); }
     1930                {
     1931                        if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type
     1932                        $$ = $1->addQualifiers( $2 );
     1933                }
    17521934        ;
    17531935
     
    17921974                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17931975        | '.' TYPEDEFname
    1794                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1976                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
    17951977        | type_name '.' TYPEDEFname
    1796                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1978                { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
    17971979        | typegen_name
    17981980        | '.' typegen_name
    1799                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1981                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
    18001982        | type_name '.' typegen_name
    1801                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1983                { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
    18021984        ;
    18031985
     
    18212003        ;
    18222004
     2005fred:
     2006        // empty
     2007                { yyy = false; }
     2008        ;
     2009
    18232010aggregate_type:                                                                                 // struct, union
    1824         aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    1825                 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1826         | aggregate_key attribute_list_opt no_attr_identifier
    1827                 {
    1828                         typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1829                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     2011        aggregate_key attribute_list_opt
     2012                { forall = false; }                                                             // reset
     2013          '{' field_declaration_list_opt '}' type_parameters_opt
     2014                { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); }
     2015        | aggregate_key attribute_list_opt identifier fred
     2016                {
     2017                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
    18302018                        forall = false;                                                         // reset
    18312019                }
    1832           '{' field_declaration_list_opt '}'
    1833                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1834         | aggregate_key attribute_list_opt type_name
    1835                 {
    1836                         typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1837                         //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
     2020          '{' field_declaration_list_opt '}' type_parameters_opt
     2021                { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); }
     2022        | aggregate_key attribute_list_opt type_name fred
     2023                {
     2024                        // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one)
     2025                        typedefTable.makeTypedef( *$3->type->leafName(), forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
    18382026                        forall = false;                                                         // reset
    18392027                }
    1840           '{' field_declaration_list_opt '}'
    1841                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $6, true )->addQualifiers( $2 ); }
    1842         | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    1843                 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     2028          '{' field_declaration_list_opt '}' type_parameters_opt
     2029                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); }
    18442030        | aggregate_type_nobody
    18452031        ;
    18462032
     2033type_parameters_opt:
     2034        // empty
     2035                { $$ = nullptr; }                                                               %prec '}'
     2036        | '(' type_list ')'
     2037                { $$ = $2; }
     2038        ;
     2039
    18472040aggregate_type_nobody:                                                                  // struct, union - {...}
    1848         aggregate_key attribute_list_opt no_attr_identifier
    1849                 {
    1850                         typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
    1851                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     2041        aggregate_key attribute_list_opt identifier fred
     2042                {
     2043                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname );
    18522044                        forall = false;                                                         // reset
    18532045                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18542046                }
    1855         | aggregate_key attribute_list_opt type_name
    1856                 {
     2047        | aggregate_key attribute_list_opt type_name fred
     2048                {
     2049                        forall = false;                                                         // reset
    18572050                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
    18582051                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
     
    18672060aggregate_key:
    18682061        STRUCT
    1869                 { $$ = DeclarationNode::Struct; }
     2062                { yyy = true; $$ = DeclarationNode::Struct; }
    18702063        | UNION
    1871                 { $$ = DeclarationNode::Union; }
     2064                { yyy = true; $$ = DeclarationNode::Union; }
    18722065        | EXCEPTION
    1873                 { $$ = DeclarationNode::Exception; }
     2066                { yyy = true; $$ = DeclarationNode::Exception; }
     2067        | GENERATOR
     2068                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18742069        | COROUTINE
    1875                 { $$ = DeclarationNode::Coroutine; }
     2070                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18762071        | MONITOR
    1877                 { $$ = DeclarationNode::Monitor; }
     2072                { yyy = true; $$ = DeclarationNode::Monitor; }
    18782073        | THREAD
    1879                 { $$ = DeclarationNode::Thread; }
     2074                { yyy = true; $$ = DeclarationNode::Thread; }
    18802075        ;
    18812076
     
    18882083
    18892084field_declaration:
    1890         type_specifier field_declaring_list ';'
    1891                 { $$ = distAttr( $1, $2 ); }
    1892         | EXTENSION type_specifier field_declaring_list ';'     // GCC
    1893                 { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
     2085        type_specifier field_declaring_list_opt ';'
     2086                { $$ = fieldDecl( $1, $2 ); }
     2087        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
     2088                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     2089        | INLINE type_specifier field_abstract_list_opt ';'     // CFA
     2090                {
     2091                        if ( ! $3 ) {                                                           // field declarator ?
     2092                                $3 = DeclarationNode::newName( nullptr );
     2093                        } // if
     2094                        $3->inLine = true;
     2095                        $$ = distAttr( $2, $3 );                                        // mark all fields in list
     2096                        distInl( $3 );
     2097                }
    18942098        | typedef_declaration ';'                                                       // CFA
    1895                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    18962099        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    18972100        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    18982101                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
     2102        | INLINE cfa_field_abstract_list ';'                            // CFA, new style field declaration
     2103                { $$ = $2; }                                                                    // mark all fields in list
    18992104        | cfa_typedef_declaration ';'                                           // CFA
    1900                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    19012105        | static_assert                                                                         // C11
    19022106        ;
    19032107
    1904 cfa_field_declaring_list:                                                               // CFA, new style field declaration
    1905         cfa_abstract_declarator_tuple                                           // CFA, no field name
    1906         | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
    1907                 { $$ = $1->addName( $2 ); }
    1908         | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
    1909                 { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    1910         | cfa_field_declaring_list ','                                          // CFA, no field name
    1911                 { $$ = $1->appendList( $1->cloneType( 0 ) ); }
    1912         ;
    1913 
    1914 field_declaring_list:
    1915         field_declarator_opt
    1916         | field_declaring_list ',' attribute_list_opt field_declarator_opt
     2108field_declaring_list_opt:
     2109        // empty
     2110                { $$ = nullptr; }
     2111        | field_declarator
     2112        | field_declaring_list_opt ',' attribute_list_opt field_declarator
    19172113                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    19182114        ;
    19192115
    1920 field_declarator_opt:
    1921         // empty
    1922                 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
    1923         // '@'
    1924         //      { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name
    1925         | bit_subrange_size                                                                     // no field name
     2116field_declarator:
     2117        bit_subrange_size                                                                       // C special case, no field name
    19262118                { $$ = DeclarationNode::newBitfield( $1 ); }
    19272119        | variable_declarator bit_subrange_size_opt
    1928                 // A semantic check is required to ensure bit_subrange only appears on base type int.
     2120                // A semantic check is required to ensure bit_subrange only appears on integral types.
    19292121                { $$ = $1->addBitfield( $2 ); }
    19302122        | variable_type_redeclarator bit_subrange_size_opt
    1931                 // A semantic check is required to ensure bit_subrange only appears on base type int.
     2123                // A semantic check is required to ensure bit_subrange only appears on integral types.
    19322124                { $$ = $1->addBitfield( $2 ); }
    1933         | variable_abstract_declarator                                          // CFA, no field name
     2125        ;
     2126
     2127field_abstract_list_opt:
     2128        // empty
     2129                { $$ = nullptr; }
     2130        | field_abstract
     2131        | field_abstract_list_opt ',' attribute_list_opt field_abstract
     2132                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     2133        ;
     2134
     2135field_abstract:
     2136                //      no bit fields
     2137        variable_abstract_declarator
     2138        ;
     2139
     2140cfa_field_declaring_list:                                                               // CFA, new style field declaration
     2141        // bit-fields are handled by C declarations
     2142        cfa_abstract_declarator_tuple identifier_or_type_name
     2143                { $$ = $1->addName( $2 ); }
     2144        | cfa_field_declaring_list ',' identifier_or_type_name
     2145                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
     2146        ;
     2147
     2148cfa_field_abstract_list:                                                                // CFA, new style field declaration
     2149        // bit-fields are handled by C declarations
     2150        cfa_abstract_declarator_tuple
     2151        | cfa_field_abstract_list ','
     2152                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
    19342153        ;
    19352154
     
    19412160
    19422161bit_subrange_size:
    1943         ':' constant_expression
     2162        ':' assignment_expression
    19442163                { $$ = $2; }
    19452164        ;
     
    19472166enum_type:                                                                                              // enum
    19482167        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    1949                 { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
    1950         | ENUM attribute_list_opt no_attr_identifier
     2168                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     2169        | ENUM attribute_list_opt identifier
    19512170                { typedefTable.makeTypedef( *$3 ); }
    19522171          '{' enumerator_list comma_opt '}'
     
    19592178
    19602179enum_type_nobody:                                                                               // enum - {...}
    1961         ENUM attribute_list_opt no_attr_identifier
     2180        ENUM attribute_list_opt identifier
    19622181                {
    19632182                        typedefTable.makeTypedef( *$3 );
     
    19722191
    19732192enumerator_list:
    1974         no_attr_identifier_or_type_name enumerator_value_opt
     2193        identifier_or_type_name enumerator_value_opt
    19752194                { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
    1976         | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt
     2195        | enumerator_list ',' identifier_or_type_name enumerator_value_opt
    19772196                { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
    19782197        ;
     
    20822301
    20832302identifier_list:                                                                                // K&R-style parameter list => no types
    2084         no_attr_identifier
     2303        identifier
    20852304                { $$ = DeclarationNode::newName( $1 ); }
    2086         | identifier_list ',' no_attr_identifier
     2305        | identifier_list ',' identifier
    20872306                { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
    20882307        ;
     
    20902309identifier_or_type_name:
    20912310        identifier
    2092         | TYPEDEFname
    2093         | TYPEGENname
    2094         ;
    2095 
    2096 no_attr_identifier_or_type_name:
    2097         no_attr_identifier
    20982311        | TYPEDEFname
    20992312        | TYPEGENname
     
    21502363designation:
    21512364        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    2152         | no_attr_identifier ':'                                                        // GCC, field name
     2365        | identifier ':'                                                                        // GCC, field name
    21532366                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    21542367        ;
     
    21622375
    21632376designator:
    2164         '.' no_attr_identifier                                                          // C99, field name
     2377        '.' identifier                                                                          // C99, field name
    21652378                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    21662379        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    21712384        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    21722385                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    2173         | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
     2386        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    21742387                { $$ = $4; }
    21752388        ;
     
    22072420
    22082421type_parameter:                                                                                 // CFA
    2209         type_class no_attr_identifier_or_type_name
     2422        type_class identifier_or_type_name
    22102423                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    22112424          type_initializer_opt assertion_list_opt
     
    22402453
    22412454assertion:                                                                                              // CFA
    2242         '|' no_attr_identifier_or_type_name '(' type_list ')'
     2455        '|' identifier_or_type_name '(' type_list ')'
    22432456                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    22442457        | '|' '{' push trait_declaration_list pop '}'
     
    22522465                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    22532466        | assignment_expression
     2467                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    22542468        | type_list ',' type
    22552469                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    22562470        | type_list ',' assignment_expression
    2257                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     2471                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     2472                // { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    22582473        ;
    22592474
     
    22752490
    22762491type_declarator_name:                                                                   // CFA
    2277         no_attr_identifier_or_type_name
     2492        identifier_or_type_name
    22782493                {
    22792494                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
    22802495                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22812496                }
    2282         | no_attr_identifier_or_type_name '(' type_parameter_list ')'
     2497        | identifier_or_type_name '(' type_parameter_list ')'
    22832498                {
    22842499                        typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
     
    22882503
    22892504trait_specifier:                                                                                // CFA
    2290         TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
     2505        TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}'
    22912506                { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
    2292         | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
     2507        | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
    22932508                { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
    22942509        ;
     
    23222537
    23232538translation_unit:
    2324         // empty
    2325                 {}                                                                                              // empty input file
     2539        // empty, input file
    23262540        | external_definition_list
    23272541                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23312545        push external_definition pop
    23322546                { $$ = $2; }
    2333         | external_definition_list
    2334                 { forall = xxx; }
    2335           push external_definition pop
    2336                 { $$ = $1 ? $1->appendList( $4 ) : $4; }
    2337         ;
    2338 
    2339         // SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope.
    2340         // However, external_definition_list creates a new scope around each external_definition, but the pop loses all the
    2341         // types in the extern "X" and distribution at the end of the block. This version of external_definition_list does
    2342 
    2343         // not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of
    2344         // external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level.
    2345 external_definition_list_no_pop_push:
    2346         external_definition
    2347         | external_definition_list_no_pop_push
    2348                 { forall = xxx; }
    2349           external_definition
     2547        | external_definition_list push external_definition pop
    23502548                { $$ = $1 ? $1->appendList( $3 ) : $3; }
    23512549        ;
     
    23542552        // empty
    23552553                { $$ = nullptr; }
    2356         | external_definition_list_no_pop_push
     2554        | external_definition_list
     2555        ;
     2556
     2557up:
     2558                { typedefTable.up( forall ); forall = false; }
     2559        ;
     2560
     2561down:
     2562                { typedefTable.down(); }
    23572563        ;
    23582564
     
    23742580                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23752581                }
    2376           '{' external_definition_list_opt '}'
     2582          '{' up external_definition_list_opt down '}'
    23772583                {
    23782584                        linkage = linkageStack.top();
    23792585                        linkageStack.pop();
     2586                        $$ = $6;
     2587                }
     2588        | type_qualifier_list
     2589                {
     2590                        if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2591                        if ( $1->type->forall ) forall = true;          // remember generic type
     2592                }
     2593          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2594                {
     2595                        distQual( $5, $1 );
     2596                        forall = false;
    23802597                        $$ = $5;
    23812598                }
    2382         | type_qualifier_list
    2383                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2384           '{' external_definition_list_opt '}'                          // CFA, namespace
    2385                 {
    2386                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    2387                                 if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    2388                                         iter->addQualifiers( $1->clone() );
    2389                                 } // if
    2390                         } // for
    2391                         xxx = false;
    2392                         delete $1;
    2393                         $$ = $4;
    2394                 }
    23952599        | declaration_qualifier_list
    2396                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2397           '{' external_definition_list_opt '}'                          // CFA, namespace
    2398                 {
    2399                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    2400                                 if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    2401                                         iter->addQualifiers( $1->clone() );
    2402                                 } // if
    2403                         } // for
    2404                         xxx = false;
    2405                         delete $1;
    2406                         $$ = $4;
     2600                {
     2601                        if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2602                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
     2603                }
     2604          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2605                {
     2606                        distQual( $5, $1 );
     2607                        forall = false;
     2608                        $$ = $5;
    24072609                }
    24082610        | declaration_qualifier_list type_qualifier_list
    24092611                {
    2410                         // forall must be in the type_qualifier_list
    2411                         if ( $2->type->forall ) xxx = forall = true; // remember generic type
    2412                 }
    2413           '{' external_definition_list_opt '}'                          // CFA, namespace
    2414                 {
    2415                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    2416                                 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    2417                                         iter->addQualifiers( $1->clone() );
    2418                                         iter->addQualifiers( $2->clone() );
    2419                                 } // if
    2420                         } // for
    2421                         xxx = false;
    2422                         delete $1;
    2423                         delete $2;
    2424                         $$ = $5;
     2612                        if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2613                        if ( ($1->type && $1->type->forall) || $2->type->forall ) forall = true; // remember generic type
     2614                }
     2615          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2616                {
     2617                        distQual( $6, $1->addQualifiers( $2 ) );
     2618                        forall = false;
     2619                        $$ = $6;
    24252620                }
    24262621        ;
     
    27322927        typedef
    27332928                // hide type name in enclosing scope by variable name
    2734                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); }
     2929                {
     2930                        // if ( ! typedefTable.existsCurr( *$1->name ) ) {
     2931                                typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" );
     2932                        // } else {
     2933                        //      SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr;
     2934                        // } // if
     2935                }
    27352936        | '(' paren_type ')'
    27362937                { $$ = $2; }
     
    27432944                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    27442945        | '(' type_ptr ')' attribute_list_opt
    2745                 { $$ = $2->addQualifiers( $4 ); }
     2946                { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
    27462947        ;
    27472948
Note: See TracChangeset for help on using the changeset viewer.