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