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