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