Changeset b067d9b for src/Parser/parser.yy
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r7951100 rb067d9b 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 10:07:12 201813 // Update Count : 352712 // Last Modified On : Sun Aug 4 21:48:23 2019 13 // Update Count : 4364 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 //cur->addType( specifier ); 102 for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 101 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 103 102 cl->cloneBaseType( cur ); 104 103 } // for 105 104 declList->addType( cl ); 106 // delete cl;107 105 return declList; 108 106 } // distAttr … … 114 112 } // for 115 113 } // distExt 114 115 void distInl( DeclarationNode * declaration ) { 116 // distribute EXTENSION across all declarations 117 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 118 iter->set_inLine( true ); 119 } // for 120 } // distInl 121 122 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 123 // distribute qualifiers across all non-variable declarations in a distribution statemement 124 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. Since 126 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To 127 // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to 128 // 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 } // if 145 } else { // just SC qualifiers 146 iter->addQualifiers( clone ); 147 } // if 148 } // for 149 delete qualifiers; 150 } // distQual 116 151 117 152 // There is an ambiguity for inline generic-routine return-types and generic routines. … … 136 171 } // build_postfix_name 137 172 138 bool forall = false, xxx = false; // aggregate have one or more forall qualifiers ? 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 ? 139 215 140 216 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 156 232 157 233 // Types declaration for productions 158 %union 159 { 234 %union { 160 235 Token tok; 161 236 ParseNode * pn; … … 167 242 WaitForStmt * wfs; 168 243 Expression * constant; 169 IfCtl * ifctl; 170 ForCtl * fctl; 244 IfCtrl * ifctl; 245 ForCtrl * fctl; 246 enum OperKinds compop; 171 247 LabelNode * label; 172 248 InitializerNode * in; … … 189 265 %token RESTRICT // C99 190 266 %token ATOMIC // C11 191 %token FORALL MUTEX VIRTUAL 267 %token FORALL MUTEX VIRTUAL COERCE // CFA 192 268 %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED 193 269 %token BOOL COMPLEX IMAGINARY // C99 194 %token INT128 FLOAT80 FLOAT128 // GCC 270 %token INT128 UINT128 uuFLOAT80 uuFLOAT128 // GCC 271 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC 195 272 %token ZERO_T ONE_T // CFA 196 273 %token VALIST // GCC 197 %token TYPEOF LABEL // GCC 274 %token AUTO_TYPE // GCC 275 %token TYPEOF BASETYPEOF LABEL // GCC 198 276 %token ENUM STRUCT UNION 199 277 %token EXCEPTION // CFA 200 %token COROUTINE MONITOR THREAD// CFA278 %token GENERATOR COROUTINE MONITOR THREAD // CFA 201 279 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 202 280 %token SIZEOF OFFSETOF 281 // %token SUSPEND RESUME // CFA 203 282 %token ATTRIBUTE EXTENSION // GCC 204 283 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 210 289 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname 211 290 %token<tok> TIMEOUT WOR 212 %token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname213 291 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 214 292 %token<tok> DIRECTIVE … … 231 309 %token ANDassign ERassign ORassign // &= ^= |= 232 310 311 %token ErangeUpEq ErangeDown ErangeDownEq // ~= -~ -~= 233 312 %token ATassign // @= 234 313 235 %type<tok> identifier no_attr_identifier236 %type<tok> identifier_or_type_name no_attr_identifier_or_type_nameattr_name314 %type<tok> identifier 315 %type<tok> identifier_or_type_name attr_name 237 316 %type<tok> quasi_keyword 238 317 %type<constant> string_literal … … 252 331 %type<en> argument_expression_list argument_expression default_initialize_opt 253 332 %type<ifctl> if_control_expression 254 %type<fctl> for_control_expression 333 %type<fctl> for_control_expression for_control_expression_list 334 %type<compop> inclexcl 255 335 %type<en> subrange 256 336 %type<decl> asm_name_opt 257 %type<en> asm_operands_opt asm_operands_listasm_operand337 %type<en> asm_operands_opt asm_operands_list asm_operand 258 338 %type<label> label_list 259 339 %type<en> asm_clobbers_list_opt 260 340 %type<flag> asm_volatile_opt 261 341 %type<en> handler_predicate_opt 262 %type<genexpr> generic_association 342 %type<genexpr> generic_association generic_assoc_list 263 343 264 344 // statements … … 304 384 %type<en> enumerator_value_opt 305 385 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 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 310 392 311 393 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 320 402 %type<decl> cfa_array_parameter_1st_dimension 321 403 322 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list 404 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list 323 405 %type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier 324 406 … … 355 437 %type<decl> type_parameter type_parameter_list type_initializer_opt 356 438 357 %type<en> type_ list439 %type<en> type_parameters_opt type_list 358 440 359 441 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 390 472 // Foo ( *fp )( int ); 391 473 // `---' matches start of TYPEGENname '(' 392 // Must be:474 // must be: 393 475 // 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 ); 394 480 395 481 // Order of these lines matters (low-to-high precedence). 396 482 %precedence TYPEGENname 483 %precedence '}' 397 484 %precedence '(' 485 486 // %precedence RESUME 487 // %precedence '{' 488 // %precedence ')' 398 489 399 490 %locations // support location tracking for error messages … … 457 548 identifier: 458 549 IDENTIFIER 459 | ATTR_IDENTIFIER // CFA460 550 | quasi_keyword 461 ; 462 463 no_attr_identifier: 464 IDENTIFIER 465 | quasi_keyword 551 | '@' // CFA 552 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; } 466 553 ; 467 554 … … 502 589 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call 503 590 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 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; } 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; } 510 595 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 511 596 { … … 514 599 $$ = new ExpressionNode( $5 ); 515 600 } 601 // | RESUME '(' comma_expression ')' 602 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; } 603 // | RESUME '(' comma_expression ')' compound_statement 604 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; } 516 605 ; 517 606 … … 553 642 | postfix_expression '(' argument_expression_list ')' 554 643 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 555 | postfix_expression '.' no_attr_identifier644 | postfix_expression '.' identifier 556 645 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } 557 646 | postfix_expression '.' INTEGERconstant // CFA, tuple index … … 559 648 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 560 649 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 561 | postfix_expression '.' '[' field_ list ']'// CFA, tuple field selector650 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 562 651 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 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 } 652 | postfix_expression ARROW identifier 653 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } 567 654 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 568 655 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 569 | postfix_expression ARROW '[' field_ list ']'// CFA, tuple field selector656 | postfix_expression ARROW '[' field_name_list ']' // CFA, tuple field selector 570 657 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 571 658 | postfix_expression ICR … … 586 673 587 674 argument_expression_list: 588 argument_expression 675 // empty 676 { $$ = nullptr; } 677 | argument_expression 589 678 | argument_expression_list ',' argument_expression 590 679 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } … … 592 681 593 682 argument_expression: 594 // empty 595 { $$ = nullptr; } 596 // | '@' // use default argument 597 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 683 '@' // CFA, default parameter 684 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 685 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 598 686 | assignment_expression 599 687 ; 600 688 601 field_ list:// CFA, tuple field selector689 field_name_list: // CFA, tuple field selector 602 690 field 603 | field_ list ',' field{ $$ = (ExpressionNode *)$1->set_last( $3 ); }691 | field_name_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); } 604 692 ; 605 693 … … 608 696 | FLOATING_DECIMALconstant field 609 697 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 610 | FLOATING_DECIMALconstant '[' field_ list ']'698 | FLOATING_DECIMALconstant '[' field_name_list ']' 611 699 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 612 700 | field_name '.' field 613 701 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 614 | field_name '.' '[' field_ list ']'702 | field_name '.' '[' field_name_list ']' 615 703 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 616 704 | field_name ARROW field 617 705 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 618 | field_name ARROW '[' field_ list ']'706 | field_name ARROW '[' field_name_list ']' 619 707 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 620 708 ; … … 625 713 | FLOATINGconstant fraction_constants_opt 626 714 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); } 627 | no_attr_identifier fraction_constants_opt715 | identifier fraction_constants_opt 628 716 { 629 717 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) ); … … 683 771 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 684 772 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } 685 | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'773 | OFFSETOF '(' type_no_function ',' identifier ')' 686 774 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); } 687 | ATTR_IDENTIFIER688 { $$ = 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 ) ) ); }693 775 ; 694 776 … … 711 793 | '(' type_no_function ')' cast_expression 712 794 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 795 // keyword cast cannot be grouped because of reduction in aggregate_key 796 | '(' GENERATOR '&' ')' cast_expression // CFA 797 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 713 798 | '(' COROUTINE '&' ')' cast_expression // CFA 714 799 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } … … 722 807 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 723 808 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 809 | '(' RETURN type_no_function ')' cast_expression // CFA 810 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } 811 | '(' COERCE type_no_function ')' cast_expression // CFA 812 { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; } 813 | '(' qualifier_cast_list ')' cast_expression // CFA 814 { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; } 724 815 // | '(' type_no_function ')' tuple 725 816 // { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 817 ; 818 819 qualifier_cast_list: 820 cast_modifier type_qualifier_name 821 | cast_modifier MUTEX 822 | qualifier_cast_list cast_modifier type_qualifier_name 823 | qualifier_cast_list cast_modifier MUTEX 824 ; 825 826 cast_modifier: 827 '-' 828 | '+' 726 829 ; 727 830 … … 904 1007 905 1008 labeled_statement: 906 // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER1009 // labels cannot be identifiers 0 or 1 907 1010 identifier_or_type_name ':' attribute_list_opt statement 908 { 909 $$ = $4->add_label( $1, $3 ); 910 } 1011 { $$ = $4->add_label( $1, $3 ); } 911 1012 ; 912 1013 … … 924 1025 statement_decl 925 1026 | statement_decl_list statement_decl 926 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; }}1027 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 927 1028 ; 928 1029 … … 931 1032 { $$ = new StatementNode( $1 ); } 932 1033 | EXTENSION declaration // GCC 933 { 934 distExt( $2 ); 935 $$ = new StatementNode( $2 ); 936 } 1034 { distExt( $2 ); $$ = new StatementNode( $2 ); } 937 1035 | function_definition 938 1036 { $$ = new StatementNode( $1 ); } 939 1037 | EXTENSION function_definition // GCC 940 { 941 distExt( $2 ); 942 $$ = new StatementNode( $2 ); 943 } 1038 { distExt( $2 ); $$ = new StatementNode( $2 ); } 944 1039 | statement 945 1040 ; … … 948 1043 statement 949 1044 | statement_list_nodecl statement 950 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; }}1045 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 951 1046 ; 952 1047 … … 992 1087 if_control_expression: 993 1088 comma_expression 994 { $$ = new IfCt l( nullptr, $1 ); }1089 { $$ = new IfCtrl( nullptr, $1 ); } 995 1090 | c_declaration // no semi-colon 996 { $$ = new IfCt l( $1, nullptr ); }1091 { $$ = new IfCtrl( $1, nullptr ); } 997 1092 | cfa_declaration // no semi-colon 998 { $$ = new IfCt l( $1, nullptr ); }1093 { $$ = new IfCtrl( $1, nullptr ); } 999 1094 | declaration comma_expression // semi-colon separated 1000 { $$ = new IfCt l( $1, $2 ); }1095 { $$ = new IfCtrl( $1, $2 ); } 1001 1096 ; 1002 1097 … … 1054 1149 WHILE '(' push if_control_expression ')' statement pop 1055 1150 { $$ = 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 ) ); } 1056 1153 | DO statement WHILE '(' comma_expression ')' ';' 1057 1154 { $$ = new StatementNode( build_do_while( $5, $2 ) ); } 1058 | FOR '(' push for_control_expression ')' statement pop 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 1059 1158 { $$ = 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_expression 1165 | for_control_expression_list ':' for_control_expression 1166 // ForCtrl + ForCtrl: 1167 // init + init => multiple declaration statements that are hoisted 1168 // 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 } // if 1176 } 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 } // if 1181 } else $1->change = $3->change; 1182 $$ = $1; 1183 } 1060 1184 ; 1061 1185 1062 1186 for_control_expression: 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 ); } 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; } 1067 1231 ; 1068 1232 … … 1097 1261 | RETURN comma_expression_opt ';' 1098 1262 { $$ = new StatementNode( build_return( $2 ) ); } 1099 | RETURN '{' initializer_list_opt comma_opt '}' 1263 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1100 1264 { 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; } 1101 1269 | THROW assignment_expression_opt ';' // handles rethrow 1102 1270 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1136 1304 1137 1305 waitfor: 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 } 1306 WAITFOR '(' cast_expression ')' 1307 { $$ = $3; } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1149 1310 ; 1150 1311 … … 1163 1324 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); } 1164 1325 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1326 | when_clause_opt timeout statement WOR ELSE statement 1327 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1165 1328 | when_clause_opt timeout statement WOR when_clause ELSE statement 1166 1329 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); } … … 1184 1347 1185 1348 handler_clause: 1186 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop1349 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1187 1350 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); } 1188 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop1351 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1189 1352 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); } 1190 1353 ; … … 1212 1375 | type_specifier_nobody variable_abstract_declarator 1213 1376 { $$ = $2->addType( $1 ); } 1214 | cfa_abstract_declarator_tuple no_attr_identifier// CFA1377 | cfa_abstract_declarator_tuple identifier // CFA 1215 1378 { $$ = $1->addName( $2 ); } 1216 1379 | cfa_abstract_declarator_tuple // CFA … … 1276 1439 1277 1440 label_list: 1278 no_attr_identifier1441 identifier 1279 1442 { 1280 1443 $$ = new LabelNode(); $$->labels.push_back( *$1 ); 1281 1444 delete $1; // allocated by lexer 1282 1445 } 1283 | label_list ',' no_attr_identifier1446 | label_list ',' identifier 1284 1447 { 1285 1448 $$ = $1; $1->labels.push_back( *$3 ); … … 1326 1489 1327 1490 local_label_list: // GCC, local label 1328 no_attr_identifier_or_type_name1329 | local_label_list ',' no_attr_identifier_or_type_name1491 identifier_or_type_name 1492 | local_label_list ',' identifier_or_type_name 1330 1493 ; 1331 1494 … … 1449 1612 $$ = $2->addTypedef(); 1450 1613 } 1451 | cfa_typedef_declaration pop ',' push no_attr_identifier1614 | cfa_typedef_declaration pop ',' push identifier 1452 1615 { 1453 1616 typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" ); … … 1489 1652 typedef_expression: 1490 1653 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1491 TYPEDEF no_attr_identifier '=' assignment_expression1654 TYPEDEF identifier '=' assignment_expression 1492 1655 { 1493 1656 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1494 1657 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1495 1658 } 1496 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression1659 | typedef_expression pop ',' push identifier '=' assignment_expression 1497 1660 { 1498 1661 // $$ = DeclarationNode::newName( 0 ); // unimplemented … … 1663 1826 | INT128 1664 1827 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); } 1828 | UINT128 1829 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ); } 1665 1830 | FLOAT 1666 1831 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); } 1667 | FLOAT801668 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }1669 | FLOAT1281670 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }1671 1832 | DOUBLE 1672 1833 { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); } 1834 | uuFLOAT80 1835 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat80 ); } 1836 | uuFLOAT128 1837 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat128 ); } 1838 | uFLOAT16 1839 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat16 ); } 1840 | uFLOAT32 1841 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32 ); } 1842 | uFLOAT32X 1843 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32x ); } 1844 | uFLOAT64 1845 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64 ); } 1846 | uFLOAT64X 1847 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64x ); } 1848 | uFLOAT128 1849 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); } 1673 1850 | COMPLEX // C99 1674 1851 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } … … 1685 1862 | VALIST // GCC, __builtin_va_list 1686 1863 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } 1864 | AUTO_TYPE 1865 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::AutoType ); } 1687 1866 ; 1688 1867 … … 1718 1897 1719 1898 indirect_type: 1720 TYPEOF '(' type ')' // GCC: typeof( x) y;1899 TYPEOF '(' type ')' // GCC: typeof( x ) y; 1721 1900 { $$ = $3; } 1722 | TYPEOF '(' comma_expression ')' // GCC: typeof( a+b) y;1901 | TYPEOF '(' comma_expression ')' // GCC: typeof( a+b ) y; 1723 1902 { $$ = DeclarationNode::newTypeof( $3 ); } 1724 | ATTR_TYPEGENname '(' type ')' // CFA: e.g., @type(x) y;1725 { $$ = DeclarationNode::new Attr( $1, $3); }1726 | ATTR_TYPEGENname '(' comma_expression ')' // CFA: e.g., @type(a+b) y;1727 { $$ = DeclarationNode::new Attr( $1, $3); }1903 | BASETYPEOF '(' type ')' // CFA: basetypeof( x ) y; 1904 { $$ = DeclarationNode::newTypeof( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ), true ); } 1905 | BASETYPEOF '(' comma_expression ')' // CFA: basetypeof( a+b ) y; 1906 { $$ = DeclarationNode::newTypeof( $3, true ); } 1728 1907 | ZERO_T // CFA 1729 1908 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); } … … 1749 1928 { $$ = $3->addQualifiers( $1 ); } 1750 1929 | sue_type_specifier type_qualifier 1751 { $$ = $1->addQualifiers( $2 ); } 1930 { 1931 if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type 1932 $$ = $1->addQualifiers( $2 ); 1933 } 1752 1934 ; 1753 1935 … … 1792 1974 { $$ = DeclarationNode::newFromTypedef( $1 ); } 1793 1975 | '.' TYPEDEFname 1794 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }1976 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); } 1795 1977 | type_name '.' TYPEDEFname 1796 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }1978 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); } 1797 1979 | typegen_name 1798 1980 | '.' typegen_name 1799 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }1981 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); } 1800 1982 | type_name '.' typegen_name 1801 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }1983 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); } 1802 1984 ; 1803 1985 … … 1821 2003 ; 1822 2004 2005 fred: 2006 // empty 2007 { yyy = false; } 2008 ; 2009 1823 2010 aggregate_type: // struct, union 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 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 1830 2018 forall = false; // reset 1831 2019 } 1832 '{' 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 typedef1837 //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update2020 '{' field_declaration_list_opt '}' type_parameters_opt 2021 { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); } 2022 | aggregate_key attribute_list_opt type_name fred 2023 { 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 typedef 1838 2026 forall = false; // reset 1839 2027 } 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 ); } 2028 '{' field_declaration_list_opt '}' type_parameters_opt 2029 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); } 1844 2030 | aggregate_type_nobody 1845 2031 ; 1846 2032 2033 type_parameters_opt: 2034 // empty 2035 { $$ = nullptr; } %prec '}' 2036 | '(' type_list ')' 2037 { $$ = $2; } 2038 ; 2039 1847 2040 aggregate_type_nobody: // struct, union - {...} 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 2041 aggregate_key attribute_list_opt identifier fred 2042 { 2043 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); 1852 2044 forall = false; // reset 1853 2045 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1854 2046 } 1855 | aggregate_key attribute_list_opt type_name 1856 { 2047 | aggregate_key attribute_list_opt type_name fred 2048 { 2049 forall = false; // reset 1857 2050 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is 1858 2051 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and … … 1867 2060 aggregate_key: 1868 2061 STRUCT 1869 { $$ = DeclarationNode::Struct; }2062 { yyy = true; $$ = DeclarationNode::Struct; } 1870 2063 | UNION 1871 { $$ = DeclarationNode::Union; }2064 { yyy = true; $$ = DeclarationNode::Union; } 1872 2065 | EXCEPTION 1873 { $$ = DeclarationNode::Exception; } 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 1874 2069 | COROUTINE 1875 { $$ = DeclarationNode::Coroutine; }2070 { yyy = true; $$ = DeclarationNode::Coroutine; } 1876 2071 | MONITOR 1877 { $$ = DeclarationNode::Monitor; }2072 { yyy = true; $$ = DeclarationNode::Monitor; } 1878 2073 | THREAD 1879 { $$ = DeclarationNode::Thread; }2074 { yyy = true; $$ = DeclarationNode::Thread; } 1880 2075 ; 1881 2076 … … 1888 2083 1889 2084 field_declaration: 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 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 } 1894 2098 | typedef_declaration ';' // CFA 1895 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }1896 2099 | cfa_field_declaring_list ';' // CFA, new style field declaration 1897 2100 | EXTENSION cfa_field_declaring_list ';' // GCC 1898 2101 { distExt( $2 ); $$ = $2; } // mark all fields in list 2102 | INLINE cfa_field_abstract_list ';' // CFA, new style field declaration 2103 { $$ = $2; } // mark all fields in list 1899 2104 | cfa_typedef_declaration ';' // CFA 1900 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }1901 2105 | static_assert // C11 1902 2106 ; 1903 2107 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 2108 field_declaring_list_opt: 2109 // empty 2110 { $$ = nullptr; } 2111 | field_declarator 2112 | field_declaring_list_opt ',' attribute_list_opt field_declarator 1917 2113 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1918 2114 ; 1919 2115 1920 field_declarator_opt: 1921 // empty 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 2116 field_declarator: 2117 bit_subrange_size // C special case, no field name 1926 2118 { $$ = DeclarationNode::newBitfield( $1 ); } 1927 2119 | variable_declarator bit_subrange_size_opt 1928 // A semantic check is required to ensure bit_subrange only appears on base type int.2120 // A semantic check is required to ensure bit_subrange only appears on integral types. 1929 2121 { $$ = $1->addBitfield( $2 ); } 1930 2122 | variable_type_redeclarator bit_subrange_size_opt 1931 // A semantic check is required to ensure bit_subrange only appears on base type int.2123 // A semantic check is required to ensure bit_subrange only appears on integral types. 1932 2124 { $$ = $1->addBitfield( $2 ); } 1933 | variable_abstract_declarator // CFA, no field name 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 ) ); } 1934 2153 ; 1935 2154 … … 1941 2160 1942 2161 bit_subrange_size: 1943 ':' constant_expression2162 ':' assignment_expression 1944 2163 { $$ = $2; } 1945 2164 ; … … 1947 2166 enum_type: // enum 1948 2167 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 1949 { $$ = DeclarationNode::newEnum( n ew string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }1950 | ENUM attribute_list_opt no_attr_identifier2168 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2169 | ENUM attribute_list_opt identifier 1951 2170 { typedefTable.makeTypedef( *$3 ); } 1952 2171 '{' enumerator_list comma_opt '}' … … 1959 2178 1960 2179 enum_type_nobody: // enum - {...} 1961 ENUM attribute_list_opt no_attr_identifier2180 ENUM attribute_list_opt identifier 1962 2181 { 1963 2182 typedefTable.makeTypedef( *$3 ); … … 1972 2191 1973 2192 enumerator_list: 1974 no_attr_identifier_or_type_name enumerator_value_opt2193 identifier_or_type_name enumerator_value_opt 1975 2194 { $$ = DeclarationNode::newEnumConstant( $1, $2 ); } 1976 | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt2195 | enumerator_list ',' identifier_or_type_name enumerator_value_opt 1977 2196 { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); } 1978 2197 ; … … 2082 2301 2083 2302 identifier_list: // K&R-style parameter list => no types 2084 no_attr_identifier2303 identifier 2085 2304 { $$ = DeclarationNode::newName( $1 ); } 2086 | identifier_list ',' no_attr_identifier2305 | identifier_list ',' identifier 2087 2306 { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); } 2088 2307 ; … … 2090 2309 identifier_or_type_name: 2091 2310 identifier 2092 | TYPEDEFname2093 | TYPEGENname2094 ;2095 2096 no_attr_identifier_or_type_name:2097 no_attr_identifier2098 2311 | TYPEDEFname 2099 2312 | TYPEGENname … … 2150 2363 designation: 2151 2364 designator_list ':' // C99, CFA uses ":" instead of "=" 2152 | no_attr_identifier ':'// GCC, field name2365 | identifier ':' // GCC, field name 2153 2366 { $$ = new ExpressionNode( build_varref( $1 ) ); } 2154 2367 ; … … 2162 2375 2163 2376 designator: 2164 '.' no_attr_identifier// C99, field name2377 '.' identifier // C99, field name 2165 2378 { $$ = new ExpressionNode( build_varref( $2 ) ); } 2166 2379 | '[' push assignment_expression pop ']' // C99, single array element … … 2171 2384 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2172 2385 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); } 2173 | '.' '[' push field_ list pop ']'// CFA, tuple field selector2386 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2174 2387 { $$ = $4; } 2175 2388 ; … … 2207 2420 2208 2421 type_parameter: // CFA 2209 type_class no_attr_identifier_or_type_name2422 type_class identifier_or_type_name 2210 2423 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2211 2424 type_initializer_opt assertion_list_opt … … 2240 2453 2241 2454 assertion: // CFA 2242 '|' no_attr_identifier_or_type_name '(' type_list ')'2455 '|' identifier_or_type_name '(' type_list ')' 2243 2456 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2244 2457 | '|' '{' push trait_declaration_list pop '}' … … 2252 2465 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2253 2466 | assignment_expression 2467 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2254 2468 | type_list ',' type 2255 2469 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2256 2470 | type_list ',' assignment_expression 2257 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2471 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } 2472 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2258 2473 ; 2259 2474 … … 2275 2490 2276 2491 type_declarator_name: // CFA 2277 no_attr_identifier_or_type_name2492 identifier_or_type_name 2278 2493 { 2279 2494 typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" ); 2280 2495 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2281 2496 } 2282 | no_attr_identifier_or_type_name '(' type_parameter_list ')'2497 | identifier_or_type_name '(' type_parameter_list ')' 2283 2498 { 2284 2499 typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" ); … … 2288 2503 2289 2504 trait_specifier: // CFA 2290 TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'2505 TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2291 2506 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 2292 | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'2507 | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2293 2508 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 2294 2509 ; … … 2322 2537 2323 2538 translation_unit: 2324 // empty 2325 {} // empty input file 2539 // empty, input file 2326 2540 | external_definition_list 2327 2541 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; } … … 2331 2545 push external_definition pop 2332 2546 { $$ = $2; } 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 2547 | external_definition_list push external_definition pop 2350 2548 { $$ = $1 ? $1->appendList( $3 ) : $3; } 2351 2549 ; … … 2354 2552 // empty 2355 2553 { $$ = nullptr; } 2356 | external_definition_list_no_pop_push 2554 | external_definition_list 2555 ; 2556 2557 up: 2558 { typedefTable.up( forall ); forall = false; } 2559 ; 2560 2561 down: 2562 { typedefTable.down(); } 2357 2563 ; 2358 2564 … … 2374 2580 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2375 2581 } 2376 '{' external_definition_list_opt'}'2582 '{' up external_definition_list_opt down '}' 2377 2583 { 2378 2584 linkage = linkageStack.top(); 2379 2585 linkageStack.pop(); 2586 $$ = $6; 2587 } 2588 | 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; 2380 2597 $$ = $5; 2381 2598 } 2382 | type_qualifier_list2383 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type2384 '{' external_definition_list_opt '}' // CFA, namespace2385 {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 } // if2390 } // for2391 xxx = false;2392 delete $1;2393 $$ = $4;2394 }2395 2599 | 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; 2600 { 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 type 2603 } 2604 '{' up external_definition_list_opt down '}' // CFA, namespace 2605 { 2606 distQual( $5, $1 ); 2607 forall = false; 2608 $$ = $5; 2407 2609 } 2408 2610 | declaration_qualifier_list type_qualifier_list 2409 2611 { 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; 2424 $$ = $5; 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 type 2614 } 2615 '{' up external_definition_list_opt down '}' // CFA, namespace 2616 { 2617 distQual( $6, $1->addQualifiers( $2 ) ); 2618 forall = false; 2619 $$ = $6; 2425 2620 } 2426 2621 ; … … 2732 2927 typedef 2733 2928 // hide type name in enclosing scope by variable name 2734 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); } 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 } 2735 2936 | '(' paren_type ')' 2736 2937 { $$ = $2; } … … 2743 2944 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2744 2945 | '(' type_ptr ')' attribute_list_opt 2745 { $$ = $2->addQualifiers( $4 ); } 2946 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis 2746 2947 ; 2747 2948
Note:
See TracChangeset
for help on using the changeset viewer.