Ignore:
Timestamp:
Feb 7, 2017, 1:01:34 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
35b1bf4
Parents:
dbe8f244 (diff), b4d65c7 (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:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rdbe8f244 rfe26fbf  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 18 15:51:25 2017
    13 // Update Count     : 2135
     12// Last Modified On : Mon Feb  6 16:00:29 2017
     13// Update Count     : 2181
    1414//
    1515
     
    3232//
    3333// 1. designation with and without '=' (use ':' instead)
     34// 2. attributes not allowed in parenthesis of declarator
    3435//
    3536// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
     
    6566        to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
    6667} // appendStr
     68
     69DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) {
     70        // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
     71        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
     72        //cur->addType( specifier );
     73        for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
     74                cl->cloneBaseType( cur );
     75        } // for
     76        declList->addType( cl );
     77//      delete cl;
     78        return declList;
     79} // distAttr
     80
     81void distExt( DeclarationNode * declaration ) {
     82        // distribute EXTENSION across all declarations
     83        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     84                iter->set_extension( true );
     85        } // for
     86} // distExt
    6787%}
    6888
     
    119139{
    120140        Token tok;
    121         ParseNode *pn;
    122         ExpressionNode *en;
    123         DeclarationNode *decl;
     141        ParseNode * pn;
     142        ExpressionNode * en;
     143        DeclarationNode * decl;
    124144        DeclarationNode::Aggregate aggKey;
    125145        DeclarationNode::TypeClass tclass;
    126         StatementNode *sn;
    127         ConstantExpr *constant;
    128         ForCtl *fctl;
    129         LabelNode *label;
    130         InitializerNode *in;
     146        StatementNode * sn;
     147        ConstantExpr * constant;
     148        ForCtl * fctl;
     149        LabelNode * label;
     150        InitializerNode * in;
    131151        OperKinds op;
    132         std::string *str;
     152        std::string * str;
    133153        bool flag;
    134154}
     
    152172%type<fctl> for_control_expression
    153173%type<en> subrange
    154 %type<constant> asm_name_opt
     174%type<decl> asm_name_opt
    155175%type<en> asm_operands_opt asm_operands_list asm_operand
    156176%type<label> label_list
     
    171191
    172192// declarations
    173 %type<decl> abstract_array abstract_declarator abstract_function abstract_parameter_array
    174 %type<decl> abstract_parameter_declaration abstract_parameter_declarator abstract_parameter_function
    175 %type<decl> abstract_parameter_ptr abstract_ptr
     193%type<decl> abstract_declarator abstract_ptr abstract_array abstract_function array_dimension multi_array_dimension
     194%type<decl> abstract_parameter_declarator abstract_parameter_ptr abstract_parameter_array abstract_parameter_function array_parameter_dimension array_parameter_1st_dimension
     195%type<decl> abstract_parameter_declaration
    176196
    177197%type<aggKey> aggregate_key
    178 %type<decl>  aggregate_name
    179 
    180 %type<decl> array_dimension array_parameter_1st_dimension array_parameter_dimension multi_array_dimension
     198%type<decl>  aggregate_type
    181199
    182200%type<decl> assertion assertion_list_opt
     
    191209%type<decl> declaration_specifier declarator declaring_list
    192210
    193 %type<decl> elaborated_type_name
    194 
    195 %type<decl> enumerator_list enum_name
     211%type<decl> elaborated_type
     212
     213%type<decl> enumerator_list enum_type
    196214%type<en> enumerator_value_opt
    197215
     
    206224%type<decl> identifier_parameter_ptr identifier_list
    207225
    208 %type<decl> new_abstract_array new_abstract_declarator_no_tuple new_abstract_declarator_tuple
    209 %type<decl> new_abstract_function new_abstract_parameter_declaration new_abstract_parameter_list
    210 %type<decl> new_abstract_ptr new_abstract_tuple
    211 
    212 %type<decl> new_array_parameter_1st_dimension
    213 
    214 %type<decl> new_trait_declaring_list new_declaration new_field_declaring_list
    215 %type<decl> new_function_declaration new_function_return new_function_specifier
    216 
    217 %type<decl> new_identifier_parameter_array new_identifier_parameter_declarator_no_tuple
    218 %type<decl> new_identifier_parameter_declarator_tuple new_identifier_parameter_ptr
    219 
    220 %type<decl> new_parameter_declaration new_parameter_list new_parameter_type_list new_parameter_type_list_opt
    221 
    222 %type<decl> new_typedef_declaration new_variable_declaration new_variable_specifier
    223 
    224 %type<decl> old_declaration old_declaration_list old_declaration_list_opt old_function_array
    225 %type<decl> old_function_declarator old_function_no_ptr old_function_ptr
     226%type<decl> cfa_abstract_array cfa_abstract_declarator_no_tuple cfa_abstract_declarator_tuple
     227%type<decl> cfa_abstract_function cfa_abstract_parameter_declaration cfa_abstract_parameter_list
     228%type<decl> cfa_abstract_ptr cfa_abstract_tuple
     229
     230%type<decl> cfa_array_parameter_1st_dimension
     231
     232%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
     233%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
     234
     235%type<decl> cfa_identifier_parameter_array cfa_identifier_parameter_declarator_no_tuple
     236%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
     237
     238%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt
     239
     240%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
     241
     242%type<decl> c_declaration
     243%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
     244%type<decl> KR_declaration_list KR_declaration_list_opt
    226245
    227246%type<decl> parameter_declaration parameter_list parameter_type_list
     
    237256%type<decl> type_declarator type_declarator_name type_declaring_list
    238257
    239 %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression
    240 %type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr
    241 %type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier
     258%type<decl> typedef typedef_type_specifier typedef_declaration typedef_declaration_specifier typedef_expression
     259
     260%type<decl> variable_type_redeclarator type_ptr type_array type_function
     261
     262%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
    242263%type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
    243264
     
    249270%type<decl> type_qualifier type_qualifier_name type_qualifier_list type_qualifier_list_opt type_specifier
    250271
    251 %type<decl> variable_abstract_array variable_abstract_declarator variable_abstract_function
    252 %type<decl> variable_abstract_ptr variable_array variable_declarator variable_function variable_ptr
     272%type<decl> variable_declarator variable_ptr variable_array variable_function
     273%type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function
    253274
    254275%type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name
     
    659680tuple:                                                                                                  // CFA, tuple
    660681                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
    661                 // comma_expression in new_identifier_parameter_array and new_abstract_array
     682                // comma_expression in cfa_identifier_parameter_array and cfa_abstract_array
    662683//      '[' ']'
    663684//              { $$ = new ExpressionNode( build_tuple() ); }
     
    723744          push push
    724745          local_label_declaration_opt                                           // GCC, local labels
    725           block_item_list pop '}'                                                       // C99, intermix declarations and statements
     746          block_item_list                                                                       // C99, intermix declarations and statements
     747          pop '}'
    726748                { $$ = new StatementNode( build_compound( $5 ) ); }
    727749        ;
     
    737759                { $$ = new StatementNode( $1 ); }
    738760        | EXTENSION declaration                                                         // GCC
    739                 {       // mark all fields in list
    740                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    741                                 iter->set_extension( true );
     761                {
     762                        distExt( $2 );
    742763                        $$ = new StatementNode( $2 );
    743764                }
    744765        | function_definition
    745766                { $$ = new StatementNode( $1 ); }
     767        | EXTENSION function_definition                                         // GCC
     768                {
     769                        distExt( $2 );
     770                        $$ = new StatementNode( $2 );
     771                }
    746772        | statement pop
    747773        ;
     
    960986        | type_specifier variable_abstract_declarator
    961987                { $$ = $2->addType( $1 ); }
    962         | new_abstract_declarator_tuple no_attr_identifier      // CFA
     988        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    963989                {
    964990                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    965991                        $$ = $1->addName( $2 );
    966992                }
    967         | new_abstract_declarator_tuple                                         // CFA
     993        | cfa_abstract_declarator_tuple                                         // CFA
    968994        ;
    969995
     
    10441070        ;
    10451071
    1046 old_declaration_list_opt:                                                               // used to declare parameter types in K&R style functions
     1072KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    10471073        pop
    10481074                { $$ = nullptr; }
    1049         | old_declaration_list
    1050         ;
    1051 
    1052 old_declaration_list:
    1053         old_declaration
    1054         | old_declaration_list push old_declaration
     1075        | KR_declaration_list
     1076        ;
     1077
     1078KR_declaration_list:
     1079        c_declaration
     1080        | KR_declaration_list push c_declaration
    10551081                { $$ = $1->appendList( $3 ); }
    10561082        ;
     
    10721098
    10731099declaration:                                                                                    // CFA, new & old style declarations
    1074         new_declaration
    1075         | old_declaration
     1100        cfa_declaration
     1101        | c_declaration
    10761102        ;
    10771103
     
    10871113//              [10] * char y;          char *y[10];    // array of 10 pointers to char
    10881114
    1089 new_declaration:                                                                                // CFA
    1090         new_variable_declaration pop ';'
    1091         | new_typedef_declaration pop ';'
    1092         | new_function_declaration pop ';'
     1115cfa_declaration:                                                                                // CFA
     1116        cfa_variable_declaration pop ';'
     1117        | cfa_typedef_declaration pop ';'
     1118        | cfa_function_declaration pop ';'
    10931119        | type_declaring_list pop ';'
    10941120        | trait_specifier pop ';'
    10951121        ;
    10961122
    1097 new_variable_declaration:                                                               // CFA
    1098         new_variable_specifier initializer_opt
     1123cfa_variable_declaration:                                                               // CFA
     1124        cfa_variable_specifier initializer_opt
    10991125                {
    11001126                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11011127                        $$ = $1->addInitializer( $2 );
    11021128                }
    1103         | declaration_qualifier_list new_variable_specifier initializer_opt
     1129        | declaration_qualifier_list cfa_variable_specifier initializer_opt
    11041130                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
    11051131                // them as a type_qualifier cannot appear in that context.
     
    11081134                        $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
    11091135                }
    1110         | new_variable_declaration pop ',' push identifier_or_type_name initializer_opt
     1136        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    11111137                {
    11121138                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     
    11151141        ;
    11161142
    1117 new_variable_specifier:                                                                 // CFA
     1143cfa_variable_specifier:                                                                 // CFA
    11181144                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
    11191145                // storage-class
    1120         new_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
     1146        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
    11211147                {
    11221148                        typedefTable.setNextIdentifier( *$2 );
    11231149                        $$ = $1->addName( $2 )->addAsmName( $3 );
    11241150                }
    1125         | new_abstract_tuple identifier_or_type_name asm_name_opt
     1151        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
    11261152                {
    11271153                        typedefTable.setNextIdentifier( *$2 );
    11281154                        $$ = $1->addName( $2 )->addAsmName( $3 );
    11291155                }
    1130         | type_qualifier_list new_abstract_tuple identifier_or_type_name asm_name_opt
     1156        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
    11311157                {
    11321158                        typedefTable.setNextIdentifier( *$3 );
     
    11351161        ;
    11361162
    1137 new_function_declaration:                                                               // CFA
    1138         new_function_specifier
     1163cfa_function_declaration:                                                               // CFA
     1164        cfa_function_specifier
    11391165                {
    11401166                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11411167                        $$ = $1;
    11421168                }
    1143         | type_qualifier_list new_function_specifier
     1169        | type_qualifier_list cfa_function_specifier
    11441170                {
    11451171                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11461172                        $$ = $2->addQualifiers( $1 );
    11471173                }
    1148         | declaration_qualifier_list new_function_specifier
     1174        | declaration_qualifier_list cfa_function_specifier
    11491175                {
    11501176                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11511177                        $$ = $2->addQualifiers( $1 );
    11521178                }
    1153         | declaration_qualifier_list type_qualifier_list new_function_specifier
     1179        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    11541180                {
    11551181                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11561182                        $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
    11571183                }
    1158         | new_function_declaration pop ',' push identifier_or_type_name
     1184        | cfa_function_declaration pop ',' push identifier_or_type_name
    11591185                {
    11601186                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     
    11631189        ;
    11641190
    1165 new_function_specifier:                                                                 // CFA
    1166 //      '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict
     1191cfa_function_specifier:                                                                 // CFA
     1192//      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
    11671193//              {
    11681194//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    11691195//              }
    1170 //      '[' ']' identifier '(' push new_parameter_type_list_opt pop ')'
     1196//      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
    11711197//              {
    11721198//                      typedefTable.setNextIdentifier( *$5 );
    11731199//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    11741200//              }
    1175 //      | '[' ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')'
     1201//      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
    11761202//              {
    11771203//                      typedefTable.setNextIdentifier( *$5 );
     
    11811207                // identifier_or_type_name must be broken apart because of the sequence:
    11821208                //
    1183                 //   '[' ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'
     1209                //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    11841210                //   '[' ']' type_specifier
    11851211                //
    11861212                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    11871213                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1188         new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
    1189                 // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator).
     1214        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1215                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    11901216                {
    11911217                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
    11921218                }
    1193         | new_function_return identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
     1219        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    11941220                {
    11951221                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
     
    11971223        ;
    11981224
    1199 new_function_return:                                                                    // CFA
    1200         '[' push new_parameter_list pop ']'
     1225cfa_function_return:                                                                    // CFA
     1226        '[' push cfa_parameter_list pop ']'
    12011227                { $$ = DeclarationNode::newTuple( $3 ); }
    1202         | '[' push new_parameter_list pop ',' push new_abstract_parameter_list pop ']'
    1203                 // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to lookahead to the
     1228        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
     1229                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
    12041230                // ']'.
    12051231                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    12061232        ;
    12071233
    1208 new_typedef_declaration:                                                                // CFA
    1209         TYPEDEF new_variable_specifier
     1234cfa_typedef_declaration:                                                                // CFA
     1235        TYPEDEF cfa_variable_specifier
    12101236                {
    12111237                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    12121238                        $$ = $2->addTypedef();
    12131239                }
    1214         | TYPEDEF new_function_specifier
     1240        | TYPEDEF cfa_function_specifier
    12151241                {
    12161242                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    12171243                        $$ = $2->addTypedef();
    12181244                }
    1219         | new_typedef_declaration pop ',' push no_attr_identifier
     1245        | cfa_typedef_declaration pop ',' push no_attr_identifier
    12201246                {
    12211247                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
     
    12601286                {
    12611287                        typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
    1262                         $$ = DeclarationNode::newName( 0 ); // XXX
     1288                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    12631289                }
    12641290        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    12651291                {
    12661292                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
    1267                         $$ = DeclarationNode::newName( 0 ); // XXX
    1268                 }
    1269         ;
    1270 
    1271 old_declaration:
    1272         declaring_list pop ';'
     1293                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
     1294                }
     1295        ;
     1296
     1297//c_declaration:
     1298//      declaring_list pop ';'
     1299//      | typedef_declaration pop ';'
     1300//      | typedef_expression pop ';'                                            // GCC, naming expression type
     1301//      | sue_declaration_specifier pop ';'
     1302//      ;
     1303//
     1304//declaring_list:
     1305//              // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
     1306//              // storage-class
     1307//       declarator asm_name_opt initializer_opt
     1308//              {
     1309//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
     1310//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
     1311//              }
     1312//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
     1313//              {
     1314//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
     1315//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
     1316//              }
     1317//      ;
     1318
     1319c_declaration:
     1320        declaration_specifier declaring_list pop ';'
     1321                {
     1322                        $$ = distAttr( $1, $2 );
     1323                }
    12731324        | typedef_declaration pop ';'
    12741325        | typedef_expression pop ';'                                            // GCC, naming expression type
     
    12791330                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
    12801331                // storage-class
    1281         declaration_specifier declarator asm_name_opt initializer_opt
     1332        declarator asm_name_opt initializer_opt
    12821333                {
    12831334                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    1284                         $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
     1335                        $$ = $1->addAsmName( $2 )->addInitializer( $3 );
    12851336                }
    12861337        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    12871338                {
    12881339                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    1289                         $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
     1340                        $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
    12901341                }
    12911342        ;
     
    14741525
    14751526sue_type_specifier:
    1476         elaborated_type_name                                                            // struct, union, enum
    1477         | type_qualifier_list elaborated_type_name
     1527        elaborated_type                                                                         // struct, union, enum
     1528        | type_qualifier_list elaborated_type
    14781529                { $$ = $2->addQualifiers( $1 ); }
    14791530        | sue_type_specifier type_qualifier
     
    15001551        ;
    15011552
    1502 elaborated_type_name:
    1503         aggregate_name
    1504         | enum_name
    1505         ;
    1506 
    1507 aggregate_name:
    1508         aggregate_key '{' field_declaration_list '}'
    1509                 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); }
    1510         | aggregate_key no_attr_identifier_or_type_name
    1511                 {
    1512                         typedefTable.makeTypedef( *$2 );
    1513                         $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false );
    1514                 }
    1515         | aggregate_key no_attr_identifier_or_type_name
    1516                 { typedefTable.makeTypedef( *$2 ); }
    1517                 '{' field_declaration_list '}'
    1518                 { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); }
    1519         | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    1520                 { $$ = DeclarationNode::newAggregate( $1, nullptr, $3, $6, false ); }
    1521         | aggregate_key typegen_name                                            // CFA, S/R conflict
    1522                 { $$ = $2; }
     1553elaborated_type:
     1554        aggregate_type
     1555        | enum_type
     1556        ;
     1557
     1558aggregate_type:
     1559        aggregate_key attribute_list_opt '{' field_declaration_list '}'
     1560                { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $4, true )->addQualifiers( $2 ); }
     1561        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
     1562                {
     1563                        typedefTable.makeTypedef( *$3 );
     1564                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     1565                }
     1566        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
     1567                { typedefTable.makeTypedef( *$3 ); }
     1568          '{' field_declaration_list '}'
     1569                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
     1570        | aggregate_key attribute_list_opt '(' type_name_list ')' '{' field_declaration_list '}' // CFA
     1571                { $$ = DeclarationNode::newAggregate( $1, nullptr, $4, $7, false )->addQualifiers( $2 ); }
     1572        | aggregate_key attribute_list_opt typegen_name         // CFA, S/R conflict
     1573                { $$ = $3->addQualifiers( $2 ); }
    15231574        ;
    15241575
    15251576aggregate_key:
    1526         STRUCT attribute_list_opt
     1577        STRUCT
    15271578                { $$ = DeclarationNode::Struct; }
    1528         | UNION attribute_list_opt
     1579        | UNION
    15291580                { $$ = DeclarationNode::Union; }
    15301581        ;
     
    15381589
    15391590field_declaration:
    1540         new_field_declaring_list ';'                                            // CFA, new style field declaration
    1541         | EXTENSION new_field_declaring_list ';'                        // GCC
    1542                 { $$ = $2->set_extension( true ); }
    1543         | field_declaring_list ';'
    1544         | EXTENSION field_declaring_list ';'                            // GCC
    1545                 {       // mark all fields in list
    1546                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    1547                                 iter->set_extension( true );
     1591        cfa_field_declaring_list ';'                                            // CFA, new style field declaration
     1592        | EXTENSION cfa_field_declaring_list ';'                        // GCC
     1593                {
     1594                        distExt( $2 );                                                          // mark all fields in list
    15481595                        $$ = $2;
    15491596                }
    1550         ;
    1551 
    1552 new_field_declaring_list:                                                               // CFA, new style field declaration
    1553         new_abstract_declarator_tuple                                           // CFA, no field name
    1554         | new_abstract_declarator_tuple no_attr_identifier_or_type_name
     1597        | type_specifier field_declaring_list ';'
     1598                {
     1599                        $$ = distAttr( $1, $2 ); }
     1600        | EXTENSION type_specifier field_declaring_list ';'     // GCC
     1601                {
     1602                        distExt( $3 );                                                          // mark all fields in list
     1603                        $$ = distAttr( $2, $3 );
     1604                }
     1605        ;
     1606
     1607cfa_field_declaring_list:                                                               // CFA, new style field declaration
     1608        cfa_abstract_declarator_tuple                                           // CFA, no field name
     1609        | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
    15551610                { $$ = $1->addName( $2 ); }
    1556         | new_field_declaring_list ',' no_attr_identifier_or_type_name
     1611        | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
    15571612                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    1558         | new_field_declaring_list ','                                          // CFA, no field name
     1613        | cfa_field_declaring_list ','                                          // CFA, no field name
    15591614                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
    15601615        ;
    15611616
    15621617field_declaring_list:
    1563         type_specifier field_declarator
    1564                 { $$ = $2->addType( $1 ); }
     1618        field_declarator
    15651619        | field_declaring_list ',' attribute_list_opt field_declarator
    1566                 { $$ = $1->appendList( $1->cloneBaseType( $4 ) ); }
     1620                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    15671621        ;
    15681622
     
    15931647        ;
    15941648
    1595 enum_key:
    1596         ENUM attribute_list_opt
    1597         ;
    1598 
    1599 enum_name:
    1600         enum_key '{' enumerator_list comma_opt '}'
    1601                 { $$ = DeclarationNode::newEnum( nullptr, $3 ); }
    1602         | enum_key no_attr_identifier_or_type_name
    1603                 {
    1604                         typedefTable.makeTypedef( *$2 );
    1605                         $$ = DeclarationNode::newEnum( $2, 0 );
    1606                 }
    1607         | enum_key no_attr_identifier_or_type_name
    1608                 { typedefTable.makeTypedef( *$2 ); }
    1609                 '{' enumerator_list comma_opt '}'
    1610                 { $$ = DeclarationNode::newEnum( $2, $5 ); }
     1649enum_type:
     1650        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
     1651                { $$ = DeclarationNode::newEnum( nullptr, $4 )->addQualifiers( $2 ); }
     1652        | ENUM attribute_list_opt no_attr_identifier_or_type_name
     1653                {
     1654                        typedefTable.makeTypedef( *$3 );
     1655                        $$ = DeclarationNode::newEnum( $3, 0 )->addQualifiers( $2 );
     1656                }
     1657        | ENUM attribute_list_opt no_attr_identifier_or_type_name
     1658                { typedefTable.makeTypedef( *$3 ); }
     1659          '{' enumerator_list comma_opt '}'
     1660                { $$ = DeclarationNode::newEnum( $3, $6 )->addQualifiers( $2 ); }
    16111661        ;
    16121662
     
    16271677// Minimum of one parameter after which ellipsis is allowed only at the end.
    16281678
    1629 new_parameter_type_list_opt:                                                    // CFA
     1679cfa_parameter_type_list_opt:                                                    // CFA
    16301680        // empty
    16311681                { $$ = nullptr; }
    1632         | new_parameter_type_list
    1633         ;
    1634 
    1635 new_parameter_type_list:                                                                // CFA, abstract + real
    1636         new_abstract_parameter_list
    1637         | new_parameter_list
    1638         | new_parameter_list pop ',' push new_abstract_parameter_list
     1682        | cfa_parameter_type_list
     1683        ;
     1684
     1685cfa_parameter_type_list:                                                                // CFA, abstract + real
     1686        cfa_abstract_parameter_list
     1687        | cfa_parameter_list
     1688        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
    16391689                { $$ = $1->appendList( $5 ); }
    1640         | new_abstract_parameter_list pop ',' push ELLIPSIS
     1690        | cfa_abstract_parameter_list pop ',' push ELLIPSIS
    16411691                { $$ = $1->addVarArgs(); }
    1642         | new_parameter_list pop ',' push ELLIPSIS
     1692        | cfa_parameter_list pop ',' push ELLIPSIS
    16431693                { $$ = $1->addVarArgs(); }
    16441694        ;
    16451695
    1646 new_parameter_list:                                                                             // CFA
    1647                 // To obtain LR(1) between new_parameter_list and new_abstract_tuple, the last new_abstract_parameter_list is
    1648                 // factored out from new_parameter_list, flattening the rules to get lookahead to the ']'.
    1649         new_parameter_declaration
    1650         | new_abstract_parameter_list pop ',' push new_parameter_declaration
     1696cfa_parameter_list:                                                                             // CFA
     1697                // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is
     1698                // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
     1699        cfa_parameter_declaration
     1700        | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
    16511701                { $$ = $1->appendList( $5 ); }
    1652         | new_parameter_list pop ',' push new_parameter_declaration
     1702        | cfa_parameter_list pop ',' push cfa_parameter_declaration
    16531703                { $$ = $1->appendList( $5 ); }
    1654         | new_parameter_list pop ',' push new_abstract_parameter_list pop ',' push new_parameter_declaration
     1704        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
    16551705                { $$ = $1->appendList( $5 )->appendList( $9 ); }
    16561706        ;
    16571707
    1658 new_abstract_parameter_list:                                                    // CFA, new & old style abstract
    1659         new_abstract_parameter_declaration
    1660         | new_abstract_parameter_list pop ',' push new_abstract_parameter_declaration
     1708cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
     1709        cfa_abstract_parameter_declaration
     1710        | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
    16611711                { $$ = $1->appendList( $5 ); }
    16621712        ;
     
    16861736// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
    16871737
    1688 new_parameter_declaration:                                                              // CFA, new & old style parameter declaration
     1738cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
    16891739        parameter_declaration
    1690         | new_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
     1740        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
    16911741                { $$ = $1->addName( $2 ); }
    1692         | new_abstract_tuple identifier_or_type_name assignment_opt
    1693                 // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).
     1742        | cfa_abstract_tuple identifier_or_type_name assignment_opt
     1743                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
    16941744                { $$ = $1->addName( $2 ); }
    1695         | type_qualifier_list new_abstract_tuple identifier_or_type_name assignment_opt
     1745        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name assignment_opt
    16961746                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    1697         | new_function_specifier
    1698         ;
    1699 
    1700 new_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
     1747        | cfa_function_specifier
     1748        ;
     1749
     1750cfa_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
    17011751        abstract_parameter_declaration
    1702         | new_identifier_parameter_declarator_no_tuple
    1703         | new_abstract_tuple
    1704                 // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).
    1705         | type_qualifier_list new_abstract_tuple
     1752        | cfa_identifier_parameter_declarator_no_tuple
     1753        | cfa_abstract_tuple
     1754                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
     1755        | type_qualifier_list cfa_abstract_tuple
    17061756                { $$ = $2->addQualifiers( $1 ); }
    1707         | new_abstract_function
     1757        | cfa_abstract_function
    17081758        ;
    17091759
     
    17571807
    17581808type_name_no_function:                                                                  // sizeof, alignof, cast (constructor)
    1759         new_abstract_declarator_tuple                                           // CFA
    1760         | type_specifier
    1761         | type_specifier variable_abstract_declarator
    1762                 { $$ = $2->addType( $1 ); }
    1763         ;
    1764 
    1765 type_name:                                                                                              // typeof, assertion
    1766         new_abstract_declarator_tuple                                           // CFA
    1767         | new_abstract_function                                                         // CFA
     1809        cfa_abstract_declarator_tuple                                           // CFA
    17681810        | type_specifier
    17691811        | type_specifier abstract_declarator
    17701812                { $$ = $2->addType( $1 ); }
     1813        ;
     1814
     1815type_name:                                                                                              // typeof, assertion
     1816        type_name_no_function
     1817        | cfa_abstract_function                                                         // CFA
    17711818        ;
    17721819
     
    19822029
    19832030trait_declaration:                                                                      // CFA
    1984         new_trait_declaring_list pop ';'
     2031        cfa_trait_declaring_list pop ';'
    19852032        | trait_declaring_list pop ';'
    19862033        ;
    19872034
    1988 new_trait_declaring_list:                                                               // CFA
    1989         new_variable_specifier
     2035cfa_trait_declaring_list:                                                               // CFA
     2036        cfa_variable_specifier
    19902037                {
    19912038                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
    19922039                        $$ = $1;
    19932040                }
    1994         | new_function_specifier
     2041        | cfa_function_specifier
    19952042                {
    19962043                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
    19972044                        $$ = $1;
    19982045                }
    1999         | new_trait_declaring_list pop ',' push identifier_or_type_name
     2046        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    20002047                {
    20012048                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
     
    20432090        | asm_statement                                                                         // GCC, global assembler statement
    20442091                {}
    2045         | EXTERN STRINGliteral
     2092        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
    20462093                {
    20472094                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    20482095                        linkage = LinkageSpec::linkageCheck( $2 );
    20492096                }
    2050           '{' external_definition_list_opt '}'                          // C++-style linkage specifier
     2097          '{' external_definition_list_opt '}'
    20512098                {
    20522099                        linkage = linkageStack.top();
     
    20542101                        $$ = $5;
    20552102                }
    2056         | EXTENSION external_definition
    2057                 {       // mark all fields in list
    2058                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    2059                                 iter->set_extension( true );
     2103        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     2104                {
     2105                        distExt( $2 );                                                          // mark all fields in list
    20602106                        $$ = $2;
    20612107                }
     
    20752121                        $$ = $1->addFunctionBody( $2 );
    20762122                }
    2077         | old_function_declarator push old_declaration_list_opt compound_statement
     2123        | KR_function_declarator push KR_declaration_list_opt compound_statement
    20782124                {
    20792125                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    20842130
    20852131function_definition:
    2086         new_function_declaration compound_statement                     // CFA
     2132        cfa_function_declaration compound_statement                     // CFA
    20872133                {
    20882134                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    21162162
    21172163                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2118         | declaration_specifier old_function_declarator push old_declaration_list_opt compound_statement
     2164        | declaration_specifier KR_function_declarator push KR_declaration_list_opt compound_statement
    21192165                {
    21202166                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    21222168                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 );
    21232169                }
    2124         | type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement
     2170        | type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    21252171                {
    21262172                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    21302176
    21312177                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2132         | declaration_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement
     2178        | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    21332179                {
    21342180                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    21362182                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
    21372183                }
    2138         | declaration_qualifier_list type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement
     2184        | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    21392185                {
    21402186                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    21592205                { $$ = nullptr; }
    21602206        | ASM '(' string_literal ')' attribute_list_opt
    2161                 { $$ = $3; }
     2207                {
     2208                        DeclarationNode * name = new DeclarationNode();
     2209                        name->asmName = $3;
     2210                        $$ = name->addQualifiers( $5 );
     2211                }
    21622212        ;
    21632213
     
    21822232        attribute_name
    21832233        | attribute_name_list ',' attribute_name
    2184                 { $$ = $1->addQualifiers( $3 ); }
     2234                { $$ = $3->addQualifiers( $1 ); }
    21852235        ;
    21862236
     
    22572307        | ptrref_operator type_qualifier_list variable_declarator
    22582308                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2259         | '(' variable_ptr ')'
    2260                 { $$ = $2; }
     2309        | '(' variable_ptr ')' attribute_list_opt
     2310                { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
    22612311        ;
    22622312
     
    23182368        ;
    23192369
    2320 // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a typedef name
    2321 // (see function_declarator for additional comments). The pattern precludes returning arrays and functions versus
    2322 // pointers to arrays and functions.
    2323 
    2324 old_function_declarator:
    2325         old_function_no_ptr
    2326         | old_function_ptr
    2327         | old_function_array
    2328         ;
    2329 
    2330 old_function_no_ptr:
     2370// This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4)
     2371//
     2372//   f( a, b, c ) int a, *b, c[]; {}
     2373//
     2374// that is not redefining a typedef name (see function_declarator for additional comments). The pattern precludes
     2375// returning arrays and functions versus pointers to arrays and functions.
     2376
     2377KR_function_declarator:
     2378        KR_function_no_ptr
     2379        | KR_function_ptr
     2380        | KR_function_array
     2381        ;
     2382
     2383KR_function_no_ptr:
    23312384        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
    23322385                { $$ = $1->addIdList( $3 ); }
    2333         | '(' old_function_ptr ')' '(' identifier_list ')'
    2334                 { $$ = $2->addIdList( $5 ); }
    2335         | '(' old_function_no_ptr ')'                                           // redundant parenthesis
     2386        | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')'
     2387                { $$ = $2->addParamList( $6 ); }
     2388        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
    23362389                { $$ = $2; }
    23372390        ;
    23382391
    2339 old_function_ptr:
    2340         ptrref_operator old_function_declarator
     2392KR_function_ptr:
     2393        ptrref_operator KR_function_declarator
    23412394                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2342         | ptrref_operator type_qualifier_list old_function_declarator
     2395        | ptrref_operator type_qualifier_list KR_function_declarator
    23432396                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2344         | '(' old_function_ptr ')'
     2397        | '(' KR_function_ptr ')'
    23452398                { $$ = $2; }
    23462399        ;
    23472400
    2348 old_function_array:
    2349         '(' old_function_ptr ')' array_dimension
     2401KR_function_array:
     2402        '(' KR_function_ptr ')' array_dimension
    23502403                { $$ = $2->addArray( $4 ); }
    2351         | '(' old_function_array ')' multi_array_dimension      // redundant parenthesis
     2404        | '(' KR_function_array ')' multi_array_dimension       // redundant parenthesis
    23522405                { $$ = $2->addArray( $4 ); }
    2353         | '(' old_function_array ')'                                            // redundant parenthesis
     2406        | '(' KR_function_array ')'                                                     // redundant parenthesis
    23542407                { $$ = $2; }
    23552408        ;
     
    23862439        | ptrref_operator type_qualifier_list variable_type_redeclarator
    23872440                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2388         | '(' type_ptr ')'
    2389                 { $$ = $2; }
     2441        | '(' type_ptr ')' attribute_list_opt
     2442                { $$ = $2->addQualifiers( $4 ); }
    23902443        ;
    23912444
     
    24102463        ;
    24112464
    2412 // This pattern parses a declaration for a parameter variable or function prototype that is not redefining a typedef
    2413 // name and allows the C99 array options, which can only appear in a parameter list.  The pattern precludes declaring an
    2414 // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to
    2415 // arrays and functions.
     2465// This pattern parses a declaration for a parameter variable of a function prototype or actual that is not redefining a
     2466// typedef name and allows the C99 array options, which can only appear in a parameter list.  The pattern precludes
     2467// declaring an array of functions versus a pointer to an array of functions, and returning arrays and functions versus
     2468// pointers to arrays and functions.
    24162469
    24172470identifier_parameter_declarator:
     
    24302483        | ptrref_operator type_qualifier_list identifier_parameter_declarator
    24312484                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2432         | '(' identifier_parameter_ptr ')'
    2433                 { $$ = $2; }
     2485        | '(' identifier_parameter_ptr ')' attribute_list_opt
     2486                { $$ = $2->addQualifiers( $4 ); }
    24342487        ;
    24352488
     
    24602513//              int f( int foo ); // redefine typedef name in new scope
    24612514//
    2462 // and allows the C99 array options, which can only appear in a parameter list.  In addition, the pattern handles the
    2463 // special meaning of parenthesis around a typedef name:
    2464 //
    2465 //              ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in
    2466 //              parentheses is taken to be an abstract declarator that specifies a function with a single parameter,
    2467 //              not as redundant parentheses around the identifier."
    2468 //
    2469 // For example:
    2470 //
    2471 //              typedef float T;
    2472 //              int f( int ( T [5] ) );                                 // see abstract_parameter_declarator
    2473 //              int g( int ( T ( int ) ) );                             // see abstract_parameter_declarator
    2474 //              int f( int f1( T a[5] ) );                              // see identifier_parameter_declarator
    2475 //              int g( int g1( T g2( int p ) ) );               // see identifier_parameter_declarator
    2476 //
    2477 // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and
    2478 // not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of
    2479 // functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and
    2480 // functions.
     2515// and allows the C99 array options, which can only appear in a parameter list.
    24812516
    24822517type_parameter_redeclarator:
     
    25082543        | ptrref_operator type_qualifier_list type_parameter_redeclarator
    25092544                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2510         | '(' type_parameter_ptr ')'
    2511                 { $$ = $2; }
     2545        | '(' type_parameter_ptr ')' attribute_list_opt
     2546                { $$ = $2->addQualifiers( $4 ); }
    25122547        ;
    25132548
     
    25302565//
    25312566//              sizeof( int );
     2567//              sizeof( int * );
    25322568//              sizeof( int [10] );
     2569//              sizeof( int (*)() );
     2570//              sizeof( int () );
    25332571//
    25342572// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
     
    25522590        | ptrref_operator type_qualifier_list abstract_declarator
    25532591                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2554         | '(' abstract_ptr ')'
    2555                 { $$ = $2; }
     2592        | '(' abstract_ptr ')' attribute_list_opt
     2593                { $$ = $2->addQualifiers( $4 ); }
    25562594        ;
    25572595
     
    25982636// identifier to which the type applies, e.g.:
    25992637//
    2600 //              int f( int );                   // abstract variable parameter; no parameter name specified
     2638//              int f( int );                   // not handled here
     2639//              int f( int * );                 // abstract function-prototype parameter; no parameter name specified
     2640//              int f( int (*)() );             // abstract function-prototype parameter; no parameter name specified
    26012641//              int f( int (int) );             // abstract function-prototype parameter; no parameter name specified
    26022642//
    26032643// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
    2604 // and functions versus pointers to arrays and functions.
     2644// and functions versus pointers to arrays and functions. In addition, the pattern handles the
     2645// special meaning of parenthesis around a typedef name:
     2646//
     2647//              ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in
     2648//              parentheses is taken to be an abstract declarator that specifies a function with a single parameter,
     2649//              not as redundant parentheses around the identifier."
     2650//
     2651// For example:
     2652//
     2653//              typedef float T;
     2654//              int f( int ( T [5] ) );                                 // see abstract_parameter_declarator
     2655//              int g( int ( T ( int ) ) );                             // see abstract_parameter_declarator
     2656//              int f( int f1( T a[5] ) );                              // see identifier_parameter_declarator
     2657//              int g( int g1( T g2( int p ) ) );               // see identifier_parameter_declarator
     2658//
     2659// In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and
     2660// not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of
     2661// functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and
     2662// functions.
    26052663
    26062664abstract_parameter_declarator:
     
    26142672abstract_parameter_ptr:
    26152673        ptrref_operator
    2616                 { $$ = DeclarationNode::newPointer( 0 ); }
     2674                { $$ = DeclarationNode::newPointer( nullptr ); }
    26172675        | ptrref_operator type_qualifier_list
    26182676                { $$ = DeclarationNode::newPointer( $2 ); }
    26192677        | ptrref_operator abstract_parameter_declarator
    2620                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
     2678                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr ) ); }
    26212679        | ptrref_operator type_qualifier_list abstract_parameter_declarator
    26222680                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2623         | '(' abstract_parameter_ptr ')'
    2624                 { $$ = $2; }
     2681        | '(' abstract_parameter_ptr ')' attribute_list_opt
     2682                { $$ = $2->addQualifiers( $4 ); }
    26252683        ;
    26262684
     
    26742732        ;
    26752733
    2676 // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type applies,
    2677 // e.g.:
    2678 //
    2679 //              sizeof( int ); // abstract variable; no identifier name specified
    2680 //
    2681 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
    2682 // and functions versus pointers to arrays and functions.
     2734// This pattern parses a declaration of an abstract variable, but does not allow "int ()" for a function pointer.
     2735//
     2736//              struct S {
     2737//          int;
     2738//          int *;
     2739//          int [10];
     2740//          int (*)();
     2741//      };
    26832742
    26842743variable_abstract_declarator:
     
    26992758        | ptrref_operator type_qualifier_list variable_abstract_declarator
    27002759                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    2701         | '(' variable_abstract_ptr ')'
    2702                 { $$ = $2; }
     2760        | '(' variable_abstract_ptr ')' attribute_list_opt
     2761                { $$ = $2->addQualifiers( $4 ); }
    27032762        ;
    27042763
     
    27232782// identifier or typedef name and allows the C99 array options, which can only appear in a parameter list.
    27242783
    2725 new_identifier_parameter_declarator_tuple:                              // CFA
    2726         new_identifier_parameter_declarator_no_tuple
    2727         | new_abstract_tuple
    2728         | type_qualifier_list new_abstract_tuple
     2784cfa_identifier_parameter_declarator_tuple:                              // CFA
     2785        cfa_identifier_parameter_declarator_no_tuple
     2786        | cfa_abstract_tuple
     2787        | type_qualifier_list cfa_abstract_tuple
    27292788                { $$ = $2->addQualifiers( $1 ); }
    27302789        ;
    27312790
    2732 new_identifier_parameter_declarator_no_tuple:                   // CFA
    2733         new_identifier_parameter_ptr
    2734         | new_identifier_parameter_array
    2735         ;
    2736 
    2737 new_identifier_parameter_ptr:                                                   // CFA
     2791cfa_identifier_parameter_declarator_no_tuple:                   // CFA
     2792        cfa_identifier_parameter_ptr
     2793        | cfa_identifier_parameter_array
     2794        ;
     2795
     2796cfa_identifier_parameter_ptr:                                                   // CFA
    27382797        ptrref_operator type_specifier
    27392798                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    27402799        | type_qualifier_list ptrref_operator type_specifier
    27412800                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2742         | ptrref_operator new_abstract_function
     2801        | ptrref_operator cfa_abstract_function
    27432802                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2744         | type_qualifier_list ptrref_operator new_abstract_function
     2803        | type_qualifier_list ptrref_operator cfa_abstract_function
    27452804                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2746         | ptrref_operator new_identifier_parameter_declarator_tuple
     2805        | ptrref_operator cfa_identifier_parameter_declarator_tuple
    27472806                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2748         | type_qualifier_list ptrref_operator new_identifier_parameter_declarator_tuple
     2807        | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple
    27492808                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    27502809        ;
    27512810
    2752 new_identifier_parameter_array:                                                 // CFA
     2811cfa_identifier_parameter_array:                                                 // CFA
    27532812                // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to
    27542813                // shift/reduce conflict with new-style empty (void) function return type.
    27552814        '[' ']' type_specifier
    27562815                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    2757         | new_array_parameter_1st_dimension type_specifier
     2816        | cfa_array_parameter_1st_dimension type_specifier
    27582817                { $$ = $2->addNewArray( $1 ); }
    27592818        | '[' ']' multi_array_dimension type_specifier
    27602819                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    2761         | new_array_parameter_1st_dimension multi_array_dimension type_specifier
     2820        | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier
    27622821                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
    27632822        | multi_array_dimension type_specifier
    27642823                { $$ = $2->addNewArray( $1 ); }
    27652824
    2766         | '[' ']' new_identifier_parameter_ptr
     2825        | '[' ']' cfa_identifier_parameter_ptr
    27672826                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    2768         | new_array_parameter_1st_dimension new_identifier_parameter_ptr
     2827        | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr
    27692828                { $$ = $2->addNewArray( $1 ); }
    2770         | '[' ']' multi_array_dimension new_identifier_parameter_ptr
     2829        | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr
    27712830                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    2772         | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr
     2831        | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr
    27732832                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
    2774         | multi_array_dimension new_identifier_parameter_ptr
     2833        | multi_array_dimension cfa_identifier_parameter_ptr
    27752834                { $$ = $2->addNewArray( $1 ); }
    27762835        ;
    27772836
    2778 new_array_parameter_1st_dimension:
     2837cfa_array_parameter_1st_dimension:
    27792838        '[' push type_qualifier_list '*' pop ']'                        // remaining C99
    27802839                { $$ = DeclarationNode::newVarArray( $3 ); }
     
    27982857// These rules need LR(3):
    27992858//
    2800 //              new_abstract_tuple identifier_or_type_name
    2801 //              '[' new_parameter_list ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'
     2859//              cfa_abstract_tuple identifier_or_type_name
     2860//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    28022861//
    28032862// since a function return type can be syntactically identical to a tuple type:
     
    28072866//
    28082867// Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce
    2809 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
    2810 // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are
    2811 // duplicated when appearing with new_function_specifier.
    2812 
    2813 new_abstract_declarator_tuple:                                                  // CFA
    2814         new_abstract_tuple
    2815         | type_qualifier_list new_abstract_tuple
     2868// cfa_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
     2869// lookahead. To accomplish this, cfa_abstract_declarator has an entry point without tuple, and tuple declarations are
     2870// duplicated when appearing with cfa_function_specifier.
     2871
     2872cfa_abstract_declarator_tuple:                                                  // CFA
     2873        cfa_abstract_tuple
     2874        | type_qualifier_list cfa_abstract_tuple
    28162875                { $$ = $2->addQualifiers( $1 ); }
    2817         | new_abstract_declarator_no_tuple
    2818         ;
    2819 
    2820 new_abstract_declarator_no_tuple:                                               // CFA
    2821         new_abstract_ptr
    2822         | new_abstract_array
    2823         ;
    2824 
    2825 new_abstract_ptr:                                                                               // CFA
     2876        | cfa_abstract_declarator_no_tuple
     2877        ;
     2878
     2879cfa_abstract_declarator_no_tuple:                                               // CFA
     2880        cfa_abstract_ptr
     2881        | cfa_abstract_array
     2882        ;
     2883
     2884cfa_abstract_ptr:                                                                               // CFA
    28262885        ptrref_operator type_specifier
    28272886                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    28282887        | type_qualifier_list ptrref_operator type_specifier
    28292888                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2830         | ptrref_operator new_abstract_function
     2889        | ptrref_operator cfa_abstract_function
    28312890                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2832         | type_qualifier_list ptrref_operator new_abstract_function
     2891        | type_qualifier_list ptrref_operator cfa_abstract_function
    28332892                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2834         | ptrref_operator new_abstract_declarator_tuple
     2893        | ptrref_operator cfa_abstract_declarator_tuple
    28352894                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2836         | type_qualifier_list ptrref_operator new_abstract_declarator_tuple
     2895        | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple
    28372896                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    28382897        ;
    28392898
    2840 new_abstract_array:                                                                             // CFA
     2899cfa_abstract_array:                                                                             // CFA
    28412900                // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with
    28422901                // empty (void) function return type.
     
    28472906        | multi_array_dimension type_specifier
    28482907                { $$ = $2->addNewArray( $1 ); }
    2849         | '[' ']' new_abstract_ptr
     2908        | '[' ']' cfa_abstract_ptr
    28502909                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    2851         | '[' ']' multi_array_dimension new_abstract_ptr
     2910        | '[' ']' multi_array_dimension cfa_abstract_ptr
    28522911                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    2853         | multi_array_dimension new_abstract_ptr
     2912        | multi_array_dimension cfa_abstract_ptr
    28542913                { $$ = $2->addNewArray( $1 ); }
    28552914        ;
    28562915
    2857 new_abstract_tuple:                                                                             // CFA
    2858         '[' push new_abstract_parameter_list pop ']'
     2916cfa_abstract_tuple:                                                                             // CFA
     2917        '[' push cfa_abstract_parameter_list pop ']'
    28592918                { $$ = DeclarationNode::newTuple( $3 ); }
    28602919        ;
    28612920
    2862 new_abstract_function:                                                                  // CFA
    2863 //      '[' ']' '(' new_parameter_type_list_opt ')'
     2921cfa_abstract_function:                                                                  // CFA
     2922//      '[' ']' '(' cfa_parameter_type_list_opt ')'
    28642923//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    2865         new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
     2924        cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
    28662925                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    2867         | new_function_return '(' push new_parameter_type_list_opt pop ')'
     2926        | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
    28682927                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28692928        ;
Note: See TracChangeset for help on using the changeset viewer.