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