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