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