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