source: src/Parser/parser.yy@ 4084928e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 4084928e was f271bdd, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

first attempt at extended for-crtl, name changes

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