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