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