source: src/Parser/parser.yy@ 2e457d8

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

fix conflict

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