| [b87a5ed] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [974906e2] | 7 | // cfa.y -- | 
|---|
|  | 8 | // | 
|---|
| [c11e31c] | 9 | // Author           : Peter A. Buhr | 
|---|
|  | 10 | // Created On       : Sat Sep  1 20:22:55 2001 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [8b7ee09] | 12 | // Last Modified On : Thu Aug 18 23:49:10 2016 | 
|---|
|  | 13 | // Update Count     : 1909 | 
|---|
| [974906e2] | 14 | // | 
|---|
| [c11e31c] | 15 |  | 
|---|
| [de62360d] | 16 | // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C | 
|---|
|  | 17 | // grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS.  While parts have been | 
|---|
|  | 18 | // copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar. | 
|---|
|  | 19 | // In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax | 
|---|
|  | 20 | // that must be subsequently rejected by semantic checks.  Nevertheless, there are still several semantic checks | 
|---|
|  | 21 | // required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions. | 
|---|
| [c11e31c] | 22 |  | 
|---|
| [de62360d] | 23 | // Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with | 
|---|
|  | 24 | // the grammar. | 
|---|
| [c11e31c] | 25 |  | 
|---|
|  | 26 | // The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for: | 
|---|
|  | 27 | // | 
|---|
|  | 28 | // 1. designation with '=' (use ':' instead) | 
|---|
|  | 29 | // | 
|---|
| [de62360d] | 30 | // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has | 
|---|
|  | 31 | // two levels of extensions. The first extensions cover most of the GCC C extensions, except for: | 
|---|
| [c11e31c] | 32 | // | 
|---|
| [e7aed49] | 33 | // 1. designation with and without '=' (use ':' instead) | 
|---|
|  | 34 | // 2. attributes not allowed in parenthesis of declarator | 
|---|
| [c11e31c] | 35 | // | 
|---|
| [de62360d] | 36 | // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall | 
|---|
|  | 37 | // (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the | 
|---|
|  | 38 | // syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable | 
|---|
|  | 39 | // parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation" | 
|---|
|  | 40 | // grammar rule. | 
|---|
| [51b73452] | 41 |  | 
|---|
|  | 42 | %{ | 
|---|
| [b87a5ed] | 43 | #define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time | 
|---|
|  | 44 | #define YYDEBUG 1                                                                               // get the pretty debugging code to compile | 
|---|
| [51b73452] | 45 |  | 
|---|
|  | 46 | #undef __GNUC_MINOR__ | 
|---|
|  | 47 |  | 
|---|
|  | 48 | #include <cstdio> | 
|---|
|  | 49 | #include <stack> | 
|---|
|  | 50 | #include "lex.h" | 
|---|
| [984dce6] | 51 | #include "parser.h" | 
|---|
| [51b73452] | 52 | #include "ParseNode.h" | 
|---|
| [984dce6] | 53 | #include "TypedefTable.h" | 
|---|
| [1db21619] | 54 | #include "TypeData.h" | 
|---|
| [51b73452] | 55 | #include "LinkageSpec.h" | 
|---|
|  | 56 |  | 
|---|
| [cbaee0d] | 57 | extern DeclarationNode * parseTree; | 
|---|
| [8b7ee09] | 58 | extern LinkageSpec::Spec linkage; | 
|---|
| [0da3e2c] | 59 | extern TypedefTable typedefTable; | 
|---|
|  | 60 |  | 
|---|
| [8b7ee09] | 61 | std::stack< LinkageSpec::Spec > linkageStack; | 
|---|
| [7bf7fb9] | 62 |  | 
|---|
|  | 63 | void appendStr( std::string &to, std::string *from ) { | 
|---|
|  | 64 | // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. | 
|---|
|  | 65 | to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) ); | 
|---|
|  | 66 | } // appendStr | 
|---|
| [51b73452] | 67 | %} | 
|---|
|  | 68 |  | 
|---|
| [c11e31c] | 69 | //************************* TERMINAL TOKENS ******************************** | 
|---|
| [51b73452] | 70 |  | 
|---|
| [c11e31c] | 71 | // keywords | 
|---|
| [51b73452] | 72 | %token TYPEDEF | 
|---|
|  | 73 | %token AUTO EXTERN REGISTER STATIC | 
|---|
| [b87a5ed] | 74 | %token INLINE                                                                                   // C99 | 
|---|
|  | 75 | %token FORTRAN                                                                                  // C99, extension ISO/IEC 9899:1999 Section J.5.9(1) | 
|---|
| [51b73452] | 76 | %token CONST VOLATILE | 
|---|
| [b87a5ed] | 77 | %token RESTRICT                                                                                 // C99 | 
|---|
|  | 78 | %token FORALL LVALUE                                                                    // CFA | 
|---|
| [51b73452] | 79 | %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED | 
|---|
| [90c3b1c] | 80 | %token VALIST                                                                                   // GCC | 
|---|
| [b87a5ed] | 81 | %token BOOL COMPLEX IMAGINARY                                                   // C99 | 
|---|
|  | 82 | %token TYPEOF LABEL                                                                             // GCC | 
|---|
| [51b73452] | 83 | %token ENUM STRUCT UNION | 
|---|
| [e7aed49] | 84 | %token OTYPE FTYPE DTYPE TRAIT                                                  // CFA | 
|---|
| [5721a6d] | 85 | %token SIZEOF OFFSETOF | 
|---|
| [b87a5ed] | 86 | %token ATTRIBUTE EXTENSION                                                              // GCC | 
|---|
| [51b73452] | 87 | %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN | 
|---|
| [02e5ab6] | 88 | %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA | 
|---|
| [b87a5ed] | 89 | %token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1) | 
|---|
| [c11e31c] | 90 | %token ALIGNAS ALIGNOF ATOMIC GENERIC NORETURN STATICASSERT THREADLOCAL // C11 | 
|---|
| [51b73452] | 91 |  | 
|---|
| [c11e31c] | 92 | // names and constants: lexer differentiates between identifier and typedef names | 
|---|
| [b87a5ed] | 93 | %token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname | 
|---|
|  | 94 | %token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname | 
|---|
|  | 95 | %token<tok> INTEGERconstant             FLOATINGconstant                CHARACTERconstant               STRINGliteral | 
|---|
|  | 96 | %token<tok> ZERO                                ONE                                             // CFA | 
|---|
| [51b73452] | 97 |  | 
|---|
| [c11e31c] | 98 | // multi-character operators | 
|---|
| [b87a5ed] | 99 | %token ARROW                                                                                    // -> | 
|---|
|  | 100 | %token ICR DECR                                                                                 // ++   -- | 
|---|
|  | 101 | %token LS RS                                                                                    // <<   >> | 
|---|
|  | 102 | %token LE GE EQ NE                                                                              // <=   >=      ==      != | 
|---|
|  | 103 | %token ANDAND OROR                                                                              // &&   || | 
|---|
|  | 104 | %token ELLIPSIS                                                                                 // ... | 
|---|
|  | 105 |  | 
|---|
|  | 106 | %token MULTassign       DIVassign       MODassign                               // *=   /=      %=/ | 
|---|
|  | 107 | %token PLUSassign       MINUSassign                                                     // +=   -= | 
|---|
|  | 108 | %token LSassign         RSassign                                                        // <<=  >>= | 
|---|
|  | 109 | %token ANDassign        ERassign        ORassign                                // &=   ^=      |= | 
|---|
| [51b73452] | 110 |  | 
|---|
| [e7aed49] | 111 | %token ATassign                                                                                 // @= | 
|---|
| [097e2b0] | 112 |  | 
|---|
| [c11e31c] | 113 | // Types declaration | 
|---|
| [51b73452] | 114 | %union | 
|---|
|  | 115 | { | 
|---|
| [b87a5ed] | 116 | Token tok; | 
|---|
|  | 117 | ParseNode *pn; | 
|---|
|  | 118 | ExpressionNode *en; | 
|---|
|  | 119 | DeclarationNode *decl; | 
|---|
| [68cd1ce] | 120 | DeclarationNode::Aggregate aggKey; | 
|---|
| [b87a5ed] | 121 | DeclarationNode::TypeClass tclass; | 
|---|
|  | 122 | StatementNode *sn; | 
|---|
| [d1625f8] | 123 | ConstantExpr *constant; | 
|---|
| [2f22cc4] | 124 | ForCtl *fctl; | 
|---|
| [7f5566b] | 125 | LabelNode *label; | 
|---|
| [b87a5ed] | 126 | InitializerNode *in; | 
|---|
| [d9e2280] | 127 | OperKinds op; | 
|---|
| [7f5566b] | 128 | bool flag; | 
|---|
| [51b73452] | 129 | } | 
|---|
|  | 130 |  | 
|---|
| [097e2b0] | 131 | %type<tok> identifier  no_01_identifier  no_attr_identifier zero_one | 
|---|
| [2871210] | 132 | %type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name | 
|---|
| [51b73452] | 133 | %type<constant> string_literal_list | 
|---|
|  | 134 |  | 
|---|
| [c11e31c] | 135 | // expressions | 
|---|
| [d1625f8] | 136 | %type<en> constant | 
|---|
| [b87a5ed] | 137 | %type<en> tuple                                                 tuple_expression_list | 
|---|
| [9706554] | 138 | %type<op> ptrref_operator                               unary_operator                          assignment_operator | 
|---|
| [b87a5ed] | 139 | %type<en> primary_expression                    postfix_expression                      unary_expression | 
|---|
|  | 140 | %type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression | 
|---|
|  | 141 | %type<en> relational_expression                 equality_expression                     AND_expression                          exclusive_OR_expression | 
|---|
|  | 142 | %type<en> inclusive_OR_expression               logical_AND_expression          logical_OR_expression           conditional_expression | 
|---|
|  | 143 | %type<en> constant_expression                   assignment_expression           assignment_expression_opt | 
|---|
|  | 144 | %type<en> comma_expression                              comma_expression_opt | 
|---|
| [2f22cc4] | 145 | %type<en> argument_expression_list              argument_expression                     assignment_opt | 
|---|
|  | 146 | %type<fctl> for_control_expression | 
|---|
| [51b73452] | 147 | %type<en> subrange | 
|---|
| [7f5566b] | 148 | %type<en> asm_operands_opt asm_operands_list asm_operand | 
|---|
|  | 149 | %type<label> label_list | 
|---|
| [d1625f8] | 150 | %type<en> asm_clobbers_list_opt | 
|---|
| [7f5566b] | 151 | %type<flag> asm_volatile_opt | 
|---|
| [51b73452] | 152 |  | 
|---|
| [c11e31c] | 153 | // statements | 
|---|
| [b87a5ed] | 154 | %type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement | 
|---|
| [097e2b0] | 155 | %type<sn> iteration_statement                   jump_statement                          exception_statement                     asm_statement | 
|---|
| [b87a5ed] | 156 | %type<sn> fall_through_opt                              fall_through | 
|---|
|  | 157 | %type<sn> statement                                             statement_list | 
|---|
|  | 158 | %type<sn> block_item_list                               block_item | 
|---|
| [51b73452] | 159 | %type<sn> case_clause | 
|---|
| [8688ce1] | 160 | %type<en> case_value | 
|---|
|  | 161 | %type<sn> case_value_list                               case_label                                      case_label_list | 
|---|
| [b87a5ed] | 162 | %type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list | 
|---|
| [1d4580a] | 163 | %type<sn> handler_list                                  handler_clause                          finally_clause | 
|---|
| [51b73452] | 164 |  | 
|---|
| [c11e31c] | 165 | // declarations | 
|---|
| [51b73452] | 166 | %type<decl> abstract_array abstract_declarator abstract_function abstract_parameter_array | 
|---|
|  | 167 | %type<decl> abstract_parameter_declaration abstract_parameter_declarator abstract_parameter_function | 
|---|
|  | 168 | %type<decl> abstract_parameter_ptr abstract_ptr | 
|---|
|  | 169 |  | 
|---|
|  | 170 | %type<aggKey> aggregate_key | 
|---|
|  | 171 | %type<decl>  aggregate_name | 
|---|
|  | 172 |  | 
|---|
|  | 173 | %type<decl> array_dimension array_parameter_1st_dimension array_parameter_dimension multi_array_dimension | 
|---|
|  | 174 |  | 
|---|
|  | 175 | %type<decl> assertion assertion_list_opt | 
|---|
|  | 176 |  | 
|---|
|  | 177 | %type<en>   bit_subrange_size_opt bit_subrange_size | 
|---|
|  | 178 |  | 
|---|
|  | 179 | %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type_name indirect_type_name | 
|---|
|  | 180 |  | 
|---|
| [4040425] | 181 | %type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier | 
|---|
| [51b73452] | 182 |  | 
|---|
|  | 183 | %type<decl> declaration declaration_list declaration_list_opt declaration_qualifier_list | 
|---|
|  | 184 | %type<decl> declaration_specifier declarator declaring_list | 
|---|
|  | 185 |  | 
|---|
|  | 186 | %type<decl> elaborated_type_name | 
|---|
|  | 187 |  | 
|---|
|  | 188 | %type<decl> enumerator_list enum_name | 
|---|
|  | 189 | %type<en> enumerator_value_opt | 
|---|
|  | 190 |  | 
|---|
|  | 191 | %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt | 
|---|
|  | 192 |  | 
|---|
|  | 193 | %type<decl> field_declaration field_declaration_list field_declarator field_declaring_list | 
|---|
|  | 194 | %type<en> field field_list | 
|---|
|  | 195 |  | 
|---|
| [4d51835] | 196 | %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr | 
|---|
| [51b73452] | 197 |  | 
|---|
|  | 198 | %type<decl> identifier_parameter_array identifier_parameter_declarator identifier_parameter_function | 
|---|
|  | 199 | %type<decl> identifier_parameter_ptr identifier_list | 
|---|
|  | 200 |  | 
|---|
|  | 201 | %type<decl> new_abstract_array new_abstract_declarator_no_tuple new_abstract_declarator_tuple | 
|---|
|  | 202 | %type<decl> new_abstract_function new_abstract_parameter_declaration new_abstract_parameter_list | 
|---|
|  | 203 | %type<decl> new_abstract_ptr new_abstract_tuple | 
|---|
|  | 204 |  | 
|---|
|  | 205 | %type<decl> new_array_parameter_1st_dimension | 
|---|
|  | 206 |  | 
|---|
| [4040425] | 207 | %type<decl> new_trait_declaring_list new_declaration new_field_declaring_list | 
|---|
| [51b73452] | 208 | %type<decl> new_function_declaration new_function_return new_function_specifier | 
|---|
|  | 209 |  | 
|---|
|  | 210 | %type<decl> new_identifier_parameter_array new_identifier_parameter_declarator_no_tuple | 
|---|
|  | 211 | %type<decl> new_identifier_parameter_declarator_tuple new_identifier_parameter_ptr | 
|---|
|  | 212 |  | 
|---|
|  | 213 | %type<decl> new_parameter_declaration new_parameter_list new_parameter_type_list new_parameter_type_list_opt | 
|---|
|  | 214 |  | 
|---|
|  | 215 | %type<decl> new_typedef_declaration new_variable_declaration new_variable_specifier | 
|---|
|  | 216 |  | 
|---|
|  | 217 | %type<decl> old_declaration old_declaration_list old_declaration_list_opt old_function_array | 
|---|
|  | 218 | %type<decl> old_function_declarator old_function_no_ptr old_function_ptr | 
|---|
|  | 219 |  | 
|---|
|  | 220 | %type<decl> parameter_declaration parameter_list parameter_type_list | 
|---|
|  | 221 | %type<decl> parameter_type_list_opt | 
|---|
|  | 222 |  | 
|---|
| [2871210] | 223 | %type<decl> paren_identifier paren_type | 
|---|
| [51b73452] | 224 |  | 
|---|
| [0da3e2c] | 225 | %type<decl> storage_class storage_class_list | 
|---|
| [51b73452] | 226 |  | 
|---|
|  | 227 | %type<decl> sue_declaration_specifier sue_type_specifier | 
|---|
|  | 228 |  | 
|---|
|  | 229 | %type<tclass> type_class | 
|---|
|  | 230 | %type<decl> type_declarator type_declarator_name type_declaring_list | 
|---|
|  | 231 |  | 
|---|
| [2871210] | 232 | %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression | 
|---|
|  | 233 | %type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr | 
|---|
| [c6b1105] | 234 | %type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier | 
|---|
| [2871210] | 235 | %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name | 
|---|
| [51b73452] | 236 |  | 
|---|
|  | 237 | %type<decl> type_name type_name_no_function | 
|---|
|  | 238 | %type<decl> type_parameter type_parameter_list | 
|---|
|  | 239 |  | 
|---|
|  | 240 | %type<en> type_name_list | 
|---|
|  | 241 |  | 
|---|
|  | 242 | %type<decl> type_qualifier type_qualifier_name type_qualifier_list type_qualifier_list_opt type_specifier | 
|---|
|  | 243 |  | 
|---|
|  | 244 | %type<decl> variable_abstract_array variable_abstract_declarator variable_abstract_function | 
|---|
|  | 245 | %type<decl> variable_abstract_ptr variable_array variable_declarator variable_function variable_ptr | 
|---|
|  | 246 |  | 
|---|
| [1db21619] | 247 | %type<decl> attribute_list_opt attribute_list attribute | 
|---|
|  | 248 |  | 
|---|
| [c11e31c] | 249 | // initializers | 
|---|
| [51b73452] | 250 | %type<in>  initializer initializer_list initializer_opt | 
|---|
|  | 251 |  | 
|---|
| [c11e31c] | 252 | // designators | 
|---|
| [51b73452] | 253 | %type<en>  designator designator_list designation | 
|---|
|  | 254 |  | 
|---|
|  | 255 |  | 
|---|
| [b87a5ed] | 256 | // Handle single shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string | 
|---|
|  | 257 | // is ambiguous: | 
|---|
|  | 258 | // .---------.                          matches IF '(' comma_expression ')' statement | 
|---|
| [c11e31c] | 259 | // if ( C ) S1 else S2 | 
|---|
| [b87a5ed] | 260 | // `-----------------'          matches IF '(' comma_expression ')' statement ELSE statement */ | 
|---|
| [51b73452] | 261 |  | 
|---|
| [c11e31c] | 262 | %nonassoc THEN  // rule precedence for IF '(' comma_expression ')' statement | 
|---|
|  | 263 | %nonassoc ELSE  // token precedence for start of else clause in IF statement | 
|---|
| [51b73452] | 264 |  | 
|---|
| [b87a5ed] | 265 | %start translation_unit                                                                 // parse-tree root | 
|---|
| [51b73452] | 266 |  | 
|---|
|  | 267 | %% | 
|---|
| [c11e31c] | 268 | //************************* Namespace Management ******************************** | 
|---|
|  | 269 |  | 
|---|
| [de62360d] | 270 | // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols | 
|---|
|  | 271 | // "identifier" and "TYPEDEFname" that are lexically identical.  While it is possible to write a purely context-free | 
|---|
|  | 272 | // grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.  Hence, this | 
|---|
|  | 273 | // grammar uses the ANSI style. | 
|---|
| [c11e31c] | 274 | // | 
|---|
| [de62360d] | 275 | // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those | 
|---|
|  | 276 | // introduced through "forall" qualifiers), and by introducing "type generators" -- parametrized types.  This latter | 
|---|
|  | 277 | // type name creates a third class of identifiers that must be distinguished by the scanner. | 
|---|
| [c11e31c] | 278 | // | 
|---|
| [de62360d] | 279 | // Since the scanner cannot distinguish among the different classes of identifiers without some context information, it | 
|---|
|  | 280 | // accesses a data structure (the TypedefTable) to allow classification of an identifier that it has just read. | 
|---|
|  | 281 | // Semantic actions during the parser update this data structure when the class of identifiers change. | 
|---|
| [c11e31c] | 282 | // | 
|---|
| [de62360d] | 283 | // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a | 
|---|
|  | 284 | // local scope; it must revert to its original class at the end of the block.  Since type names can be local to a | 
|---|
|  | 285 | // particular declaration, each declaration is itself a scope.  This requires distinguishing between type names that are | 
|---|
|  | 286 | // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in | 
|---|
|  | 287 | // "typedef" or "type" declarations). | 
|---|
| [c11e31c] | 288 | // | 
|---|
| [de62360d] | 289 | // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of | 
|---|
|  | 290 | // scopes.  Every push must have a matching pop, although it is regrettable the matching pairs do not always occur | 
|---|
|  | 291 | // within the same rule.  These non-terminals may appear in more contexts than strictly necessary from a semantic point | 
|---|
|  | 292 | // of view.  Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have | 
|---|
|  | 293 | // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra | 
|---|
|  | 294 | // rules is to open a new scope unconditionally.  As the grammar evolves, it may be neccesary to add or move around | 
|---|
|  | 295 | // "push" and "pop" nonterminals to resolve conflicts of this sort. | 
|---|
| [51b73452] | 296 |  | 
|---|
|  | 297 | push: | 
|---|
| [4d51835] | 298 | { | 
|---|
|  | 299 | typedefTable.enterScope(); | 
|---|
|  | 300 | } | 
|---|
|  | 301 | ; | 
|---|
| [51b73452] | 302 |  | 
|---|
|  | 303 | pop: | 
|---|
| [4d51835] | 304 | { | 
|---|
|  | 305 | typedefTable.leaveScope(); | 
|---|
|  | 306 | } | 
|---|
|  | 307 | ; | 
|---|
| [51b73452] | 308 |  | 
|---|
| [c11e31c] | 309 | //************************* CONSTANTS ******************************** | 
|---|
| [51b73452] | 310 |  | 
|---|
|  | 311 | constant: | 
|---|
| [de62360d] | 312 | // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". | 
|---|
| [ac71a86] | 313 | INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( assign_strptr($1) ) ); } | 
|---|
|  | 314 | | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( assign_strptr($1) ) ); } | 
|---|
|  | 315 | | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( assign_strptr($1) ) ); } | 
|---|
| [4d51835] | 316 | ; | 
|---|
| [51b73452] | 317 |  | 
|---|
|  | 318 | identifier: | 
|---|
| [4d51835] | 319 | IDENTIFIER | 
|---|
|  | 320 | | ATTR_IDENTIFIER                                                                       // CFA | 
|---|
|  | 321 | | zero_one                                                                                      // CFA | 
|---|
|  | 322 | ; | 
|---|
| [51b73452] | 323 |  | 
|---|
|  | 324 | no_01_identifier: | 
|---|
| [4d51835] | 325 | IDENTIFIER | 
|---|
|  | 326 | | ATTR_IDENTIFIER                                                                       // CFA | 
|---|
|  | 327 | ; | 
|---|
| [51b73452] | 328 |  | 
|---|
|  | 329 | no_attr_identifier: | 
|---|
| [4d51835] | 330 | IDENTIFIER | 
|---|
| [bd85400] | 331 | | zero_one                                                                                      // CFA | 
|---|
| [4d51835] | 332 | ; | 
|---|
| [51b73452] | 333 |  | 
|---|
| [b87a5ed] | 334 | zero_one:                                                                                               // CFA | 
|---|
| [4d51835] | 335 | ZERO | 
|---|
|  | 336 | | ONE | 
|---|
|  | 337 | ; | 
|---|
| [51b73452] | 338 |  | 
|---|
| [b87a5ed] | 339 | string_literal_list:                                                                    // juxtaposed strings are concatenated | 
|---|
| [ac71a86] | 340 | STRINGliteral                                                           { $$ = build_constantStr( assign_strptr($1) ); } | 
|---|
| [7bf7fb9] | 341 | | string_literal_list STRINGliteral | 
|---|
|  | 342 | { | 
|---|
| [d1625f8] | 343 | appendStr( $1->get_constant()->get_value(), $2 ); | 
|---|
| [7bf7fb9] | 344 | delete $2;                                                                      // allocated by lexer | 
|---|
|  | 345 | $$ = $1; | 
|---|
|  | 346 | } | 
|---|
| [4d51835] | 347 | ; | 
|---|
| [51b73452] | 348 |  | 
|---|
| [c11e31c] | 349 | //************************* EXPRESSIONS ******************************** | 
|---|
| [51b73452] | 350 |  | 
|---|
|  | 351 | primary_expression: | 
|---|
| [4d51835] | 352 | IDENTIFIER                                                                                      // typedef name cannot be used as a variable name | 
|---|
| [d1625f8] | 353 | { $$ = new ExpressionNode( build_varref( $1 ) ); } | 
|---|
| [4d51835] | 354 | | zero_one | 
|---|
| [d1625f8] | 355 | { $$ = new ExpressionNode( build_varref( $1 ) ); } | 
|---|
| [4d51835] | 356 | | '(' comma_expression ')' | 
|---|
|  | 357 | { $$ = $2; } | 
|---|
|  | 358 | | '(' compound_statement ')'                                            // GCC, lambda expression | 
|---|
| [d1625f8] | 359 | { $$ = new ExpressionNode( build_valexpr( $2 ) ); } | 
|---|
| [4d51835] | 360 | ; | 
|---|
| [51b73452] | 361 |  | 
|---|
|  | 362 | postfix_expression: | 
|---|
| [4d51835] | 363 | primary_expression | 
|---|
|  | 364 | | postfix_expression '[' push assignment_expression pop ']' | 
|---|
| [c6b1105] | 365 | // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a | 
|---|
| [de62360d] | 366 | // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be | 
|---|
|  | 367 | // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is | 
|---|
|  | 368 | // equivalent to the old x[i,j]. | 
|---|
| [d1625f8] | 369 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); } | 
|---|
| [4d51835] | 370 | | postfix_expression '(' argument_expression_list ')' | 
|---|
| [d1625f8] | 371 | { $$ = new ExpressionNode( build_func( $1, $3 ) ); } | 
|---|
| [bd85400] | 372 | // ambiguity with .0 so space required after field-selection, e.g. | 
|---|
|  | 373 | //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; | 
|---|
| [4d51835] | 374 | | postfix_expression '.' no_attr_identifier | 
|---|
| [d1625f8] | 375 | { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } | 
|---|
| [4d51835] | 376 | | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector | 
|---|
|  | 377 | | postfix_expression ARROW no_attr_identifier | 
|---|
| [d1625f8] | 378 | { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } | 
|---|
| [4d51835] | 379 | | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector | 
|---|
|  | 380 | | postfix_expression ICR | 
|---|
| [d1625f8] | 381 | { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } | 
|---|
| [4d51835] | 382 | | postfix_expression DECR | 
|---|
| [d1625f8] | 383 | { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } | 
|---|
| [4d51835] | 384 | | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 | 
|---|
| [d1625f8] | 385 | { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } | 
|---|
| [097e2b0] | 386 | | postfix_expression '{' argument_expression_list '}' // CFA | 
|---|
|  | 387 | { | 
|---|
| [9706554] | 388 | Token fn; | 
|---|
|  | 389 | fn.str = new std::string( "?{}" ); // location undefined | 
|---|
| [1d4580a] | 390 | $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ); | 
|---|
| [097e2b0] | 391 | } | 
|---|
| [4d51835] | 392 | ; | 
|---|
| [51b73452] | 393 |  | 
|---|
|  | 394 | argument_expression_list: | 
|---|
| [4d51835] | 395 | argument_expression | 
|---|
|  | 396 | | argument_expression_list ',' argument_expression | 
|---|
| [1d4580a] | 397 | { $$ = (ExpressionNode *)( $1->set_last( $3 )); } | 
|---|
| [4d51835] | 398 | ; | 
|---|
| [51b73452] | 399 |  | 
|---|
|  | 400 | argument_expression: | 
|---|
| [4d51835] | 401 | // empty | 
|---|
|  | 402 | { $$ = 0; }                                                                             // use default argument | 
|---|
|  | 403 | | assignment_expression | 
|---|
|  | 404 | ; | 
|---|
| [b87a5ed] | 405 |  | 
|---|
|  | 406 | field_list:                                                                                             // CFA, tuple field selector | 
|---|
| [4d51835] | 407 | field | 
|---|
| [1d4580a] | 408 | | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); } | 
|---|
| [4d51835] | 409 | ; | 
|---|
| [b87a5ed] | 410 |  | 
|---|
|  | 411 | field:                                                                                                  // CFA, tuple field selector | 
|---|
| [4d51835] | 412 | no_attr_identifier | 
|---|
| [d1625f8] | 413 | { $$ = new ExpressionNode( build_varref( $1 ) ); } | 
|---|
| [bd85400] | 414 | // ambiguity with .0 so space required after field-selection, e.g. | 
|---|
|  | 415 | //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; | 
|---|
| [4d51835] | 416 | | no_attr_identifier '.' field | 
|---|
| [d1625f8] | 417 | { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); } | 
|---|
| [4d51835] | 418 | | no_attr_identifier '.' '[' push field_list pop ']' | 
|---|
| [d1625f8] | 419 | { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) ) ); } | 
|---|
| [4d51835] | 420 | | no_attr_identifier ARROW field | 
|---|
| [d1625f8] | 421 | { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) ) ); } | 
|---|
| [4d51835] | 422 | | no_attr_identifier ARROW '[' push field_list pop ']' | 
|---|
| [d1625f8] | 423 | { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) ) ); } | 
|---|
| [4d51835] | 424 | ; | 
|---|
| [51b73452] | 425 |  | 
|---|
|  | 426 | unary_expression: | 
|---|
| [4d51835] | 427 | postfix_expression | 
|---|
| [c6b1105] | 428 | // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires | 
|---|
|  | 429 | // semantics checks, e.g., ++3, 3--, *3, &&3 | 
|---|
| [51b1202] | 430 | | constant | 
|---|
|  | 431 | { $$ = $1; } | 
|---|
|  | 432 | | string_literal_list | 
|---|
| [d1625f8] | 433 | { $$ = new ExpressionNode( $1 ); } | 
|---|
| [4d51835] | 434 | | EXTENSION cast_expression                                                     // GCC | 
|---|
| [e04ef3a] | 435 | { $$ = $2->set_extension( true ); } | 
|---|
| [c6b1105] | 436 | // '*' ('&') is separated from unary_operator because of shift/reduce conflict in: | 
|---|
|  | 437 | //              { * X; }         // dereference X | 
|---|
|  | 438 | //              { * int X; } // CFA declaration of pointer to int | 
|---|
| [51e076e] | 439 | | ptrref_operator cast_expression                                       // CFA | 
|---|
| [9706554] | 440 | { | 
|---|
|  | 441 | switch ( $1 ) { | 
|---|
| [d9e2280] | 442 | case OperKinds::AddressOf: | 
|---|
| [d1625f8] | 443 | $$ = new ExpressionNode( build_addressOf( $2 ) ); | 
|---|
| [9706554] | 444 | break; | 
|---|
| [d9e2280] | 445 | case OperKinds::PointTo: | 
|---|
| [d1625f8] | 446 | $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); | 
|---|
| [9706554] | 447 | break; | 
|---|
|  | 448 | default: | 
|---|
|  | 449 | assert( false ); | 
|---|
|  | 450 | } | 
|---|
|  | 451 | } | 
|---|
| [4d51835] | 452 | | unary_operator cast_expression | 
|---|
| [d1625f8] | 453 | { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); } | 
|---|
| [dd51906] | 454 | | ICR unary_expression | 
|---|
| [d1625f8] | 455 | { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); } | 
|---|
| [dd51906] | 456 | | DECR unary_expression | 
|---|
| [d1625f8] | 457 | { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); } | 
|---|
| [4d51835] | 458 | | SIZEOF unary_expression | 
|---|
| [d1625f8] | 459 | { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); } | 
|---|
| [4d51835] | 460 | | SIZEOF '(' type_name_no_function ')' | 
|---|
| [d1625f8] | 461 | { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); } | 
|---|
|  | 462 | | ALIGNOF unary_expression                                                      // GCC, variable alignment | 
|---|
|  | 463 | { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); } | 
|---|
|  | 464 | | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment | 
|---|
|  | 465 | { $$ = new ExpressionNode( build_alignOftype( $3 ) ); } | 
|---|
| [5721a6d] | 466 | | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')' | 
|---|
| [d1625f8] | 467 | { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); } | 
|---|
| [4d51835] | 468 | | ATTR_IDENTIFIER | 
|---|
| [d1625f8] | 469 | { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); } | 
|---|
| [4d51835] | 470 | | ATTR_IDENTIFIER '(' argument_expression ')' | 
|---|
| [d1625f8] | 471 | { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); } | 
|---|
|  | 472 | | ATTR_IDENTIFIER '(' type_name ')' | 
|---|
|  | 473 | { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } | 
|---|
| [c6b1105] | 474 | //      | ANDAND IDENTIFIER                                                                     // GCC, address of label | 
|---|
| [d1625f8] | 475 | //              { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2, true ) ); } | 
|---|
| [4d51835] | 476 | ; | 
|---|
| [51b73452] | 477 |  | 
|---|
| [dd51906] | 478 | ptrref_operator: | 
|---|
| [d9e2280] | 479 | '*'                                                                                     { $$ = OperKinds::PointTo; } | 
|---|
|  | 480 | | '&'                                                                           { $$ = OperKinds::AddressOf; } | 
|---|
| [c6b1105] | 481 | // GCC, address of label must be handled by semantic check for ref,ref,label | 
|---|
| [d9e2280] | 482 | //      | ANDAND                                                                        { $$ = OperKinds::And; } | 
|---|
| [dd51906] | 483 | ; | 
|---|
|  | 484 |  | 
|---|
| [51b73452] | 485 | unary_operator: | 
|---|
| [d9e2280] | 486 | '+'                                                                                     { $$ = OperKinds::UnPlus; } | 
|---|
|  | 487 | | '-'                                                                           { $$ = OperKinds::UnMinus; } | 
|---|
|  | 488 | | '!'                                                                           { $$ = OperKinds::Neg; } | 
|---|
|  | 489 | | '~'                                                                           { $$ = OperKinds::BitNeg; } | 
|---|
| [4d51835] | 490 | ; | 
|---|
| [51b73452] | 491 |  | 
|---|
|  | 492 | cast_expression: | 
|---|
| [4d51835] | 493 | unary_expression | 
|---|
|  | 494 | | '(' type_name_no_function ')' cast_expression | 
|---|
| [d1625f8] | 495 | { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } | 
|---|
| [4d51835] | 496 | | '(' type_name_no_function ')' tuple | 
|---|
| [d1625f8] | 497 | { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } | 
|---|
| [4d51835] | 498 | ; | 
|---|
| [51b73452] | 499 |  | 
|---|
|  | 500 | multiplicative_expression: | 
|---|
| [4d51835] | 501 | cast_expression | 
|---|
|  | 502 | | multiplicative_expression '*' cast_expression | 
|---|
| [d1625f8] | 503 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); } | 
|---|
| [4d51835] | 504 | | multiplicative_expression '/' cast_expression | 
|---|
| [d1625f8] | 505 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); } | 
|---|
| [4d51835] | 506 | | multiplicative_expression '%' cast_expression | 
|---|
| [d1625f8] | 507 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); } | 
|---|
| [4d51835] | 508 | ; | 
|---|
| [51b73452] | 509 |  | 
|---|
|  | 510 | additive_expression: | 
|---|
| [4d51835] | 511 | multiplicative_expression | 
|---|
|  | 512 | | additive_expression '+' multiplicative_expression | 
|---|
| [d1625f8] | 513 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); } | 
|---|
| [4d51835] | 514 | | additive_expression '-' multiplicative_expression | 
|---|
| [d1625f8] | 515 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); } | 
|---|
| [4d51835] | 516 | ; | 
|---|
| [51b73452] | 517 |  | 
|---|
|  | 518 | shift_expression: | 
|---|
| [4d51835] | 519 | additive_expression | 
|---|
|  | 520 | | shift_expression LS additive_expression | 
|---|
| [d1625f8] | 521 | { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); } | 
|---|
| [4d51835] | 522 | | shift_expression RS additive_expression | 
|---|
| [d1625f8] | 523 | { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); } | 
|---|
| [4d51835] | 524 | ; | 
|---|
| [51b73452] | 525 |  | 
|---|
|  | 526 | relational_expression: | 
|---|
| [4d51835] | 527 | shift_expression | 
|---|
|  | 528 | | relational_expression '<' shift_expression | 
|---|
| [d1625f8] | 529 | { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); } | 
|---|
| [4d51835] | 530 | | relational_expression '>' shift_expression | 
|---|
| [d1625f8] | 531 | { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); } | 
|---|
| [4d51835] | 532 | | relational_expression LE shift_expression | 
|---|
| [d1625f8] | 533 | { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); } | 
|---|
| [4d51835] | 534 | | relational_expression GE shift_expression | 
|---|
| [d1625f8] | 535 | { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); } | 
|---|
| [4d51835] | 536 | ; | 
|---|
| [51b73452] | 537 |  | 
|---|
|  | 538 | equality_expression: | 
|---|
| [4d51835] | 539 | relational_expression | 
|---|
|  | 540 | | equality_expression EQ relational_expression | 
|---|
| [d1625f8] | 541 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); } | 
|---|
| [4d51835] | 542 | | equality_expression NE relational_expression | 
|---|
| [d1625f8] | 543 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); } | 
|---|
| [4d51835] | 544 | ; | 
|---|
| [51b73452] | 545 |  | 
|---|
|  | 546 | AND_expression: | 
|---|
| [4d51835] | 547 | equality_expression | 
|---|
|  | 548 | | AND_expression '&' equality_expression | 
|---|
| [d1625f8] | 549 | { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); } | 
|---|
| [4d51835] | 550 | ; | 
|---|
| [51b73452] | 551 |  | 
|---|
|  | 552 | exclusive_OR_expression: | 
|---|
| [4d51835] | 553 | AND_expression | 
|---|
|  | 554 | | exclusive_OR_expression '^' AND_expression | 
|---|
| [d1625f8] | 555 | { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); } | 
|---|
| [4d51835] | 556 | ; | 
|---|
| [51b73452] | 557 |  | 
|---|
|  | 558 | inclusive_OR_expression: | 
|---|
| [4d51835] | 559 | exclusive_OR_expression | 
|---|
|  | 560 | | inclusive_OR_expression '|' exclusive_OR_expression | 
|---|
| [d1625f8] | 561 | { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); } | 
|---|
| [4d51835] | 562 | ; | 
|---|
| [51b73452] | 563 |  | 
|---|
|  | 564 | logical_AND_expression: | 
|---|
| [4d51835] | 565 | inclusive_OR_expression | 
|---|
|  | 566 | | logical_AND_expression ANDAND inclusive_OR_expression | 
|---|
| [d1625f8] | 567 | { $$ = new ExpressionNode( build_and_or( $1, $3, true ) ); } | 
|---|
| [4d51835] | 568 | ; | 
|---|
| [51b73452] | 569 |  | 
|---|
|  | 570 | logical_OR_expression: | 
|---|
| [4d51835] | 571 | logical_AND_expression | 
|---|
|  | 572 | | logical_OR_expression OROR logical_AND_expression | 
|---|
| [d1625f8] | 573 | { $$ = new ExpressionNode( build_and_or( $1, $3, false ) ); } | 
|---|
| [4d51835] | 574 | ; | 
|---|
| [51b73452] | 575 |  | 
|---|
|  | 576 | conditional_expression: | 
|---|
| [4d51835] | 577 | logical_OR_expression | 
|---|
|  | 578 | | logical_OR_expression '?' comma_expression ':' conditional_expression | 
|---|
| [d1625f8] | 579 | { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } | 
|---|
| [d9e2280] | 580 | // FIX ME: this hack computes $1 twice | 
|---|
| [4d51835] | 581 | | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand | 
|---|
| [d1625f8] | 582 | { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); } | 
|---|
| [4d51835] | 583 | | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression | 
|---|
| [d1625f8] | 584 | { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } | 
|---|
| [4d51835] | 585 | ; | 
|---|
| [51b73452] | 586 |  | 
|---|
|  | 587 | constant_expression: | 
|---|
| [4d51835] | 588 | conditional_expression | 
|---|
|  | 589 | ; | 
|---|
| [51b73452] | 590 |  | 
|---|
|  | 591 | assignment_expression: | 
|---|
| [4d51835] | 592 | // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples | 
|---|
|  | 593 | conditional_expression | 
|---|
|  | 594 | | unary_expression assignment_operator assignment_expression | 
|---|
| [d1625f8] | 595 | { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); } | 
|---|
| [4d51835] | 596 | | tuple assignment_opt                                                          // CFA, tuple expression | 
|---|
| [d1625f8] | 597 | { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); } | 
|---|
| [4d51835] | 598 | ; | 
|---|
| [51b73452] | 599 |  | 
|---|
|  | 600 | assignment_expression_opt: | 
|---|
| [4d51835] | 601 | // empty | 
|---|
| [d1625f8] | 602 | { $$ = nullptr; } | 
|---|
| [4d51835] | 603 | | assignment_expression | 
|---|
|  | 604 | ; | 
|---|
| [b87a5ed] | 605 |  | 
|---|
| [9706554] | 606 | assignment_operator: | 
|---|
| [d9e2280] | 607 | '='                                                                                     { $$ = OperKinds::Assign; } | 
|---|
|  | 608 | | MULTassign                                                            { $$ = OperKinds::MulAssn; } | 
|---|
|  | 609 | | DIVassign                                                                     { $$ = OperKinds::DivAssn; } | 
|---|
|  | 610 | | MODassign                                                                     { $$ = OperKinds::ModAssn; } | 
|---|
|  | 611 | | PLUSassign                                                            { $$ = OperKinds::PlusAssn; } | 
|---|
|  | 612 | | MINUSassign                                                           { $$ = OperKinds::MinusAssn; } | 
|---|
|  | 613 | | LSassign                                                                      { $$ = OperKinds::LSAssn; } | 
|---|
|  | 614 | | RSassign                                                                      { $$ = OperKinds::RSAssn; } | 
|---|
|  | 615 | | ANDassign                                                                     { $$ = OperKinds::AndAssn; } | 
|---|
|  | 616 | | ERassign                                                                      { $$ = OperKinds::ERAssn; } | 
|---|
|  | 617 | | ORassign                                                                      { $$ = OperKinds::OrAssn; } | 
|---|
| [9706554] | 618 | ; | 
|---|
|  | 619 |  | 
|---|
| [b87a5ed] | 620 | tuple:                                                                                                  // CFA, tuple | 
|---|
| [de62360d] | 621 | // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with | 
|---|
|  | 622 | // comma_expression in new_identifier_parameter_array and new_abstract_array | 
|---|
| [2871210] | 623 | '[' ']' | 
|---|
| [d1625f8] | 624 | { $$ = new ExpressionNode( build_tuple() ); } | 
|---|
| [4d51835] | 625 | | '[' push assignment_expression pop ']' | 
|---|
| [d1625f8] | 626 | { $$ = new ExpressionNode( build_tuple( $3 ) ); } | 
|---|
| [4d51835] | 627 | | '[' push ',' tuple_expression_list pop ']' | 
|---|
| [1d4580a] | 628 | { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); } | 
|---|
| [4d51835] | 629 | | '[' push assignment_expression ',' tuple_expression_list pop ']' | 
|---|
| [1d4580a] | 630 | { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); } | 
|---|
| [4d51835] | 631 | ; | 
|---|
| [51b73452] | 632 |  | 
|---|
|  | 633 | tuple_expression_list: | 
|---|
| [4d51835] | 634 | assignment_expression_opt | 
|---|
|  | 635 | | tuple_expression_list ',' assignment_expression_opt | 
|---|
| [1d4580a] | 636 | { $$ = (ExpressionNode *)$1->set_last( $3 ); } | 
|---|
| [4d51835] | 637 | ; | 
|---|
| [51b73452] | 638 |  | 
|---|
|  | 639 | comma_expression: | 
|---|
| [4d51835] | 640 | assignment_expression | 
|---|
| [9706554] | 641 | | comma_expression ',' assignment_expression | 
|---|
| [d1625f8] | 642 | { $$ = new ExpressionNode( build_comma( $1, $3 ) ); } | 
|---|
| [4d51835] | 643 | ; | 
|---|
| [51b73452] | 644 |  | 
|---|
|  | 645 | comma_expression_opt: | 
|---|
| [4d51835] | 646 | // empty | 
|---|
|  | 647 | { $$ = 0; } | 
|---|
|  | 648 | | comma_expression | 
|---|
|  | 649 | ; | 
|---|
| [51b73452] | 650 |  | 
|---|
| [c11e31c] | 651 | //*************************** STATEMENTS ******************************* | 
|---|
| [51b73452] | 652 |  | 
|---|
|  | 653 | statement: | 
|---|
| [4d51835] | 654 | labeled_statement | 
|---|
|  | 655 | | compound_statement | 
|---|
|  | 656 | | expression_statement                                          { $$ = $1; } | 
|---|
|  | 657 | | selection_statement | 
|---|
|  | 658 | | iteration_statement | 
|---|
|  | 659 | | jump_statement | 
|---|
|  | 660 | | exception_statement | 
|---|
|  | 661 | | asm_statement | 
|---|
| [097e2b0] | 662 | | '^' postfix_expression '{' argument_expression_list '}' ';' // CFA | 
|---|
|  | 663 | { | 
|---|
| [d9e2280] | 664 | Token fn; | 
|---|
|  | 665 | fn.str = new std::string( "^?{}" ); // location undefined | 
|---|
| [e82aa9df] | 666 | $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) ); | 
|---|
| [097e2b0] | 667 | } | 
|---|
| [4d51835] | 668 | ; | 
|---|
| [51b73452] | 669 |  | 
|---|
|  | 670 | labeled_statement: | 
|---|
| [c6b1105] | 671 | // labels cannot be identifiers 0 or 1 | 
|---|
|  | 672 | IDENTIFIER ':' attribute_list_opt statement | 
|---|
| [1db21619] | 673 | { | 
|---|
|  | 674 | $$ = $4->add_label( $1 ); | 
|---|
|  | 675 | } | 
|---|
| [4d51835] | 676 | ; | 
|---|
| [51b73452] | 677 |  | 
|---|
|  | 678 | compound_statement: | 
|---|
| [4d51835] | 679 | '{' '}' | 
|---|
| [e82aa9df] | 680 | { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } | 
|---|
| [4d51835] | 681 | | '{' | 
|---|
| [de62360d] | 682 | // Two scopes are necessary because the block itself has a scope, but every declaration within the block also | 
|---|
|  | 683 | // requires its own scope | 
|---|
| [4d51835] | 684 | push push | 
|---|
| [51b1202] | 685 | local_label_declaration_opt                                           // GCC, local labels | 
|---|
| [4d51835] | 686 | block_item_list pop '}'                                                       // C99, intermix declarations and statements | 
|---|
| [e82aa9df] | 687 | { $$ = new StatementNode( build_compound( $5 ) ); } | 
|---|
| [4d51835] | 688 | ; | 
|---|
| [b87a5ed] | 689 |  | 
|---|
|  | 690 | block_item_list:                                                                                // C99 | 
|---|
| [4d51835] | 691 | block_item | 
|---|
|  | 692 | | block_item_list push block_item | 
|---|
| [1d4580a] | 693 | { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } } | 
|---|
| [4d51835] | 694 | ; | 
|---|
| [51b73452] | 695 |  | 
|---|
|  | 696 | block_item: | 
|---|
| [4d51835] | 697 | declaration                                                                                     // CFA, new & old style declarations | 
|---|
| [e82aa9df] | 698 | { $$ = new StatementNode( $1 ); } | 
|---|
| [4d51835] | 699 | | EXTENSION declaration                                                         // GCC | 
|---|
| [8e9cbb2] | 700 | {       // mark all fields in list | 
|---|
| [926af74] | 701 | for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) | 
|---|
| [8e9cbb2] | 702 | iter->set_extension( true ); | 
|---|
| [e82aa9df] | 703 | $$ = new StatementNode( $2 ); | 
|---|
| [8e9cbb2] | 704 | } | 
|---|
| [4d51835] | 705 | | function_definition | 
|---|
| [e82aa9df] | 706 | { $$ = new StatementNode( $1 ); } | 
|---|
| [4d51835] | 707 | | statement pop | 
|---|
|  | 708 | ; | 
|---|
| [51b73452] | 709 |  | 
|---|
|  | 710 | statement_list: | 
|---|
| [4d51835] | 711 | statement | 
|---|
|  | 712 | | statement_list statement | 
|---|
| [1d4580a] | 713 | { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } | 
|---|
| [4d51835] | 714 | ; | 
|---|
| [51b73452] | 715 |  | 
|---|
|  | 716 | expression_statement: | 
|---|
| [4d51835] | 717 | comma_expression_opt ';' | 
|---|
| [e82aa9df] | 718 | { $$ = new StatementNode( build_expr( $1 ) ); } | 
|---|
| [4d51835] | 719 | ; | 
|---|
| [51b73452] | 720 |  | 
|---|
|  | 721 | selection_statement: | 
|---|
| [4d51835] | 722 | IF '(' comma_expression ')' statement                           %prec THEN | 
|---|
|  | 723 | // explicitly deal with the shift/reduce conflict on if/else | 
|---|
| [e82aa9df] | 724 | { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } | 
|---|
| [4d51835] | 725 | | IF '(' comma_expression ')' statement ELSE statement | 
|---|
| [e82aa9df] | 726 | { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } | 
|---|
| [4d51835] | 727 | | SWITCH '(' comma_expression ')' case_clause           // CFA | 
|---|
| [e82aa9df] | 728 | { $$ = new StatementNode( build_switch( $3, $5 ) ); } | 
|---|
| [4d51835] | 729 | | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA | 
|---|
| [4e06c1e] | 730 | { | 
|---|
| [e82aa9df] | 731 | StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); | 
|---|
| [4e06c1e] | 732 | // The semantics of the declaration list is changed to include associated initialization, which is performed | 
|---|
|  | 733 | // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound | 
|---|
|  | 734 | // statement around the switch.  Statements after the initial declaration list can never be executed, and | 
|---|
| [8688ce1] | 735 | // therefore, are removed from the grammar even though C allows it. The change also applies to choose | 
|---|
|  | 736 | // statement. | 
|---|
| [e82aa9df] | 737 | $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; | 
|---|
| [4e06c1e] | 738 | } | 
|---|
| [4d51835] | 739 | | CHOOSE '(' comma_expression ')' case_clause           // CFA | 
|---|
| [e82aa9df] | 740 | { $$ = new StatementNode( build_switch( $3, $5 ) ); } | 
|---|
| [4d51835] | 741 | | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA | 
|---|
| [4e06c1e] | 742 | { | 
|---|
| [e82aa9df] | 743 | StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); | 
|---|
|  | 744 | $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; | 
|---|
| [4e06c1e] | 745 | } | 
|---|
| [4d51835] | 746 | ; | 
|---|
| [b87a5ed] | 747 |  | 
|---|
| [de62360d] | 748 | // CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case | 
|---|
|  | 749 | // clause allows a list of values and subranges. | 
|---|
| [b87a5ed] | 750 |  | 
|---|
|  | 751 | case_value:                                                                                             // CFA | 
|---|
| [4d51835] | 752 | constant_expression                                                     { $$ = $1; } | 
|---|
|  | 753 | | constant_expression ELLIPSIS constant_expression      // GCC, subrange | 
|---|
| [d1625f8] | 754 | { $$ = new ExpressionNode( build_range( $1, $3 ) ); } | 
|---|
| [4d51835] | 755 | | subrange                                                                                      // CFA, subrange | 
|---|
|  | 756 | ; | 
|---|
| [b87a5ed] | 757 |  | 
|---|
|  | 758 | case_value_list:                                                                                // CFA | 
|---|
| [e82aa9df] | 759 | case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); } | 
|---|
| [064e3ff] | 760 | // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" | 
|---|
| [e82aa9df] | 761 | | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); } | 
|---|
| [4d51835] | 762 | ; | 
|---|
| [b87a5ed] | 763 |  | 
|---|
|  | 764 | case_label:                                                                                             // CFA | 
|---|
| [8688ce1] | 765 | CASE case_value_list ':'                                        { $$ = $2; } | 
|---|
| [e82aa9df] | 766 | | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); } | 
|---|
| [4d51835] | 767 | // A semantic check is required to ensure only one default clause per switch/choose statement. | 
|---|
|  | 768 | ; | 
|---|
| [b87a5ed] | 769 |  | 
|---|
|  | 770 | case_label_list:                                                                                // CFA | 
|---|
| [4d51835] | 771 | case_label | 
|---|
| [1d4580a] | 772 | | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); } | 
|---|
| [4d51835] | 773 | ; | 
|---|
| [b87a5ed] | 774 |  | 
|---|
|  | 775 | case_clause:                                                                                    // CFA | 
|---|
| [e82aa9df] | 776 | case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); } | 
|---|
| [4d51835] | 777 | ; | 
|---|
| [b87a5ed] | 778 |  | 
|---|
|  | 779 | switch_clause_list_opt:                                                                 // CFA | 
|---|
| [4d51835] | 780 | // empty | 
|---|
|  | 781 | { $$ = 0; } | 
|---|
|  | 782 | | switch_clause_list | 
|---|
|  | 783 | ; | 
|---|
| [b87a5ed] | 784 |  | 
|---|
|  | 785 | switch_clause_list:                                                                             // CFA | 
|---|
| [4d51835] | 786 | case_label_list statement_list | 
|---|
| [e82aa9df] | 787 | { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); } | 
|---|
| [4d51835] | 788 | | switch_clause_list case_label_list statement_list | 
|---|
| [e82aa9df] | 789 | { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); } | 
|---|
| [4d51835] | 790 | ; | 
|---|
| [b87a5ed] | 791 |  | 
|---|
|  | 792 | choose_clause_list_opt:                                                                 // CFA | 
|---|
| [4d51835] | 793 | // empty | 
|---|
|  | 794 | { $$ = 0; } | 
|---|
|  | 795 | | choose_clause_list | 
|---|
|  | 796 | ; | 
|---|
| [b87a5ed] | 797 |  | 
|---|
|  | 798 | choose_clause_list:                                                                             // CFA | 
|---|
| [4d51835] | 799 | case_label_list fall_through | 
|---|
| [de62360d] | 800 | { $$ = $1->append_last_case( $2 ); } | 
|---|
| [4d51835] | 801 | | case_label_list statement_list fall_through_opt | 
|---|
| [e82aa9df] | 802 | { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); } | 
|---|
| [4d51835] | 803 | | choose_clause_list case_label_list fall_through | 
|---|
| [1d4580a] | 804 | { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); } | 
|---|
| [4d51835] | 805 | | choose_clause_list case_label_list statement_list fall_through_opt | 
|---|
| [e82aa9df] | 806 | { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); } | 
|---|
| [4d51835] | 807 | ; | 
|---|
| [b87a5ed] | 808 |  | 
|---|
|  | 809 | fall_through_opt:                                                                               // CFA | 
|---|
| [4d51835] | 810 | // empty | 
|---|
| [e82aa9df] | 811 | { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break | 
|---|
| [4d51835] | 812 | | fall_through | 
|---|
|  | 813 | ; | 
|---|
| [b87a5ed] | 814 |  | 
|---|
|  | 815 | fall_through:                                                                                   // CFA | 
|---|
| [4e06c1e] | 816 | FALLTHRU | 
|---|
|  | 817 | { $$ = 0; } | 
|---|
|  | 818 | | FALLTHRU ';' | 
|---|
|  | 819 | { $$ = 0; } | 
|---|
| [4d51835] | 820 | ; | 
|---|
| [51b73452] | 821 |  | 
|---|
|  | 822 | iteration_statement: | 
|---|
| [4d51835] | 823 | WHILE '(' comma_expression ')' statement | 
|---|
| [e82aa9df] | 824 | { $$ = new StatementNode( build_while( $3, $5 ) ); } | 
|---|
| [4d51835] | 825 | | DO statement WHILE '(' comma_expression ')' ';' | 
|---|
| [e82aa9df] | 826 | { $$ = new StatementNode( build_while( $5, $2 ) ); } | 
|---|
| [4d51835] | 827 | | FOR '(' push for_control_expression ')' statement | 
|---|
| [e82aa9df] | 828 | { $$ = new StatementNode( build_for( $4, $6 ) ); } | 
|---|
| [4d51835] | 829 | ; | 
|---|
| [51b73452] | 830 |  | 
|---|
|  | 831 | for_control_expression: | 
|---|
| [4d51835] | 832 | comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt | 
|---|
| [2f22cc4] | 833 | { $$ = new ForCtl( $1, $4, $6 ); } | 
|---|
| [4d51835] | 834 | | declaration comma_expression_opt ';' comma_expression_opt // C99 | 
|---|
| [2f22cc4] | 835 | { $$ = new ForCtl( $1, $2, $4 ); } | 
|---|
| [d1625f8] | 836 | ; | 
|---|
| [51b73452] | 837 |  | 
|---|
|  | 838 | jump_statement: | 
|---|
| [c6b1105] | 839 | GOTO IDENTIFIER ';' | 
|---|
| [ac71a86] | 840 | { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Goto ) ); } | 
|---|
| [4d51835] | 841 | | GOTO '*' comma_expression ';'                                         // GCC, computed goto | 
|---|
| [4e06c1e] | 842 | // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); | 
|---|
| [de62360d] | 843 | // whereas normal operator precedence yields goto (*i)+3; | 
|---|
| [e82aa9df] | 844 | { $$ = new StatementNode( build_computedgoto( $3 ) ); } | 
|---|
| [4d51835] | 845 | | CONTINUE ';' | 
|---|
| [de62360d] | 846 | // A semantic check is required to ensure this statement appears only in the body of an iteration statement. | 
|---|
| [e82aa9df] | 847 | { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); } | 
|---|
| [4e06c1e] | 848 | | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue | 
|---|
| [de62360d] | 849 | // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and | 
|---|
|  | 850 | // the target of the transfer appears only at the start of an iteration statement. | 
|---|
| [ac71a86] | 851 | { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Continue ) ); } | 
|---|
| [4d51835] | 852 | | BREAK ';' | 
|---|
| [de62360d] | 853 | // A semantic check is required to ensure this statement appears only in the body of an iteration statement. | 
|---|
| [e82aa9df] | 854 | { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } | 
|---|
| [4e06c1e] | 855 | | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit | 
|---|
| [de62360d] | 856 | // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and | 
|---|
|  | 857 | // the target of the transfer appears only at the start of an iteration statement. | 
|---|
| [ac71a86] | 858 | { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Break ) ); } | 
|---|
| [4d51835] | 859 | | RETURN comma_expression_opt ';' | 
|---|
| [e82aa9df] | 860 | { $$ = new StatementNode( build_return( $2 ) ); } | 
|---|
| [8cc5cb0] | 861 | | THROW assignment_expression_opt ';'                           // handles rethrow | 
|---|
| [e82aa9df] | 862 | { $$ = new StatementNode( build_throw( $2 ) ); } | 
|---|
| [8cc5cb0] | 863 | | THROWRESUME assignment_expression_opt ';'                     // handles reresume | 
|---|
| [e82aa9df] | 864 | { $$ = new StatementNode( build_throw( $2 ) ); } | 
|---|
| [8cc5cb0] | 865 | | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume | 
|---|
| [e82aa9df] | 866 | { $$ = new StatementNode( build_throw( $2 ) ); } | 
|---|
| [4d51835] | 867 | ; | 
|---|
| [51b73452] | 868 |  | 
|---|
|  | 869 | exception_statement: | 
|---|
| [4d51835] | 870 | TRY compound_statement handler_list | 
|---|
| [e82aa9df] | 871 | { $$ = new StatementNode( build_try( $2, $3, 0 ) ); } | 
|---|
| [4d51835] | 872 | | TRY compound_statement finally_clause | 
|---|
| [e82aa9df] | 873 | { $$ = new StatementNode( build_try( $2, 0, $3 ) ); } | 
|---|
| [4d51835] | 874 | | TRY compound_statement handler_list finally_clause | 
|---|
| [e82aa9df] | 875 | { $$ = new StatementNode( build_try( $2, $3, $4 ) ); } | 
|---|
| [4d51835] | 876 | ; | 
|---|
| [51b73452] | 877 |  | 
|---|
|  | 878 | handler_list: | 
|---|
| [4d51835] | 879 | handler_clause | 
|---|
| [de62360d] | 880 | // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. | 
|---|
| [4d51835] | 881 | | CATCH '(' ELLIPSIS ')' compound_statement | 
|---|
| [e82aa9df] | 882 | { $$ = new StatementNode( build_catch( 0, $5, true ) ); } | 
|---|
| [4d51835] | 883 | | handler_clause CATCH '(' ELLIPSIS ')' compound_statement | 
|---|
| [e82aa9df] | 884 | { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } | 
|---|
| [02e5ab6] | 885 | | CATCHRESUME '(' ELLIPSIS ')' compound_statement | 
|---|
| [e82aa9df] | 886 | { $$ = new StatementNode( build_catch( 0, $5, true ) ); } | 
|---|
| [02e5ab6] | 887 | | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement | 
|---|
| [e82aa9df] | 888 | { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } | 
|---|
| [4d51835] | 889 | ; | 
|---|
| [51b73452] | 890 |  | 
|---|
|  | 891 | handler_clause: | 
|---|
| [4d51835] | 892 | CATCH '(' push push exception_declaration pop ')' compound_statement pop | 
|---|
| [e82aa9df] | 893 | { $$ = new StatementNode( build_catch( $5, $8 ) ); } | 
|---|
| [4d51835] | 894 | | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop | 
|---|
| [e82aa9df] | 895 | { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } | 
|---|
| [02e5ab6] | 896 | | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop | 
|---|
| [e82aa9df] | 897 | { $$ = new StatementNode( build_catch( $5, $8 ) ); } | 
|---|
| [02e5ab6] | 898 | | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop | 
|---|
| [e82aa9df] | 899 | { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } | 
|---|
| [4d51835] | 900 | ; | 
|---|
| [51b73452] | 901 |  | 
|---|
|  | 902 | finally_clause: | 
|---|
| [4d51835] | 903 | FINALLY compound_statement | 
|---|
|  | 904 | { | 
|---|
| [e82aa9df] | 905 | $$ = new StatementNode( build_finally( $2 ) ); | 
|---|
| [4d51835] | 906 | } | 
|---|
|  | 907 | ; | 
|---|
| [51b73452] | 908 |  | 
|---|
|  | 909 | exception_declaration: | 
|---|
| [4d51835] | 910 | // A semantic check is required to ensure type_specifier does not create a new type, e.g.: | 
|---|
|  | 911 | // | 
|---|
|  | 912 | //              catch ( struct { int i; } x ) ... | 
|---|
|  | 913 | // | 
|---|
|  | 914 | // This new type cannot catch any thrown type because of name equivalence among types. | 
|---|
|  | 915 | type_specifier | 
|---|
|  | 916 | | type_specifier declarator | 
|---|
|  | 917 | { | 
|---|
|  | 918 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 919 | $$ = $2->addType( $1 ); | 
|---|
|  | 920 | } | 
|---|
|  | 921 | | type_specifier variable_abstract_declarator | 
|---|
|  | 922 | { $$ = $2->addType( $1 ); } | 
|---|
|  | 923 | | new_abstract_declarator_tuple no_attr_identifier      // CFA | 
|---|
|  | 924 | { | 
|---|
|  | 925 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 926 | $$ = $1->addName( $2 ); | 
|---|
|  | 927 | } | 
|---|
|  | 928 | | new_abstract_declarator_tuple                                         // CFA | 
|---|
|  | 929 | ; | 
|---|
| [51b73452] | 930 |  | 
|---|
|  | 931 | asm_statement: | 
|---|
| [7f5566b] | 932 | ASM asm_volatile_opt '(' string_literal_list ')' ';' | 
|---|
| [e82aa9df] | 933 | { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); } | 
|---|
| [7f5566b] | 934 | | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC | 
|---|
| [e82aa9df] | 935 | { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); } | 
|---|
| [7f5566b] | 936 | | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';' | 
|---|
| [e82aa9df] | 937 | { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); } | 
|---|
| [7f5566b] | 938 | | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' | 
|---|
| [e82aa9df] | 939 | { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); } | 
|---|
| [7f5566b] | 940 | | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' | 
|---|
| [e82aa9df] | 941 | { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); } | 
|---|
| [7f5566b] | 942 | ; | 
|---|
|  | 943 |  | 
|---|
|  | 944 | asm_volatile_opt:                                                                               // GCC | 
|---|
|  | 945 | // empty | 
|---|
|  | 946 | { $$ = false; } | 
|---|
|  | 947 | | VOLATILE | 
|---|
|  | 948 | { $$ = true; } | 
|---|
| [4d51835] | 949 | ; | 
|---|
| [b87a5ed] | 950 |  | 
|---|
|  | 951 | asm_operands_opt:                                                                               // GCC | 
|---|
| [4d51835] | 952 | // empty | 
|---|
| [7f5566b] | 953 | { $$ = 0; }                                                                             // use default argument | 
|---|
| [4d51835] | 954 | | asm_operands_list | 
|---|
|  | 955 | ; | 
|---|
| [b87a5ed] | 956 |  | 
|---|
|  | 957 | asm_operands_list:                                                                              // GCC | 
|---|
| [4d51835] | 958 | asm_operand | 
|---|
|  | 959 | | asm_operands_list ',' asm_operand | 
|---|
| [1d4580a] | 960 | { $$ = (ExpressionNode *)$1->set_last( $3 ); } | 
|---|
| [4d51835] | 961 | ; | 
|---|
| [b87a5ed] | 962 |  | 
|---|
|  | 963 | asm_operand:                                                                                    // GCC | 
|---|
| [7f5566b] | 964 | string_literal_list '(' constant_expression ')' | 
|---|
| [e82aa9df] | 965 | { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); } | 
|---|
| [7f5566b] | 966 | | '[' constant_expression ']' string_literal_list '(' constant_expression ')' | 
|---|
| [e82aa9df] | 967 | { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); } | 
|---|
| [7f5566b] | 968 | ; | 
|---|
|  | 969 |  | 
|---|
| [4e06c1e] | 970 | asm_clobbers_list_opt:                                                                  // GCC | 
|---|
| [7f5566b] | 971 | // empty | 
|---|
|  | 972 | { $$ = 0; }                                                                             // use default argument | 
|---|
|  | 973 | | string_literal_list | 
|---|
| [d1625f8] | 974 | { $$ = new ExpressionNode( $1 ); } | 
|---|
| [7f5566b] | 975 | | asm_clobbers_list_opt ',' string_literal_list | 
|---|
| [e82aa9df] | 976 | { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } | 
|---|
| [4d51835] | 977 | ; | 
|---|
| [b87a5ed] | 978 |  | 
|---|
| [7f5566b] | 979 | label_list: | 
|---|
|  | 980 | no_attr_identifier | 
|---|
| [ac71a86] | 981 | { $$ = new LabelNode(); $$->labels.push_back( assign_strptr($1) ); } | 
|---|
| [7f5566b] | 982 | | label_list ',' no_attr_identifier | 
|---|
| [ac71a86] | 983 | { $$ = $1; $1->labels.push_back( assign_strptr($3) ); } | 
|---|
| [4d51835] | 984 | ; | 
|---|
| [51b73452] | 985 |  | 
|---|
| [c11e31c] | 986 | //******************************* DECLARATIONS ********************************* | 
|---|
| [51b73452] | 987 |  | 
|---|
| [b87a5ed] | 988 | declaration_list_opt:                                                                   // used at beginning of switch statement | 
|---|
| [4d51835] | 989 | pop | 
|---|
|  | 990 | { $$ = 0; } | 
|---|
|  | 991 | | declaration_list | 
|---|
|  | 992 | ; | 
|---|
| [51b73452] | 993 |  | 
|---|
|  | 994 | declaration_list: | 
|---|
| [4d51835] | 995 | declaration | 
|---|
|  | 996 | | declaration_list push declaration | 
|---|
|  | 997 | { $$ = $1->appendList( $3 ); } | 
|---|
|  | 998 | ; | 
|---|
| [51b73452] | 999 |  | 
|---|
| [b87a5ed] | 1000 | old_declaration_list_opt:                                                               // used to declare parameter types in K&R style functions | 
|---|
| [4d51835] | 1001 | pop | 
|---|
|  | 1002 | { $$ = 0; } | 
|---|
|  | 1003 | | old_declaration_list | 
|---|
|  | 1004 | ; | 
|---|
| [51b73452] | 1005 |  | 
|---|
|  | 1006 | old_declaration_list: | 
|---|
| [4d51835] | 1007 | old_declaration | 
|---|
|  | 1008 | | old_declaration_list push old_declaration | 
|---|
|  | 1009 | { $$ = $1->appendList( $3 ); } | 
|---|
|  | 1010 | ; | 
|---|
| [b87a5ed] | 1011 |  | 
|---|
| [51b1202] | 1012 | local_label_declaration_opt:                                                    // GCC, local label | 
|---|
| [4d51835] | 1013 | // empty | 
|---|
| [51b1202] | 1014 | | local_label_declaration_list | 
|---|
| [4d51835] | 1015 | ; | 
|---|
| [b87a5ed] | 1016 |  | 
|---|
| [51b1202] | 1017 | local_label_declaration_list:                                                   // GCC, local label | 
|---|
|  | 1018 | LABEL local_label_list ';' | 
|---|
|  | 1019 | | local_label_declaration_list LABEL local_label_list ';' | 
|---|
| [4d51835] | 1020 | ; | 
|---|
| [b87a5ed] | 1021 |  | 
|---|
| [51b1202] | 1022 | local_label_list:                                                                               // GCC, local label | 
|---|
| [7f5566b] | 1023 | no_attr_identifier_or_type_name                         {} | 
|---|
| [51b1202] | 1024 | | local_label_list ',' no_attr_identifier_or_type_name {} | 
|---|
| [4d51835] | 1025 | ; | 
|---|
| [b87a5ed] | 1026 |  | 
|---|
|  | 1027 | declaration:                                                                                    // CFA, new & old style declarations | 
|---|
| [4d51835] | 1028 | new_declaration | 
|---|
|  | 1029 | | old_declaration | 
|---|
|  | 1030 | ; | 
|---|
| [b87a5ed] | 1031 |  | 
|---|
| [de62360d] | 1032 | // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function | 
|---|
|  | 1033 | // declarations. CFA declarations use the same declaration tokens as in C; however, CFA places declaration modifiers to | 
|---|
|  | 1034 | // the left of the base type, while C declarations place modifiers to the right of the base type. CFA declaration | 
|---|
|  | 1035 | // modifiers are interpreted from left to right and the entire type specification is distributed across all variables in | 
|---|
|  | 1036 | // the declaration list (as in Pascal).  ANSI C and the new CFA declarations may appear together in the same program | 
|---|
|  | 1037 | // block, but cannot be mixed within a specific declaration. | 
|---|
| [c11e31c] | 1038 | // | 
|---|
| [b87a5ed] | 1039 | //                      CFA                                     C | 
|---|
|  | 1040 | //              [10] int x;                     int x[10];              // array of 10 integers | 
|---|
|  | 1041 | //              [10] * char y;          char *y[10];    // array of 10 pointers to char | 
|---|
|  | 1042 |  | 
|---|
|  | 1043 | new_declaration:                                                                                // CFA | 
|---|
| [4d51835] | 1044 | new_variable_declaration pop ';' | 
|---|
|  | 1045 | | new_typedef_declaration pop ';' | 
|---|
|  | 1046 | | new_function_declaration pop ';' | 
|---|
|  | 1047 | | type_declaring_list pop ';' | 
|---|
| [4040425] | 1048 | | trait_specifier pop ';' | 
|---|
| [4d51835] | 1049 | ; | 
|---|
| [b87a5ed] | 1050 |  | 
|---|
|  | 1051 | new_variable_declaration:                                                               // CFA | 
|---|
| [4d51835] | 1052 | new_variable_specifier initializer_opt | 
|---|
|  | 1053 | { | 
|---|
|  | 1054 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
| [3cfe27f] | 1055 | $$ = $1->addInitializer( $2 ); | 
|---|
| [4d51835] | 1056 | } | 
|---|
|  | 1057 | | declaration_qualifier_list new_variable_specifier initializer_opt | 
|---|
| [de62360d] | 1058 | // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude | 
|---|
|  | 1059 | // them as a type_qualifier cannot appear in that context. | 
|---|
| [4d51835] | 1060 | { | 
|---|
|  | 1061 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
| [3cfe27f] | 1062 | $$ = $2->addQualifiers( $1 )->addInitializer( $3 );; | 
|---|
| [4d51835] | 1063 | } | 
|---|
| [2871210] | 1064 | | new_variable_declaration pop ',' push identifier_or_type_name initializer_opt | 
|---|
| [4d51835] | 1065 | { | 
|---|
|  | 1066 | typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); | 
|---|
| [3cfe27f] | 1067 | $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); | 
|---|
| [4d51835] | 1068 | } | 
|---|
|  | 1069 | ; | 
|---|
| [b87a5ed] | 1070 |  | 
|---|
|  | 1071 | new_variable_specifier:                                                                 // CFA | 
|---|
| [de62360d] | 1072 | // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static | 
|---|
|  | 1073 | // storage-class | 
|---|
| [2871210] | 1074 | new_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt | 
|---|
| [4d51835] | 1075 | { | 
|---|
|  | 1076 | typedefTable.setNextIdentifier( *$2 ); | 
|---|
|  | 1077 | $$ = $1->addName( $2 ); | 
|---|
|  | 1078 | } | 
|---|
| [2871210] | 1079 | | new_abstract_tuple identifier_or_type_name asm_name_opt | 
|---|
| [4d51835] | 1080 | { | 
|---|
|  | 1081 | typedefTable.setNextIdentifier( *$2 ); | 
|---|
|  | 1082 | $$ = $1->addName( $2 ); | 
|---|
|  | 1083 | } | 
|---|
| [2871210] | 1084 | | type_qualifier_list new_abstract_tuple identifier_or_type_name asm_name_opt | 
|---|
| [4d51835] | 1085 | { | 
|---|
|  | 1086 | typedefTable.setNextIdentifier( *$3 ); | 
|---|
|  | 1087 | $$ = $2->addQualifiers( $1 )->addName( $3 ); | 
|---|
|  | 1088 | } | 
|---|
|  | 1089 | ; | 
|---|
| [b87a5ed] | 1090 |  | 
|---|
|  | 1091 | new_function_declaration:                                                               // CFA | 
|---|
| [4d51835] | 1092 | new_function_specifier | 
|---|
|  | 1093 | { | 
|---|
|  | 1094 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 1095 | $$ = $1; | 
|---|
|  | 1096 | } | 
|---|
|  | 1097 | | type_qualifier_list new_function_specifier | 
|---|
|  | 1098 | { | 
|---|
|  | 1099 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 1100 | $$ = $2->addQualifiers( $1 ); | 
|---|
|  | 1101 | } | 
|---|
|  | 1102 | | declaration_qualifier_list new_function_specifier | 
|---|
|  | 1103 | { | 
|---|
|  | 1104 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 1105 | $$ = $2->addQualifiers( $1 ); | 
|---|
|  | 1106 | } | 
|---|
|  | 1107 | | declaration_qualifier_list type_qualifier_list new_function_specifier | 
|---|
|  | 1108 | { | 
|---|
|  | 1109 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 1110 | $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); | 
|---|
|  | 1111 | } | 
|---|
| [2871210] | 1112 | | new_function_declaration pop ',' push identifier_or_type_name | 
|---|
| [4d51835] | 1113 | { | 
|---|
|  | 1114 | typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); | 
|---|
|  | 1115 | $$ = $1->appendList( $1->cloneType( $5 ) ); | 
|---|
|  | 1116 | } | 
|---|
|  | 1117 | ; | 
|---|
| [b87a5ed] | 1118 |  | 
|---|
|  | 1119 | new_function_specifier:                                                                 // CFA | 
|---|
| [2871210] | 1120 | '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict | 
|---|
| [4d51835] | 1121 | { | 
|---|
| [2871210] | 1122 | $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true ); | 
|---|
| [4d51835] | 1123 | } | 
|---|
| [2871210] | 1124 | //      '[' ']' identifier '(' push new_parameter_type_list_opt pop ')' | 
|---|
|  | 1125 | //              { | 
|---|
|  | 1126 | //                      typedefTable.setNextIdentifier( *$5 ); | 
|---|
|  | 1127 | //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); | 
|---|
|  | 1128 | //              } | 
|---|
|  | 1129 | //      | '[' ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')' | 
|---|
|  | 1130 | //              { | 
|---|
|  | 1131 | //                      typedefTable.setNextIdentifier( *$5 ); | 
|---|
|  | 1132 | //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); | 
|---|
|  | 1133 | //              } | 
|---|
|  | 1134 | //      | '[' ']' typegen_name | 
|---|
|  | 1135 | // identifier_or_type_name must be broken apart because of the sequence: | 
|---|
| [4d51835] | 1136 | // | 
|---|
| [2871210] | 1137 | //   '[' ']' identifier_or_type_name '(' new_parameter_type_list_opt ')' | 
|---|
| [4d51835] | 1138 | //   '[' ']' type_specifier | 
|---|
|  | 1139 | // | 
|---|
| [2871210] | 1140 | // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be | 
|---|
|  | 1141 | // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. | 
|---|
|  | 1142 | | new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' | 
|---|
| [de62360d] | 1143 | // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator). | 
|---|
| [4d51835] | 1144 | { | 
|---|
|  | 1145 | $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); | 
|---|
|  | 1146 | } | 
|---|
| [2871210] | 1147 | | new_function_return identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' | 
|---|
| [4d51835] | 1148 | { | 
|---|
|  | 1149 | $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); | 
|---|
|  | 1150 | } | 
|---|
|  | 1151 | ; | 
|---|
| [b87a5ed] | 1152 |  | 
|---|
|  | 1153 | new_function_return:                                                                    // CFA | 
|---|
| [4d51835] | 1154 | '[' push new_parameter_list pop ']' | 
|---|
|  | 1155 | { $$ = DeclarationNode::newTuple( $3 ); } | 
|---|
|  | 1156 | | '[' push new_parameter_list pop ',' push new_abstract_parameter_list pop ']' | 
|---|
| [de62360d] | 1157 | // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to lookahead to the | 
|---|
|  | 1158 | // ']'. | 
|---|
| [4d51835] | 1159 | { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } | 
|---|
|  | 1160 | ; | 
|---|
| [b87a5ed] | 1161 |  | 
|---|
|  | 1162 | new_typedef_declaration:                                                                // CFA | 
|---|
| [4d51835] | 1163 | TYPEDEF new_variable_specifier | 
|---|
|  | 1164 | { | 
|---|
| [de62360d] | 1165 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
| [4d51835] | 1166 | $$ = $2->addTypedef(); | 
|---|
|  | 1167 | } | 
|---|
|  | 1168 | | TYPEDEF new_function_specifier | 
|---|
|  | 1169 | { | 
|---|
| [de62360d] | 1170 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
| [4d51835] | 1171 | $$ = $2->addTypedef(); | 
|---|
|  | 1172 | } | 
|---|
|  | 1173 | | new_typedef_declaration pop ',' push no_attr_identifier | 
|---|
|  | 1174 | { | 
|---|
| [de62360d] | 1175 | typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); | 
|---|
| [4d51835] | 1176 | $$ = $1->appendList( $1->cloneType( $5 ) ); | 
|---|
|  | 1177 | } | 
|---|
|  | 1178 | ; | 
|---|
| [b87a5ed] | 1179 |  | 
|---|
| [de62360d] | 1180 | // Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is factored out as | 
|---|
|  | 1181 | // a separate form of declaration, which syntactically precludes storage-class specifiers and initialization. | 
|---|
| [51b73452] | 1182 |  | 
|---|
|  | 1183 | typedef_declaration: | 
|---|
| [4d51835] | 1184 | TYPEDEF type_specifier declarator | 
|---|
|  | 1185 | { | 
|---|
| [de62360d] | 1186 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
| [4d51835] | 1187 | $$ = $3->addType( $2 )->addTypedef(); | 
|---|
|  | 1188 | } | 
|---|
|  | 1189 | | typedef_declaration pop ',' push declarator | 
|---|
|  | 1190 | { | 
|---|
| [de62360d] | 1191 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
| [4d51835] | 1192 | $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); | 
|---|
|  | 1193 | } | 
|---|
| [de62360d] | 1194 | | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) | 
|---|
| [4d51835] | 1195 | { | 
|---|
| [de62360d] | 1196 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
| [4d51835] | 1197 | $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); | 
|---|
|  | 1198 | } | 
|---|
|  | 1199 | | type_specifier TYPEDEF declarator | 
|---|
|  | 1200 | { | 
|---|
| [de62360d] | 1201 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
| [4d51835] | 1202 | $$ = $3->addType( $1 )->addTypedef(); | 
|---|
|  | 1203 | } | 
|---|
|  | 1204 | | type_specifier TYPEDEF type_qualifier_list declarator | 
|---|
|  | 1205 | { | 
|---|
| [de62360d] | 1206 | typedefTable.addToEnclosingScope( TypedefTable::TD ); | 
|---|
|  | 1207 | $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); | 
|---|
| [4d51835] | 1208 | } | 
|---|
|  | 1209 | ; | 
|---|
| [b87a5ed] | 1210 |  | 
|---|
| [721f17a] | 1211 | typedef_expression: | 
|---|
|  | 1212 | // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression | 
|---|
| [4d51835] | 1213 | TYPEDEF no_attr_identifier '=' assignment_expression | 
|---|
|  | 1214 | { | 
|---|
| [de62360d] | 1215 | typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); | 
|---|
| [4d51835] | 1216 | $$ = DeclarationNode::newName( 0 ); // XXX | 
|---|
|  | 1217 | } | 
|---|
|  | 1218 | | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression | 
|---|
|  | 1219 | { | 
|---|
| [de62360d] | 1220 | typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); | 
|---|
| [4d51835] | 1221 | $$ = DeclarationNode::newName( 0 ); // XXX | 
|---|
|  | 1222 | } | 
|---|
|  | 1223 | ; | 
|---|
| [51b73452] | 1224 |  | 
|---|
|  | 1225 | old_declaration: | 
|---|
| [4d51835] | 1226 | declaring_list pop ';' | 
|---|
|  | 1227 | | typedef_declaration pop ';' | 
|---|
|  | 1228 | | typedef_expression pop ';'                                            // GCC, naming expression type | 
|---|
|  | 1229 | | sue_declaration_specifier pop ';' | 
|---|
|  | 1230 | ; | 
|---|
| [51b73452] | 1231 |  | 
|---|
|  | 1232 | declaring_list: | 
|---|
| [de62360d] | 1233 | // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static | 
|---|
|  | 1234 | // storage-class | 
|---|
| [4d51835] | 1235 | declaration_specifier declarator asm_name_opt initializer_opt | 
|---|
|  | 1236 | { | 
|---|
|  | 1237 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
| [de62360d] | 1238 | $$ = ( $2->addType( $1 ))->addInitializer( $4 ); | 
|---|
| [4d51835] | 1239 | } | 
|---|
|  | 1240 | | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt | 
|---|
|  | 1241 | { | 
|---|
|  | 1242 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
| [de62360d] | 1243 | $$ = $1->appendList( $1->cloneBaseType( $4->addInitializer( $6 ) ) ); | 
|---|
| [4d51835] | 1244 | } | 
|---|
|  | 1245 | ; | 
|---|
| [b87a5ed] | 1246 |  | 
|---|
|  | 1247 | declaration_specifier:                                                                  // type specifier + storage class | 
|---|
| [4d51835] | 1248 | basic_declaration_specifier | 
|---|
|  | 1249 | | sue_declaration_specifier | 
|---|
|  | 1250 | | typedef_declaration_specifier | 
|---|
|  | 1251 | | typegen_declaration_specifier | 
|---|
|  | 1252 | ; | 
|---|
| [b87a5ed] | 1253 |  | 
|---|
|  | 1254 | type_specifier:                                                                                 // declaration specifier - storage class | 
|---|
| [4d51835] | 1255 | basic_type_specifier | 
|---|
|  | 1256 | | sue_type_specifier | 
|---|
|  | 1257 | | typedef_type_specifier | 
|---|
|  | 1258 | | typegen_type_specifier | 
|---|
|  | 1259 | ; | 
|---|
| [b87a5ed] | 1260 |  | 
|---|
|  | 1261 | type_qualifier_list_opt:                                                                // GCC, used in asm_statement | 
|---|
| [4d51835] | 1262 | // empty | 
|---|
|  | 1263 | { $$ = 0; } | 
|---|
|  | 1264 | | type_qualifier_list | 
|---|
|  | 1265 | ; | 
|---|
| [51b73452] | 1266 |  | 
|---|
|  | 1267 | type_qualifier_list: | 
|---|
| [de62360d] | 1268 | // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration. | 
|---|
| [4d51835] | 1269 | // | 
|---|
| [de62360d] | 1270 | // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same | 
|---|
|  | 1271 | // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it | 
|---|
|  | 1272 | // appeared only once. | 
|---|
| [4d51835] | 1273 | type_qualifier | 
|---|
|  | 1274 | | type_qualifier_list type_qualifier | 
|---|
|  | 1275 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1276 | ; | 
|---|
| [51b73452] | 1277 |  | 
|---|
|  | 1278 | type_qualifier: | 
|---|
| [4d51835] | 1279 | type_qualifier_name | 
|---|
|  | 1280 | | attribute | 
|---|
| [1db21619] | 1281 | //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); } | 
|---|
| [4d51835] | 1282 | ; | 
|---|
| [51b73452] | 1283 |  | 
|---|
|  | 1284 | type_qualifier_name: | 
|---|
| [4d51835] | 1285 | CONST | 
|---|
|  | 1286 | { $$ = DeclarationNode::newQualifier( DeclarationNode::Const ); } | 
|---|
|  | 1287 | | RESTRICT | 
|---|
|  | 1288 | { $$ = DeclarationNode::newQualifier( DeclarationNode::Restrict ); } | 
|---|
|  | 1289 | | VOLATILE | 
|---|
|  | 1290 | { $$ = DeclarationNode::newQualifier( DeclarationNode::Volatile ); } | 
|---|
|  | 1291 | | LVALUE                                                                                        // CFA | 
|---|
|  | 1292 | { $$ = DeclarationNode::newQualifier( DeclarationNode::Lvalue ); } | 
|---|
|  | 1293 | | ATOMIC | 
|---|
|  | 1294 | { $$ = DeclarationNode::newQualifier( DeclarationNode::Atomic ); } | 
|---|
|  | 1295 | | FORALL '(' | 
|---|
|  | 1296 | { | 
|---|
|  | 1297 | typedefTable.enterScope(); | 
|---|
|  | 1298 | } | 
|---|
|  | 1299 | type_parameter_list ')'                                                       // CFA | 
|---|
|  | 1300 | { | 
|---|
|  | 1301 | typedefTable.leaveScope(); | 
|---|
|  | 1302 | $$ = DeclarationNode::newForall( $4 ); | 
|---|
|  | 1303 | } | 
|---|
|  | 1304 | ; | 
|---|
| [51b73452] | 1305 |  | 
|---|
|  | 1306 | declaration_qualifier_list: | 
|---|
| [4d51835] | 1307 | storage_class_list | 
|---|
| [de62360d] | 1308 | | type_qualifier_list storage_class_list                        // remaining OBSOLESCENT (see 2 ) | 
|---|
| [4d51835] | 1309 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1310 | | declaration_qualifier_list type_qualifier_list storage_class_list | 
|---|
|  | 1311 | { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } | 
|---|
|  | 1312 | ; | 
|---|
| [51b73452] | 1313 |  | 
|---|
|  | 1314 | storage_class_list: | 
|---|
| [de62360d] | 1315 | // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that | 
|---|
|  | 1316 | // only one of each is specified, except for inline, which can appear with the others. | 
|---|
| [4d51835] | 1317 | // | 
|---|
| [de62360d] | 1318 | // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration | 
|---|
|  | 1319 | // specifiers in a declaration. | 
|---|
| [4d51835] | 1320 | storage_class | 
|---|
|  | 1321 | | storage_class_list storage_class | 
|---|
|  | 1322 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1323 | ; | 
|---|
| [51b73452] | 1324 |  | 
|---|
|  | 1325 | storage_class: | 
|---|
| [4d51835] | 1326 | EXTERN | 
|---|
|  | 1327 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); } | 
|---|
|  | 1328 | | STATIC | 
|---|
|  | 1329 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Static ); } | 
|---|
|  | 1330 | | AUTO | 
|---|
|  | 1331 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Auto ); } | 
|---|
|  | 1332 | | REGISTER | 
|---|
|  | 1333 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); } | 
|---|
|  | 1334 | | INLINE                                                                                        // C99 | 
|---|
|  | 1335 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); } | 
|---|
|  | 1336 | | FORTRAN                                                                                       // C99 | 
|---|
|  | 1337 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); } | 
|---|
| [68cd1ce] | 1338 | | NORETURN                                                                                      // C11 | 
|---|
|  | 1339 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); } | 
|---|
|  | 1340 | | THREADLOCAL                                                                           // C11 | 
|---|
|  | 1341 | { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); } | 
|---|
| [4d51835] | 1342 | ; | 
|---|
| [51b73452] | 1343 |  | 
|---|
|  | 1344 | basic_type_name: | 
|---|
| [4d51835] | 1345 | CHAR | 
|---|
|  | 1346 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); } | 
|---|
|  | 1347 | | DOUBLE | 
|---|
|  | 1348 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); } | 
|---|
|  | 1349 | | FLOAT | 
|---|
|  | 1350 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); } | 
|---|
|  | 1351 | | INT | 
|---|
|  | 1352 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); } | 
|---|
|  | 1353 | | LONG | 
|---|
|  | 1354 | { $$ = DeclarationNode::newModifier( DeclarationNode::Long ); } | 
|---|
|  | 1355 | | SHORT | 
|---|
|  | 1356 | { $$ = DeclarationNode::newModifier( DeclarationNode::Short ); } | 
|---|
|  | 1357 | | SIGNED | 
|---|
|  | 1358 | { $$ = DeclarationNode::newModifier( DeclarationNode::Signed ); } | 
|---|
|  | 1359 | | UNSIGNED | 
|---|
|  | 1360 | { $$ = DeclarationNode::newModifier( DeclarationNode::Unsigned ); } | 
|---|
|  | 1361 | | VOID | 
|---|
|  | 1362 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } | 
|---|
|  | 1363 | | BOOL                                                                                          // C99 | 
|---|
|  | 1364 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); } | 
|---|
|  | 1365 | | COMPLEX                                                                                       // C99 | 
|---|
|  | 1366 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Complex ); } | 
|---|
|  | 1367 | | IMAGINARY                                                                                     // C99 | 
|---|
|  | 1368 | { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); } | 
|---|
| [90c3b1c] | 1369 | | VALIST                                                                                        // GCC, __builtin_va_list | 
|---|
|  | 1370 | { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } | 
|---|
| [4d51835] | 1371 | ; | 
|---|
| [51b73452] | 1372 |  | 
|---|
|  | 1373 | basic_declaration_specifier: | 
|---|
| [4d51835] | 1374 | // A semantic check is necessary for conflicting storage classes. | 
|---|
|  | 1375 | basic_type_specifier | 
|---|
|  | 1376 | | declaration_qualifier_list basic_type_specifier | 
|---|
|  | 1377 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1378 | | basic_declaration_specifier storage_class                     // remaining OBSOLESCENT (see 2) | 
|---|
|  | 1379 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1380 | | basic_declaration_specifier storage_class type_qualifier_list | 
|---|
|  | 1381 | { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } | 
|---|
|  | 1382 | | basic_declaration_specifier storage_class basic_type_specifier | 
|---|
|  | 1383 | { $$ = $3->addQualifiers( $2 )->addType( $1 ); } | 
|---|
|  | 1384 | ; | 
|---|
| [51b73452] | 1385 |  | 
|---|
|  | 1386 | basic_type_specifier: | 
|---|
| [4d51835] | 1387 | direct_type_name | 
|---|
|  | 1388 | | type_qualifier_list_opt indirect_type_name type_qualifier_list_opt | 
|---|
|  | 1389 | { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } | 
|---|
|  | 1390 | ; | 
|---|
| [51b73452] | 1391 |  | 
|---|
|  | 1392 | direct_type_name: | 
|---|
| [4d51835] | 1393 | // A semantic check is necessary for conflicting type qualifiers. | 
|---|
|  | 1394 | basic_type_name | 
|---|
|  | 1395 | | type_qualifier_list basic_type_name | 
|---|
|  | 1396 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1397 | | direct_type_name type_qualifier | 
|---|
|  | 1398 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1399 | | direct_type_name basic_type_name | 
|---|
|  | 1400 | { $$ = $1->addType( $2 ); } | 
|---|
|  | 1401 | ; | 
|---|
| [51b73452] | 1402 |  | 
|---|
|  | 1403 | indirect_type_name: | 
|---|
| [4d51835] | 1404 | TYPEOF '(' type_name ')'                                                        // GCC: typeof(x) y; | 
|---|
|  | 1405 | { $$ = $3; } | 
|---|
|  | 1406 | | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y; | 
|---|
|  | 1407 | { $$ = DeclarationNode::newTypeof( $3 ); } | 
|---|
|  | 1408 | | ATTR_TYPEGENname '(' type_name ')'                            // CFA: e.g., @type(x) y; | 
|---|
|  | 1409 | { $$ = DeclarationNode::newAttr( $1, $3 ); } | 
|---|
|  | 1410 | | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y; | 
|---|
|  | 1411 | { $$ = DeclarationNode::newAttr( $1, $3 ); } | 
|---|
|  | 1412 | ; | 
|---|
| [51b73452] | 1413 |  | 
|---|
|  | 1414 | sue_declaration_specifier: | 
|---|
| [4d51835] | 1415 | sue_type_specifier | 
|---|
|  | 1416 | | declaration_qualifier_list sue_type_specifier | 
|---|
|  | 1417 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1418 | | sue_declaration_specifier storage_class                       // remaining OBSOLESCENT (see 2) | 
|---|
|  | 1419 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1420 | | sue_declaration_specifier storage_class type_qualifier_list | 
|---|
|  | 1421 | { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } | 
|---|
|  | 1422 | ; | 
|---|
| [51b73452] | 1423 |  | 
|---|
|  | 1424 | sue_type_specifier: | 
|---|
| [4d51835] | 1425 | elaborated_type_name                                                            // struct, union, enum | 
|---|
|  | 1426 | | type_qualifier_list elaborated_type_name | 
|---|
|  | 1427 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1428 | | sue_type_specifier type_qualifier | 
|---|
|  | 1429 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1430 | ; | 
|---|
| [51b73452] | 1431 |  | 
|---|
|  | 1432 | typedef_declaration_specifier: | 
|---|
| [4d51835] | 1433 | typedef_type_specifier | 
|---|
|  | 1434 | | declaration_qualifier_list typedef_type_specifier | 
|---|
|  | 1435 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1436 | | typedef_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2) | 
|---|
|  | 1437 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1438 | | typedef_declaration_specifier storage_class type_qualifier_list | 
|---|
|  | 1439 | { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } | 
|---|
|  | 1440 | ; | 
|---|
| [b87a5ed] | 1441 |  | 
|---|
|  | 1442 | typedef_type_specifier:                                                                 // typedef types | 
|---|
| [4d51835] | 1443 | TYPEDEFname | 
|---|
|  | 1444 | { $$ = DeclarationNode::newFromTypedef( $1 ); } | 
|---|
|  | 1445 | | type_qualifier_list TYPEDEFname | 
|---|
|  | 1446 | { $$ = DeclarationNode::newFromTypedef( $2 )->addQualifiers( $1 ); } | 
|---|
|  | 1447 | | typedef_type_specifier type_qualifier | 
|---|
|  | 1448 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1449 | ; | 
|---|
| [51b73452] | 1450 |  | 
|---|
|  | 1451 | elaborated_type_name: | 
|---|
| [4d51835] | 1452 | aggregate_name | 
|---|
|  | 1453 | | enum_name | 
|---|
|  | 1454 | ; | 
|---|
| [51b73452] | 1455 |  | 
|---|
|  | 1456 | aggregate_name: | 
|---|
| [4d51835] | 1457 | aggregate_key '{' field_declaration_list '}' | 
|---|
| [5d125e4] | 1458 | { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3, true ); } | 
|---|
| [2871210] | 1459 | | aggregate_key no_attr_identifier_or_type_name | 
|---|
| [45161b4d] | 1460 | { | 
|---|
|  | 1461 | typedefTable.makeTypedef( *$2 ); | 
|---|
| [5d125e4] | 1462 | $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false ); | 
|---|
| [45161b4d] | 1463 | } | 
|---|
|  | 1464 | | aggregate_key no_attr_identifier_or_type_name | 
|---|
|  | 1465 | { typedefTable.makeTypedef( *$2 ); } | 
|---|
|  | 1466 | '{' field_declaration_list '}' | 
|---|
| [5d125e4] | 1467 | { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5, true ); } | 
|---|
| [721f17a] | 1468 | | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA | 
|---|
| [5d125e4] | 1469 | { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6, false ); } | 
|---|
| [2871210] | 1470 | | aggregate_key typegen_name                                            // CFA, S/R conflict | 
|---|
|  | 1471 | { $$ = $2; } | 
|---|
| [4d51835] | 1472 | ; | 
|---|
| [51b73452] | 1473 |  | 
|---|
|  | 1474 | aggregate_key: | 
|---|
| [4d51835] | 1475 | STRUCT attribute_list_opt | 
|---|
|  | 1476 | { $$ = DeclarationNode::Struct; } | 
|---|
|  | 1477 | | UNION attribute_list_opt | 
|---|
|  | 1478 | { $$ = DeclarationNode::Union; } | 
|---|
|  | 1479 | ; | 
|---|
| [51b73452] | 1480 |  | 
|---|
|  | 1481 | field_declaration_list: | 
|---|
| [5d125e4] | 1482 | // empty | 
|---|
|  | 1483 | { $$ = 0; } | 
|---|
| [4d51835] | 1484 | | field_declaration_list field_declaration | 
|---|
| [5d125e4] | 1485 | { $$ = $1 != 0 ? $1->appendList( $2 ) : $2; } | 
|---|
| [4d51835] | 1486 | ; | 
|---|
| [51b73452] | 1487 |  | 
|---|
|  | 1488 | field_declaration: | 
|---|
| [4d51835] | 1489 | new_field_declaring_list ';'                                            // CFA, new style field declaration | 
|---|
|  | 1490 | | EXTENSION new_field_declaring_list ';'                        // GCC | 
|---|
| [ca35c51] | 1491 | { $$ = $2->set_extension( true ); } | 
|---|
| [4d51835] | 1492 | | field_declaring_list ';' | 
|---|
|  | 1493 | | EXTENSION field_declaring_list ';'                            // GCC | 
|---|
| [8e9cbb2] | 1494 | {       // mark all fields in list | 
|---|
| [926af74] | 1495 | for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) | 
|---|
| [8e9cbb2] | 1496 | iter->set_extension( true ); | 
|---|
|  | 1497 | $$ = $2; | 
|---|
|  | 1498 | } | 
|---|
| [4d51835] | 1499 | ; | 
|---|
| [b87a5ed] | 1500 |  | 
|---|
|  | 1501 | new_field_declaring_list:                                                               // CFA, new style field declaration | 
|---|
| [4d51835] | 1502 | new_abstract_declarator_tuple                                           // CFA, no field name | 
|---|
| [2871210] | 1503 | | new_abstract_declarator_tuple no_attr_identifier_or_type_name | 
|---|
| [4d51835] | 1504 | { $$ = $1->addName( $2 ); } | 
|---|
| [2871210] | 1505 | | new_field_declaring_list ',' no_attr_identifier_or_type_name | 
|---|
| [4d51835] | 1506 | { $$ = $1->appendList( $1->cloneType( $3 ) ); } | 
|---|
|  | 1507 | | new_field_declaring_list ','                                          // CFA, no field name | 
|---|
|  | 1508 | { $$ = $1->appendList( $1->cloneType( 0 ) ); } | 
|---|
|  | 1509 | ; | 
|---|
| [51b73452] | 1510 |  | 
|---|
|  | 1511 | field_declaring_list: | 
|---|
| [4d51835] | 1512 | type_specifier field_declarator | 
|---|
|  | 1513 | { $$ = $2->addType( $1 ); } | 
|---|
|  | 1514 | | field_declaring_list ',' attribute_list_opt field_declarator | 
|---|
|  | 1515 | { $$ = $1->appendList( $1->cloneBaseType( $4 ) ); } | 
|---|
|  | 1516 | ; | 
|---|
| [51b73452] | 1517 |  | 
|---|
|  | 1518 | field_declarator: | 
|---|
| [4d51835] | 1519 | // empty | 
|---|
|  | 1520 | { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name | 
|---|
|  | 1521 | | bit_subrange_size                                                                     // no field name | 
|---|
|  | 1522 | { $$ = DeclarationNode::newBitfield( $1 ); } | 
|---|
|  | 1523 | | variable_declarator bit_subrange_size_opt | 
|---|
|  | 1524 | // A semantic check is required to ensure bit_subrange only appears on base type int. | 
|---|
|  | 1525 | { $$ = $1->addBitfield( $2 ); } | 
|---|
| [c6b1105] | 1526 | | variable_type_redeclarator bit_subrange_size_opt | 
|---|
| [4d51835] | 1527 | // A semantic check is required to ensure bit_subrange only appears on base type int. | 
|---|
|  | 1528 | { $$ = $1->addBitfield( $2 ); } | 
|---|
|  | 1529 | | variable_abstract_declarator                                          // CFA, no field name | 
|---|
|  | 1530 | ; | 
|---|
| [51b73452] | 1531 |  | 
|---|
|  | 1532 | bit_subrange_size_opt: | 
|---|
| [4d51835] | 1533 | // empty | 
|---|
|  | 1534 | { $$ = 0; } | 
|---|
|  | 1535 | | bit_subrange_size | 
|---|
|  | 1536 | { $$ = $1; } | 
|---|
|  | 1537 | ; | 
|---|
| [51b73452] | 1538 |  | 
|---|
|  | 1539 | bit_subrange_size: | 
|---|
| [4d51835] | 1540 | ':' constant_expression | 
|---|
|  | 1541 | { $$ = $2; } | 
|---|
|  | 1542 | ; | 
|---|
| [51b73452] | 1543 |  | 
|---|
|  | 1544 | enum_key: | 
|---|
| [4d51835] | 1545 | ENUM attribute_list_opt | 
|---|
|  | 1546 | ; | 
|---|
| [51b73452] | 1547 |  | 
|---|
|  | 1548 | enum_name: | 
|---|
| [4d51835] | 1549 | enum_key '{' enumerator_list comma_opt '}' | 
|---|
|  | 1550 | { $$ = DeclarationNode::newEnum( 0, $3 ); } | 
|---|
| [2871210] | 1551 | | enum_key no_attr_identifier_or_type_name | 
|---|
| [45161b4d] | 1552 | { | 
|---|
|  | 1553 | typedefTable.makeTypedef( *$2 ); | 
|---|
|  | 1554 | $$ = DeclarationNode::newEnum( $2, 0 ); | 
|---|
|  | 1555 | } | 
|---|
|  | 1556 | | enum_key no_attr_identifier_or_type_name | 
|---|
|  | 1557 | { typedefTable.makeTypedef( *$2 ); } | 
|---|
|  | 1558 | '{' enumerator_list comma_opt '}' | 
|---|
|  | 1559 | { $$ = DeclarationNode::newEnum( $2, $5 ); } | 
|---|
| [4d51835] | 1560 | ; | 
|---|
| [51b73452] | 1561 |  | 
|---|
|  | 1562 | enumerator_list: | 
|---|
| [2871210] | 1563 | no_attr_identifier_or_type_name enumerator_value_opt | 
|---|
| [4d51835] | 1564 | { $$ = DeclarationNode::newEnumConstant( $1, $2 ); } | 
|---|
| [2871210] | 1565 | | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt | 
|---|
| [4d51835] | 1566 | { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); } | 
|---|
|  | 1567 | ; | 
|---|
| [51b73452] | 1568 |  | 
|---|
|  | 1569 | enumerator_value_opt: | 
|---|
| [4d51835] | 1570 | // empty | 
|---|
|  | 1571 | { $$ = 0; } | 
|---|
|  | 1572 | | '=' constant_expression | 
|---|
|  | 1573 | { $$ = $2; } | 
|---|
|  | 1574 | ; | 
|---|
| [51b73452] | 1575 |  | 
|---|
| [c11e31c] | 1576 | // Minimum of one parameter after which ellipsis is allowed only at the end. | 
|---|
| [51b73452] | 1577 |  | 
|---|
| [b87a5ed] | 1578 | new_parameter_type_list_opt:                                                    // CFA | 
|---|
| [4d51835] | 1579 | // empty | 
|---|
|  | 1580 | { $$ = 0; } | 
|---|
|  | 1581 | | new_parameter_type_list | 
|---|
|  | 1582 | ; | 
|---|
| [b87a5ed] | 1583 |  | 
|---|
|  | 1584 | new_parameter_type_list:                                                                // CFA, abstract + real | 
|---|
| [4d51835] | 1585 | new_abstract_parameter_list | 
|---|
|  | 1586 | | new_parameter_list | 
|---|
|  | 1587 | | new_parameter_list pop ',' push new_abstract_parameter_list | 
|---|
|  | 1588 | { $$ = $1->appendList( $5 ); } | 
|---|
|  | 1589 | | new_abstract_parameter_list pop ',' push ELLIPSIS | 
|---|
|  | 1590 | { $$ = $1->addVarArgs(); } | 
|---|
|  | 1591 | | new_parameter_list pop ',' push ELLIPSIS | 
|---|
|  | 1592 | { $$ = $1->addVarArgs(); } | 
|---|
|  | 1593 | ; | 
|---|
| [b87a5ed] | 1594 |  | 
|---|
|  | 1595 | new_parameter_list:                                                                             // CFA | 
|---|
| [de62360d] | 1596 | // To obtain LR(1) between new_parameter_list and new_abstract_tuple, the last new_abstract_parameter_list is | 
|---|
|  | 1597 | // factored out from new_parameter_list, flattening the rules to get lookahead to the ']'. | 
|---|
| [4d51835] | 1598 | new_parameter_declaration | 
|---|
|  | 1599 | | new_abstract_parameter_list pop ',' push new_parameter_declaration | 
|---|
|  | 1600 | { $$ = $1->appendList( $5 ); } | 
|---|
|  | 1601 | | new_parameter_list pop ',' push new_parameter_declaration | 
|---|
|  | 1602 | { $$ = $1->appendList( $5 ); } | 
|---|
|  | 1603 | | new_parameter_list pop ',' push new_abstract_parameter_list pop ',' push new_parameter_declaration | 
|---|
|  | 1604 | { $$ = $1->appendList( $5 )->appendList( $9 ); } | 
|---|
|  | 1605 | ; | 
|---|
| [b87a5ed] | 1606 |  | 
|---|
|  | 1607 | new_abstract_parameter_list:                                                    // CFA, new & old style abstract | 
|---|
| [4d51835] | 1608 | new_abstract_parameter_declaration | 
|---|
|  | 1609 | | new_abstract_parameter_list pop ',' push new_abstract_parameter_declaration | 
|---|
|  | 1610 | { $$ = $1->appendList( $5 ); } | 
|---|
|  | 1611 | ; | 
|---|
| [51b73452] | 1612 |  | 
|---|
|  | 1613 | parameter_type_list_opt: | 
|---|
| [4d51835] | 1614 | // empty | 
|---|
|  | 1615 | { $$ = 0; } | 
|---|
|  | 1616 | | parameter_type_list | 
|---|
|  | 1617 | ; | 
|---|
| [51b73452] | 1618 |  | 
|---|
|  | 1619 | parameter_type_list: | 
|---|
| [4d51835] | 1620 | parameter_list | 
|---|
|  | 1621 | | parameter_list pop ',' push ELLIPSIS | 
|---|
|  | 1622 | { $$ = $1->addVarArgs(); } | 
|---|
|  | 1623 | ; | 
|---|
| [b87a5ed] | 1624 |  | 
|---|
|  | 1625 | parameter_list:                                                                                 // abstract + real | 
|---|
| [4d51835] | 1626 | abstract_parameter_declaration | 
|---|
|  | 1627 | | parameter_declaration | 
|---|
|  | 1628 | | parameter_list pop ',' push abstract_parameter_declaration | 
|---|
|  | 1629 | { $$ = $1->appendList( $5 ); } | 
|---|
|  | 1630 | | parameter_list pop ',' push parameter_declaration | 
|---|
|  | 1631 | { $$ = $1->appendList( $5 ); } | 
|---|
|  | 1632 | ; | 
|---|
| [51b73452] | 1633 |  | 
|---|
| [de62360d] | 1634 | // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics | 
|---|
| [2871210] | 1635 | // for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes. | 
|---|
| [51b73452] | 1636 |  | 
|---|
| [b87a5ed] | 1637 | new_parameter_declaration:                                                              // CFA, new & old style parameter declaration | 
|---|
| [4d51835] | 1638 | parameter_declaration | 
|---|
| [2871210] | 1639 | | new_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt | 
|---|
| [4d51835] | 1640 | { $$ = $1->addName( $2 ); } | 
|---|
| [2871210] | 1641 | | new_abstract_tuple identifier_or_type_name assignment_opt | 
|---|
| [4d51835] | 1642 | // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator). | 
|---|
|  | 1643 | { $$ = $1->addName( $2 ); } | 
|---|
| [2871210] | 1644 | | type_qualifier_list new_abstract_tuple identifier_or_type_name assignment_opt | 
|---|
| [4d51835] | 1645 | { $$ = $2->addName( $3 )->addQualifiers( $1 ); } | 
|---|
|  | 1646 | | new_function_specifier | 
|---|
|  | 1647 | ; | 
|---|
| [b87a5ed] | 1648 |  | 
|---|
|  | 1649 | new_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration | 
|---|
| [4d51835] | 1650 | abstract_parameter_declaration | 
|---|
|  | 1651 | | new_identifier_parameter_declarator_no_tuple | 
|---|
|  | 1652 | | new_abstract_tuple | 
|---|
|  | 1653 | // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator). | 
|---|
|  | 1654 | | type_qualifier_list new_abstract_tuple | 
|---|
|  | 1655 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1656 | | new_abstract_function | 
|---|
|  | 1657 | ; | 
|---|
| [51b73452] | 1658 |  | 
|---|
|  | 1659 | parameter_declaration: | 
|---|
| [4d51835] | 1660 | declaration_specifier identifier_parameter_declarator assignment_opt | 
|---|
|  | 1661 | { | 
|---|
|  | 1662 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
| [de62360d] | 1663 | $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) ); | 
|---|
| [4d51835] | 1664 | } | 
|---|
| [2871210] | 1665 | | declaration_specifier type_parameter_redeclarator assignment_opt | 
|---|
| [4d51835] | 1666 | { | 
|---|
|  | 1667 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
| [de62360d] | 1668 | $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) ); | 
|---|
| [4d51835] | 1669 | } | 
|---|
|  | 1670 | ; | 
|---|
| [51b73452] | 1671 |  | 
|---|
|  | 1672 | abstract_parameter_declaration: | 
|---|
| [4d51835] | 1673 | declaration_specifier | 
|---|
|  | 1674 | | declaration_specifier abstract_parameter_declarator | 
|---|
|  | 1675 | { $$ = $2->addType( $1 ); } | 
|---|
|  | 1676 | ; | 
|---|
| [51b73452] | 1677 |  | 
|---|
| [c11e31c] | 1678 | // ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a | 
|---|
| [de62360d] | 1679 | // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on | 
|---|
|  | 1680 | // identifiers.  The ANSI-style parameter-list can redefine a typedef name. | 
|---|
| [51b73452] | 1681 |  | 
|---|
| [b87a5ed] | 1682 | identifier_list:                                                                                // K&R-style parameter list => no types | 
|---|
| [4d51835] | 1683 | no_attr_identifier | 
|---|
|  | 1684 | { $$ = DeclarationNode::newName( $1 ); } | 
|---|
|  | 1685 | | identifier_list ',' no_attr_identifier | 
|---|
|  | 1686 | { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); } | 
|---|
|  | 1687 | ; | 
|---|
| [51b73452] | 1688 |  | 
|---|
| [2871210] | 1689 | identifier_or_type_name: | 
|---|
| [4d51835] | 1690 | identifier | 
|---|
|  | 1691 | | TYPEDEFname | 
|---|
|  | 1692 | | TYPEGENname | 
|---|
|  | 1693 | ; | 
|---|
| [51b73452] | 1694 |  | 
|---|
| [2871210] | 1695 | no_01_identifier_or_type_name: | 
|---|
| [4d51835] | 1696 | no_01_identifier | 
|---|
|  | 1697 | | TYPEDEFname | 
|---|
|  | 1698 | | TYPEGENname | 
|---|
|  | 1699 | ; | 
|---|
| [51b73452] | 1700 |  | 
|---|
| [2871210] | 1701 | no_attr_identifier_or_type_name: | 
|---|
| [4d51835] | 1702 | no_attr_identifier | 
|---|
|  | 1703 | | TYPEDEFname | 
|---|
| [721f17a] | 1704 | | TYPEGENname | 
|---|
| [4d51835] | 1705 | ; | 
|---|
| [b87a5ed] | 1706 |  | 
|---|
|  | 1707 | type_name_no_function:                                                                  // sizeof, alignof, cast (constructor) | 
|---|
| [4d51835] | 1708 | new_abstract_declarator_tuple                                           // CFA | 
|---|
|  | 1709 | | type_specifier | 
|---|
|  | 1710 | | type_specifier variable_abstract_declarator | 
|---|
|  | 1711 | { $$ = $2->addType( $1 ); } | 
|---|
|  | 1712 | ; | 
|---|
| [b87a5ed] | 1713 |  | 
|---|
|  | 1714 | type_name:                                                                                              // typeof, assertion | 
|---|
| [4d51835] | 1715 | new_abstract_declarator_tuple                                           // CFA | 
|---|
|  | 1716 | | new_abstract_function                                                         // CFA | 
|---|
|  | 1717 | | type_specifier | 
|---|
|  | 1718 | | type_specifier abstract_declarator | 
|---|
|  | 1719 | { $$ = $2->addType( $1 ); } | 
|---|
|  | 1720 | ; | 
|---|
| [51b73452] | 1721 |  | 
|---|
|  | 1722 | initializer_opt: | 
|---|
| [4d51835] | 1723 | // empty | 
|---|
|  | 1724 | { $$ = 0; } | 
|---|
| [2871210] | 1725 | | '=' initializer | 
|---|
|  | 1726 | { $$ = $2; } | 
|---|
| [097e2b0] | 1727 | | ATassign initializer | 
|---|
| [974906e2] | 1728 | { $$ = $2->set_maybeConstructed( false ); } | 
|---|
| [4d51835] | 1729 | ; | 
|---|
| [51b73452] | 1730 |  | 
|---|
|  | 1731 | initializer: | 
|---|
| [de62360d] | 1732 | assignment_expression                                           { $$ = new InitializerNode( $1 ); } | 
|---|
|  | 1733 | | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); } | 
|---|
| [4d51835] | 1734 | ; | 
|---|
| [51b73452] | 1735 |  | 
|---|
|  | 1736 | initializer_list: | 
|---|
| [097e2b0] | 1737 | // empty | 
|---|
|  | 1738 | { $$ = 0; } | 
|---|
|  | 1739 | | initializer | 
|---|
| [4d51835] | 1740 | | designation initializer                                       { $$ = $2->set_designators( $1 ); } | 
|---|
| [1d4580a] | 1741 | | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } | 
|---|
| [4d51835] | 1742 | | initializer_list ',' designation initializer | 
|---|
| [1d4580a] | 1743 | { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } | 
|---|
| [4d51835] | 1744 | ; | 
|---|
| [b87a5ed] | 1745 |  | 
|---|
| [de62360d] | 1746 | // There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is use of | 
|---|
|  | 1747 | // '=' to separator the designator from the initializer value, as in: | 
|---|
| [c11e31c] | 1748 | // | 
|---|
| [b87a5ed] | 1749 | //              int x[10] = { [1] = 3 }; | 
|---|
| [c11e31c] | 1750 | // | 
|---|
| [de62360d] | 1751 | // The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment.  To disambiguate this case, CFA | 
|---|
|  | 1752 | // changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for | 
|---|
|  | 1753 | // field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to | 
|---|
|  | 1754 | // shift/reduce conflicts | 
|---|
| [51b73452] | 1755 |  | 
|---|
|  | 1756 | designation: | 
|---|
| [4d51835] | 1757 | designator_list ':'                                                                     // C99, CFA uses ":" instead of "=" | 
|---|
| [2871210] | 1758 | | no_attr_identifier_or_type_name ':'                           // GCC, field name | 
|---|
| [d1625f8] | 1759 | { $$ = new ExpressionNode( build_varref( $1 ) ); } | 
|---|
| [4d51835] | 1760 | ; | 
|---|
| [51b73452] | 1761 |  | 
|---|
| [b87a5ed] | 1762 | designator_list:                                                                                // C99 | 
|---|
| [4d51835] | 1763 | designator | 
|---|
| [2871210] | 1764 | | designator_list designator | 
|---|
| [1d4580a] | 1765 | { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); } | 
|---|
| [d1625f8] | 1766 | //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); } | 
|---|
| [4d51835] | 1767 | ; | 
|---|
| [51b73452] | 1768 |  | 
|---|
|  | 1769 | designator: | 
|---|
| [d1625f8] | 1770 | '.' no_attr_identifier_or_type_name                                     // C99, field name | 
|---|
|  | 1771 | { $$ = new ExpressionNode( build_varref( $2 ) ); } | 
|---|
| [4d51835] | 1772 | | '[' push assignment_expression pop ']'                        // C99, single array element | 
|---|
| [de62360d] | 1773 | // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. | 
|---|
| [d1625f8] | 1774 | { $$ = $3; } | 
|---|
| [4d51835] | 1775 | | '[' push subrange pop ']'                                                     // CFA, multiple array elements | 
|---|
| [d1625f8] | 1776 | { $$ = $3; } | 
|---|
| [4d51835] | 1777 | | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements | 
|---|
| [d1625f8] | 1778 | { $$ = new ExpressionNode( build_range( $3, $5 ) ); } | 
|---|
| [4d51835] | 1779 | | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector | 
|---|
| [d1625f8] | 1780 | { $$ = $4; } | 
|---|
| [4d51835] | 1781 | ; | 
|---|
| [51b73452] | 1782 |  | 
|---|
| [de62360d] | 1783 | // The CFA type system is based on parametric polymorphism, the ability to declare functions with type parameters, | 
|---|
|  | 1784 | // rather than an object-oriented type system. This required four groups of extensions: | 
|---|
| [c11e31c] | 1785 | // | 
|---|
|  | 1786 | // Overloading: function, data, and operator identifiers may be overloaded. | 
|---|
|  | 1787 | // | 
|---|
| [de62360d] | 1788 | // Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object | 
|---|
|  | 1789 | //     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide | 
|---|
|  | 1790 | //     definitions of new types. Type declarations with storage class "extern" provide opaque types. | 
|---|
| [c11e31c] | 1791 | // | 
|---|
| [de62360d] | 1792 | // Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at the call | 
|---|
|  | 1793 | //     site. A polymorphic function is not a template; it is a function, with an address and a type. | 
|---|
| [c11e31c] | 1794 | // | 
|---|
|  | 1795 | // Specifications and Assertions: Specifications are collections of declarations parameterized by one or more | 
|---|
| [de62360d] | 1796 | //     types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass | 
|---|
|  | 1797 | //     hierarchies. Unlike classes, they can define relationships between types.  Assertions declare that a type or | 
|---|
|  | 1798 | //     types provide the operations declared by a specification.  Assertions are normally used to declare requirements | 
|---|
|  | 1799 | //     on type arguments of polymorphic functions. | 
|---|
| [c11e31c] | 1800 |  | 
|---|
| [b87a5ed] | 1801 | typegen_declaration_specifier:                                                  // CFA | 
|---|
| [4d51835] | 1802 | typegen_type_specifier | 
|---|
|  | 1803 | | declaration_qualifier_list typegen_type_specifier | 
|---|
|  | 1804 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 1805 | | typegen_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2) | 
|---|
|  | 1806 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1807 | | typegen_declaration_specifier storage_class type_qualifier_list | 
|---|
|  | 1808 | { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } | 
|---|
|  | 1809 | ; | 
|---|
| [b87a5ed] | 1810 |  | 
|---|
|  | 1811 | typegen_type_specifier:                                                                 // CFA | 
|---|
| [2871210] | 1812 | typegen_name | 
|---|
|  | 1813 | | type_qualifier_list typegen_name | 
|---|
|  | 1814 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
| [4d51835] | 1815 | | typegen_type_specifier type_qualifier | 
|---|
|  | 1816 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
|  | 1817 | ; | 
|---|
| [b87a5ed] | 1818 |  | 
|---|
| [2871210] | 1819 | typegen_name:                                                                                   // CFA | 
|---|
|  | 1820 | TYPEGENname '(' type_name_list ')' | 
|---|
|  | 1821 | { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); } | 
|---|
|  | 1822 | ; | 
|---|
|  | 1823 |  | 
|---|
| [b87a5ed] | 1824 | type_parameter_list:                                                                    // CFA | 
|---|
| [4d51835] | 1825 | type_parameter assignment_opt | 
|---|
|  | 1826 | | type_parameter_list ',' type_parameter assignment_opt | 
|---|
|  | 1827 | { $$ = $1->appendList( $3 ); } | 
|---|
|  | 1828 | ; | 
|---|
| [b87a5ed] | 1829 |  | 
|---|
|  | 1830 | type_parameter:                                                                                 // CFA | 
|---|
| [2871210] | 1831 | type_class no_attr_identifier_or_type_name | 
|---|
|  | 1832 | { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); } | 
|---|
| [4d51835] | 1833 | assertion_list_opt | 
|---|
|  | 1834 | { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); } | 
|---|
|  | 1835 | | type_specifier identifier_parameter_declarator | 
|---|
|  | 1836 | ; | 
|---|
| [b87a5ed] | 1837 |  | 
|---|
|  | 1838 | type_class:                                                                                             // CFA | 
|---|
| [4040425] | 1839 | OTYPE | 
|---|
| [4d51835] | 1840 | { $$ = DeclarationNode::Type; } | 
|---|
|  | 1841 | | DTYPE | 
|---|
|  | 1842 | { $$ = DeclarationNode::Ftype; } | 
|---|
|  | 1843 | | FTYPE | 
|---|
|  | 1844 | { $$ = DeclarationNode::Dtype; } | 
|---|
|  | 1845 | ; | 
|---|
| [b87a5ed] | 1846 |  | 
|---|
|  | 1847 | assertion_list_opt:                                                                             // CFA | 
|---|
| [4d51835] | 1848 | // empty | 
|---|
|  | 1849 | { $$ = 0; } | 
|---|
|  | 1850 | | assertion_list_opt assertion | 
|---|
| [4e06c1e] | 1851 | { $$ = $1 != 0 ? $1->appendList( $2 ) : $2; } | 
|---|
| [4d51835] | 1852 | ; | 
|---|
| [b87a5ed] | 1853 |  | 
|---|
|  | 1854 | assertion:                                                                                              // CFA | 
|---|
| [2871210] | 1855 | '|' no_attr_identifier_or_type_name '(' type_name_list ')' | 
|---|
| [4d51835] | 1856 | { | 
|---|
| [4040425] | 1857 | typedefTable.openTrait( *$2 ); | 
|---|
|  | 1858 | $$ = DeclarationNode::newTraitUse( $2, $4 ); | 
|---|
| [4d51835] | 1859 | } | 
|---|
| [4040425] | 1860 | | '|' '{' push trait_declaration_list '}' | 
|---|
| [4d51835] | 1861 | { $$ = $4; } | 
|---|
| [4040425] | 1862 | | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_name_list ')' | 
|---|
| [4d51835] | 1863 | { $$ = 0; } | 
|---|
|  | 1864 | ; | 
|---|
| [b87a5ed] | 1865 |  | 
|---|
|  | 1866 | type_name_list:                                                                                 // CFA | 
|---|
| [4d51835] | 1867 | type_name | 
|---|
| [d1625f8] | 1868 | { $$ = new ExpressionNode( build_typevalue( $1 ) ); } | 
|---|
| [4d51835] | 1869 | | assignment_expression | 
|---|
|  | 1870 | | type_name_list ',' type_name | 
|---|
| [1d4580a] | 1871 | { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); } | 
|---|
| [4d51835] | 1872 | | type_name_list ',' assignment_expression | 
|---|
| [1d4580a] | 1873 | { $$ = (ExpressionNode *)( $1->set_last( $3 )); } | 
|---|
| [4d51835] | 1874 | ; | 
|---|
| [b87a5ed] | 1875 |  | 
|---|
|  | 1876 | type_declaring_list:                                                                    // CFA | 
|---|
| [4040425] | 1877 | OTYPE type_declarator | 
|---|
| [4d51835] | 1878 | { $$ = $2; } | 
|---|
| [4040425] | 1879 | | storage_class_list OTYPE type_declarator | 
|---|
| [4d51835] | 1880 | { $$ = $3->addQualifiers( $1 ); } | 
|---|
|  | 1881 | | type_declaring_list ',' type_declarator | 
|---|
|  | 1882 | { $$ = $1->appendList( $3->copyStorageClasses( $1 ) ); } | 
|---|
|  | 1883 | ; | 
|---|
| [b87a5ed] | 1884 |  | 
|---|
|  | 1885 | type_declarator:                                                                                // CFA | 
|---|
| [4d51835] | 1886 | type_declarator_name assertion_list_opt | 
|---|
|  | 1887 | { $$ = $1->addAssertions( $2 ); } | 
|---|
|  | 1888 | | type_declarator_name assertion_list_opt '=' type_name | 
|---|
|  | 1889 | { $$ = $1->addAssertions( $2 )->addType( $4 ); } | 
|---|
|  | 1890 | ; | 
|---|
| [b87a5ed] | 1891 |  | 
|---|
|  | 1892 | type_declarator_name:                                                                   // CFA | 
|---|
| [2871210] | 1893 | no_attr_identifier_or_type_name | 
|---|
| [4d51835] | 1894 | { | 
|---|
| [de62360d] | 1895 | typedefTable.addToEnclosingScope( *$1, TypedefTable::TD ); | 
|---|
| [4d51835] | 1896 | $$ = DeclarationNode::newTypeDecl( $1, 0 ); | 
|---|
|  | 1897 | } | 
|---|
| [2871210] | 1898 | | no_01_identifier_or_type_name '(' push type_parameter_list pop ')' | 
|---|
| [4d51835] | 1899 | { | 
|---|
| [de62360d] | 1900 | typedefTable.addToEnclosingScope( *$1, TypedefTable::TG ); | 
|---|
| [4d51835] | 1901 | $$ = DeclarationNode::newTypeDecl( $1, $4 ); | 
|---|
|  | 1902 | } | 
|---|
|  | 1903 | ; | 
|---|
| [b87a5ed] | 1904 |  | 
|---|
| [4040425] | 1905 | trait_specifier:                                                                                // CFA | 
|---|
|  | 1906 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}' | 
|---|
| [4d51835] | 1907 | { | 
|---|
| [de62360d] | 1908 | typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); | 
|---|
| [4040425] | 1909 | $$ = DeclarationNode::newTrait( $2, $5, 0 ); | 
|---|
| [4d51835] | 1910 | } | 
|---|
| [4040425] | 1911 | | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' | 
|---|
| [4d51835] | 1912 | { | 
|---|
| [4040425] | 1913 | typedefTable.enterTrait( *$2 ); | 
|---|
| [4d51835] | 1914 | typedefTable.enterScope(); | 
|---|
|  | 1915 | } | 
|---|
| [4040425] | 1916 | trait_declaration_list '}' | 
|---|
| [4d51835] | 1917 | { | 
|---|
| [4040425] | 1918 | typedefTable.leaveTrait(); | 
|---|
| [de62360d] | 1919 | typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); | 
|---|
| [4040425] | 1920 | $$ = DeclarationNode::newTrait( $2, $5, $10 ); | 
|---|
| [4d51835] | 1921 | } | 
|---|
|  | 1922 | ; | 
|---|
| [b87a5ed] | 1923 |  | 
|---|
| [4040425] | 1924 | trait_declaration_list:                                                         // CFA | 
|---|
|  | 1925 | trait_declaration | 
|---|
|  | 1926 | | trait_declaration_list push trait_declaration | 
|---|
| [4d51835] | 1927 | { $$ = $1->appendList( $3 ); } | 
|---|
|  | 1928 | ; | 
|---|
| [b87a5ed] | 1929 |  | 
|---|
| [4040425] | 1930 | trait_declaration:                                                                      // CFA | 
|---|
|  | 1931 | new_trait_declaring_list pop ';' | 
|---|
|  | 1932 | | trait_declaring_list pop ';' | 
|---|
| [4d51835] | 1933 | ; | 
|---|
| [b87a5ed] | 1934 |  | 
|---|
| [4040425] | 1935 | new_trait_declaring_list:                                                               // CFA | 
|---|
| [4d51835] | 1936 | new_variable_specifier | 
|---|
|  | 1937 | { | 
|---|
|  | 1938 | typedefTable.addToEnclosingScope2( TypedefTable::ID ); | 
|---|
|  | 1939 | $$ = $1; | 
|---|
|  | 1940 | } | 
|---|
|  | 1941 | | new_function_specifier | 
|---|
|  | 1942 | { | 
|---|
|  | 1943 | typedefTable.addToEnclosingScope2( TypedefTable::ID ); | 
|---|
|  | 1944 | $$ = $1; | 
|---|
|  | 1945 | } | 
|---|
| [4040425] | 1946 | | new_trait_declaring_list pop ',' push identifier_or_type_name | 
|---|
| [4d51835] | 1947 | { | 
|---|
| [de62360d] | 1948 | typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); | 
|---|
| [4d51835] | 1949 | $$ = $1->appendList( $1->cloneType( $5 ) ); | 
|---|
|  | 1950 | } | 
|---|
|  | 1951 | ; | 
|---|
| [b87a5ed] | 1952 |  | 
|---|
| [4040425] | 1953 | trait_declaring_list:                                                                   // CFA | 
|---|
| [4d51835] | 1954 | type_specifier declarator | 
|---|
|  | 1955 | { | 
|---|
|  | 1956 | typedefTable.addToEnclosingScope2( TypedefTable::ID ); | 
|---|
|  | 1957 | $$ = $2->addType( $1 ); | 
|---|
|  | 1958 | } | 
|---|
| [4040425] | 1959 | | trait_declaring_list pop ',' push declarator | 
|---|
| [4d51835] | 1960 | { | 
|---|
|  | 1961 | typedefTable.addToEnclosingScope2( TypedefTable::ID ); | 
|---|
|  | 1962 | $$ = $1->appendList( $1->cloneBaseType( $5 ) ); | 
|---|
|  | 1963 | } | 
|---|
|  | 1964 | ; | 
|---|
| [51b73452] | 1965 |  | 
|---|
| [c11e31c] | 1966 | //***************************** EXTERNAL DEFINITIONS ***************************** | 
|---|
| [51b73452] | 1967 |  | 
|---|
|  | 1968 | translation_unit: | 
|---|
| [4d51835] | 1969 | // empty | 
|---|
|  | 1970 | {}                                                                                              // empty input file | 
|---|
|  | 1971 | | external_definition_list | 
|---|
| [926af74] | 1972 | { parseTree = parseTree != nullptr ? parseTree->appendList( $1 ) : $1;  } | 
|---|
| [4d51835] | 1973 | ; | 
|---|
| [51b73452] | 1974 |  | 
|---|
|  | 1975 | external_definition_list: | 
|---|
| [4d51835] | 1976 | external_definition | 
|---|
|  | 1977 | | external_definition_list push external_definition | 
|---|
| [926af74] | 1978 | { $$ = $1 != nullptr ? $1->appendList( $3 ) : $3; } | 
|---|
| [4d51835] | 1979 | ; | 
|---|
| [51b73452] | 1980 |  | 
|---|
|  | 1981 | external_definition_list_opt: | 
|---|
| [4d51835] | 1982 | // empty | 
|---|
|  | 1983 | { $$ = 0; } | 
|---|
|  | 1984 | | external_definition_list | 
|---|
|  | 1985 | ; | 
|---|
| [51b73452] | 1986 |  | 
|---|
|  | 1987 | external_definition: | 
|---|
| [4d51835] | 1988 | declaration | 
|---|
|  | 1989 | | external_function_definition | 
|---|
|  | 1990 | | asm_statement                                                                         // GCC, global assembler statement | 
|---|
|  | 1991 | {} | 
|---|
|  | 1992 | | EXTERN STRINGliteral | 
|---|
|  | 1993 | { | 
|---|
| [3b8e52c] | 1994 | linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall" | 
|---|
| [ac71a86] | 1995 | linkage = LinkageSpec::fromString( assign_strptr($2) ); | 
|---|
| [4d51835] | 1996 | } | 
|---|
|  | 1997 | '{' external_definition_list_opt '}'                          // C++-style linkage specifier | 
|---|
|  | 1998 | { | 
|---|
|  | 1999 | linkage = linkageStack.top(); | 
|---|
|  | 2000 | linkageStack.pop(); | 
|---|
|  | 2001 | $$ = $5; | 
|---|
|  | 2002 | } | 
|---|
|  | 2003 | | EXTENSION external_definition | 
|---|
| [8e9cbb2] | 2004 | {       // mark all fields in list | 
|---|
| [926af74] | 2005 | for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) | 
|---|
| [8e9cbb2] | 2006 | iter->set_extension( true ); | 
|---|
|  | 2007 | $$ = $2; | 
|---|
|  | 2008 | } | 
|---|
| [4d51835] | 2009 | ; | 
|---|
|  | 2010 |  | 
|---|
|  | 2011 | external_function_definition: | 
|---|
|  | 2012 | function_definition | 
|---|
| [de62360d] | 2013 | // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of | 
|---|
| [c6b1105] | 2014 | // legacy code with global functions missing the type-specifier for the return type, and assuming "int". | 
|---|
|  | 2015 | // Parsing is possible because function_definition does not appear in the context of an expression (nested | 
|---|
|  | 2016 | // functions preclude this concession, i.e., all nested function must have a return type). A function prototype | 
|---|
|  | 2017 | // declaration must still have a type_specifier.  OBSOLESCENT (see 1) | 
|---|
| [4d51835] | 2018 | | function_declarator compound_statement | 
|---|
|  | 2019 | { | 
|---|
|  | 2020 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2021 | typedefTable.leaveScope(); | 
|---|
|  | 2022 | $$ = $1->addFunctionBody( $2 ); | 
|---|
|  | 2023 | } | 
|---|
|  | 2024 | | old_function_declarator push old_declaration_list_opt compound_statement | 
|---|
|  | 2025 | { | 
|---|
|  | 2026 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2027 | typedefTable.leaveScope(); | 
|---|
|  | 2028 | $$ = $1->addOldDeclList( $3 )->addFunctionBody( $4 ); | 
|---|
|  | 2029 | } | 
|---|
|  | 2030 | ; | 
|---|
| [51b73452] | 2031 |  | 
|---|
|  | 2032 | function_definition: | 
|---|
| [4d51835] | 2033 | new_function_declaration compound_statement                     // CFA | 
|---|
|  | 2034 | { | 
|---|
|  | 2035 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2036 | typedefTable.leaveScope(); | 
|---|
|  | 2037 | $$ = $1->addFunctionBody( $2 ); | 
|---|
|  | 2038 | } | 
|---|
|  | 2039 | | declaration_specifier function_declarator compound_statement | 
|---|
|  | 2040 | { | 
|---|
|  | 2041 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2042 | typedefTable.leaveScope(); | 
|---|
|  | 2043 | $$ = $2->addFunctionBody( $3 )->addType( $1 ); | 
|---|
|  | 2044 | } | 
|---|
|  | 2045 | | type_qualifier_list function_declarator compound_statement | 
|---|
|  | 2046 | { | 
|---|
|  | 2047 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2048 | typedefTable.leaveScope(); | 
|---|
|  | 2049 | $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 ); | 
|---|
|  | 2050 | } | 
|---|
|  | 2051 | | declaration_qualifier_list function_declarator compound_statement | 
|---|
|  | 2052 | { | 
|---|
|  | 2053 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2054 | typedefTable.leaveScope(); | 
|---|
|  | 2055 | $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 ); | 
|---|
|  | 2056 | } | 
|---|
|  | 2057 | | declaration_qualifier_list type_qualifier_list function_declarator compound_statement | 
|---|
|  | 2058 | { | 
|---|
|  | 2059 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2060 | typedefTable.leaveScope(); | 
|---|
|  | 2061 | $$ = $3->addFunctionBody( $4 )->addQualifiers( $2 )->addQualifiers( $1 ); | 
|---|
|  | 2062 | } | 
|---|
|  | 2063 |  | 
|---|
|  | 2064 | // Old-style K&R function definition, OBSOLESCENT (see 4) | 
|---|
|  | 2065 | | declaration_specifier old_function_declarator push old_declaration_list_opt compound_statement | 
|---|
|  | 2066 | { | 
|---|
|  | 2067 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2068 | typedefTable.leaveScope(); | 
|---|
|  | 2069 | $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 ); | 
|---|
|  | 2070 | } | 
|---|
|  | 2071 | | type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement | 
|---|
|  | 2072 | { | 
|---|
|  | 2073 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2074 | typedefTable.leaveScope(); | 
|---|
|  | 2075 | $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 ); | 
|---|
|  | 2076 | } | 
|---|
|  | 2077 |  | 
|---|
|  | 2078 | // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4) | 
|---|
|  | 2079 | | declaration_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement | 
|---|
|  | 2080 | { | 
|---|
|  | 2081 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2082 | typedefTable.leaveScope(); | 
|---|
|  | 2083 | $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 ); | 
|---|
|  | 2084 | } | 
|---|
|  | 2085 | | declaration_qualifier_list type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement | 
|---|
|  | 2086 | { | 
|---|
|  | 2087 | typedefTable.addToEnclosingScope( TypedefTable::ID ); | 
|---|
|  | 2088 | typedefTable.leaveScope(); | 
|---|
|  | 2089 | $$ = $3->addOldDeclList( $5 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 ); | 
|---|
|  | 2090 | } | 
|---|
|  | 2091 | ; | 
|---|
| [51b73452] | 2092 |  | 
|---|
|  | 2093 | declarator: | 
|---|
| [4d51835] | 2094 | variable_declarator | 
|---|
| [c6b1105] | 2095 | | variable_type_redeclarator | 
|---|
| [4d51835] | 2096 | | function_declarator | 
|---|
|  | 2097 | ; | 
|---|
| [51b73452] | 2098 |  | 
|---|
|  | 2099 | subrange: | 
|---|
| [4d51835] | 2100 | constant_expression '~' constant_expression                     // CFA, integer subrange | 
|---|
| [d1625f8] | 2101 | { $$ = new ExpressionNode( build_range( $1, $3 ) ); } | 
|---|
| [4d51835] | 2102 | ; | 
|---|
| [b87a5ed] | 2103 |  | 
|---|
|  | 2104 | asm_name_opt:                                                                                   // GCC | 
|---|
| [4d51835] | 2105 | // empty | 
|---|
|  | 2106 | | ASM '(' string_literal_list ')' attribute_list_opt | 
|---|
|  | 2107 | ; | 
|---|
| [b87a5ed] | 2108 |  | 
|---|
|  | 2109 | attribute_list_opt:                                                                             // GCC | 
|---|
| [4d51835] | 2110 | // empty | 
|---|
| [1db21619] | 2111 | { $$ = 0; } | 
|---|
| [4d51835] | 2112 | | attribute_list | 
|---|
|  | 2113 | ; | 
|---|
| [b87a5ed] | 2114 |  | 
|---|
|  | 2115 | attribute_list:                                                                                 // GCC | 
|---|
| [4d51835] | 2116 | attribute | 
|---|
|  | 2117 | | attribute_list attribute | 
|---|
| [1db21619] | 2118 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
| [4d51835] | 2119 | ; | 
|---|
| [b87a5ed] | 2120 |  | 
|---|
|  | 2121 | attribute:                                                                                              // GCC | 
|---|
| [4d51835] | 2122 | ATTRIBUTE '(' '(' attribute_parameter_list ')' ')' | 
|---|
| [1db21619] | 2123 | //              { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); } | 
|---|
|  | 2124 | { $$ = 0; } | 
|---|
| [4d51835] | 2125 | ; | 
|---|
| [b87a5ed] | 2126 |  | 
|---|
|  | 2127 | attribute_parameter_list:                                                               // GCC | 
|---|
| [4d51835] | 2128 | attrib | 
|---|
|  | 2129 | | attribute_parameter_list ',' attrib | 
|---|
|  | 2130 | ; | 
|---|
| [b87a5ed] | 2131 |  | 
|---|
|  | 2132 | attrib:                                                                                                 // GCC | 
|---|
| [4d51835] | 2133 | // empty | 
|---|
|  | 2134 | | any_word | 
|---|
|  | 2135 | | any_word '(' comma_expression_opt ')' | 
|---|
|  | 2136 | ; | 
|---|
| [b87a5ed] | 2137 |  | 
|---|
|  | 2138 | any_word:                                                                                               // GCC | 
|---|
| [2037f82] | 2139 | identifier_or_type_name { delete $1; } | 
|---|
|  | 2140 | | storage_class { delete $1; } | 
|---|
|  | 2141 | | basic_type_name { delete $1; } | 
|---|
|  | 2142 | | type_qualifier { delete $1; } | 
|---|
| [4d51835] | 2143 | ; | 
|---|
| [51b73452] | 2144 |  | 
|---|
| [c11e31c] | 2145 | // ============================================================================ | 
|---|
| [de62360d] | 2146 | // The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary | 
|---|
|  | 2147 | // because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as | 
|---|
|  | 2148 | // in: | 
|---|
| [c11e31c] | 2149 | // | 
|---|
| [b87a5ed] | 2150 | //              int (*f())[10] { ... }; | 
|---|
|  | 2151 | //              ... (*f())[3] += 1;             // definition mimics usage | 
|---|
| [c11e31c] | 2152 | // | 
|---|
| [de62360d] | 2153 | // Because these patterns are highly recursive, changes at a lower level in the recursion require copying some or all of | 
|---|
|  | 2154 | // the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a particular context. | 
|---|
| [c11e31c] | 2155 | // ============================================================================ | 
|---|
|  | 2156 |  | 
|---|
|  | 2157 | // ---------------------------------------------------------------------------- | 
|---|
| [de62360d] | 2158 | // The set of valid declarators before a compound statement for defining a function is less than the set of declarators | 
|---|
|  | 2159 | // to define a variable or function prototype, e.g.: | 
|---|
| [c11e31c] | 2160 | // | 
|---|
| [b87a5ed] | 2161 | //              valid declaration               invalid definition | 
|---|
|  | 2162 | //              -----------------               ------------------ | 
|---|
| [4d51835] | 2163 | //              int f;                                  int f {} | 
|---|
|  | 2164 | //              int *f;                                 int *f {} | 
|---|
| [b87a5ed] | 2165 | //              int f[10];                              int f[10] {} | 
|---|
| [4d51835] | 2166 | //              int (*f)(int);                  int (*f)(int) {} | 
|---|
| [c11e31c] | 2167 | // | 
|---|
| [de62360d] | 2168 | // To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence | 
|---|
|  | 2169 | // variable_declarator and function_declarator. | 
|---|
| [c11e31c] | 2170 | // ---------------------------------------------------------------------------- | 
|---|
|  | 2171 |  | 
|---|
| [de62360d] | 2172 | // This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes | 
|---|
|  | 2173 | // declaring an array of functions versus a pointer to an array of functions. | 
|---|
| [51b73452] | 2174 |  | 
|---|
|  | 2175 | variable_declarator: | 
|---|
| [4d51835] | 2176 | paren_identifier attribute_list_opt | 
|---|
| [1db21619] | 2177 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2178 | | variable_ptr | 
|---|
|  | 2179 | | variable_array attribute_list_opt | 
|---|
| [1db21619] | 2180 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2181 | | variable_function attribute_list_opt | 
|---|
| [1db21619] | 2182 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2183 | ; | 
|---|
| [51b73452] | 2184 |  | 
|---|
|  | 2185 | paren_identifier: | 
|---|
| [4d51835] | 2186 | identifier | 
|---|
|  | 2187 | { | 
|---|
| [de62360d] | 2188 | typedefTable.setNextIdentifier( *$1 ); | 
|---|
| [4d51835] | 2189 | $$ = DeclarationNode::newName( $1 ); | 
|---|
|  | 2190 | } | 
|---|
|  | 2191 | | '(' paren_identifier ')'                                                      // redundant parenthesis | 
|---|
|  | 2192 | { $$ = $2; } | 
|---|
|  | 2193 | ; | 
|---|
| [51b73452] | 2194 |  | 
|---|
|  | 2195 | variable_ptr: | 
|---|
| [dd51906] | 2196 | ptrref_operator variable_declarator | 
|---|
| [4d51835] | 2197 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2198 | | ptrref_operator type_qualifier_list variable_declarator | 
|---|
| [4d51835] | 2199 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2200 | | '(' variable_ptr ')' | 
|---|
|  | 2201 | { $$ = $2; } | 
|---|
|  | 2202 | ; | 
|---|
| [51b73452] | 2203 |  | 
|---|
|  | 2204 | variable_array: | 
|---|
| [4d51835] | 2205 | paren_identifier array_dimension | 
|---|
|  | 2206 | { $$ = $1->addArray( $2 ); } | 
|---|
|  | 2207 | | '(' variable_ptr ')' array_dimension | 
|---|
|  | 2208 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2209 | | '(' variable_array ')' multi_array_dimension          // redundant parenthesis | 
|---|
|  | 2210 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2211 | | '(' variable_array ')'                                                        // redundant parenthesis | 
|---|
|  | 2212 | { $$ = $2; } | 
|---|
|  | 2213 | ; | 
|---|
| [51b73452] | 2214 |  | 
|---|
|  | 2215 | variable_function: | 
|---|
| [4d51835] | 2216 | '(' variable_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2217 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2218 | | '(' variable_function ')'                                                     // redundant parenthesis | 
|---|
|  | 2219 | { $$ = $2; } | 
|---|
|  | 2220 | ; | 
|---|
| [51b73452] | 2221 |  | 
|---|
| [c6b1105] | 2222 | // This pattern parses a function declarator that is not redefining a typedef name. For non-nested functions, there is | 
|---|
|  | 2223 | // no context where a function definition can redefine a typedef name, i.e., the typedef and function name cannot exist | 
|---|
|  | 2224 | // is the same scope.  The pattern precludes returning arrays and functions versus pointers to arrays and functions. | 
|---|
| [51b73452] | 2225 |  | 
|---|
|  | 2226 | function_declarator: | 
|---|
| [4d51835] | 2227 | function_no_ptr attribute_list_opt | 
|---|
| [1db21619] | 2228 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2229 | | function_ptr | 
|---|
|  | 2230 | | function_array attribute_list_opt | 
|---|
| [1db21619] | 2231 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2232 | ; | 
|---|
| [51b73452] | 2233 |  | 
|---|
|  | 2234 | function_no_ptr: | 
|---|
| [4d51835] | 2235 | paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2236 | { $$ = $1->addParamList( $4 ); } | 
|---|
|  | 2237 | | '(' function_ptr ')' '(' push parameter_type_list_opt pop ')' | 
|---|
|  | 2238 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2239 | | '(' function_no_ptr ')'                                                       // redundant parenthesis | 
|---|
|  | 2240 | { $$ = $2; } | 
|---|
|  | 2241 | ; | 
|---|
| [51b73452] | 2242 |  | 
|---|
|  | 2243 | function_ptr: | 
|---|
| [dd51906] | 2244 | ptrref_operator function_declarator | 
|---|
| [4d51835] | 2245 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2246 | | ptrref_operator type_qualifier_list function_declarator | 
|---|
| [4d51835] | 2247 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2248 | | '(' function_ptr ')' | 
|---|
|  | 2249 | { $$ = $2; } | 
|---|
|  | 2250 | ; | 
|---|
| [51b73452] | 2251 |  | 
|---|
|  | 2252 | function_array: | 
|---|
| [4d51835] | 2253 | '(' function_ptr ')' array_dimension | 
|---|
|  | 2254 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2255 | | '(' function_array ')' multi_array_dimension          // redundant parenthesis | 
|---|
|  | 2256 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2257 | | '(' function_array ')'                                                        // redundant parenthesis | 
|---|
|  | 2258 | { $$ = $2; } | 
|---|
|  | 2259 | ; | 
|---|
| [51b73452] | 2260 |  | 
|---|
| [de62360d] | 2261 | // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a typedef name | 
|---|
|  | 2262 | // (see function_declarator for additional comments). The pattern precludes returning arrays and functions versus | 
|---|
|  | 2263 | // pointers to arrays and functions. | 
|---|
| [51b73452] | 2264 |  | 
|---|
|  | 2265 | old_function_declarator: | 
|---|
| [4d51835] | 2266 | old_function_no_ptr | 
|---|
|  | 2267 | | old_function_ptr | 
|---|
|  | 2268 | | old_function_array | 
|---|
|  | 2269 | ; | 
|---|
| [51b73452] | 2270 |  | 
|---|
|  | 2271 | old_function_no_ptr: | 
|---|
| [4d51835] | 2272 | paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter | 
|---|
|  | 2273 | { $$ = $1->addIdList( $3 ); } | 
|---|
|  | 2274 | | '(' old_function_ptr ')' '(' identifier_list ')' | 
|---|
|  | 2275 | { $$ = $2->addIdList( $5 ); } | 
|---|
|  | 2276 | | '(' old_function_no_ptr ')'                                           // redundant parenthesis | 
|---|
|  | 2277 | { $$ = $2; } | 
|---|
|  | 2278 | ; | 
|---|
| [51b73452] | 2279 |  | 
|---|
|  | 2280 | old_function_ptr: | 
|---|
| [dd51906] | 2281 | ptrref_operator old_function_declarator | 
|---|
| [4d51835] | 2282 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2283 | | ptrref_operator type_qualifier_list old_function_declarator | 
|---|
| [4d51835] | 2284 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2285 | | '(' old_function_ptr ')' | 
|---|
|  | 2286 | { $$ = $2; } | 
|---|
|  | 2287 | ; | 
|---|
| [51b73452] | 2288 |  | 
|---|
|  | 2289 | old_function_array: | 
|---|
| [4d51835] | 2290 | '(' old_function_ptr ')' array_dimension | 
|---|
|  | 2291 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2292 | | '(' old_function_array ')' multi_array_dimension      // redundant parenthesis | 
|---|
|  | 2293 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2294 | | '(' old_function_array ')'                                            // redundant parenthesis | 
|---|
|  | 2295 | { $$ = $2; } | 
|---|
|  | 2296 | ; | 
|---|
| [51b73452] | 2297 |  | 
|---|
| [2871210] | 2298 | // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.: | 
|---|
| [c11e31c] | 2299 | // | 
|---|
| [b87a5ed] | 2300 | //              typedef int foo; | 
|---|
|  | 2301 | //              { | 
|---|
|  | 2302 | //                 int foo; // redefine typedef name in new scope | 
|---|
|  | 2303 | //              } | 
|---|
| [c11e31c] | 2304 | // | 
|---|
| [de62360d] | 2305 | // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays | 
|---|
|  | 2306 | // and functions versus pointers to arrays and functions. | 
|---|
| [51b73452] | 2307 |  | 
|---|
| [c6b1105] | 2308 | variable_type_redeclarator: | 
|---|
| [2871210] | 2309 | paren_type attribute_list_opt | 
|---|
| [1db21619] | 2310 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [2871210] | 2311 | | type_ptr | 
|---|
|  | 2312 | | type_array attribute_list_opt | 
|---|
| [1db21619] | 2313 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [2871210] | 2314 | | type_function attribute_list_opt | 
|---|
| [1db21619] | 2315 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2316 | ; | 
|---|
| [51b73452] | 2317 |  | 
|---|
| [2871210] | 2318 | paren_type: | 
|---|
|  | 2319 | typedef | 
|---|
|  | 2320 | | '(' paren_type ')' | 
|---|
| [4d51835] | 2321 | { $$ = $2; } | 
|---|
|  | 2322 | ; | 
|---|
| [51b73452] | 2323 |  | 
|---|
| [2871210] | 2324 | type_ptr: | 
|---|
| [c6b1105] | 2325 | ptrref_operator variable_type_redeclarator | 
|---|
| [4d51835] | 2326 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [c6b1105] | 2327 | | ptrref_operator type_qualifier_list variable_type_redeclarator | 
|---|
| [4d51835] | 2328 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
| [2871210] | 2329 | | '(' type_ptr ')' | 
|---|
| [4d51835] | 2330 | { $$ = $2; } | 
|---|
|  | 2331 | ; | 
|---|
| [51b73452] | 2332 |  | 
|---|
| [2871210] | 2333 | type_array: | 
|---|
|  | 2334 | paren_type array_dimension | 
|---|
| [4d51835] | 2335 | { $$ = $1->addArray( $2 ); } | 
|---|
| [2871210] | 2336 | | '(' type_ptr ')' array_dimension | 
|---|
| [4d51835] | 2337 | { $$ = $2->addArray( $4 ); } | 
|---|
| [2871210] | 2338 | | '(' type_array ')' multi_array_dimension                      // redundant parenthesis | 
|---|
| [4d51835] | 2339 | { $$ = $2->addArray( $4 ); } | 
|---|
| [2871210] | 2340 | | '(' type_array ')'                                                            // redundant parenthesis | 
|---|
| [4d51835] | 2341 | { $$ = $2; } | 
|---|
|  | 2342 | ; | 
|---|
| [51b73452] | 2343 |  | 
|---|
| [2871210] | 2344 | type_function: | 
|---|
|  | 2345 | paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
| [4d51835] | 2346 | { $$ = $1->addParamList( $4 ); } | 
|---|
| [2871210] | 2347 | | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
| [4d51835] | 2348 | { $$ = $2->addParamList( $6 ); } | 
|---|
| [2871210] | 2349 | | '(' type_function ')'                                                         // redundant parenthesis | 
|---|
| [4d51835] | 2350 | { $$ = $2; } | 
|---|
|  | 2351 | ; | 
|---|
| [51b73452] | 2352 |  | 
|---|
| [de62360d] | 2353 | // This pattern parses a declaration for a parameter variable or function prototype that is not redefining a typedef | 
|---|
|  | 2354 | // name and allows the C99 array options, which can only appear in a parameter list.  The pattern precludes declaring an | 
|---|
|  | 2355 | // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to | 
|---|
|  | 2356 | // arrays and functions. | 
|---|
| [51b73452] | 2357 |  | 
|---|
|  | 2358 | identifier_parameter_declarator: | 
|---|
| [4d51835] | 2359 | paren_identifier attribute_list_opt | 
|---|
| [1db21619] | 2360 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2361 | | identifier_parameter_ptr | 
|---|
|  | 2362 | | identifier_parameter_array attribute_list_opt | 
|---|
| [1db21619] | 2363 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2364 | | identifier_parameter_function attribute_list_opt | 
|---|
| [1db21619] | 2365 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2366 | ; | 
|---|
| [51b73452] | 2367 |  | 
|---|
|  | 2368 | identifier_parameter_ptr: | 
|---|
| [dd51906] | 2369 | ptrref_operator identifier_parameter_declarator | 
|---|
| [4d51835] | 2370 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2371 | | ptrref_operator type_qualifier_list identifier_parameter_declarator | 
|---|
| [4d51835] | 2372 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2373 | | '(' identifier_parameter_ptr ')' | 
|---|
|  | 2374 | { $$ = $2; } | 
|---|
|  | 2375 | ; | 
|---|
| [51b73452] | 2376 |  | 
|---|
|  | 2377 | identifier_parameter_array: | 
|---|
| [4d51835] | 2378 | paren_identifier array_parameter_dimension | 
|---|
|  | 2379 | { $$ = $1->addArray( $2 ); } | 
|---|
|  | 2380 | | '(' identifier_parameter_ptr ')' array_dimension | 
|---|
|  | 2381 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2382 | | '(' identifier_parameter_array ')' multi_array_dimension // redundant parenthesis | 
|---|
|  | 2383 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2384 | | '(' identifier_parameter_array ')'                            // redundant parenthesis | 
|---|
|  | 2385 | { $$ = $2; } | 
|---|
|  | 2386 | ; | 
|---|
| [51b73452] | 2387 |  | 
|---|
|  | 2388 | identifier_parameter_function: | 
|---|
| [4d51835] | 2389 | paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2390 | { $$ = $1->addParamList( $4 ); } | 
|---|
|  | 2391 | | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2392 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2393 | | '(' identifier_parameter_function ')'                         // redundant parenthesis | 
|---|
|  | 2394 | { $$ = $2; } | 
|---|
|  | 2395 | ; | 
|---|
| [b87a5ed] | 2396 |  | 
|---|
| [de62360d] | 2397 | // This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name, | 
|---|
|  | 2398 | // e.g.: | 
|---|
| [c11e31c] | 2399 | // | 
|---|
| [b87a5ed] | 2400 | //              typedef int foo; | 
|---|
|  | 2401 | //              int f( int foo ); // redefine typedef name in new scope | 
|---|
| [c11e31c] | 2402 | // | 
|---|
| [de62360d] | 2403 | // and allows the C99 array options, which can only appear in a parameter list.  In addition, the pattern handles the | 
|---|
|  | 2404 | // special meaning of parenthesis around a typedef name: | 
|---|
| [c11e31c] | 2405 | // | 
|---|
| [b87a5ed] | 2406 | //              ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in | 
|---|
|  | 2407 | //              parentheses is taken to be an abstract declarator that specifies a function with a single parameter, | 
|---|
|  | 2408 | //              not as redundant parentheses around the identifier." | 
|---|
| [c11e31c] | 2409 | // | 
|---|
| [c6b1105] | 2410 | // For example: | 
|---|
| [c11e31c] | 2411 | // | 
|---|
| [b87a5ed] | 2412 | //              typedef float T; | 
|---|
| [4d51835] | 2413 | //              int f( int ( T [5] ) );                                 // see abstract_parameter_declarator | 
|---|
| [b87a5ed] | 2414 | //              int g( int ( T ( int ) ) );                             // see abstract_parameter_declarator | 
|---|
|  | 2415 | //              int f( int f1( T a[5] ) );                              // see identifier_parameter_declarator | 
|---|
|  | 2416 | //              int g( int g1( T g2( int p ) ) );               // see identifier_parameter_declarator | 
|---|
| [c11e31c] | 2417 | // | 
|---|
| [de62360d] | 2418 | // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and | 
|---|
|  | 2419 | // not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of | 
|---|
|  | 2420 | // functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and | 
|---|
|  | 2421 | // functions. | 
|---|
| [51b73452] | 2422 |  | 
|---|
| [2871210] | 2423 | type_parameter_redeclarator: | 
|---|
| [4d51835] | 2424 | typedef attribute_list_opt | 
|---|
| [1db21619] | 2425 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [2871210] | 2426 | | type_parameter_ptr | 
|---|
|  | 2427 | | type_parameter_array attribute_list_opt | 
|---|
| [1db21619] | 2428 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [2871210] | 2429 | | type_parameter_function attribute_list_opt | 
|---|
| [1db21619] | 2430 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2431 | ; | 
|---|
| [51b73452] | 2432 |  | 
|---|
|  | 2433 | typedef: | 
|---|
| [4d51835] | 2434 | TYPEDEFname | 
|---|
|  | 2435 | { | 
|---|
| [de62360d] | 2436 | typedefTable.setNextIdentifier( *$1 ); | 
|---|
| [4d51835] | 2437 | $$ = DeclarationNode::newName( $1 ); | 
|---|
|  | 2438 | } | 
|---|
| [2871210] | 2439 | | TYPEGENname | 
|---|
|  | 2440 | { | 
|---|
|  | 2441 | typedefTable.setNextIdentifier( *$1 ); | 
|---|
|  | 2442 | $$ = DeclarationNode::newName( $1 ); | 
|---|
|  | 2443 | } | 
|---|
| [4d51835] | 2444 | ; | 
|---|
| [51b73452] | 2445 |  | 
|---|
| [2871210] | 2446 | type_parameter_ptr: | 
|---|
| [dd51906] | 2447 | ptrref_operator type_parameter_redeclarator | 
|---|
| [4d51835] | 2448 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2449 | | ptrref_operator type_qualifier_list type_parameter_redeclarator | 
|---|
| [4d51835] | 2450 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
| [2871210] | 2451 | | '(' type_parameter_ptr ')' | 
|---|
| [4d51835] | 2452 | { $$ = $2; } | 
|---|
|  | 2453 | ; | 
|---|
| [51b73452] | 2454 |  | 
|---|
| [2871210] | 2455 | type_parameter_array: | 
|---|
| [4d51835] | 2456 | typedef array_parameter_dimension | 
|---|
|  | 2457 | { $$ = $1->addArray( $2 ); } | 
|---|
| [2871210] | 2458 | | '(' type_parameter_ptr ')' array_parameter_dimension | 
|---|
| [4d51835] | 2459 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2460 | ; | 
|---|
| [51b73452] | 2461 |  | 
|---|
| [2871210] | 2462 | type_parameter_function: | 
|---|
| [4d51835] | 2463 | typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2464 | { $$ = $1->addParamList( $4 ); } | 
|---|
| [2871210] | 2465 | | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
| [4d51835] | 2466 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2467 | ; | 
|---|
| [b87a5ed] | 2468 |  | 
|---|
| [de62360d] | 2469 | // This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to | 
|---|
|  | 2470 | // which the type applies, e.g.: | 
|---|
| [c11e31c] | 2471 | // | 
|---|
| [b87a5ed] | 2472 | //              sizeof( int ); | 
|---|
|  | 2473 | //              sizeof( int [10] ); | 
|---|
| [c11e31c] | 2474 | // | 
|---|
| [de62360d] | 2475 | // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays | 
|---|
|  | 2476 | // and functions versus pointers to arrays and functions. | 
|---|
| [51b73452] | 2477 |  | 
|---|
|  | 2478 | abstract_declarator: | 
|---|
| [4d51835] | 2479 | abstract_ptr | 
|---|
|  | 2480 | | abstract_array attribute_list_opt | 
|---|
| [1db21619] | 2481 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2482 | | abstract_function attribute_list_opt | 
|---|
| [1db21619] | 2483 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2484 | ; | 
|---|
| [51b73452] | 2485 |  | 
|---|
|  | 2486 | abstract_ptr: | 
|---|
| [dd51906] | 2487 | ptrref_operator | 
|---|
| [4d51835] | 2488 | { $$ = DeclarationNode::newPointer( 0 ); } | 
|---|
| [dd51906] | 2489 | | ptrref_operator type_qualifier_list | 
|---|
| [4d51835] | 2490 | { $$ = DeclarationNode::newPointer( $2 ); } | 
|---|
| [dd51906] | 2491 | | ptrref_operator abstract_declarator | 
|---|
| [4d51835] | 2492 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2493 | | ptrref_operator type_qualifier_list abstract_declarator | 
|---|
| [4d51835] | 2494 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2495 | | '(' abstract_ptr ')' | 
|---|
|  | 2496 | { $$ = $2; } | 
|---|
|  | 2497 | ; | 
|---|
| [51b73452] | 2498 |  | 
|---|
|  | 2499 | abstract_array: | 
|---|
| [4d51835] | 2500 | array_dimension | 
|---|
|  | 2501 | | '(' abstract_ptr ')' array_dimension | 
|---|
|  | 2502 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2503 | | '(' abstract_array ')' multi_array_dimension          // redundant parenthesis | 
|---|
|  | 2504 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2505 | | '(' abstract_array ')'                                                        // redundant parenthesis | 
|---|
|  | 2506 | { $$ = $2; } | 
|---|
|  | 2507 | ; | 
|---|
| [51b73452] | 2508 |  | 
|---|
|  | 2509 | abstract_function: | 
|---|
| [4d51835] | 2510 | '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2511 | { $$ = DeclarationNode::newFunction( 0, 0, $3, 0 ); } | 
|---|
|  | 2512 | | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2513 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2514 | | '(' abstract_function ')'                                                     // redundant parenthesis | 
|---|
|  | 2515 | { $$ = $2; } | 
|---|
|  | 2516 | ; | 
|---|
| [51b73452] | 2517 |  | 
|---|
|  | 2518 | array_dimension: | 
|---|
| [4d51835] | 2519 | // Only the first dimension can be empty. | 
|---|
| [2871210] | 2520 | '[' ']' | 
|---|
| [4d51835] | 2521 | { $$ = DeclarationNode::newArray( 0, 0, false ); } | 
|---|
| [2871210] | 2522 | | '[' ']' multi_array_dimension | 
|---|
|  | 2523 | { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); } | 
|---|
| [4d51835] | 2524 | | multi_array_dimension | 
|---|
|  | 2525 | ; | 
|---|
| [51b73452] | 2526 |  | 
|---|
|  | 2527 | multi_array_dimension: | 
|---|
| [4d51835] | 2528 | '[' push assignment_expression pop ']' | 
|---|
|  | 2529 | { $$ = DeclarationNode::newArray( $3, 0, false ); } | 
|---|
|  | 2530 | | '[' push '*' pop ']'                                                          // C99 | 
|---|
|  | 2531 | { $$ = DeclarationNode::newVarArray( 0 ); } | 
|---|
|  | 2532 | | multi_array_dimension '[' push assignment_expression pop ']' | 
|---|
|  | 2533 | { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); } | 
|---|
|  | 2534 | | multi_array_dimension '[' push '*' pop ']'            // C99 | 
|---|
|  | 2535 | { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); } | 
|---|
|  | 2536 | ; | 
|---|
| [51b73452] | 2537 |  | 
|---|
| [c11e31c] | 2538 | // This pattern parses a declaration of a parameter abstract variable or function prototype, i.e., there is no | 
|---|
|  | 2539 | // identifier to which the type applies, e.g.: | 
|---|
|  | 2540 | // | 
|---|
| [b87a5ed] | 2541 | //              int f( int );                   // abstract variable parameter; no parameter name specified | 
|---|
|  | 2542 | //              int f( int (int) );             // abstract function-prototype parameter; no parameter name specified | 
|---|
| [c11e31c] | 2543 | // | 
|---|
| [de62360d] | 2544 | // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays | 
|---|
|  | 2545 | // and functions versus pointers to arrays and functions. | 
|---|
| [51b73452] | 2546 |  | 
|---|
|  | 2547 | abstract_parameter_declarator: | 
|---|
| [4d51835] | 2548 | abstract_parameter_ptr | 
|---|
|  | 2549 | | abstract_parameter_array attribute_list_opt | 
|---|
| [1db21619] | 2550 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2551 | | abstract_parameter_function attribute_list_opt | 
|---|
| [1db21619] | 2552 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2553 | ; | 
|---|
| [51b73452] | 2554 |  | 
|---|
|  | 2555 | abstract_parameter_ptr: | 
|---|
| [dd51906] | 2556 | ptrref_operator | 
|---|
| [4d51835] | 2557 | { $$ = DeclarationNode::newPointer( 0 ); } | 
|---|
| [dd51906] | 2558 | | ptrref_operator type_qualifier_list | 
|---|
| [4d51835] | 2559 | { $$ = DeclarationNode::newPointer( $2 ); } | 
|---|
| [dd51906] | 2560 | | ptrref_operator abstract_parameter_declarator | 
|---|
| [4d51835] | 2561 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2562 | | ptrref_operator type_qualifier_list abstract_parameter_declarator | 
|---|
| [4d51835] | 2563 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2564 | | '(' abstract_parameter_ptr ')' | 
|---|
|  | 2565 | { $$ = $2; } | 
|---|
|  | 2566 | ; | 
|---|
| [51b73452] | 2567 |  | 
|---|
|  | 2568 | abstract_parameter_array: | 
|---|
| [4d51835] | 2569 | array_parameter_dimension | 
|---|
|  | 2570 | | '(' abstract_parameter_ptr ')' array_parameter_dimension | 
|---|
|  | 2571 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2572 | | '(' abstract_parameter_array ')' multi_array_dimension // redundant parenthesis | 
|---|
|  | 2573 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2574 | | '(' abstract_parameter_array ')'                                      // redundant parenthesis | 
|---|
|  | 2575 | { $$ = $2; } | 
|---|
|  | 2576 | ; | 
|---|
| [51b73452] | 2577 |  | 
|---|
|  | 2578 | abstract_parameter_function: | 
|---|
| [4d51835] | 2579 | '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2580 | { $$ = DeclarationNode::newFunction( 0, 0, $3, 0 ); } | 
|---|
|  | 2581 | | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2582 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2583 | | '(' abstract_parameter_function ')'                           // redundant parenthesis | 
|---|
|  | 2584 | { $$ = $2; } | 
|---|
|  | 2585 | ; | 
|---|
| [51b73452] | 2586 |  | 
|---|
|  | 2587 | array_parameter_dimension: | 
|---|
| [4d51835] | 2588 | // Only the first dimension can be empty or have qualifiers. | 
|---|
|  | 2589 | array_parameter_1st_dimension | 
|---|
|  | 2590 | | array_parameter_1st_dimension multi_array_dimension | 
|---|
|  | 2591 | { $$ = $1->addArray( $2 ); } | 
|---|
|  | 2592 | | multi_array_dimension | 
|---|
|  | 2593 | ; | 
|---|
| [51b73452] | 2594 |  | 
|---|
| [c11e31c] | 2595 | // The declaration of an array parameter has additional syntax over arrays in normal variable declarations: | 
|---|
|  | 2596 | // | 
|---|
| [de62360d] | 2597 | //              ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall appear only in | 
|---|
|  | 2598 | //              a declaration of a function parameter with an array type, and then only in the outermost array type derivation." | 
|---|
| [51b73452] | 2599 |  | 
|---|
|  | 2600 | array_parameter_1st_dimension: | 
|---|
| [2871210] | 2601 | '[' ']' | 
|---|
| [4d51835] | 2602 | { $$ = DeclarationNode::newArray( 0, 0, false ); } | 
|---|
|  | 2603 | // multi_array_dimension handles the '[' '*' ']' case | 
|---|
|  | 2604 | | '[' push type_qualifier_list '*' pop ']'                      // remaining C99 | 
|---|
|  | 2605 | { $$ = DeclarationNode::newVarArray( $3 ); } | 
|---|
|  | 2606 | | '[' push type_qualifier_list pop ']' | 
|---|
|  | 2607 | { $$ = DeclarationNode::newArray( 0, $3, false ); } | 
|---|
|  | 2608 | // multi_array_dimension handles the '[' assignment_expression ']' case | 
|---|
|  | 2609 | | '[' push type_qualifier_list assignment_expression pop ']' | 
|---|
|  | 2610 | { $$ = DeclarationNode::newArray( $4, $3, false ); } | 
|---|
|  | 2611 | | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']' | 
|---|
|  | 2612 | { $$ = DeclarationNode::newArray( $5, $4, true ); } | 
|---|
|  | 2613 | | '[' push type_qualifier_list STATIC assignment_expression pop ']' | 
|---|
|  | 2614 | { $$ = DeclarationNode::newArray( $5, $3, true ); } | 
|---|
|  | 2615 | ; | 
|---|
| [b87a5ed] | 2616 |  | 
|---|
| [de62360d] | 2617 | // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type applies, | 
|---|
|  | 2618 | // e.g.: | 
|---|
| [c11e31c] | 2619 | // | 
|---|
| [b87a5ed] | 2620 | //              sizeof( int ); // abstract variable; no identifier name specified | 
|---|
| [c11e31c] | 2621 | // | 
|---|
| [de62360d] | 2622 | // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays | 
|---|
|  | 2623 | // and functions versus pointers to arrays and functions. | 
|---|
| [51b73452] | 2624 |  | 
|---|
|  | 2625 | variable_abstract_declarator: | 
|---|
| [4d51835] | 2626 | variable_abstract_ptr | 
|---|
|  | 2627 | | variable_abstract_array attribute_list_opt | 
|---|
| [1db21619] | 2628 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2629 | | variable_abstract_function attribute_list_opt | 
|---|
| [1db21619] | 2630 | { $$ = $1->addQualifiers( $2 ); } | 
|---|
| [4d51835] | 2631 | ; | 
|---|
| [51b73452] | 2632 |  | 
|---|
|  | 2633 | variable_abstract_ptr: | 
|---|
| [dd51906] | 2634 | ptrref_operator | 
|---|
| [4d51835] | 2635 | { $$ = DeclarationNode::newPointer( 0 ); } | 
|---|
| [dd51906] | 2636 | | ptrref_operator type_qualifier_list | 
|---|
| [4d51835] | 2637 | { $$ = DeclarationNode::newPointer( $2 ); } | 
|---|
| [dd51906] | 2638 | | ptrref_operator variable_abstract_declarator | 
|---|
| [4d51835] | 2639 | { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2640 | | ptrref_operator type_qualifier_list variable_abstract_declarator | 
|---|
| [4d51835] | 2641 | { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } | 
|---|
|  | 2642 | | '(' variable_abstract_ptr ')' | 
|---|
|  | 2643 | { $$ = $2; } | 
|---|
|  | 2644 | ; | 
|---|
| [51b73452] | 2645 |  | 
|---|
|  | 2646 | variable_abstract_array: | 
|---|
| [4d51835] | 2647 | array_dimension | 
|---|
|  | 2648 | | '(' variable_abstract_ptr ')' array_dimension | 
|---|
|  | 2649 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2650 | | '(' variable_abstract_array ')' multi_array_dimension // redundant parenthesis | 
|---|
|  | 2651 | { $$ = $2->addArray( $4 ); } | 
|---|
|  | 2652 | | '(' variable_abstract_array ')'                                       // redundant parenthesis | 
|---|
|  | 2653 | { $$ = $2; } | 
|---|
|  | 2654 | ; | 
|---|
| [51b73452] | 2655 |  | 
|---|
|  | 2656 | variable_abstract_function: | 
|---|
| [4d51835] | 2657 | '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) | 
|---|
|  | 2658 | { $$ = $2->addParamList( $6 ); } | 
|---|
|  | 2659 | | '(' variable_abstract_function ')'                            // redundant parenthesis | 
|---|
|  | 2660 | { $$ = $2; } | 
|---|
|  | 2661 | ; | 
|---|
| [b87a5ed] | 2662 |  | 
|---|
| [de62360d] | 2663 | // This pattern parses a new-style declaration for a parameter variable or function prototype that is either an | 
|---|
|  | 2664 | // identifier or typedef name and allows the C99 array options, which can only appear in a parameter list. | 
|---|
| [b87a5ed] | 2665 |  | 
|---|
|  | 2666 | new_identifier_parameter_declarator_tuple:                              // CFA | 
|---|
| [4d51835] | 2667 | new_identifier_parameter_declarator_no_tuple | 
|---|
|  | 2668 | | new_abstract_tuple | 
|---|
|  | 2669 | | type_qualifier_list new_abstract_tuple | 
|---|
|  | 2670 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 2671 | ; | 
|---|
| [b87a5ed] | 2672 |  | 
|---|
|  | 2673 | new_identifier_parameter_declarator_no_tuple:                   // CFA | 
|---|
| [4d51835] | 2674 | new_identifier_parameter_ptr | 
|---|
|  | 2675 | | new_identifier_parameter_array | 
|---|
|  | 2676 | ; | 
|---|
| [b87a5ed] | 2677 |  | 
|---|
|  | 2678 | new_identifier_parameter_ptr:                                                   // CFA | 
|---|
| [dd51906] | 2679 | ptrref_operator type_specifier | 
|---|
| [4d51835] | 2680 | { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2681 | | type_qualifier_list ptrref_operator type_specifier | 
|---|
| [4d51835] | 2682 | { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } | 
|---|
| [dd51906] | 2683 | | ptrref_operator new_abstract_function | 
|---|
| [4d51835] | 2684 | { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2685 | | type_qualifier_list ptrref_operator new_abstract_function | 
|---|
| [4d51835] | 2686 | { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } | 
|---|
| [dd51906] | 2687 | | ptrref_operator new_identifier_parameter_declarator_tuple | 
|---|
| [4d51835] | 2688 | { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2689 | | type_qualifier_list ptrref_operator new_identifier_parameter_declarator_tuple | 
|---|
| [4d51835] | 2690 | { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } | 
|---|
|  | 2691 | ; | 
|---|
| [b87a5ed] | 2692 |  | 
|---|
|  | 2693 | new_identifier_parameter_array:                                                 // CFA | 
|---|
| [de62360d] | 2694 | // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to | 
|---|
|  | 2695 | // shift/reduce conflict with new-style empty (void) function return type. | 
|---|
| [2871210] | 2696 | '[' ']' type_specifier | 
|---|
|  | 2697 | { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
| [4d51835] | 2698 | | new_array_parameter_1st_dimension type_specifier | 
|---|
|  | 2699 | { $$ = $2->addNewArray( $1 ); } | 
|---|
| [2871210] | 2700 | | '[' ']' multi_array_dimension type_specifier | 
|---|
|  | 2701 | { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
| [4d51835] | 2702 | | new_array_parameter_1st_dimension multi_array_dimension type_specifier | 
|---|
|  | 2703 | { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } | 
|---|
|  | 2704 | | multi_array_dimension type_specifier | 
|---|
|  | 2705 | { $$ = $2->addNewArray( $1 ); } | 
|---|
| [2871210] | 2706 | | '[' ']' new_identifier_parameter_ptr | 
|---|
|  | 2707 | { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
| [4d51835] | 2708 | | new_array_parameter_1st_dimension new_identifier_parameter_ptr | 
|---|
|  | 2709 | { $$ = $2->addNewArray( $1 ); } | 
|---|
| [2871210] | 2710 | | '[' ']' multi_array_dimension new_identifier_parameter_ptr | 
|---|
|  | 2711 | { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
| [4d51835] | 2712 | | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr | 
|---|
|  | 2713 | { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } | 
|---|
|  | 2714 | | multi_array_dimension new_identifier_parameter_ptr | 
|---|
|  | 2715 | { $$ = $2->addNewArray( $1 ); } | 
|---|
|  | 2716 | ; | 
|---|
| [51b73452] | 2717 |  | 
|---|
|  | 2718 | new_array_parameter_1st_dimension: | 
|---|
| [4d51835] | 2719 | '[' push type_qualifier_list '*' pop ']'                        // remaining C99 | 
|---|
|  | 2720 | { $$ = DeclarationNode::newVarArray( $3 ); } | 
|---|
|  | 2721 | | '[' push type_qualifier_list assignment_expression pop ']' | 
|---|
|  | 2722 | { $$ = DeclarationNode::newArray( $4, $3, false ); } | 
|---|
|  | 2723 | | '[' push declaration_qualifier_list assignment_expression pop ']' | 
|---|
|  | 2724 | // declaration_qualifier_list must be used because of shift/reduce conflict with | 
|---|
|  | 2725 | // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot | 
|---|
|  | 2726 | // appear in this context. | 
|---|
|  | 2727 | { $$ = DeclarationNode::newArray( $4, $3, true ); } | 
|---|
|  | 2728 | | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']' | 
|---|
|  | 2729 | { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); } | 
|---|
|  | 2730 | ; | 
|---|
| [b87a5ed] | 2731 |  | 
|---|
| [de62360d] | 2732 | // This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no | 
|---|
|  | 2733 | // identifier to which the type applies, e.g.: | 
|---|
| [c11e31c] | 2734 | // | 
|---|
| [b87a5ed] | 2735 | //              [int] f( int );                         // abstract variable parameter; no parameter name specified | 
|---|
|  | 2736 | //              [int] f( [int] (int) );         // abstract function-prototype parameter; no parameter name specified | 
|---|
| [c11e31c] | 2737 | // | 
|---|
|  | 2738 | // These rules need LR(3): | 
|---|
|  | 2739 | // | 
|---|
| [2871210] | 2740 | //              new_abstract_tuple identifier_or_type_name | 
|---|
|  | 2741 | //              '[' new_parameter_list ']' identifier_or_type_name '(' new_parameter_type_list_opt ')' | 
|---|
| [c11e31c] | 2742 | // | 
|---|
|  | 2743 | // since a function return type can be syntactically identical to a tuple type: | 
|---|
|  | 2744 | // | 
|---|
| [b87a5ed] | 2745 | //              [int, int] t; | 
|---|
|  | 2746 | //              [int, int] f( int ); | 
|---|
| [c11e31c] | 2747 | // | 
|---|
| [2871210] | 2748 | // Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce | 
|---|
| [de62360d] | 2749 | // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary | 
|---|
|  | 2750 | // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are | 
|---|
|  | 2751 | // duplicated when appearing with new_function_specifier. | 
|---|
| [b87a5ed] | 2752 |  | 
|---|
|  | 2753 | new_abstract_declarator_tuple:                                                  // CFA | 
|---|
| [4d51835] | 2754 | new_abstract_tuple | 
|---|
|  | 2755 | | type_qualifier_list new_abstract_tuple | 
|---|
|  | 2756 | { $$ = $2->addQualifiers( $1 ); } | 
|---|
|  | 2757 | | new_abstract_declarator_no_tuple | 
|---|
|  | 2758 | ; | 
|---|
| [b87a5ed] | 2759 |  | 
|---|
|  | 2760 | new_abstract_declarator_no_tuple:                                               // CFA | 
|---|
| [4d51835] | 2761 | new_abstract_ptr | 
|---|
|  | 2762 | | new_abstract_array | 
|---|
|  | 2763 | ; | 
|---|
| [b87a5ed] | 2764 |  | 
|---|
|  | 2765 | new_abstract_ptr:                                                                               // CFA | 
|---|
| [dd51906] | 2766 | ptrref_operator type_specifier | 
|---|
| [4d51835] | 2767 | { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2768 | | type_qualifier_list ptrref_operator type_specifier | 
|---|
| [4d51835] | 2769 | { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } | 
|---|
| [dd51906] | 2770 | | ptrref_operator new_abstract_function | 
|---|
| [4d51835] | 2771 | { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2772 | | type_qualifier_list ptrref_operator new_abstract_function | 
|---|
| [4d51835] | 2773 | { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } | 
|---|
| [dd51906] | 2774 | | ptrref_operator new_abstract_declarator_tuple | 
|---|
| [4d51835] | 2775 | { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } | 
|---|
| [dd51906] | 2776 | | type_qualifier_list ptrref_operator new_abstract_declarator_tuple | 
|---|
| [4d51835] | 2777 | { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } | 
|---|
|  | 2778 | ; | 
|---|
| [b87a5ed] | 2779 |  | 
|---|
|  | 2780 | new_abstract_array:                                                                             // CFA | 
|---|
| [de62360d] | 2781 | // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with | 
|---|
|  | 2782 | // empty (void) function return type. | 
|---|
| [2871210] | 2783 | '[' ']' type_specifier | 
|---|
|  | 2784 | { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
|  | 2785 | | '[' ']' multi_array_dimension type_specifier | 
|---|
|  | 2786 | { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
| [4d51835] | 2787 | | multi_array_dimension type_specifier | 
|---|
|  | 2788 | { $$ = $2->addNewArray( $1 ); } | 
|---|
| [2871210] | 2789 | | '[' ']' new_abstract_ptr | 
|---|
|  | 2790 | { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
|  | 2791 | | '[' ']' multi_array_dimension new_abstract_ptr | 
|---|
|  | 2792 | { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } | 
|---|
| [4d51835] | 2793 | | multi_array_dimension new_abstract_ptr | 
|---|
|  | 2794 | { $$ = $2->addNewArray( $1 ); } | 
|---|
|  | 2795 | ; | 
|---|
| [b87a5ed] | 2796 |  | 
|---|
|  | 2797 | new_abstract_tuple:                                                                             // CFA | 
|---|
| [4d51835] | 2798 | '[' push new_abstract_parameter_list pop ']' | 
|---|
|  | 2799 | { $$ = DeclarationNode::newTuple( $3 ); } | 
|---|
|  | 2800 | ; | 
|---|
| [b87a5ed] | 2801 |  | 
|---|
|  | 2802 | new_abstract_function:                                                                  // CFA | 
|---|
| [2871210] | 2803 | '[' ']' '(' new_parameter_type_list_opt ')' | 
|---|
|  | 2804 | { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0 ); } | 
|---|
| [4d51835] | 2805 | | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')' | 
|---|
|  | 2806 | { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); } | 
|---|
|  | 2807 | | new_function_return '(' push new_parameter_type_list_opt pop ')' | 
|---|
|  | 2808 | { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); } | 
|---|
|  | 2809 | ; | 
|---|
| [b87a5ed] | 2810 |  | 
|---|
| [de62360d] | 2811 | // 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration specifiers in | 
|---|
|  | 2812 | //    each declaration, and in the specifier-qualifier list in each structure declaration and type name." | 
|---|
| [c11e31c] | 2813 | // | 
|---|
| [de62360d] | 2814 | // 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the beginning of | 
|---|
|  | 2815 | //    the declaration specifiers in a declaration is an obsolescent feature." | 
|---|
| [c11e31c] | 2816 | // | 
|---|
|  | 2817 | // 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not | 
|---|
|  | 2818 | //    prototype-format parameter type declarators) is an obsolescent feature." | 
|---|
|  | 2819 | // | 
|---|
| [de62360d] | 2820 | // 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter identifier and | 
|---|
|  | 2821 | //    declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature. | 
|---|
| [51b73452] | 2822 |  | 
|---|
| [c11e31c] | 2823 | //************************* MISCELLANEOUS ******************************** | 
|---|
| [51b73452] | 2824 |  | 
|---|
| [b87a5ed] | 2825 | comma_opt:                                                                                              // redundant comma | 
|---|
| [4d51835] | 2826 | // empty | 
|---|
|  | 2827 | | ',' | 
|---|
|  | 2828 | ; | 
|---|
| [51b73452] | 2829 |  | 
|---|
|  | 2830 | assignment_opt: | 
|---|
| [4d51835] | 2831 | // empty | 
|---|
|  | 2832 | { $$ = 0; } | 
|---|
|  | 2833 | | '=' assignment_expression | 
|---|
|  | 2834 | { $$ = $2; } | 
|---|
|  | 2835 | ; | 
|---|
| [51b73452] | 2836 |  | 
|---|
|  | 2837 | %% | 
|---|
| [c11e31c] | 2838 | // ----end of grammar---- | 
|---|
| [51b73452] | 2839 |  | 
|---|
| [0da3e2c] | 2840 | extern char *yytext; | 
|---|
|  | 2841 |  | 
|---|
| [5f2f2d7] | 2842 | void yyerror( const char * ) { | 
|---|
|  | 2843 | std::cout << "Error "; | 
|---|
| [b87a5ed] | 2844 | if ( yyfilename ) { | 
|---|
| [45161b4d] | 2845 | std::cout << "in file " << yyfilename << " "; | 
|---|
| [5f2f2d7] | 2846 | } // if | 
|---|
| [b1d6dd5] | 2847 | std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl; | 
|---|
| [51b73452] | 2848 | } | 
|---|
|  | 2849 |  | 
|---|
| [c11e31c] | 2850 | // Local Variables: // | 
|---|
| [b87a5ed] | 2851 | // mode: c++ // | 
|---|
| [de62360d] | 2852 | // tab-width: 4 // | 
|---|
| [c11e31c] | 2853 | // compile-command: "make install" // | 
|---|
|  | 2854 | // End: // | 
|---|