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