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