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