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