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