source: src/Parser/parser.yy@ 7fabfdf

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 stuck-waitfor-destruct
Last change on this file since 7fabfdf was ba01b14, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

update constant parsing add _FloatNN

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