source: src/Parser/parser.yy@ c42b8a1

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since c42b8a1 was afe9e45, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

add more detailed syntax-error messages

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