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