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