Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rf1da02c ra1c9ddd  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 21:48:23 2019
    13 // Update Count     : 4364
     12// Last Modified On : Thu Jun  7 10:07:12 2018
     13// Update Count     : 3527
    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         for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
     101        //cur->addType( specifier );
     102        for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    102103                cl->cloneBaseType( cur );
    103104        } // for
    104105        declList->addType( cl );
     106//      delete cl;
    105107        return declList;
    106108} // distAttr
     
    112114        } // for
    113115} // distExt
    114 
    115 void 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 
    122 void 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
    151116
    152117// There is an ambiguity for inline generic-routine return-types and generic routines.
     
    171136} // build_postfix_name
    172137
    173 DeclarationNode * 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 
    186 ForCtrl * 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 
    199 ForCtrl * 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 
    214 bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
     138bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
    215139
    216140// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    232156
    233157// Types declaration for productions
    234 %union {
     158%union
     159{
    235160        Token tok;
    236161        ParseNode * pn;
     
    242167        WaitForStmt * wfs;
    243168        Expression * constant;
    244         IfCtrl * ifctl;
    245         ForCtrl * fctl;
    246         enum OperKinds compop;
     169        IfCtl * ifctl;
     170        ForCtl * fctl;
    247171        LabelNode * label;
    248172        InitializerNode * in;
     
    265189%token RESTRICT                                                                                 // C99
    266190%token ATOMIC                                                                                   // C11
    267 %token FORALL MUTEX VIRTUAL COERCE                                              // CFA
     191%token FORALL MUTEX VIRTUAL                                                             // CFA
    268192%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    269193%token BOOL COMPLEX IMAGINARY                                                   // C99
    270 %token INT128 UINT128 uuFLOAT80 uuFLOAT128                              // GCC
    271 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC
     194%token INT128 FLOAT80 FLOAT128                                                  // GCC
    272195%token ZERO_T ONE_T                                                                             // CFA
    273196%token VALIST                                                                                   // GCC
    274 %token AUTO_TYPE                                                                                // GCC
    275 %token TYPEOF BASETYPEOF LABEL                                                  // GCC
     197%token TYPEOF LABEL                                                                             // GCC
    276198%token ENUM STRUCT UNION
    277199%token EXCEPTION                                                                                // CFA
    278 %token GENERATOR COROUTINE MONITOR THREAD                               // CFA
     200%token COROUTINE MONITOR THREAD                                                 // CFA
    279201%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    280202%token SIZEOF OFFSETOF
    281 // %token SUSPEND RESUME                                                                        // CFA
    282203%token ATTRIBUTE EXTENSION                                                              // GCC
    283204%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    289210%token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
    290211%token<tok> TIMEOUT                             WOR
     212%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
    291213%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
    292214%token<tok> DIRECTIVE
     
    309231%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
    310232
    311 %token ErangeUpEq       ErangeDown      ErangeDownEq                    // ~=   -~      -~=
    312233%token ATassign                                                                                 // @=
    313234
    314 %type<tok> identifier
    315 %type<tok> identifier_or_type_name  attr_name
     235%type<tok> identifier  no_attr_identifier
     236%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
    316237%type<tok> quasi_keyword
    317238%type<constant> string_literal
     
    331252%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    332253%type<ifctl> if_control_expression
    333 %type<fctl> for_control_expression              for_control_expression_list
    334 %type<compop> inclexcl
     254%type<fctl> for_control_expression
    335255%type<en> subrange
    336256%type<decl> asm_name_opt
    337 %type<en> asm_operands_opt                              asm_operands_list                       asm_operand
     257%type<en> asm_operands_opt asm_operands_list asm_operand
    338258%type<label> label_list
    339259%type<en> asm_clobbers_list_opt
    340260%type<flag> asm_volatile_opt
    341261%type<en> handler_predicate_opt
    342 %type<genexpr> generic_association              generic_assoc_list
     262%type<genexpr> generic_association generic_assoc_list
    343263
    344264// statements
     
    384304%type<en> enumerator_value_opt
    385305
    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
     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
    392310
    393311%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    402320%type<decl> cfa_array_parameter_1st_dimension
    403321
    404 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
     322%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
    405323%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
    406324
     
    437355%type<decl> type_parameter type_parameter_list type_initializer_opt
    438356
    439 %type<en> type_parameters_opt type_list
     357%type<en> type_list
    440358
    441359%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    472390//   Foo ( *fp )( int );
    473391//   `---'                                              matches start of TYPEGENname '('
    474 // must be:
     392// Must be:
    475393//   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 );
    480394
    481395// Order of these lines matters (low-to-high precedence).
    482396%precedence TYPEGENname
    483 %precedence '}'
    484397%precedence '('
    485 
    486 // %precedence RESUME
    487 // %precedence '{'
    488 // %precedence ')'
    489398
    490399%locations                                                                                              // support location tracking for error messages
     
    548457identifier:
    549458        IDENTIFIER
     459        | ATTR_IDENTIFIER                                                                       // CFA
    550460        | quasi_keyword
    551         | '@'                                                                                           // CFA
    552                 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
     461        ;
     462
     463no_attr_identifier:
     464        IDENTIFIER
     465        | quasi_keyword
    553466        ;
    554467
     
    589502        | '(' comma_expression ')' '`' IDENTIFIER                       // CFA, postfix call
    590503                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    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; }
     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; }
    595510        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    596511                {
     
    599514                        $$ = new ExpressionNode( $5 );
    600515                }
    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; }
    605516        ;
    606517
     
    642553        | postfix_expression '(' argument_expression_list ')'
    643554                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    644         | postfix_expression '.' identifier
     555        | postfix_expression '.' no_attr_identifier
    645556                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    646557        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
     
    648559        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    649560                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    650         | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
     561        | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
    651562                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    652         | postfix_expression ARROW identifier
    653                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     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                }
    654567        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    655568                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    656         | postfix_expression ARROW '[' field_name_list ']'      // CFA, tuple field selector
     569        | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
    657570                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    658571        | postfix_expression ICR
     
    673586
    674587argument_expression_list:
     588        argument_expression
     589        | argument_expression_list ',' argument_expression
     590                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     591        ;
     592
     593argument_expression:
    675594        // empty
    676595                { $$ = nullptr; }
    677         | argument_expression
    678         | argument_expression_list ',' argument_expression
    679                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    680         ;
    681 
    682 argument_expression:
    683         '@'                                                                                                     // CFA, default parameter
    684                 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    685                 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     596        // | '@'                                                                                                // use default argument
     597        //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    686598        | assignment_expression
    687599        ;
    688600
    689 field_name_list:                                                                                // CFA, tuple field selector
     601field_list:                                                                                             // CFA, tuple field selector
    690602        field
    691         | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     603        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    692604        ;
    693605
     
    696608        | FLOATING_DECIMALconstant field
    697609                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    698         | FLOATING_DECIMALconstant '[' field_name_list ']'
     610        | FLOATING_DECIMALconstant '[' field_list ']'
    699611                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    700612        | field_name '.' field
    701613                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    702         | field_name '.' '[' field_name_list ']'
     614        | field_name '.' '[' field_list ']'
    703615                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    704616        | field_name ARROW field
    705617                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    706         | field_name ARROW '[' field_name_list ']'
     618        | field_name ARROW '[' field_list ']'
    707619                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    708620        ;
     
    713625        | FLOATINGconstant fraction_constants_opt
    714626                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
    715         | identifier fraction_constants_opt
     627        | no_attr_identifier fraction_constants_opt
    716628                {
    717629                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     
    771683        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    772684                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
    773         | OFFSETOF '(' type_no_function ',' identifier ')'
     685        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
    774686                { $$ = 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 ) ) ); }
    775693        ;
    776694
     
    793711        | '(' type_no_function ')' cast_expression
    794712                { $$ = 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 ) ); }
    798713        | '(' COROUTINE '&' ')' cast_expression                         // CFA
    799714                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     
    807722        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    808723                { $$ = 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; }
    815724//      | '(' type_no_function ')' tuple
    816725//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    817         ;
    818 
    819 qualifier_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 
    826 cast_modifier:
    827         '-'
    828         | '+'
    829726        ;
    830727
     
    1007904
    1008905labeled_statement:
    1009                 // labels cannot be identifiers 0 or 1
     906                // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
    1010907        identifier_or_type_name ':' attribute_list_opt statement
    1011                 { $$ = $4->add_label( $1, $3 ); }
     908                {
     909                        $$ = $4->add_label( $1, $3 );
     910                }
    1012911        ;
    1013912
     
    1025924        statement_decl
    1026925        | statement_decl_list statement_decl
    1027                 { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
     926                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    1028927        ;
    1029928
     
    1032931                { $$ = new StatementNode( $1 ); }
    1033932        | EXTENSION declaration                                                         // GCC
    1034                 { distExt( $2 ); $$ = new StatementNode( $2 ); }
     933                {
     934                        distExt( $2 );
     935                        $$ = new StatementNode( $2 );
     936                }
    1035937        | function_definition
    1036938                { $$ = new StatementNode( $1 ); }
    1037939        | EXTENSION function_definition                                         // GCC
    1038                 { distExt( $2 ); $$ = new StatementNode( $2 ); }
     940                {
     941                        distExt( $2 );
     942                        $$ = new StatementNode( $2 );
     943                }
    1039944        | statement
    1040945        ;
     
    1043948        statement
    1044949        | statement_list_nodecl statement
    1045                 { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
     950                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    1046951        ;
    1047952
     
    1087992if_control_expression:
    1088993        comma_expression
    1089                 { $$ = new IfCtrl( nullptr, $1 ); }
     994                { $$ = new IfCtl( nullptr, $1 ); }
    1090995        | c_declaration                                                                         // no semi-colon
    1091                 { $$ = new IfCtrl( $1, nullptr ); }
     996                { $$ = new IfCtl( $1, nullptr ); }
    1092997        | cfa_declaration                                                                       // no semi-colon
    1093                 { $$ = new IfCtrl( $1, nullptr ); }
     998                { $$ = new IfCtl( $1, nullptr ); }
    1094999        | declaration comma_expression                                          // semi-colon separated
    1095                 { $$ = new IfCtrl( $1, $2 ); }
     1000                { $$ = new IfCtl( $1, $2 ); }
    10961001        ;
    10971002
     
    11491054        WHILE '(' push if_control_expression ')' statement pop
    11501055                { $$ = 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 ) ); }
    11531056        | DO statement WHILE '(' comma_expression ')' ';'
    11541057                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
    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
     1058        | FOR '(' push for_control_expression ')' statement pop
    11581059                { $$ = 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 
    1163 for_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                 }
    11841060        ;
    11851061
    11861062for_control_expression:
    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 
    1222 inclexcl:
    1223         '~'
    1224                 { $$ = OperKinds::LThan; }
    1225         | ErangeUpEq
    1226                 { $$ = OperKinds::LEThan; }
    1227         | ErangeDown
    1228                 { $$ = OperKinds::GThan; }
    1229         | ErangeDownEq
    1230                 { $$ = OperKinds::GEThan; }
     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 ); }
    12311067        ;
    12321068
     
    12611097        | RETURN comma_expression_opt ';'
    12621098                { $$ = new StatementNode( build_return( $2 ) ); }
    1263         | RETURN '{' initializer_list_opt comma_opt '}' ';'
     1099        | RETURN '{' initializer_list_opt comma_opt '}'
    12641100                { 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; }
    12691101        | THROW assignment_expression_opt ';'                           // handles rethrow
    12701102                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    13041136
    13051137waitfor:
    1306         WAITFOR '(' cast_expression ')'
    1307                 { $$ = $3; }
    1308         | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1309                 { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     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                }
    13101149        ;
    13111150
     
    13241163                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    13251164                // "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; }
    13281165        | when_clause_opt timeout statement WOR when_clause ELSE statement
    13291166                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
     
    13471184
    13481185handler_clause:
    1349         handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
     1186        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    13501187                { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
    1351         | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
     1188        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    13521189                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
    13531190        ;
     
    13751212        | type_specifier_nobody variable_abstract_declarator
    13761213                { $$ = $2->addType( $1 ); }
    1377         | cfa_abstract_declarator_tuple identifier                      // CFA
     1214        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    13781215                { $$ = $1->addName( $2 ); }
    13791216        | cfa_abstract_declarator_tuple                                         // CFA
     
    14391276
    14401277label_list:
    1441         identifier
     1278        no_attr_identifier
    14421279                {
    14431280                        $$ = new LabelNode(); $$->labels.push_back( *$1 );
    14441281                        delete $1;                                                                      // allocated by lexer
    14451282                }
    1446         | label_list ',' identifier
     1283        | label_list ',' no_attr_identifier
    14471284                {
    14481285                        $$ = $1; $1->labels.push_back( *$3 );
     
    14891326
    14901327local_label_list:                                                                               // GCC, local label
    1491         identifier_or_type_name
    1492         | local_label_list ',' identifier_or_type_name
     1328        no_attr_identifier_or_type_name
     1329        | local_label_list ',' no_attr_identifier_or_type_name
    14931330        ;
    14941331
     
    16121449                        $$ = $2->addTypedef();
    16131450                }
    1614         | cfa_typedef_declaration pop ',' push identifier
     1451        | cfa_typedef_declaration pop ',' push no_attr_identifier
    16151452                {
    16161453                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
     
    16521489typedef_expression:
    16531490                // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
    1654         TYPEDEF identifier '=' assignment_expression
     1491        TYPEDEF no_attr_identifier '=' assignment_expression
    16551492                {
    16561493                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    16571494                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    16581495                }
    1659         | typedef_expression pop ',' push identifier '=' assignment_expression
     1496        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    16601497                {
    16611498                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     
    18261663        | INT128
    18271664                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); }
    1828         | UINT128
    1829                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ); }
    18301665        | FLOAT
    18311666                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
     1667        | FLOAT80
     1668                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }
     1669        | FLOAT128
     1670                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }
    18321671        | DOUBLE
    18331672                { $$ = 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 ); }
    18501673        | COMPLEX                                                                                       // C99
    18511674                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     
    18621685        | VALIST                                                                                        // GCC, __builtin_va_list
    18631686                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
    1864         | AUTO_TYPE
    1865                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::AutoType ); }
    18661687        ;
    18671688
     
    18971718
    18981719indirect_type:
    1899         TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
     1720        TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
    19001721                { $$ = $3; }
    1901         | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
     1722        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
    19021723                { $$ = DeclarationNode::newTypeof( $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 ); }
     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 ); }
    19071728        | ZERO_T                                                                                        // CFA
    19081729                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
     
    19281749                { $$ = $3->addQualifiers( $1 ); }
    19291750        | sue_type_specifier type_qualifier
    1930                 {
    1931                         if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type
    1932                         $$ = $1->addQualifiers( $2 );
    1933                 }
     1751                { $$ = $1->addQualifiers( $2 ); }
    19341752        ;
    19351753
     
    19741792                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    19751793        | '.' TYPEDEFname
    1976                 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
     1794                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    19771795        | type_name '.' TYPEDEFname
    1978                 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
     1796                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    19791797        | typegen_name
    19801798        | '.' typegen_name
    1981                 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
     1799                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    19821800        | type_name '.' typegen_name
    1983                 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
     1801                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    19841802        ;
    19851803
     
    20031821        ;
    20041822
    2005 fred:
    2006         // empty
    2007                 { yyy = false; }
    2008         ;
    2009 
    20101823aggregate_type:                                                                                 // struct, union
    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
     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
    20181830                        forall = false;                                                         // reset
    20191831                }
    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
     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
    20261838                        forall = false;                                                         // reset
    20271839                }
    2028           '{' field_declaration_list_opt '}' type_parameters_opt
    2029                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); }
     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 ); }
    20301844        | aggregate_type_nobody
    20311845        ;
    20321846
    2033 type_parameters_opt:
    2034         // empty
    2035                 { $$ = nullptr; }                                                               %prec '}'
    2036         | '(' type_list ')'
    2037                 { $$ = $2; }
    2038         ;
    2039 
    20401847aggregate_type_nobody:                                                                  // struct, union - {...}
    2041         aggregate_key attribute_list_opt identifier fred
    2042                 {
    2043                         typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname );
     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
    20441852                        forall = false;                                                         // reset
    20451853                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    20461854                }
    2047         | aggregate_key attribute_list_opt type_name fred
    2048                 {
    2049                         forall = false;                                                         // reset
     1855        | aggregate_key attribute_list_opt type_name
     1856                {
    20501857                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
    20511858                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
     
    20601867aggregate_key:
    20611868        STRUCT
    2062                 { yyy = true; $$ = DeclarationNode::Struct; }
     1869                { $$ = DeclarationNode::Struct; }
    20631870        | UNION
    2064                 { yyy = true; $$ = DeclarationNode::Union; }
     1871                { $$ = DeclarationNode::Union; }
    20651872        | EXCEPTION
    2066                 { yyy = true; $$ = DeclarationNode::Exception; }
    2067         | GENERATOR
    2068                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1873                { $$ = DeclarationNode::Exception; }
    20691874        | COROUTINE
    2070                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1875                { $$ = DeclarationNode::Coroutine; }
    20711876        | MONITOR
    2072                 { yyy = true; $$ = DeclarationNode::Monitor; }
     1877                { $$ = DeclarationNode::Monitor; }
    20731878        | THREAD
    2074                 { yyy = true; $$ = DeclarationNode::Thread; }
     1879                { $$ = DeclarationNode::Thread; }
    20751880        ;
    20761881
     
    20831888
    20841889field_declaration:
    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                 }
     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
    20981894        | typedef_declaration ';'                                                       // CFA
     1895                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    20991896        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    21001897        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    21011898                { 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
    21041899        | cfa_typedef_declaration ';'                                           // CFA
     1900                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    21051901        | static_assert                                                                         // C11
    21061902        ;
    21071903
    2108 field_declaring_list_opt:
     1904cfa_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
     1914field_declaring_list:
     1915        field_declarator_opt
     1916        | field_declaring_list ',' attribute_list_opt field_declarator_opt
     1917                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     1918        ;
     1919
     1920field_declarator_opt:
    21091921        // empty
    2110                 { $$ = nullptr; }
    2111         | field_declarator
    2112         | field_declaring_list_opt ',' attribute_list_opt field_declarator
    2113                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    2114         ;
    2115 
    2116 field_declarator:
    2117         bit_subrange_size                                                                       // C special case, no field name
     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
    21181926                { $$ = DeclarationNode::newBitfield( $1 ); }
    21191927        | variable_declarator bit_subrange_size_opt
    2120                 // A semantic check is required to ensure bit_subrange only appears on integral types.
     1928                // A semantic check is required to ensure bit_subrange only appears on base type int.
    21211929                { $$ = $1->addBitfield( $2 ); }
    21221930        | variable_type_redeclarator bit_subrange_size_opt
    2123                 // A semantic check is required to ensure bit_subrange only appears on integral types.
     1931                // A semantic check is required to ensure bit_subrange only appears on base type int.
    21241932                { $$ = $1->addBitfield( $2 ); }
    2125         ;
    2126 
    2127 field_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 
    2135 field_abstract:
    2136                 //      no bit fields
    2137         variable_abstract_declarator
    2138         ;
    2139 
    2140 cfa_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 
    2148 cfa_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 ) ); }
     1933        | variable_abstract_declarator                                          // CFA, no field name
    21531934        ;
    21541935
     
    21601941
    21611942bit_subrange_size:
    2162         ':' assignment_expression
     1943        ':' constant_expression
    21631944                { $$ = $2; }
    21641945        ;
     
    21661947enum_type:                                                                                              // enum
    21671948        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2168                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    2169         | ENUM attribute_list_opt identifier
     1949                { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
     1950        | ENUM attribute_list_opt no_attr_identifier
    21701951                { typedefTable.makeTypedef( *$3 ); }
    21711952          '{' enumerator_list comma_opt '}'
     
    21781959
    21791960enum_type_nobody:                                                                               // enum - {...}
    2180         ENUM attribute_list_opt identifier
     1961        ENUM attribute_list_opt no_attr_identifier
    21811962                {
    21821963                        typedefTable.makeTypedef( *$3 );
     
    21911972
    21921973enumerator_list:
    2193         identifier_or_type_name enumerator_value_opt
     1974        no_attr_identifier_or_type_name enumerator_value_opt
    21941975                { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
    2195         | enumerator_list ',' identifier_or_type_name enumerator_value_opt
     1976        | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt
    21961977                { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
    21971978        ;
     
    23012082
    23022083identifier_list:                                                                                // K&R-style parameter list => no types
    2303         identifier
     2084        no_attr_identifier
    23042085                { $$ = DeclarationNode::newName( $1 ); }
    2305         | identifier_list ',' identifier
     2086        | identifier_list ',' no_attr_identifier
    23062087                { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
    23072088        ;
     
    23092090identifier_or_type_name:
    23102091        identifier
     2092        | TYPEDEFname
     2093        | TYPEGENname
     2094        ;
     2095
     2096no_attr_identifier_or_type_name:
     2097        no_attr_identifier
    23112098        | TYPEDEFname
    23122099        | TYPEGENname
     
    23632150designation:
    23642151        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    2365         | identifier ':'                                                                        // GCC, field name
     2152        | no_attr_identifier ':'                                                        // GCC, field name
    23662153                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    23672154        ;
     
    23752162
    23762163designator:
    2377         '.' identifier                                                                          // C99, field name
     2164        '.' no_attr_identifier                                                          // C99, field name
    23782165                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    23792166        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    23842171        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    23852172                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    2386         | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
     2173        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    23872174                { $$ = $4; }
    23882175        ;
     
    24202207
    24212208type_parameter:                                                                                 // CFA
    2422         type_class identifier_or_type_name
     2209        type_class no_attr_identifier_or_type_name
    24232210                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    24242211          type_initializer_opt assertion_list_opt
     
    24532240
    24542241assertion:                                                                                              // CFA
    2455         '|' identifier_or_type_name '(' type_list ')'
     2242        '|' no_attr_identifier_or_type_name '(' type_list ')'
    24562243                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    24572244        | '|' '{' push trait_declaration_list pop '}'
     
    24652252                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    24662253        | assignment_expression
    2467                 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    24682254        | type_list ',' type
    24692255                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    24702256        | type_list ',' assignment_expression
    2471                 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
    2472                 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     2257                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    24732258        ;
    24742259
     
    24902275
    24912276type_declarator_name:                                                                   // CFA
    2492         identifier_or_type_name
     2277        no_attr_identifier_or_type_name
    24932278                {
    24942279                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
    24952280                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    24962281                }
    2497         | identifier_or_type_name '(' type_parameter_list ')'
     2282        | no_attr_identifier_or_type_name '(' type_parameter_list ')'
    24982283                {
    24992284                        typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
     
    25032288
    25042289trait_specifier:                                                                                // CFA
    2505         TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}'
     2290        TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
    25062291                { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
    2507         | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
     2292        | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
    25082293                { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
    25092294        ;
     
    25372322
    25382323translation_unit:
    2539         // empty, input file
     2324        // empty
     2325                {}                                                                                              // empty input file
    25402326        | external_definition_list
    25412327                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    25452331        push external_definition pop
    25462332                { $$ = $2; }
    2547         | external_definition_list push external_definition pop
     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.
     2345external_definition_list_no_pop_push:
     2346        external_definition
     2347        | external_definition_list_no_pop_push
     2348                { forall = xxx; }
     2349          external_definition
    25482350                { $$ = $1 ? $1->appendList( $3 ) : $3; }
    25492351        ;
     
    25522354        // empty
    25532355                { $$ = nullptr; }
    2554         | external_definition_list
    2555         ;
    2556 
    2557 up:
    2558                 { typedefTable.up( forall ); forall = false; }
    2559         ;
    2560 
    2561 down:
    2562                 { typedefTable.down(); }
     2356        | external_definition_list_no_pop_push
    25632357        ;
    25642358
     
    25802374                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    25812375                }
    2582           '{' up external_definition_list_opt down '}'
     2376          '{' external_definition_list_opt '}'
    25832377                {
    25842378                        linkage = linkageStack.top();
    25852379                        linkageStack.pop();
    2586                         $$ = $6;
     2380                        $$ = $5;
    25872381                }
    25882382        | 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;
     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                }
     2395        | 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;
     2407                }
     2408        | declaration_qualifier_list type_qualifier_list
     2409                {
     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;
    25972424                        $$ = $5;
    2598                 }
    2599         | declaration_qualifier_list
    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;
    2609                 }
    2610         | declaration_qualifier_list type_qualifier_list
    2611                 {
    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;
    26202425                }
    26212426        ;
     
    29272732        typedef
    29282733                // hide type name in enclosing scope by variable name
    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                 }
     2734                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); }
    29362735        | '(' paren_type ')'
    29372736                { $$ = $2; }
     
    29442743                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    29452744        | '(' type_ptr ')' attribute_list_opt
    2946                 { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
     2745                { $$ = $2->addQualifiers( $4 ); }
    29472746        ;
    29482747
Note: See TracChangeset for help on using the changeset viewer.