Changeset e02e13f for src/Parser/parser.yy
- Timestamp:
- Apr 4, 2023, 10:12:57 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 9bb8ee42
- Parents:
- ff71057 (diff), bb7422a (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
rff71057 re02e13f 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 30 21:28:25202313 // Update Count : 632 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Apr 4 14:02:00 2023 13 // Update Count : 6329 14 14 // 15 15 … … 64 64 65 65 extern DeclarationNode * parseTree; 66 extern LinkageSpec::Spec linkage;66 extern ast::Linkage::Spec linkage; 67 67 extern TypedefTable typedefTable; 68 68 69 stack< LinkageSpec::Spec> linkageStack;69 stack<ast::Linkage::Spec> linkageStack; 70 70 71 71 bool appendStr( string & to, string & from ) { … … 200 200 } // fieldDecl 201 201 202 #define NEW_ZERO new ExpressionNode( build_constantInteger( *new string( "0" ) ) )203 #define NEW_ONE new ExpressionNode( build_constantInteger( *new string( "1" ) ) )202 #define NEW_ZERO new ExpressionNode( build_constantInteger( yylloc, *new string( "0" ) ) ) 203 #define NEW_ONE new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) ) 204 204 #define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right) 205 205 #define MISSING_ANON_FIELD "Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body." … … 208 208 209 209 static ForCtrl * makeForCtrl( 210 const CodeLocation & location, 210 211 DeclarationNode * init, 211 212 enum OperKinds compop, … … 213 214 ExpressionNode * inc ) { 214 215 // Wrap both comp/inc if they are non-null. 215 if ( comp ) comp = new ExpressionNode( build_binary_val( 216 if ( comp ) comp = new ExpressionNode( build_binary_val( location, 216 217 compop, 217 new ExpressionNode( build_varref( new string( *init->name ) ) ),218 new ExpressionNode( build_varref( location, new string( *init->name ) ) ), 218 219 comp ) ); 219 if ( inc ) inc = new ExpressionNode( build_binary_val( 220 if ( inc ) inc = new ExpressionNode( build_binary_val( location, 220 221 // choose += or -= for upto/downto 221 222 compop == OperKinds::LThan || compop == OperKinds::LEThan ? OperKinds::PlusAssn : OperKinds::MinusAssn, 222 new ExpressionNode( build_varref( new string( *init->name ) ) ),223 new ExpressionNode( build_varref( location, new string( *init->name ) ) ), 223 224 inc ) ); 224 225 // The StatementNode call frees init->name, it must happen later. … … 226 227 } 227 228 228 ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {229 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 229 230 if ( index->initializer ) { 230 231 SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." ); … … 234 235 } // if 235 236 DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) ); 236 return makeForCtrl( initDecl, compop, comp, inc );237 return makeForCtrl( location, initDecl, compop, comp, inc ); 237 238 } // forCtrl 238 239 239 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {240 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());241 if ( constant && (constant-> get_constant()->get_value() == "0" || constant->get_constant()->get_value()== "1") ) {242 type = new ExpressionNode( new CastExpr( maybeMoveBuild( type ), new BasicType( Type::Qualifiers(),BasicType::SignedInt ) ) );240 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 241 ast::ConstantExpr * constant = dynamic_cast<ast::ConstantExpr *>(type->expr.get()); 242 if ( constant && (constant->rep == "0" || constant->rep == "1") ) { 243 type = new ExpressionNode( new ast::CastExpr( location, maybeMoveBuild(type), new ast::BasicType( ast::BasicType::SignedInt ) ) ); 243 244 } // if 244 245 DeclarationNode * initDecl = distAttr( … … 246 247 DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) 247 248 ); 248 return makeForCtrl( initDecl, compop, comp, inc );249 return makeForCtrl( location, initDecl, compop, comp, inc ); 249 250 } // forCtrl 250 251 251 ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {252 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->expr.get()) ) {253 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );254 } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->expr.get()) ) {255 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1) ) {256 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );252 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 253 if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) { 254 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 255 } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) { 256 if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) { 257 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 257 258 } else { 258 259 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; … … 299 300 ExpressionNode * en; 300 301 DeclarationNode * decl; 301 AggregateDecl::Aggregate aggKey;302 TypeDecl::Kind tclass;302 ast::AggregateDecl::Aggregate aggKey; 303 ast::TypeDecl::Kind tclass; 303 304 StatementNode * sn; 304 WaitForStmt * wfs;305 Expression* constant;305 ast::WaitForStmt * wfs; 306 ast::Expr * constant; 306 307 CondCtl * ifctl; 307 308 ForCtrl * fctl; … … 313 314 bool flag; 314 315 EnumHiding hide; 315 CatchStmt::Kind catch_kind;316 GenericExpr * genexpr;316 ast::ExceptionKind catch_kind; 317 ast::GenericExpr * genexpr; 317 318 } 318 319 319 // ************************* TERMINAL TOKENS ********************************320 // ************************ TERMINAL TOKENS ******************************** 320 321 321 322 // keywords … … 611 612 constant: 612 613 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 613 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }614 | FLOATING_DECIMALconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }615 | FLOATING_FRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }616 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }617 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }614 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( yylloc, *$1 ) ); } 615 | FLOATING_DECIMALconstant { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); } 616 | FLOATING_FRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); } 617 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); } 618 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( yylloc, *$1 ) ); } 618 619 ; 619 620 … … 641 642 642 643 string_literal: 643 string_literal_list { $$ = build_constantStr( *$1 ); }644 string_literal_list { $$ = build_constantStr( yylloc, *$1 ); } 644 645 ; 645 646 … … 658 659 primary_expression: 659 660 IDENTIFIER // typedef name cannot be used as a variable name 660 { $$ = new ExpressionNode( build_varref( $1 ) ); }661 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 661 662 | quasi_keyword 662 { $$ = new ExpressionNode( build_varref( $1 ) ); }663 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 663 664 | TYPEDIMname // CFA, generic length argument 664 665 // { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( DeclarationNode::newFromTypedef( $1 ) ) ) ); } 665 666 // { $$ = new ExpressionNode( build_varref( $1 ) ); } 666 { $$ = new ExpressionNode( build_dimensionref( $1 ) ); }667 { $$ = new ExpressionNode( build_dimensionref( yylloc, $1 ) ); } 667 668 | tuple 668 669 | '(' comma_expression ')' 669 670 { $$ = $2; } 670 671 | '(' compound_statement ')' // GCC, lambda expression 671 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild( $2 ) ) ) ); }672 { $$ = new ExpressionNode( new ast::StmtExpr( yylloc, dynamic_cast<ast::CompoundStmt *>( maybeMoveBuild( $2 ) ) ) ); } 672 673 | type_name '.' identifier // CFA, nested type 673 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref($3 ) ) ); }674 { $$ = new ExpressionNode( build_qualified_expr( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 674 675 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 675 676 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 703 704 { 704 705 // steal the association node from the singleton and delete the wrapper 705 $1->associations.splice($1->associations.end(), $3->associations); 706 assert( 1 == $3->associations.size() ); 707 $1->associations.push_back( $3->associations.front() ); 706 708 delete $3; 707 709 $$ = $1; … … 713 715 { 714 716 // create a GenericExpr wrapper with one association pair 715 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild( $3 ) } } );717 $$ = new ast::GenericExpr( yylloc, nullptr, { { maybeMoveBuildType( $1 ), maybeMoveBuild( $3 ) } } ); 716 718 } 717 719 | DEFAULT ':' assignment_expression 718 { $$ = new GenericExpr(nullptr, { { maybeMoveBuild( $3 ) } } ); }720 { $$ = new ast::GenericExpr( yylloc, nullptr, { { maybeMoveBuild( $3 ) } } ); } 719 721 ; 720 722 … … 725 727 // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts. 726 728 // Current: Commas in subscripts make tuples. 727 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple((ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }729 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); } 728 730 | postfix_expression '[' assignment_expression ']' 729 731 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a … … 731 733 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 732 734 // equivalent to the old x[i,j]. 733 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }735 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 734 736 | constant '[' assignment_expression ']' // 3[a], 'a'[a], 3.5[a] 735 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }737 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 736 738 | string_literal '[' assignment_expression ']' // "abc"[3], 3["abc"] 737 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }739 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); } 738 740 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 739 741 { 740 742 Token fn; 741 743 fn.str = new std::string( "?{}" ); // location undefined - use location of '{'? 742 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref(fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );744 $$ = new ExpressionNode( new ast::ConstructorExpr( yylloc, build_func( yylloc, new ExpressionNode( build_varref( yylloc, fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 743 745 } 744 746 | postfix_expression '(' argument_expression_list_opt ')' 745 { $$ = new ExpressionNode( build_func( $1, $3 ) ); }747 { $$ = new ExpressionNode( build_func( yylloc, $1, $3 ) ); } 746 748 | VA_ARG '(' primary_expression ',' declaration_specifier_nobody abstract_parameter_declarator_opt ')' 747 749 // { SemanticError( yylloc, "va_arg is currently unimplemented." ); $$ = nullptr; } 748 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(new string( "__builtin_va_arg") ) ),750 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, new string( "__builtin_va_arg") ) ), 749 751 (ExpressionNode *)($3->set_last( (ExpressionNode *)($6 ? $6->addType( $5 ) : $5) )) ) ); } 750 752 | postfix_expression '`' identifier // CFA, postfix call 751 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(build_postfix_name( $3 ) ) ), $1 ) ); }753 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 752 754 | constant '`' identifier // CFA, postfix call 753 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(build_postfix_name( $3 ) ) ), $1 ) ); }755 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 754 756 | string_literal '`' identifier // CFA, postfix call 755 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }757 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); } 756 758 | postfix_expression '.' identifier 757 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref($3 ) ) ); }759 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 758 760 | postfix_expression '.' INTEGERconstant // CFA, tuple index 759 { $$ = new ExpressionNode( build_fieldSel( $1, build_constantInteger(*$3 ) ) ); }761 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); } 760 762 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 761 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant(*$2 ) ) ); }763 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_field_name_FLOATING_FRACTIONconstant( yylloc, *$2 ) ) ); } 762 764 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 763 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple($4 ) ) ); }765 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 764 766 | postfix_expression '.' aggregate_control 765 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }767 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $3, $1 ) ); } 766 768 | postfix_expression ARROW identifier 767 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref($3 ) ) ); }769 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 768 770 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 769 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger(*$3 ) ) ); }771 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); } 770 772 | postfix_expression ARROW '[' field_name_list ']' // CFA, tuple field selector 771 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple($4 ) ) ); }773 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 772 774 | postfix_expression ICR 773 { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }775 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::IncrPost, $1 ) ); } 774 776 | postfix_expression DECR 775 { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }777 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::DecrPost, $1 ) ); } 776 778 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 777 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }779 { $$ = new ExpressionNode( build_compoundLiteral( yylloc, $2, new InitializerNode( $5, true ) ) ); } 778 780 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 779 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }781 { $$ = new ExpressionNode( build_compoundLiteral( yylloc, $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 780 782 | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call 781 783 { 782 784 Token fn; 783 785 fn.str = new string( "^?{}" ); // location undefined 784 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) );786 $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ); 785 787 } 786 788 ; … … 813 815 field_name 814 816 | FLOATING_DECIMALconstant field 815 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant(*$1 ) ), maybeMoveBuild( $2 ) ) ); }817 { $$ = new ExpressionNode( build_fieldSel( yylloc, new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( yylloc, *$1 ) ), maybeMoveBuild( $2 ) ) ); } 816 818 | FLOATING_DECIMALconstant '[' field_name_list ']' 817 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple($3 ) ) ); }819 { $$ = new ExpressionNode( build_fieldSel( yylloc, new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( yylloc, *$1 ) ), build_tuple( yylloc, $3 ) ) ); } 818 820 | field_name '.' field 819 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild( $3 ) ) ); }821 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, maybeMoveBuild( $3 ) ) ); } 820 822 | field_name '.' '[' field_name_list ']' 821 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple($4 ) ) ); }823 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 822 824 | field_name ARROW field 823 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild( $3 ) ) ); }825 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, maybeMoveBuild( $3 ) ) ); } 824 826 | field_name ARROW '[' field_name_list ']' 825 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple($4 ) ) ); }827 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 826 828 ; 827 829 828 830 field_name: 829 831 INTEGERconstant fraction_constants_opt 830 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger(*$1 ), $2 ) ); }832 { $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_constantInteger( yylloc, *$1 ), $2 ) ); } 831 833 | FLOATINGconstant fraction_constants_opt 832 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant(*$1 ), $2 ) ); }834 { $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_field_name_FLOATINGconstant( yylloc, *$1 ), $2 ) ); } 833 835 | identifier_at fraction_constants_opt // CFA, allow anonymous fields 834 836 { 835 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref($1 ), $2 ) );837 $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_varref( yylloc, $1 ), $2 ) ); 836 838 } 837 839 ; … … 842 844 | fraction_constants_opt FLOATING_FRACTIONconstant 843 845 { 844 Expression * constant = build_field_name_FLOATING_FRACTIONconstant(*$2 );845 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1,constant ) ) : new ExpressionNode( constant );846 ast::Expr * constant = build_field_name_FLOATING_FRACTIONconstant( yylloc, *$2 ); 847 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( yylloc, $1, constant ) ) : new ExpressionNode( constant ); 846 848 } 847 849 ; … … 862 864 { 863 865 switch ( $1 ) { 864 865 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild( $2 ) ) );866 case OperKinds::AddressOf: 867 $$ = new ExpressionNode( new ast::AddressExpr( maybeMoveBuild( $2 ) ) ); 866 868 break; 867 868 $$ = new ExpressionNode( build_unary_val( $1, $2 ) );869 case OperKinds::PointTo: 870 $$ = new ExpressionNode( build_unary_val( yylloc, $1, $2 ) ); 869 871 break; 870 871 $$ = new ExpressionNode( new AddressExpr( newAddressExpr( maybeMoveBuild( $2 ) ) ) );872 case OperKinds::And: 873 $$ = new ExpressionNode( new ast::AddressExpr( new ast::AddressExpr( maybeMoveBuild( $2 ) ) ) ); 872 874 break; 873 875 default: 874 876 assert( false ); 875 877 } 876 878 } 877 879 | unary_operator cast_expression 878 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }880 { $$ = new ExpressionNode( build_unary_val( yylloc, $1, $2 ) ); } 879 881 | ICR unary_expression 880 { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }882 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::Incr, $2 ) ); } 881 883 | DECR unary_expression 882 { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }884 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::Decr, $2 ) ); } 883 885 | SIZEOF unary_expression 884 { $$ = new ExpressionNode( new SizeofExpr(maybeMoveBuild( $2 ) ) ); }886 { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuild( $2 ) ) ); } 885 887 | SIZEOF '(' type_no_function ')' 886 { $$ = new ExpressionNode( new SizeofExpr(maybeMoveBuildType( $3 ) ) ); }888 { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 887 889 | ALIGNOF unary_expression // GCC, variable alignment 888 { $$ = new ExpressionNode( new AlignofExpr(maybeMoveBuild( $2 ) ) ); }890 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuild( $2 ) ) ); } 889 891 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 890 { $$ = new ExpressionNode( new AlignofExpr(maybeMoveBuildType( $3 ) ) ); }892 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 891 893 | OFFSETOF '(' type_no_function ',' identifier ')' 892 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref($5 ) ) ); }894 { $$ = new ExpressionNode( build_offsetOf( yylloc, $3, build_varref( yylloc, $5 ) ) ); } 893 895 | TYPEID '(' type_no_function ')' 894 896 { … … 915 917 unary_expression 916 918 | '(' type_no_function ')' cast_expression 917 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }919 { $$ = new ExpressionNode( build_cast( yylloc, $2, $4 ) ); } 918 920 | '(' aggregate_control '&' ')' cast_expression // CFA 919 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }921 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); } 920 922 | '(' aggregate_control '*' ')' cast_expression // CFA 921 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }923 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); } 922 924 | '(' VIRTUAL ')' cast_expression // CFA 923 { $$ = new ExpressionNode( new VirtualCastExpr(maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); }925 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); } 924 926 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 925 { $$ = new ExpressionNode( new VirtualCastExpr(maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); }927 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); } 926 928 | '(' RETURN type_no_function ')' cast_expression // CFA 927 929 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } … … 931 933 { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; } 932 934 // | '(' type_no_function ')' tuple 933 // { $$ = new ExpressionNode( build_cast($2, $4 ) ); }935 // { $$ = new ast::ExpressionNode( build_cast( yylloc, $2, $4 ) ); } 934 936 ; 935 937 … … 949 951 cast_expression 950 952 | exponential_expression '\\' cast_expression 951 { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }953 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Exp, $1, $3 ) ); } 952 954 ; 953 955 … … 955 957 exponential_expression 956 958 | multiplicative_expression '*' exponential_expression 957 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }959 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Mul, $1, $3 ) ); } 958 960 | multiplicative_expression '/' exponential_expression 959 { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }961 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Div, $1, $3 ) ); } 960 962 | multiplicative_expression '%' exponential_expression 961 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }963 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Mod, $1, $3 ) ); } 962 964 ; 963 965 … … 965 967 multiplicative_expression 966 968 | additive_expression '+' multiplicative_expression 967 { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); }969 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Plus, $1, $3 ) ); } 968 970 | additive_expression '-' multiplicative_expression 969 { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); }971 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Minus, $1, $3 ) ); } 970 972 ; 971 973 … … 973 975 additive_expression 974 976 | shift_expression LS additive_expression 975 { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); }977 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LShift, $1, $3 ) ); } 976 978 | shift_expression RS additive_expression 977 { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); }979 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::RShift, $1, $3 ) ); } 978 980 ; 979 981 … … 981 983 shift_expression 982 984 | relational_expression '<' shift_expression 983 { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); }985 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LThan, $1, $3 ) ); } 984 986 | relational_expression '>' shift_expression 985 { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); }987 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::GThan, $1, $3 ) ); } 986 988 | relational_expression LE shift_expression 987 { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); }989 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LEThan, $1, $3 ) ); } 988 990 | relational_expression GE shift_expression 989 { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); }991 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::GEThan, $1, $3 ) ); } 990 992 ; 991 993 … … 993 995 relational_expression 994 996 | equality_expression EQ relational_expression 995 { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); }997 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Eq, $1, $3 ) ); } 996 998 | equality_expression NE relational_expression 997 { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); }999 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Neq, $1, $3 ) ); } 998 1000 ; 999 1001 … … 1001 1003 equality_expression 1002 1004 | AND_expression '&' equality_expression 1003 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); }1005 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::BitAnd, $1, $3 ) ); } 1004 1006 ; 1005 1007 … … 1007 1009 AND_expression 1008 1010 | exclusive_OR_expression '^' AND_expression 1009 { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); }1011 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Xor, $1, $3 ) ); } 1010 1012 ; 1011 1013 … … 1013 1015 exclusive_OR_expression 1014 1016 | inclusive_OR_expression '|' exclusive_OR_expression 1015 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); }1017 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::BitOr, $1, $3 ) ); } 1016 1018 ; 1017 1019 … … 1019 1021 inclusive_OR_expression 1020 1022 | logical_AND_expression ANDAND inclusive_OR_expression 1021 { $$ = new ExpressionNode( build_and_or( $1, $3, true) ); }1023 { $$ = new ExpressionNode( build_and_or( yylloc, $1, $3, ast::AndExpr ) ); } 1022 1024 ; 1023 1025 … … 1025 1027 logical_AND_expression 1026 1028 | logical_OR_expression OROR logical_AND_expression 1027 { $$ = new ExpressionNode( build_and_or( $1, $3, false) ); }1029 { $$ = new ExpressionNode( build_and_or( yylloc, $1, $3, ast::OrExpr ) ); } 1028 1030 ; 1029 1031 … … 1031 1033 logical_OR_expression 1032 1034 | logical_OR_expression '?' comma_expression ':' conditional_expression 1033 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }1035 { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); } 1034 1036 // FIX ME: computes $1 twice 1035 1037 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 1036 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }1038 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1, $4 ) ); } 1037 1039 ; 1038 1040 … … 1049 1051 // SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr; 1050 1052 // } else { 1051 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) );1053 $$ = new ExpressionNode( build_binary_val( yylloc, $2, $1, $3 ) ); 1052 1054 // } // if 1053 1055 } … … 1094 1096 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 1095 1097 '[' ',' tuple_expression_list ']' 1096 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }1098 { $$ = new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 1097 1099 | '[' push assignment_expression pop ',' tuple_expression_list ']' 1098 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); }1100 { $$ = new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)($3->set_last( $6 ) ) )); } 1099 1101 ; 1100 1102 … … 1112 1114 assignment_expression 1113 1115 | comma_expression ',' assignment_expression 1114 { $$ = new ExpressionNode( new CommaExpr(maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }1116 { $$ = new ExpressionNode( new ast::CommaExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1115 1117 ; 1116 1118 … … 1139 1141 | asm_statement 1140 1142 | DIRECTIVE 1141 { $$ = new StatementNode( build_directive( $1 ) ); }1143 { $$ = new StatementNode( build_directive( yylloc, $1 ) ); } 1142 1144 ; 1143 1145 … … 1145 1147 // labels cannot be identifiers 0 or 1 1146 1148 identifier_or_type_name ':' attribute_list_opt statement 1147 { $$ = $4->add_label( $1, $3 ); }1149 { $$ = $4->add_label( yylloc, $1, $3 ); } 1148 1150 | identifier_or_type_name ':' attribute_list_opt error // syntax error 1149 1151 { … … 1157 1159 compound_statement: 1158 1160 '{' '}' 1159 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }1161 { $$ = new StatementNode( build_compound( yylloc, (StatementNode *)0 ) ); } 1160 1162 | '{' push 1161 1163 local_label_declaration_opt // GCC, local labels appear at start of block 1162 1164 statement_decl_list // C99, intermix declarations and statements 1163 1165 pop '}' 1164 { $$ = new StatementNode( build_compound( $4 ) ); }1166 { $$ = new StatementNode( build_compound( yylloc, $4 ) ); } 1165 1167 ; 1166 1168 … … 1193 1195 expression_statement: 1194 1196 comma_expression_opt ';' 1195 { $$ = new StatementNode( build_expr( $1 ) ); }1197 { $$ = new StatementNode( build_expr( yylloc, $1 ) ); } 1196 1198 ; 1197 1199 … … 1202 1204 { $$ = $2; } 1203 1205 | SWITCH '(' comma_expression ')' case_clause 1204 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }1206 { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); } 1205 1207 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 1206 1208 { 1207 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );1209 StatementNode *sw = new StatementNode( build_switch( yylloc, true, $3, $8 ) ); 1208 1210 // The semantics of the declaration list is changed to include associated initialization, which is performed 1209 1211 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 1211 1213 // therefore, are removed from the grammar even though C allows it. The change also applies to choose 1212 1214 // statement. 1213 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;1215 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1214 1216 } 1215 1217 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, syntax error 1216 1218 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; } 1217 1219 | CHOOSE '(' comma_expression ')' case_clause // CFA 1218 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }1220 { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); } 1219 1221 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 1220 1222 { 1221 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );1222 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;1223 StatementNode *sw = new StatementNode( build_switch( yylloc, false, $3, $8 ) ); 1224 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1223 1225 } 1224 1226 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, syntax error … … 1229 1231 IF '(' conditional_declaration ')' statement %prec THEN 1230 1232 // explicitly deal with the shift/reduce conflict on if/else 1231 { $$ = new StatementNode( build_if( $3, maybe_build_compound($5 ), nullptr ) ); }1233 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); } 1232 1234 | IF '(' conditional_declaration ')' statement ELSE statement 1233 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound($7 ) ) ); }1235 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); } 1234 1236 ; 1235 1237 … … 1251 1253 constant_expression { $$ = $1; } 1252 1254 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1253 { $$ = new ExpressionNode( new RangeExpr(maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }1255 { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1254 1256 | subrange // CFA, subrange 1255 1257 ; … … 1267 1269 | CASE case_value_list error // syntax error 1268 1270 { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; } 1269 | DEFAULT ':' { $$ = new StatementNode( build_default( ) ); }1271 | DEFAULT ':' { $$ = new StatementNode( build_default( yylloc ) ); } 1270 1272 // A semantic check is required to ensure only one default clause per switch/choose statement. 1271 1273 | DEFAULT error // syntax error … … 1279 1281 1280 1282 case_clause: // CFA 1281 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( $2 ) ); }1283 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( yylloc, $2 ) ); } 1282 1284 ; 1283 1285 … … 1290 1292 switch_clause_list: // CFA 1291 1293 case_label_list statement_list_nodecl 1292 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }1294 { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); } 1293 1295 | switch_clause_list case_label_list statement_list_nodecl 1294 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }1296 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ) ); } 1295 1297 ; 1296 1298 1297 1299 iteration_statement: 1298 1300 WHILE '(' ')' statement %prec THEN // CFA => while ( 1 ) 1299 { $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound($4 ) ) ); }1301 { $$ = new StatementNode( build_while( yylloc, new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( yylloc, $4 ) ) ); } 1300 1302 | WHILE '(' ')' statement ELSE statement // CFA 1301 1303 { 1302 $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound($4 ) ) );1304 $$ = new StatementNode( build_while( yylloc, new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( yylloc, $4 ) ) ); 1303 1305 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1304 1306 } 1305 1307 | WHILE '(' conditional_declaration ')' statement %prec THEN 1306 { $$ = new StatementNode( build_while( $3, maybe_build_compound($5 ) ) ); }1308 { $$ = new StatementNode( build_while( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); } 1307 1309 | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA 1308 { $$ = new StatementNode( build_while( $3, maybe_build_compound($5 ), $7 ) ); }1310 { $$ = new StatementNode( build_while( yylloc, $3, maybe_build_compound( yylloc, $5 ), $7 ) ); } 1309 1311 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1310 { $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound($2 ) ) ); }1312 { $$ = new StatementNode( build_do_while( yylloc, NEW_ONE, maybe_build_compound( yylloc, $2 ) ) ); } 1311 1313 | DO statement WHILE '(' ')' ELSE statement // CFA 1312 1314 { 1313 $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound($2 ) ) );1315 $$ = new StatementNode( build_do_while( yylloc, NEW_ONE, maybe_build_compound( yylloc, $2 ) ) ); 1314 1316 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1315 1317 } 1316 1318 | DO statement WHILE '(' comma_expression ')' ';' 1317 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound($2 ) ) ); }1319 { $$ = new StatementNode( build_do_while( yylloc, $5, maybe_build_compound( yylloc, $2 ) ) ); } 1318 1320 | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA 1319 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound($2 ), $8 ) ); }1321 { $$ = new StatementNode( build_do_while( yylloc, $5, maybe_build_compound( yylloc, $2 ), $8 ) ); } 1320 1322 | FOR '(' ')' statement %prec THEN // CFA => for ( ;; ) 1321 { $$ = new StatementNode( build_for( new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound($4 ) ) ); }1323 { $$ = new StatementNode( build_for( yylloc, new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( yylloc, $4 ) ) ); } 1322 1324 | FOR '(' ')' statement ELSE statement // CFA 1323 1325 { 1324 $$ = new StatementNode( build_for( new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound($4 ) ) );1326 $$ = new StatementNode( build_for( yylloc, new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( yylloc, $4 ) ) ); 1325 1327 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1326 1328 } 1327 1329 | FOR '(' for_control_expression_list ')' statement %prec THEN 1328 { $$ = new StatementNode( build_for( $3, maybe_build_compound($5 ) ) ); }1330 { $$ = new StatementNode( build_for( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); } 1329 1331 | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA 1330 { $$ = new StatementNode( build_for( $3, maybe_build_compound($5 ), $7 ) ); }1332 { $$ = new StatementNode( build_for( yylloc, $3, maybe_build_compound( yylloc, $5 ), $7 ) ); } 1331 1333 ; 1332 1334 … … 1342 1344 if ( $1->condition ) { 1343 1345 if ( $3->condition ) { 1344 $1->condition->expr.reset( new LogicalExpr( $1->condition->expr.release(), $3->condition->expr.release(), true) );1346 $1->condition->expr.reset( new ast::LogicalExpr( yylloc, $1->condition->expr.release(), $3->condition->expr.release(), ast::AndExpr ) ); 1345 1347 } // if 1346 1348 } else $1->condition = $3->condition; 1347 1349 if ( $1->change ) { 1348 1350 if ( $3->change ) { 1349 $1->change->expr.reset( new CommaExpr($1->change->expr.release(), $3->change->expr.release() ) );1351 $1->change->expr.reset( new ast::CommaExpr( yylloc, $1->change->expr.release(), $3->change->expr.release() ) ); 1350 1352 } // if 1351 1353 } else $1->change = $3->change; … … 1359 1361 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1360 1362 { 1361 StatementNode * init = $1 ? new StatementNode( new ExprStmt(maybeMoveBuild( $1 ) ) ) : nullptr;1363 StatementNode * init = $1 ? new StatementNode( new ast::ExprStmt( yylloc, maybeMoveBuild( $1 ) ) ) : nullptr; 1362 1364 $$ = new ForCtrl( init, $3, $5 ); 1363 1365 } … … 1371 1373 1372 1374 | comma_expression // CFA, anonymous loop-index 1373 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); }1375 { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); } 1374 1376 | downupdowneq comma_expression // CFA, anonymous loop-index 1375 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $1, NEW_ZERO, $2->clone() ), $1, UPDOWN( $1, $2->clone(), NEW_ZERO ), NEW_ONE ); }1377 { $$ = forCtrl( yylloc, $2, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $1, NEW_ZERO, $2->clone() ), $1, UPDOWN( $1, $2->clone(), NEW_ZERO ), NEW_ONE ); } 1376 1378 1377 1379 | comma_expression updowneq comma_expression // CFA, anonymous loop-index 1378 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), NEW_ONE ); }1380 { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), NEW_ONE ); } 1379 1381 | '@' updowneq comma_expression // CFA, anonymous loop-index 1380 1382 { 1381 1383 if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1382 else $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, NEW_ONE );1384 else $$ = forCtrl( yylloc, $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, NEW_ONE ); 1383 1385 } 1384 1386 | comma_expression updowneq '@' // CFA, anonymous loop-index … … 1388 1390 } 1389 1391 | comma_expression updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index 1390 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), $5 ); }1392 { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), $5 ); } 1391 1393 | '@' updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index 1392 1394 { 1393 1395 if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1394 else $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, $5 );1396 else $$ = forCtrl( yylloc, $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, $5 ); 1395 1397 } 1396 1398 | comma_expression updowneq '@' '~' comma_expression // CFA, anonymous loop-index … … 1411 1413 1412 1414 | comma_expression ';' comma_expression // CFA 1413 { $$ = forCtrl( $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }1415 { $$ = forCtrl( yylloc, $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); } 1414 1416 | comma_expression ';' downupdowneq comma_expression // CFA 1415 { $$ = forCtrl( $4, $1, UPDOWN( $3, NEW_ZERO, $4->clone() ), $3, UPDOWN( $3, $4->clone(), NEW_ZERO ), NEW_ONE ); }1417 { $$ = forCtrl( yylloc, $4, $1, UPDOWN( $3, NEW_ZERO, $4->clone() ), $3, UPDOWN( $3, $4->clone(), NEW_ZERO ), NEW_ONE ); } 1416 1418 1417 1419 | comma_expression ';' comma_expression updowneq comma_expression // CFA 1418 { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), NEW_ONE ); }1420 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), NEW_ONE ); } 1419 1421 | comma_expression ';' '@' updowneq comma_expression // CFA 1420 1422 { 1421 1423 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1422 else $$ = forCtrl( $5, $1, $5->clone(), $4, nullptr, NEW_ONE );1424 else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, NEW_ONE ); 1423 1425 } 1424 1426 | comma_expression ';' comma_expression updowneq '@' // CFA … … 1426 1428 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1427 1429 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1428 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, NEW_ONE );1430 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); 1429 1431 } 1430 1432 | comma_expression ';' '@' updowneq '@' // CFA, error … … 1432 1434 1433 1435 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA 1434 { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); }1436 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); } 1435 1437 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error 1436 1438 { 1437 1439 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1438 else $$ = forCtrl( $5, $1, $5->clone(), $4, nullptr, $7 );1440 else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, $7 ); 1439 1441 } 1440 1442 | comma_expression ';' comma_expression updowneq '@' '~' comma_expression // CFA … … 1442 1444 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1443 1445 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1444 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, $7 );1446 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 ); 1445 1447 } 1446 1448 | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA 1447 { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); }1449 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); } 1448 1450 | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error 1449 1451 { 1450 1452 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1451 else $$ = forCtrl( $5, $1, $5->clone(), $4, nullptr, nullptr );1453 else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, nullptr ); 1452 1454 } 1453 1455 | comma_expression ';' comma_expression updowneq '@' '~' '@' // CFA … … 1455 1457 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1456 1458 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1457 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, nullptr );1459 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr ); 1458 1460 } 1459 1461 | comma_expression ';' '@' updowneq '@' '~' '@' // CFA … … 1461 1463 1462 1464 | declaration comma_expression // CFA 1463 { $$ = forCtrl( $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); }1465 { $$ = forCtrl( yylloc, $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); } 1464 1466 | declaration downupdowneq comma_expression // CFA 1465 { $$ = forCtrl( $1, UPDOWN( $2, NEW_ZERO, $3 ), $2, UPDOWN( $2, $3->clone(), NEW_ZERO ), NEW_ONE ); }1467 { $$ = forCtrl( yylloc, $1, UPDOWN( $2, NEW_ZERO, $3 ), $2, UPDOWN( $2, $3->clone(), NEW_ZERO ), NEW_ONE ); } 1466 1468 1467 1469 | declaration comma_expression updowneq comma_expression // CFA 1468 { $$ = forCtrl( $1, UPDOWN( $3, $2->clone(), $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), NEW_ONE ); }1470 { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2->clone(), $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), NEW_ONE ); } 1469 1471 | declaration '@' updowneq comma_expression // CFA 1470 1472 { 1471 1473 if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1472 else $$ = forCtrl( $1, $4, $3, nullptr, NEW_ONE );1474 else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, NEW_ONE ); 1473 1475 } 1474 1476 | declaration comma_expression updowneq '@' // CFA … … 1476 1478 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1477 1479 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1478 else $$ = forCtrl( $1, $2, $3, nullptr, NEW_ONE );1480 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE ); 1479 1481 } 1480 1482 1481 1483 | declaration comma_expression updowneq comma_expression '~' comma_expression // CFA 1482 { $$ = forCtrl( $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), $6 ); }1484 { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), $6 ); } 1483 1485 | declaration '@' updowneq comma_expression '~' comma_expression // CFA 1484 1486 { 1485 1487 if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1486 else $$ = forCtrl( $1, $4, $3, nullptr, $6 );1488 else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, $6 ); 1487 1489 } 1488 1490 | declaration comma_expression updowneq '@' '~' comma_expression // CFA … … 1490 1492 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1491 1493 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1492 else $$ = forCtrl( $1, $2, $3, nullptr, $6 );1494 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 ); 1493 1495 } 1494 1496 | declaration comma_expression updowneq comma_expression '~' '@' // CFA 1495 { $$ = forCtrl( $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), nullptr ); }1497 { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), nullptr ); } 1496 1498 | declaration '@' updowneq comma_expression '~' '@' // CFA 1497 1499 { 1498 1500 if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1499 else $$ = forCtrl( $1, $4, $3, nullptr, nullptr );1501 else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, nullptr ); 1500 1502 } 1501 1503 | declaration comma_expression updowneq '@' '~' '@' // CFA … … 1503 1505 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1504 1506 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1505 else $$ = forCtrl( $1, $2, $3, nullptr, nullptr );1507 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr ); 1506 1508 } 1507 1509 | declaration '@' updowneq '@' '~' '@' // CFA, error … … 1546 1548 jump_statement: 1547 1549 GOTO identifier_or_type_name ';' 1548 { $$ = new StatementNode( build_branch( $2,BranchStmt::Goto ) ); }1550 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Goto ) ); } 1549 1551 | GOTO '*' comma_expression ';' // GCC, computed goto 1550 1552 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); … … 1553 1555 // A semantic check is required to ensure fallthru appears only in the body of a choose statement. 1554 1556 | fall_through_name ';' // CFA 1555 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }1557 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::FallThrough ) ); } 1556 1558 | fall_through_name identifier_or_type_name ';' // CFA 1557 { $$ = new StatementNode( build_branch( $2,BranchStmt::FallThrough ) ); }1559 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::FallThrough ) ); } 1558 1560 | fall_through_name DEFAULT ';' // CFA 1559 { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); }1561 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::FallThroughDefault ) ); } 1560 1562 | CONTINUE ';' 1561 1563 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 1562 { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }1564 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::Continue ) ); } 1563 1565 | CONTINUE identifier_or_type_name ';' // CFA, multi-level continue 1564 1566 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 1565 1567 // the target of the transfer appears only at the start of an iteration statement. 1566 { $$ = new StatementNode( build_branch( $2,BranchStmt::Continue ) ); }1568 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Continue ) ); } 1567 1569 | BREAK ';' 1568 1570 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 1569 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }1571 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::Break ) ); } 1570 1572 | BREAK identifier_or_type_name ';' // CFA, multi-level exit 1571 1573 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 1572 1574 // the target of the transfer appears only at the start of an iteration statement. 1573 { $$ = new StatementNode( build_branch( $2,BranchStmt::Break ) ); }1575 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Break ) ); } 1574 1576 | RETURN comma_expression_opt ';' 1575 { $$ = new StatementNode( build_return( $2 ) ); }1577 { $$ = new StatementNode( build_return( yylloc, $2 ) ); } 1576 1578 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1577 1579 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1578 1580 | SUSPEND ';' 1579 { $$ = new StatementNode( build_suspend( nullptr) ); }1581 { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::None ) ); } 1580 1582 | SUSPEND compound_statement 1581 { $$ = new StatementNode( build_suspend( $2) ); }1583 { $$ = new StatementNode( build_suspend( yylloc, $2, ast::SuspendStmt::None ) ); } 1582 1584 | SUSPEND COROUTINE ';' 1583 { $$ = new StatementNode( build_suspend( nullptr,SuspendStmt::Coroutine ) ); }1585 { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::Coroutine ) ); } 1584 1586 | SUSPEND COROUTINE compound_statement 1585 { $$ = new StatementNode( build_suspend( $3,SuspendStmt::Coroutine ) ); }1587 { $$ = new StatementNode( build_suspend( yylloc, $3, ast::SuspendStmt::Coroutine ) ); } 1586 1588 | SUSPEND GENERATOR ';' 1587 { $$ = new StatementNode( build_suspend( nullptr,SuspendStmt::Generator ) ); }1589 { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::Generator ) ); } 1588 1590 | SUSPEND GENERATOR compound_statement 1589 { $$ = new StatementNode( build_suspend( $3,SuspendStmt::Generator ) ); }1591 { $$ = new StatementNode( build_suspend( yylloc, $3, ast::SuspendStmt::Generator ) ); } 1590 1592 | THROW assignment_expression_opt ';' // handles rethrow 1591 { $$ = new StatementNode( build_throw( $2 ) ); }1593 { $$ = new StatementNode( build_throw( yylloc, $2 ) ); } 1592 1594 | THROWRESUME assignment_expression_opt ';' // handles reresume 1593 { $$ = new StatementNode( build_resume( $2 ) ); }1595 { $$ = new StatementNode( build_resume( yylloc, $2 ) ); } 1594 1596 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 1595 1597 { $$ = new StatementNode( build_resume_at( $2, $4 ) ); } … … 1603 1605 with_statement: 1604 1606 WITH '(' tuple_expression_list ')' statement 1605 { $$ = new StatementNode( build_with( $3, $5 ) ); }1607 { $$ = new StatementNode( build_with( yylloc, $3, $5 ) ); } 1606 1608 ; 1607 1609 … … 1611 1613 { 1612 1614 if ( ! $3 ) { SemanticError( yylloc, "mutex argument list cannot be empty." ); $$ = nullptr; } 1613 $$ = new StatementNode( build_mutex( $3, $5 ) );1615 $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) ); 1614 1616 } 1615 1617 ; … … 1650 1652 when_clause_opt waitfor statement %prec THEN 1651 1653 // Called first: create header for WaitForStmt. 1652 { $$ = build_waitfor( new WaitForStmt(), $1, $2, maybe_build_compound($3 ) ); }1654 { $$ = build_waitfor( yylloc, new ast::WaitForStmt( yylloc ), $1, $2, maybe_build_compound( yylloc, $3 ) ); } 1653 1655 | wor_waitfor_clause wor when_clause_opt waitfor statement 1654 { $$ = build_waitfor( $1, $3, $4, maybe_build_compound($5 ) ); }1656 { $$ = build_waitfor( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); } 1655 1657 | wor_waitfor_clause wor when_clause_opt ELSE statement 1656 { $$ = build_waitfor_else( $1, $3, maybe_build_compound($5 ) ); }1658 { $$ = build_waitfor_else( yylloc, $1, $3, maybe_build_compound( yylloc, $5 ) ); } 1657 1659 | wor_waitfor_clause wor when_clause_opt timeout statement %prec THEN 1658 { $$ = build_waitfor_timeout( $1, $3, $4, maybe_build_compound($5 ) ); }1660 { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); } 1659 1661 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1660 1662 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1661 1663 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1662 1664 | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1663 { $$ = build_waitfor_else( build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ), $7, maybe_build_compound( $9 ) ); } 1665 { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); } 1666 ; 1664 1667 1665 1668 waitfor_statement: … … 1711 1714 wor_waituntil_clause %prec THEN 1712 1715 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement. 1713 { $$ = new StatementNode( build_compound( (StatementNode *)0) ); }1716 { $$ = new StatementNode( build_compound( yylloc, nullptr ) ); } 1714 1717 ; 1715 1718 1716 1719 exception_statement: 1717 TRY compound_statement handler_clause %prec THEN1718 { $$ = new StatementNode( build_try( $2, $3, nullptr ) ); }1720 TRY compound_statement handler_clause %prec THEN 1721 { $$ = new StatementNode( build_try( yylloc, $2, $3, nullptr ) ); } 1719 1722 | TRY compound_statement finally_clause 1720 { $$ = new StatementNode( build_try( $2, nullptr, $3 ) ); }1723 { $$ = new StatementNode( build_try( yylloc, $2, nullptr, $3 ) ); } 1721 1724 | TRY compound_statement handler_clause finally_clause 1722 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }1725 { $$ = new StatementNode( build_try( yylloc, $2, $3, $4 ) ); } 1723 1726 ; 1724 1727 1725 1728 handler_clause: 1726 1729 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1727 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }1730 { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); } 1728 1731 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1729 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }1732 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); } 1730 1733 ; 1731 1734 … … 1737 1740 1738 1741 handler_key: 1739 CATCH { $$ = CatchStmt::Terminate; }1740 | RECOVER { $$ = CatchStmt::Terminate; }1741 | CATCHRESUME { $$ = CatchStmt::Resume; }1742 | FIXUP { $$ = CatchStmt::Resume; }1742 CATCH { $$ = ast::Terminate; } 1743 | RECOVER { $$ = ast::Terminate; } 1744 | CATCHRESUME { $$ = ast::Resume; } 1745 | FIXUP { $$ = ast::Resume; } 1743 1746 ; 1744 1747 1745 1748 finally_clause: 1746 FINALLY compound_statement { $$ = new StatementNode( build_finally( $2 ) ); }1749 FINALLY compound_statement { $$ = new StatementNode( build_finally( yylloc, $2 ) ); } 1747 1750 ; 1748 1751 … … 1770 1773 asm_statement: 1771 1774 ASM asm_volatile_opt '(' string_literal ')' ';' 1772 { $$ = new StatementNode( build_asm( $2, $4, nullptr ) ); }1775 { $$ = new StatementNode( build_asm( yylloc, $2, $4, nullptr ) ); } 1773 1776 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC 1774 { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); }1777 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6 ) ); } 1775 1778 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';' 1776 { $$ = new StatementNode( build_asm( $2, $4, $6, $8 ) ); }1779 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8 ) ); } 1777 1780 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 1778 { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); }1781 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8, $10 ) ); } 1779 1782 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 1780 { $$ = new StatementNode( build_asm( $2, $5, nullptr, $8, $10, $12 ) ); }1783 { $$ = new StatementNode( build_asm( yylloc, $2, $5, nullptr, $8, $10, $12 ) ); } 1781 1784 ; 1782 1785 … … 1802 1805 asm_operand: // GCC 1803 1806 string_literal '(' constant_expression ')' 1804 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild( $3 ) ) ); }1807 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); } 1805 1808 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1806 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild( $6 ) ) ); } 1809 { 1810 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) ); 1811 delete $2.str; 1812 } 1807 1813 ; 1808 1814 … … 1819 1825 identifier 1820 1826 { 1821 $$ = new LabelNode(); $$->labels. push_back(*$1 );1827 $$ = new LabelNode(); $$->labels.emplace_back( yylloc, *$1 ); 1822 1828 delete $1; // allocated by lexer 1823 1829 } 1824 1830 | label_list ',' identifier 1825 1831 { 1826 $$ = $1; $1->labels. push_back(*$3 );1832 $$ = $1; $1->labels.emplace_back( yylloc, *$3 ); 1827 1833 delete $3; // allocated by lexer 1828 1834 } … … 1887 1893 { $$ = DeclarationNode::newStaticAssert( $3, $5 ); } 1888 1894 | STATICASSERT '(' constant_expression ')' ';' // CFA 1889 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); }1895 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); } 1890 1896 1891 1897 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function … … 2087 2093 { 2088 2094 SemanticError( yylloc, ::toString( "Missing ';' after end of ", 2089 $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ),2095 $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ), 2090 2096 " declaration" ) ); 2091 2097 $$ = nullptr; … … 2321 2327 { $$ = DeclarationNode::newTypeof( $3 ); } 2322 2328 | BASETYPEOF '(' type ')' // CFA: basetypeof( x ) y; 2323 { $$ = DeclarationNode::newTypeof( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ), true ); }2329 { $$ = DeclarationNode::newTypeof( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ), true ); } 2324 2330 | BASETYPEOF '(' comma_expression ')' // CFA: basetypeof( a+b ) y; 2325 2331 { $$ = DeclarationNode::newTypeof( $3, true ); } … … 2515 2521 aggregate_data: 2516 2522 STRUCT vtable_opt 2517 { $$ = AggregateDecl::Struct; }2523 { $$ = ast::AggregateDecl::Struct; } 2518 2524 | UNION 2519 { $$ = AggregateDecl::Union; }2525 { $$ = ast::AggregateDecl::Union; } 2520 2526 | EXCEPTION // CFA 2521 { $$ = AggregateDecl::Exception; }2522 // { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }2527 { $$ = ast::AggregateDecl::Exception; } 2528 // { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = ast::AggregateDecl::NoAggregate; } 2523 2529 ; 2524 2530 2525 2531 aggregate_control: // CFA 2526 2532 MONITOR 2527 { $$ = AggregateDecl::Monitor; }2533 { $$ = ast::AggregateDecl::Monitor; } 2528 2534 | MUTEX STRUCT 2529 { $$ = AggregateDecl::Monitor; }2535 { $$ = ast::AggregateDecl::Monitor; } 2530 2536 | GENERATOR 2531 { $$ = AggregateDecl::Generator; }2537 { $$ = ast::AggregateDecl::Generator; } 2532 2538 | MUTEX GENERATOR 2533 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2539 { 2540 SemanticError( yylloc, "monitor generator is currently unimplemented." ); 2541 $$ = ast::AggregateDecl::NoAggregate; 2542 } 2534 2543 | COROUTINE 2535 { $$ = AggregateDecl::Coroutine; }2544 { $$ = ast::AggregateDecl::Coroutine; } 2536 2545 | MUTEX COROUTINE 2537 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2546 { 2547 SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); 2548 $$ = ast::AggregateDecl::NoAggregate; 2549 } 2538 2550 | THREAD 2539 { $$ = AggregateDecl::Thread; }2551 { $$ = ast::AggregateDecl::Thread; } 2540 2552 | MUTEX THREAD 2541 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2553 { 2554 SemanticError( yylloc, "monitor thread is currently unimplemented." ); 2555 $$ = ast::AggregateDecl::NoAggregate; 2556 } 2542 2557 ; 2543 2558 … … 2889 2904 designator_list ':' // C99, CFA uses ":" instead of "=" 2890 2905 | identifier_at ':' // GCC, field name 2891 { $$ = new ExpressionNode( build_varref( $1 ) ); }2906 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 2892 2907 ; 2893 2908 … … 2901 2916 designator: 2902 2917 '.' identifier_at // C99, field name 2903 { $$ = new ExpressionNode( build_varref( $2 ) ); }2918 { $$ = new ExpressionNode( build_varref( yylloc, $2 ) ); } 2904 2919 | '[' push assignment_expression pop ']' // C99, single array element 2905 2920 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. … … 2908 2923 { $$ = $3; } 2909 2924 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2910 { $$ = new ExpressionNode( new RangeExpr(maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); }2925 { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); } 2911 2926 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2912 2927 { $$ = $4; } … … 2948 2963 { 2949 2964 typedefTable.addToScope( *$2, TYPEDEFname, "9" ); 2950 if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); }2951 if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); }2952 if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); }2965 if ( $1 == ast::TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); } 2966 if ( $1 == ast::TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); } 2967 if ( $1 == ast::TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); } 2953 2968 } 2954 2969 type_initializer_opt assertion_list_opt … … 2961 2976 { 2962 2977 typedefTable.addToScope( *$2, TYPEDIMname, "9" ); 2963 $$ = DeclarationNode::newTypeParam( TypeDecl::Dimension, $2 );2978 $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dimension, $2 ); 2964 2979 } 2965 2980 // | type_specifier identifier_parameter_declarator 2966 2981 | assertion_list 2967 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2982 { $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2968 2983 ; 2969 2984 2970 2985 new_type_class: // CFA 2971 2986 // empty 2972 { $$ = TypeDecl::Otype; }2987 { $$ = ast::TypeDecl::Otype; } 2973 2988 | '&' 2974 { $$ = TypeDecl::Dtype; }2989 { $$ = ast::TypeDecl::Dtype; } 2975 2990 | '*' 2976 { $$ = TypeDecl::DStype; } // dtype + sized2991 { $$ = ast::TypeDecl::DStype; } // dtype + sized 2977 2992 // | '(' '*' ')' 2978 // { $$ = TypeDecl::Ftype; }2993 // { $$ = ast::TypeDecl::Ftype; } 2979 2994 | ELLIPSIS 2980 { $$ = TypeDecl::Ttype; }2995 { $$ = ast::TypeDecl::Ttype; } 2981 2996 ; 2982 2997 2983 2998 type_class: // CFA 2984 2999 OTYPE 2985 { $$ = TypeDecl::Otype; }3000 { $$ = ast::TypeDecl::Otype; } 2986 3001 | DTYPE 2987 { $$ = TypeDecl::Dtype; }3002 { $$ = ast::TypeDecl::Dtype; } 2988 3003 | FTYPE 2989 { $$ = TypeDecl::Ftype; }3004 { $$ = ast::TypeDecl::Ftype; } 2990 3005 | TTYPE 2991 { $$ = TypeDecl::Ttype; }3006 { $$ = ast::TypeDecl::Ttype; } 2992 3007 ; 2993 3008 … … 3015 3030 type_list: // CFA 3016 3031 type 3017 { $$ = new ExpressionNode( new TypeExpr(maybeMoveBuildType( $1 ) ) ); }3032 { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); } 3018 3033 | assignment_expression 3019 3034 | type_list ',' type 3020 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ) )); }3035 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); } 3021 3036 | type_list ',' assignment_expression 3022 3037 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } … … 3125 3140 external_definition: 3126 3141 DIRECTIVE 3127 { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); }3142 { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( yylloc, $1 ) ) ); } 3128 3143 | declaration 3129 3144 { … … 3131 3146 // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is 3132 3147 // disallowed at the moment. 3133 if ( $1->linkage == LinkageSpec::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {3148 if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) { 3134 3149 if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) { 3135 3150 SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr; … … 3158 3173 } 3159 3174 | ASM '(' string_literal ')' ';' // GCC, global assembler statement 3160 { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, nullptr ) ) ); }3175 { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( yylloc, false, $3, nullptr ) ) ); } 3161 3176 | EXTERN STRINGliteral 3162 3177 { 3163 3178 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 3164 linkage = LinkageSpec::update( yylloc, linkage, $2 );3179 linkage = ast::Linkage::update( yylloc, linkage, $2 ); 3165 3180 } 3166 3181 up external_definition down … … 3173 3188 { 3174 3189 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 3175 linkage = LinkageSpec::update( yylloc, linkage, $2 );3190 linkage = ast::Linkage::update( yylloc, linkage, $2 ); 3176 3191 } 3177 3192 '{' up external_definition_list_opt down '}' … … 3297 3312 subrange: 3298 3313 constant_expression '~' constant_expression // CFA, integer subrange 3299 { $$ = new ExpressionNode( new RangeExpr(maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }3314 { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 3300 3315 ; 3301 3316 … … 3826 3841 array_type_list: 3827 3842 basic_type_name 3828 { $$ = new ExpressionNode( new TypeExpr(maybeMoveBuildType( $1 ) ) ); }3843 { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); } 3829 3844 | type_name 3830 { $$ = new ExpressionNode( new TypeExpr(maybeMoveBuildType( $1 ) ) ); }3845 { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); } 3831 3846 | assignment_expression upupeq assignment_expression 3832 3847 | array_type_list ',' basic_type_name 3833 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ) )); }3834 | array_type_list ',' type_name 3835 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ) )); }3848 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); } 3849 | array_type_list ',' type_name 3850 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); } 3836 3851 | array_type_list ',' assignment_expression upupeq assignment_expression 3837 3852 ;
Note:
See TracChangeset
for help on using the changeset viewer.