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