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