Changes in src/Parser/parser.yy [f1da02c:a1c9ddd]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (68 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rf1da02c ra1c9ddd 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 4 21:48:23 201913 // Update Count : 436412 // Last Modified On : Thu Jun 7 10:07:12 2018 13 // Update Count : 3527 14 14 // 15 15 … … 99 99 // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__. 100 100 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier ); 101 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 101 //cur->addType( specifier ); 102 for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 102 103 cl->cloneBaseType( cur ); 103 104 } // for 104 105 declList->addType( cl ); 106 // delete cl; 105 107 return declList; 106 108 } // distAttr … … 112 114 } // for 113 115 } // distExt 114 115 void distInl( DeclarationNode * declaration ) {116 // distribute EXTENSION across all declarations117 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {118 iter->set_inLine( true );119 } // for120 } // distInl121 122 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {123 // distribute qualifiers across all non-variable declarations in a distribution statemement124 for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {125 // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since126 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To127 // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to128 // be copied to add to front), the appropriate forall pointers are interchanged before calling addQualifiers.129 DeclarationNode * clone = qualifiers->clone();130 if ( qualifiers->type ) { // forall clause ? (handles SC)131 if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ?132 swap( clone->type->forall, iter->type->aggregate.params );133 iter->addQualifiers( clone );134 } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ?135 // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together.136 DeclarationNode newnode;137 swap( newnode.type, iter->type->aggInst.aggregate );138 swap( clone->type->forall, newnode.type->aggregate.params );139 newnode.addQualifiers( clone );140 swap( newnode.type, iter->type->aggInst.aggregate );141 } else if ( iter->type->kind == TypeData::Function ) { // routines ?142 swap( clone->type->forall, iter->type->forall );143 iter->addQualifiers( clone );144 } // if145 } else { // just SC qualifiers146 iter->addQualifiers( clone );147 } // if148 } // for149 delete qualifiers;150 } // distQual151 116 152 117 // There is an ambiguity for inline generic-routine return-types and generic routines. … … 171 136 } // build_postfix_name 172 137 173 DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) { 174 if ( ! fieldList ) { // field declarator ? 175 if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) { 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 186 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 187 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); 188 if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) { 189 type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) ); 190 } // if 191 return new ForCtrl( 192 distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 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 ); 197 } // forCtrl 198 199 ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 200 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->expr.get()) ) { 201 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 202 } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->expr.get()) ) { 203 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1 ) ) { 204 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 205 } else { 206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr; 207 } // if 208 } else { 209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr; 210 } // if 211 } // forCtrl 212 213 214 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? 138 bool forall = false, xxx = false; // aggregate have one or more forall qualifiers ? 215 139 216 140 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 232 156 233 157 // Types declaration for productions 234 %union { 158 %union 159 { 235 160 Token tok; 236 161 ParseNode * pn; … … 242 167 WaitForStmt * wfs; 243 168 Expression * constant; 244 IfCtrl * ifctl; 245 ForCtrl * fctl; 246 enum OperKinds compop; 169 IfCtl * ifctl; 170 ForCtl * fctl; 247 171 LabelNode * label; 248 172 InitializerNode * in; … … 265 189 %token RESTRICT // C99 266 190 %token ATOMIC // C11 267 %token FORALL MUTEX VIRTUAL COERCE// CFA191 %token FORALL MUTEX VIRTUAL // CFA 268 192 %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED 269 193 %token BOOL COMPLEX IMAGINARY // C99 270 %token INT128 UINT128 uuFLOAT80 uuFLOAT128 // GCC 271 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC 194 %token INT128 FLOAT80 FLOAT128 // GCC 272 195 %token ZERO_T ONE_T // CFA 273 196 %token VALIST // GCC 274 %token AUTO_TYPE // GCC 275 %token TYPEOF BASETYPEOF LABEL // GCC 197 %token TYPEOF LABEL // GCC 276 198 %token ENUM STRUCT UNION 277 199 %token EXCEPTION // CFA 278 %token GENERATOR COROUTINE MONITOR THREAD// CFA200 %token COROUTINE MONITOR THREAD // CFA 279 201 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 280 202 %token SIZEOF OFFSETOF 281 // %token SUSPEND RESUME // CFA282 203 %token ATTRIBUTE EXTENSION // GCC 283 204 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 289 210 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname 290 211 %token<tok> TIMEOUT WOR 212 %token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname 291 213 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 292 214 %token<tok> DIRECTIVE … … 309 231 %token ANDassign ERassign ORassign // &= ^= |= 310 232 311 %token ErangeUpEq ErangeDown ErangeDownEq // ~= -~ -~=312 233 %token ATassign // @= 313 234 314 %type<tok> identifier 315 %type<tok> identifier_or_type_name attr_name235 %type<tok> identifier no_attr_identifier 236 %type<tok> identifier_or_type_name no_attr_identifier_or_type_name attr_name 316 237 %type<tok> quasi_keyword 317 238 %type<constant> string_literal … … 331 252 %type<en> argument_expression_list argument_expression default_initialize_opt 332 253 %type<ifctl> if_control_expression 333 %type<fctl> for_control_expression for_control_expression_list 334 %type<compop> inclexcl 254 %type<fctl> for_control_expression 335 255 %type<en> subrange 336 256 %type<decl> asm_name_opt 337 %type<en> asm_operands_opt asm_operands_listasm_operand257 %type<en> asm_operands_opt asm_operands_list asm_operand 338 258 %type<label> label_list 339 259 %type<en> asm_clobbers_list_opt 340 260 %type<flag> asm_volatile_opt 341 261 %type<en> handler_predicate_opt 342 %type<genexpr> generic_association generic_assoc_list262 %type<genexpr> generic_association generic_assoc_list 343 263 344 264 // statements … … 384 304 %type<en> enumerator_value_opt 385 305 386 %type<decl> external_definition external_definition_list external_definition_list_opt 387 388 %type<decl> exception_declaration 389 390 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract 391 %type<en> field field_name_list field_name fraction_constants_opt 306 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt 307 308 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list 309 %type<en> field field_list field_name fraction_constants_opt 392 310 393 311 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 402 320 %type<decl> cfa_array_parameter_1st_dimension 403 321 404 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list322 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list 405 323 %type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier 406 324 … … 437 355 %type<decl> type_parameter type_parameter_list type_initializer_opt 438 356 439 %type<en> type_ parameters_opt type_list357 %type<en> type_list 440 358 441 359 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 472 390 // Foo ( *fp )( int ); 473 391 // `---' matches start of TYPEGENname '(' 474 // must be:392 // Must be: 475 393 // Foo( int ) ( *fp )( int ); 476 // The same problem occurs here:477 // forall( otype T ) struct Foo { T v; } ( *fp )( int );478 // must be:479 // forall( otype T ) struct Foo { T v; } ( int ) ( *fp )( int );480 394 481 395 // Order of these lines matters (low-to-high precedence). 482 396 %precedence TYPEGENname 483 %precedence '}'484 397 %precedence '(' 485 486 // %precedence RESUME487 // %precedence '{'488 // %precedence ')'489 398 490 399 %locations // support location tracking for error messages … … 548 457 identifier: 549 458 IDENTIFIER 459 | ATTR_IDENTIFIER // CFA 550 460 | quasi_keyword 551 | '@' // CFA 552 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; } 461 ; 462 463 no_attr_identifier: 464 IDENTIFIER 465 | quasi_keyword 553 466 ; 554 467 … … 589 502 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call 590 503 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 591 | type_name '.' identifier // CFA, nested type 592 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 593 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 594 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 504 | type_name '.' no_attr_identifier // CFA, nested type 505 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 506 { $$ = nullptr; } 507 | type_name '.' '[' field_list ']' // CFA, nested type / tuple field selector 508 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 509 { $$ = nullptr; } 595 510 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 596 511 { … … 599 514 $$ = new ExpressionNode( $5 ); 600 515 } 601 // | RESUME '(' comma_expression ')'602 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }603 // | RESUME '(' comma_expression ')' compound_statement604 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }605 516 ; 606 517 … … 642 553 | postfix_expression '(' argument_expression_list ')' 643 554 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 644 | postfix_expression '.' identifier555 | postfix_expression '.' no_attr_identifier 645 556 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } 646 557 | postfix_expression '.' INTEGERconstant // CFA, tuple index … … 648 559 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 649 560 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 650 | postfix_expression '.' '[' field_ name_list ']'// CFA, tuple field selector561 | postfix_expression '.' '[' field_list ']' // CFA, tuple field selector 651 562 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 652 | postfix_expression ARROW identifier 653 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } 563 | postfix_expression ARROW no_attr_identifier 564 { 565 $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) ); 566 } 654 567 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 655 568 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 656 | postfix_expression ARROW '[' field_ name_list ']'// CFA, tuple field selector569 | postfix_expression ARROW '[' field_list ']' // CFA, tuple field selector 657 570 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 658 571 | postfix_expression ICR … … 673 586 674 587 argument_expression_list: 588 argument_expression 589 | argument_expression_list ',' argument_expression 590 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 591 ; 592 593 argument_expression: 675 594 // empty 676 595 { $$ = nullptr; } 677 | argument_expression 678 | argument_expression_list ',' argument_expression 679 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 680 ; 681 682 argument_expression: 683 '@' // CFA, default parameter 684 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 685 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 596 // | '@' // use default argument 597 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 686 598 | assignment_expression 687 599 ; 688 600 689 field_ name_list:// CFA, tuple field selector601 field_list: // CFA, tuple field selector 690 602 field 691 | field_ name_list ',' field{ $$ = (ExpressionNode *)$1->set_last( $3 ); }603 | field_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); } 692 604 ; 693 605 … … 696 608 | FLOATING_DECIMALconstant field 697 609 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 698 | FLOATING_DECIMALconstant '[' field_ name_list ']'610 | FLOATING_DECIMALconstant '[' field_list ']' 699 611 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 700 612 | field_name '.' field 701 613 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 702 | field_name '.' '[' field_ name_list ']'614 | field_name '.' '[' field_list ']' 703 615 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 704 616 | field_name ARROW field 705 617 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 706 | field_name ARROW '[' field_ name_list ']'618 | field_name ARROW '[' field_list ']' 707 619 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 708 620 ; … … 713 625 | FLOATINGconstant fraction_constants_opt 714 626 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); } 715 | identifier fraction_constants_opt627 | no_attr_identifier fraction_constants_opt 716 628 { 717 629 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) ); … … 771 683 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 772 684 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } 773 | OFFSETOF '(' type_no_function ',' identifier ')'685 | OFFSETOF '(' type_no_function ',' no_attr_identifier ')' 774 686 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); } 687 | ATTR_IDENTIFIER 688 { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ) ) ); } 689 | ATTR_IDENTIFIER '(' argument_expression ')' 690 { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); } 691 | ATTR_IDENTIFIER '(' type ')' 692 { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuildType( $3 ) ) ); } 775 693 ; 776 694 … … 793 711 | '(' type_no_function ')' cast_expression 794 712 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 795 // keyword cast cannot be grouped because of reduction in aggregate_key796 | '(' GENERATOR '&' ')' cast_expression // CFA797 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }798 713 | '(' COROUTINE '&' ')' cast_expression // CFA 799 714 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } … … 807 722 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 808 723 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 809 | '(' RETURN type_no_function ')' cast_expression // CFA810 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }811 | '(' COERCE type_no_function ')' cast_expression // CFA812 { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; }813 | '(' qualifier_cast_list ')' cast_expression // CFA814 { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; }815 724 // | '(' type_no_function ')' tuple 816 725 // { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 817 ;818 819 qualifier_cast_list:820 cast_modifier type_qualifier_name821 | cast_modifier MUTEX822 | qualifier_cast_list cast_modifier type_qualifier_name823 | qualifier_cast_list cast_modifier MUTEX824 ;825 826 cast_modifier:827 '-'828 | '+'829 726 ; 830 727 … … 1007 904 1008 905 labeled_statement: 1009 // labels cannot be identifiers 0 or 1 906 // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER 1010 907 identifier_or_type_name ':' attribute_list_opt statement 1011 { $$ = $4->add_label( $1, $3 ); } 908 { 909 $$ = $4->add_label( $1, $3 ); 910 } 1012 911 ; 1013 912 … … 1025 924 statement_decl 1026 925 | statement_decl_list statement_decl 1027 { assert( $1 ); $1->set_last( $2 ); $$ = $1;}926 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 1028 927 ; 1029 928 … … 1032 931 { $$ = new StatementNode( $1 ); } 1033 932 | EXTENSION declaration // GCC 1034 { distExt( $2 ); $$ = new StatementNode( $2 ); } 933 { 934 distExt( $2 ); 935 $$ = new StatementNode( $2 ); 936 } 1035 937 | function_definition 1036 938 { $$ = new StatementNode( $1 ); } 1037 939 | EXTENSION function_definition // GCC 1038 { distExt( $2 ); $$ = new StatementNode( $2 ); } 940 { 941 distExt( $2 ); 942 $$ = new StatementNode( $2 ); 943 } 1039 944 | statement 1040 945 ; … … 1043 948 statement 1044 949 | statement_list_nodecl statement 1045 { assert( $1 ); $1->set_last( $2 ); $$ = $1;}950 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 1046 951 ; 1047 952 … … 1087 992 if_control_expression: 1088 993 comma_expression 1089 { $$ = new IfCt rl( nullptr, $1 ); }994 { $$ = new IfCtl( nullptr, $1 ); } 1090 995 | c_declaration // no semi-colon 1091 { $$ = new IfCt rl( $1, nullptr ); }996 { $$ = new IfCtl( $1, nullptr ); } 1092 997 | cfa_declaration // no semi-colon 1093 { $$ = new IfCt rl( $1, nullptr ); }998 { $$ = new IfCtl( $1, nullptr ); } 1094 999 | declaration comma_expression // semi-colon separated 1095 { $$ = new IfCt rl( $1, $2 ); }1000 { $$ = new IfCtl( $1, $2 ); } 1096 1001 ; 1097 1002 … … 1149 1054 WHILE '(' push if_control_expression ')' statement pop 1150 1055 { $$ = new StatementNode( build_while( $4, $6 ) ); } 1151 | WHILE '(' ')' statement // CFA => while ( 1 )1152 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); }1153 1056 | DO statement WHILE '(' comma_expression ')' ';' 1154 1057 { $$ = new StatementNode( build_do_while( $5, $2 ) ); } 1155 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1156 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); } 1157 | FOR '(' push for_control_expression_list ')' statement pop 1058 | FOR '(' push for_control_expression ')' statement pop 1158 1059 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1159 | FOR '(' ')' statement // CFA => for ( ;; )1160 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4 ) ); }1161 ;1162 1163 for_control_expression_list:1164 for_control_expression1165 | for_control_expression_list ':' for_control_expression1166 // ForCtrl + ForCtrl:1167 // init + init => multiple declaration statements that are hoisted1168 // condition + condition => (expression) && (expression)1169 // change + change => (expression), (expression)1170 {1171 $1->init->set_last( $3->init );1172 if ( $1->condition ) {1173 if ( $3->condition ) {1174 $1->condition->expr.reset( new LogicalExpr( $1->condition->expr.release(), $3->condition->expr.release(), true ) );1175 } // if1176 } else $1->condition = $3->condition;1177 if ( $1->change ) {1178 if ( $3->change ) {1179 $1->change->expr.reset( new CommaExpr( $1->change->expr.release(), $3->change->expr.release() ) );1180 } // if1181 } else $1->change = $3->change;1182 $$ = $1;1183 }1184 1060 ; 1185 1061 1186 1062 for_control_expression: 1187 ';' comma_expression_opt ';' comma_expression_opt 1188 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); } 1189 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1190 { $$ = new ForCtrl( $1, $3, $5 ); } 1191 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1192 { $$ = new ForCtrl( $1, $2, $4 ); } 1193 1194 | comma_expression // CFA 1195 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 | comma_expression inclexcl comma_expression // CFA 1198 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1199 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1200 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1201 | comma_expression ';' comma_expression // CFA 1202 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1203 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1204 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1205 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1206 | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA 1207 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); } 1208 1209 // There is a S/R conflicit if ~ and -~ are factored out. 1210 | comma_expression ';' comma_expression '~' '@' // CFA 1211 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1212 | comma_expression ';' comma_expression ErangeDown '@' // CFA 1213 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1214 | comma_expression ';' comma_expression '~' '@' '~' comma_expression // CFA 1215 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, $7 ); } 1216 | comma_expression ';' comma_expression ErangeDown '@' '~' comma_expression // CFA 1217 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, $7 ); } 1218 | comma_expression ';' comma_expression '~' '@' '~' '@' // CFA 1219 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, nullptr ); } 1220 ; 1221 1222 inclexcl: 1223 '~' 1224 { $$ = OperKinds::LThan; } 1225 | ErangeUpEq 1226 { $$ = OperKinds::LEThan; } 1227 | ErangeDown 1228 { $$ = OperKinds::GThan; } 1229 | ErangeDownEq 1230 { $$ = OperKinds::GEThan; } 1063 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1064 { $$ = new ForCtl( $1, $3, $5 ); } 1065 | declaration comma_expression_opt ';' comma_expression_opt // C99 1066 { $$ = new ForCtl( $1, $2, $4 ); } 1231 1067 ; 1232 1068 … … 1261 1097 | RETURN comma_expression_opt ';' 1262 1098 { $$ = new StatementNode( build_return( $2 ) ); } 1263 | RETURN '{' initializer_list_opt comma_opt '}' ';'1099 | RETURN '{' initializer_list_opt comma_opt '}' 1264 1100 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1265 // | SUSPEND ';'1266 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }1267 // | SUSPEND compound_statement ';'1268 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }1269 1101 | THROW assignment_expression_opt ';' // handles rethrow 1270 1102 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1304 1136 1305 1137 waitfor: 1306 WAITFOR '(' cast_expression ')' 1307 { $$ = $3; } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1138 WAITFOR '(' identifier ')' 1139 { 1140 $$ = new ExpressionNode( new NameExpr( *$3 ) ); 1141 delete $3; 1142 } 1143 | WAITFOR '(' identifier ',' argument_expression_list ')' 1144 { 1145 $$ = new ExpressionNode( new NameExpr( *$3 ) ); 1146 $$->set_last( $5 ); 1147 delete $3; 1148 } 1310 1149 ; 1311 1150 … … 1324 1163 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); } 1325 1164 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1326 | when_clause_opt timeout statement WOR ELSE statement1327 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1328 1165 | when_clause_opt timeout statement WOR when_clause ELSE statement 1329 1166 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); } … … 1347 1184 1348 1185 handler_clause: 1349 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1186 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1350 1187 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); } 1351 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1188 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1352 1189 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); } 1353 1190 ; … … 1375 1212 | type_specifier_nobody variable_abstract_declarator 1376 1213 { $$ = $2->addType( $1 ); } 1377 | cfa_abstract_declarator_tuple identifier// CFA1214 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1378 1215 { $$ = $1->addName( $2 ); } 1379 1216 | cfa_abstract_declarator_tuple // CFA … … 1439 1276 1440 1277 label_list: 1441 identifier1278 no_attr_identifier 1442 1279 { 1443 1280 $$ = new LabelNode(); $$->labels.push_back( *$1 ); 1444 1281 delete $1; // allocated by lexer 1445 1282 } 1446 | label_list ',' identifier1283 | label_list ',' no_attr_identifier 1447 1284 { 1448 1285 $$ = $1; $1->labels.push_back( *$3 ); … … 1489 1326 1490 1327 local_label_list: // GCC, local label 1491 identifier_or_type_name1492 | local_label_list ',' identifier_or_type_name1328 no_attr_identifier_or_type_name 1329 | local_label_list ',' no_attr_identifier_or_type_name 1493 1330 ; 1494 1331 … … 1612 1449 $$ = $2->addTypedef(); 1613 1450 } 1614 | cfa_typedef_declaration pop ',' push identifier1451 | cfa_typedef_declaration pop ',' push no_attr_identifier 1615 1452 { 1616 1453 typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" ); … … 1652 1489 typedef_expression: 1653 1490 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1654 TYPEDEF identifier '=' assignment_expression1491 TYPEDEF no_attr_identifier '=' assignment_expression 1655 1492 { 1656 1493 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1657 1494 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1658 1495 } 1659 | typedef_expression pop ',' push identifier '=' assignment_expression1496 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1660 1497 { 1661 1498 // $$ = DeclarationNode::newName( 0 ); // unimplemented … … 1826 1663 | INT128 1827 1664 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); } 1828 | UINT1281829 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ); }1830 1665 | FLOAT 1831 1666 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); } 1667 | FLOAT80 1668 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); } 1669 | FLOAT128 1670 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); } 1832 1671 | DOUBLE 1833 1672 { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); } 1834 | uuFLOAT801835 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat80 ); }1836 | uuFLOAT1281837 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat128 ); }1838 | uFLOAT161839 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat16 ); }1840 | uFLOAT321841 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32 ); }1842 | uFLOAT32X1843 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32x ); }1844 | uFLOAT641845 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64 ); }1846 | uFLOAT64X1847 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64x ); }1848 | uFLOAT1281849 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); }1850 1673 | COMPLEX // C99 1851 1674 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } … … 1862 1685 | VALIST // GCC, __builtin_va_list 1863 1686 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } 1864 | AUTO_TYPE1865 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::AutoType ); }1866 1687 ; 1867 1688 … … 1897 1718 1898 1719 indirect_type: 1899 TYPEOF '(' type ')' // GCC: typeof( x) y;1720 TYPEOF '(' type ')' // GCC: typeof(x) y; 1900 1721 { $$ = $3; } 1901 | TYPEOF '(' comma_expression ')' // GCC: typeof( a+b) y;1722 | TYPEOF '(' comma_expression ')' // GCC: typeof(a+b) y; 1902 1723 { $$ = DeclarationNode::newTypeof( $3 ); } 1903 | BASETYPEOF '(' type ')' // CFA: basetypeof( x) y;1904 { $$ = DeclarationNode::new Typeof( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ), true); }1905 | BASETYPEOF '(' comma_expression ')' // CFA: basetypeof( a+b) y;1906 { $$ = DeclarationNode::new Typeof( $3, true); }1724 | ATTR_TYPEGENname '(' type ')' // CFA: e.g., @type(x) y; 1725 { $$ = DeclarationNode::newAttr( $1, $3 ); } 1726 | ATTR_TYPEGENname '(' comma_expression ')' // CFA: e.g., @type(a+b) y; 1727 { $$ = DeclarationNode::newAttr( $1, $3 ); } 1907 1728 | ZERO_T // CFA 1908 1729 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); } … … 1928 1749 { $$ = $3->addQualifiers( $1 ); } 1929 1750 | sue_type_specifier type_qualifier 1930 { 1931 if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type 1932 $$ = $1->addQualifiers( $2 ); 1933 } 1751 { $$ = $1->addQualifiers( $2 ); } 1934 1752 ; 1935 1753 … … 1974 1792 { $$ = DeclarationNode::newFromTypedef( $1 ); } 1975 1793 | '.' TYPEDEFname 1976 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }1794 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 1977 1795 | type_name '.' TYPEDEFname 1978 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }1796 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 1979 1797 | typegen_name 1980 1798 | '.' typegen_name 1981 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }1799 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 1982 1800 | type_name '.' typegen_name 1983 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }1801 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 1984 1802 ; 1985 1803 … … 2003 1821 ; 2004 1822 2005 fred:2006 // empty2007 { yyy = false; }2008 ;2009 2010 1823 aggregate_type: // struct, union 2011 aggregate_key attribute_list_opt 2012 { forall = false; } // reset 2013 '{' field_declaration_list_opt '}' type_parameters_opt 2014 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); } 2015 | aggregate_key attribute_list_opt identifier fred 2016 { 2017 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 1824 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' 1825 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1826 | aggregate_key attribute_list_opt no_attr_identifier 1827 { 1828 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef 1829 //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 2018 1830 forall = false; // reset 2019 1831 } 2020 '{' field_declaration_list_opt '}' type_parameters_opt2021 { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); }2022 | aggregate_key attribute_list_opt type_name fred2023 { 2024 // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one)2025 typedefTable.makeTypedef( *$3->type->leafName(), forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef1832 '{' field_declaration_list_opt '}' 1833 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1834 | aggregate_key attribute_list_opt type_name 1835 { 1836 typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef 1837 //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update 2026 1838 forall = false; // reset 2027 1839 } 2028 '{' field_declaration_list_opt '}' type_parameters_opt 2029 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); } 1840 '{' field_declaration_list_opt '}' 1841 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $6, true )->addQualifiers( $2 ); } 1842 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA 1843 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 2030 1844 | aggregate_type_nobody 2031 1845 ; 2032 1846 2033 type_parameters_opt:2034 // empty2035 { $$ = nullptr; } %prec '}'2036 | '(' type_list ')'2037 { $$ = $2; }2038 ;2039 2040 1847 aggregate_type_nobody: // struct, union - {...} 2041 aggregate_key attribute_list_opt identifier fred 2042 { 2043 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); 1848 aggregate_key attribute_list_opt no_attr_identifier 1849 { 1850 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); 1851 //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 2044 1852 forall = false; // reset 2045 1853 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 2046 1854 } 2047 | aggregate_key attribute_list_opt type_name fred 2048 { 2049 forall = false; // reset 1855 | aggregate_key attribute_list_opt type_name 1856 { 2050 1857 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is 2051 1858 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and … … 2060 1867 aggregate_key: 2061 1868 STRUCT 2062 { yyy = true;$$ = DeclarationNode::Struct; }1869 { $$ = DeclarationNode::Struct; } 2063 1870 | UNION 2064 { yyy = true;$$ = DeclarationNode::Union; }1871 { $$ = DeclarationNode::Union; } 2065 1872 | EXCEPTION 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 1873 { $$ = DeclarationNode::Exception; } 2069 1874 | COROUTINE 2070 { yyy = true;$$ = DeclarationNode::Coroutine; }1875 { $$ = DeclarationNode::Coroutine; } 2071 1876 | MONITOR 2072 { yyy = true;$$ = DeclarationNode::Monitor; }1877 { $$ = DeclarationNode::Monitor; } 2073 1878 | THREAD 2074 { yyy = true;$$ = DeclarationNode::Thread; }1879 { $$ = DeclarationNode::Thread; } 2075 1880 ; 2076 1881 … … 2083 1888 2084 1889 field_declaration: 2085 type_specifier field_declaring_list_opt ';' 2086 { $$ = fieldDecl( $1, $2 ); } 2087 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2088 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } 2089 | INLINE type_specifier field_abstract_list_opt ';' // CFA 2090 { 2091 if ( ! $3 ) { // field declarator ? 2092 $3 = DeclarationNode::newName( nullptr ); 2093 } // if 2094 $3->inLine = true; 2095 $$ = distAttr( $2, $3 ); // mark all fields in list 2096 distInl( $3 ); 2097 } 1890 type_specifier field_declaring_list ';' 1891 { $$ = distAttr( $1, $2 ); } 1892 | EXTENSION type_specifier field_declaring_list ';' // GCC 1893 { distExt( $3 ); $$ = distAttr( $2, $3 ); } // mark all fields in list 2098 1894 | typedef_declaration ';' // CFA 1895 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; } 2099 1896 | cfa_field_declaring_list ';' // CFA, new style field declaration 2100 1897 | EXTENSION cfa_field_declaring_list ';' // GCC 2101 1898 { distExt( $2 ); $$ = $2; } // mark all fields in list 2102 | INLINE cfa_field_abstract_list ';' // CFA, new style field declaration2103 { $$ = $2; } // mark all fields in list2104 1899 | cfa_typedef_declaration ';' // CFA 1900 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; } 2105 1901 | static_assert // C11 2106 1902 ; 2107 1903 2108 field_declaring_list_opt: 1904 cfa_field_declaring_list: // CFA, new style field declaration 1905 cfa_abstract_declarator_tuple // CFA, no field name 1906 | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name 1907 { $$ = $1->addName( $2 ); } 1908 | cfa_field_declaring_list ',' no_attr_identifier_or_type_name 1909 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 1910 | cfa_field_declaring_list ',' // CFA, no field name 1911 { $$ = $1->appendList( $1->cloneType( 0 ) ); } 1912 ; 1913 1914 field_declaring_list: 1915 field_declarator_opt 1916 | field_declaring_list ',' attribute_list_opt field_declarator_opt 1917 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1918 ; 1919 1920 field_declarator_opt: 2109 1921 // empty 2110 { $$ = nullptr; } 2111 | field_declarator 2112 | field_declaring_list_opt ',' attribute_list_opt field_declarator 2113 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 2114 ; 2115 2116 field_declarator: 2117 bit_subrange_size // C special case, no field name 1922 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name 1923 // '@' 1924 // { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name 1925 | bit_subrange_size // no field name 2118 1926 { $$ = DeclarationNode::newBitfield( $1 ); } 2119 1927 | variable_declarator bit_subrange_size_opt 2120 // A semantic check is required to ensure bit_subrange only appears on integral types.1928 // A semantic check is required to ensure bit_subrange only appears on base type int. 2121 1929 { $$ = $1->addBitfield( $2 ); } 2122 1930 | variable_type_redeclarator bit_subrange_size_opt 2123 // A semantic check is required to ensure bit_subrange only appears on integral types.1931 // A semantic check is required to ensure bit_subrange only appears on base type int. 2124 1932 { $$ = $1->addBitfield( $2 ); } 2125 ; 2126 2127 field_abstract_list_opt: 2128 // empty 2129 { $$ = nullptr; } 2130 | field_abstract 2131 | field_abstract_list_opt ',' attribute_list_opt field_abstract 2132 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 2133 ; 2134 2135 field_abstract: 2136 // no bit fields 2137 variable_abstract_declarator 2138 ; 2139 2140 cfa_field_declaring_list: // CFA, new style field declaration 2141 // bit-fields are handled by C declarations 2142 cfa_abstract_declarator_tuple identifier_or_type_name 2143 { $$ = $1->addName( $2 ); } 2144 | cfa_field_declaring_list ',' identifier_or_type_name 2145 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 2146 ; 2147 2148 cfa_field_abstract_list: // CFA, new style field declaration 2149 // bit-fields are handled by C declarations 2150 cfa_abstract_declarator_tuple 2151 | cfa_field_abstract_list ',' 2152 { $$ = $1->appendList( $1->cloneType( 0 ) ); } 1933 | variable_abstract_declarator // CFA, no field name 2153 1934 ; 2154 1935 … … 2160 1941 2161 1942 bit_subrange_size: 2162 ':' assignment_expression1943 ':' constant_expression 2163 1944 { $$ = $2; } 2164 1945 ; … … 2166 1947 enum_type: // enum 2167 1948 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2168 { $$ = DeclarationNode::newEnum( n ullptr, $4, true )->addQualifiers( $2 ); }2169 | ENUM attribute_list_opt identifier1949 { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); } 1950 | ENUM attribute_list_opt no_attr_identifier 2170 1951 { typedefTable.makeTypedef( *$3 ); } 2171 1952 '{' enumerator_list comma_opt '}' … … 2178 1959 2179 1960 enum_type_nobody: // enum - {...} 2180 ENUM attribute_list_opt identifier1961 ENUM attribute_list_opt no_attr_identifier 2181 1962 { 2182 1963 typedefTable.makeTypedef( *$3 ); … … 2191 1972 2192 1973 enumerator_list: 2193 identifier_or_type_name enumerator_value_opt1974 no_attr_identifier_or_type_name enumerator_value_opt 2194 1975 { $$ = DeclarationNode::newEnumConstant( $1, $2 ); } 2195 | enumerator_list ',' identifier_or_type_name enumerator_value_opt1976 | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt 2196 1977 { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); } 2197 1978 ; … … 2301 2082 2302 2083 identifier_list: // K&R-style parameter list => no types 2303 identifier2084 no_attr_identifier 2304 2085 { $$ = DeclarationNode::newName( $1 ); } 2305 | identifier_list ',' identifier2086 | identifier_list ',' no_attr_identifier 2306 2087 { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); } 2307 2088 ; … … 2309 2090 identifier_or_type_name: 2310 2091 identifier 2092 | TYPEDEFname 2093 | TYPEGENname 2094 ; 2095 2096 no_attr_identifier_or_type_name: 2097 no_attr_identifier 2311 2098 | TYPEDEFname 2312 2099 | TYPEGENname … … 2363 2150 designation: 2364 2151 designator_list ':' // C99, CFA uses ":" instead of "=" 2365 | identifier ':'// GCC, field name2152 | no_attr_identifier ':' // GCC, field name 2366 2153 { $$ = new ExpressionNode( build_varref( $1 ) ); } 2367 2154 ; … … 2375 2162 2376 2163 designator: 2377 '.' identifier// C99, field name2164 '.' no_attr_identifier // C99, field name 2378 2165 { $$ = new ExpressionNode( build_varref( $2 ) ); } 2379 2166 | '[' push assignment_expression pop ']' // C99, single array element … … 2384 2171 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2385 2172 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); } 2386 | '.' '[' push field_ name_list pop ']'// CFA, tuple field selector2173 | '.' '[' push field_list pop ']' // CFA, tuple field selector 2387 2174 { $$ = $4; } 2388 2175 ; … … 2420 2207 2421 2208 type_parameter: // CFA 2422 type_class identifier_or_type_name2209 type_class no_attr_identifier_or_type_name 2423 2210 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2424 2211 type_initializer_opt assertion_list_opt … … 2453 2240 2454 2241 assertion: // CFA 2455 '|' identifier_or_type_name '(' type_list ')'2242 '|' no_attr_identifier_or_type_name '(' type_list ')' 2456 2243 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2457 2244 | '|' '{' push trait_declaration_list pop '}' … … 2465 2252 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2466 2253 | assignment_expression 2467 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }2468 2254 | type_list ',' type 2469 2255 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2470 2256 | type_list ',' assignment_expression 2471 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } 2472 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2257 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2473 2258 ; 2474 2259 … … 2490 2275 2491 2276 type_declarator_name: // CFA 2492 identifier_or_type_name2277 no_attr_identifier_or_type_name 2493 2278 { 2494 2279 typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" ); 2495 2280 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2496 2281 } 2497 | identifier_or_type_name '(' type_parameter_list ')'2282 | no_attr_identifier_or_type_name '(' type_parameter_list ')' 2498 2283 { 2499 2284 typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" ); … … 2503 2288 2504 2289 trait_specifier: // CFA 2505 TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}'2290 TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2506 2291 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 2507 | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'2292 | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2508 2293 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 2509 2294 ; … … 2537 2322 2538 2323 translation_unit: 2539 // empty, input file 2324 // empty 2325 {} // empty input file 2540 2326 | external_definition_list 2541 2327 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; } … … 2545 2331 push external_definition pop 2546 2332 { $$ = $2; } 2547 | external_definition_list push external_definition pop 2333 | external_definition_list 2334 { forall = xxx; } 2335 push external_definition pop 2336 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2337 ; 2338 2339 // SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope. 2340 // However, external_definition_list creates a new scope around each external_definition, but the pop loses all the 2341 // types in the extern "X" and distribution at the end of the block. This version of external_definition_list does 2342 2343 // not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of 2344 // external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level. 2345 external_definition_list_no_pop_push: 2346 external_definition 2347 | external_definition_list_no_pop_push 2348 { forall = xxx; } 2349 external_definition 2548 2350 { $$ = $1 ? $1->appendList( $3 ) : $3; } 2549 2351 ; … … 2552 2354 // empty 2553 2355 { $$ = nullptr; } 2554 | external_definition_list 2555 ; 2556 2557 up: 2558 { typedefTable.up( forall ); forall = false; } 2559 ; 2560 2561 down: 2562 { typedefTable.down(); } 2356 | external_definition_list_no_pop_push 2563 2357 ; 2564 2358 … … 2580 2374 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2581 2375 } 2582 '{' up external_definition_list_opt down'}'2376 '{' external_definition_list_opt '}' 2583 2377 { 2584 2378 linkage = linkageStack.top(); 2585 2379 linkageStack.pop(); 2586 $$ = $ 6;2380 $$ = $5; 2587 2381 } 2588 2382 | type_qualifier_list 2589 { 2590 if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2591 if ( $1->type->forall ) forall = true; // remember generic type 2592 } 2593 '{' up external_definition_list_opt down '}' // CFA, namespace 2594 { 2595 distQual( $5, $1 ); 2596 forall = false; 2383 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2384 '{' external_definition_list_opt '}' // CFA, namespace 2385 { 2386 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2387 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2388 iter->addQualifiers( $1->clone() ); 2389 } // if 2390 } // for 2391 xxx = false; 2392 delete $1; 2393 $$ = $4; 2394 } 2395 | declaration_qualifier_list 2396 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2397 '{' external_definition_list_opt '}' // CFA, namespace 2398 { 2399 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2400 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2401 iter->addQualifiers( $1->clone() ); 2402 } // if 2403 } // for 2404 xxx = false; 2405 delete $1; 2406 $$ = $4; 2407 } 2408 | declaration_qualifier_list type_qualifier_list 2409 { 2410 // forall must be in the type_qualifier_list 2411 if ( $2->type->forall ) xxx = forall = true; // remember generic type 2412 } 2413 '{' external_definition_list_opt '}' // CFA, namespace 2414 { 2415 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2416 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2417 iter->addQualifiers( $1->clone() ); 2418 iter->addQualifiers( $2->clone() ); 2419 } // if 2420 } // for 2421 xxx = false; 2422 delete $1; 2423 delete $2; 2597 2424 $$ = $5; 2598 }2599 | declaration_qualifier_list2600 {2601 if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }2602 if ( $1->type && $1->type->forall ) forall = true; // remember generic type2603 }2604 '{' up external_definition_list_opt down '}' // CFA, namespace2605 {2606 distQual( $5, $1 );2607 forall = false;2608 $$ = $5;2609 }2610 | declaration_qualifier_list type_qualifier_list2611 {2612 if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }2613 if ( ($1->type && $1->type->forall) || $2->type->forall ) forall = true; // remember generic type2614 }2615 '{' up external_definition_list_opt down '}' // CFA, namespace2616 {2617 distQual( $6, $1->addQualifiers( $2 ) );2618 forall = false;2619 $$ = $6;2620 2425 } 2621 2426 ; … … 2927 2732 typedef 2928 2733 // hide type name in enclosing scope by variable name 2929 { 2930 // if ( ! typedefTable.existsCurr( *$1->name ) ) { 2931 typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); 2932 // } else { 2933 // SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr; 2934 // } // if 2935 } 2734 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); } 2936 2735 | '(' paren_type ')' 2937 2736 { $$ = $2; } … … 2944 2743 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2945 2744 | '(' type_ptr ')' attribute_list_opt 2946 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis2745 { $$ = $2->addQualifiers( $4 ); } 2947 2746 ; 2948 2747
Note:
See TracChangeset
for help on using the changeset viewer.