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