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