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