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