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