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