Changes in src/Parser/parser.yy [3d937e2:9fa61f5]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r3d937e2 r9fa61f5 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 25 13:23:16202313 // Update Count : 59 8912 // Last Modified On : Tue Mar 14 09:37:58 2023 13 // Update Count : 5990 14 14 // 15 15 … … 206 206 #define MISSING_HIGH "Missing high value for down-to range so index is uninitialized." 207 207 208 static ForCtrl * makeForCtrl( 209 DeclarationNode * init, 210 enum OperKinds compop, 211 ExpressionNode * comp, 212 ExpressionNode * inc ) { 213 // Wrap both comp/inc if they are non-null. 214 if ( comp ) comp = new ExpressionNode( build_binary_val( 215 compop, 216 new ExpressionNode( build_varref( new string( *init->name ) ) ), 217 comp ) ); 218 if ( inc ) inc = new ExpressionNode( build_binary_val( 219 // choose += or -= for upto/downto 220 compop == OperKinds::LThan || compop == OperKinds::LEThan ? OperKinds::PlusAssn : OperKinds::MinusAssn, 221 new ExpressionNode( build_varref( new string( *init->name ) ) ), 222 inc ) ); 223 // The StatementNode call frees init->name, it must happen later. 224 return new ForCtrl( new StatementNode( init ), comp, inc ); 225 } 226 208 227 ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 209 228 if ( index->initializer ) { … … 213 232 SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." ); 214 233 } // if 215 return new ForCtrl( index->addInitializer( new InitializerNode( start ) ), 216 // NULL comp/inc => leave blank 217 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index->name ) ) ), comp ) ) : nullptr, 218 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 219 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index->name ) ) ), inc ) ) : nullptr ); 234 DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) ); 235 return makeForCtrl( initDecl, compop, comp, inc ); 220 236 } // forCtrl 221 237 … … 223 239 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); 224 240 if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) { 225 type = new ExpressionNode( new CastExpr( maybeMoveBuild <Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );241 type = new ExpressionNode( new CastExpr( maybeMoveBuild( type ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) ); 226 242 } // if 227 // type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) ); 228 return new ForCtrl( 229 distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 230 // NULL comp/inc => leave blank 231 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : nullptr, 232 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 233 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : nullptr ); 243 DeclarationNode * initDecl = distAttr( 244 DeclarationNode::newTypeof( type, true ), 245 DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) 246 ); 247 return makeForCtrl( initDecl, compop, comp, inc ); 234 248 } // forCtrl 235 249 … … 649 663 { $$ = $2; } 650 664 | '(' compound_statement ')' // GCC, lambda expression 651 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild <Statement>($2) ) ) ); }665 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild( $2 ) ) ) ); } 652 666 | type_name '.' identifier // CFA, nested type 653 667 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); } … … 657 671 { 658 672 // add the missing control expression to the GenericExpr and return it 659 $5->control = maybeMoveBuild <Expression>( $3 );673 $5->control = maybeMoveBuild( $3 ); 660 674 $$ = new ExpressionNode( $5 ); 661 675 } … … 693 707 { 694 708 // create a GenericExpr wrapper with one association pair 695 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild <Expression>( $3 ) } } );709 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild( $3 ) } } ); 696 710 } 697 711 | DEFAULT ':' assignment_expression 698 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild <Expression>( $3 ) } } ); }712 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild( $3 ) } } ); } 699 713 ; 700 714 … … 751 765 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 752 766 | postfix_expression ICR 753 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::IncrPost, $1 ) ); }767 { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); } 754 768 | postfix_expression DECR 755 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::DecrPost, $1 ) ); }769 { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); } 756 770 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 757 771 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } … … 793 807 field_name 794 808 | FLOATING_DECIMALconstant field 795 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild <Expression>( $2 ) ) ); }809 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild( $2 ) ) ); } 796 810 | FLOATING_DECIMALconstant '[' field_name_list ']' 797 811 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 798 812 | field_name '.' field 799 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild <Expression>( $3 ) ) ); }813 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild( $3 ) ) ); } 800 814 | field_name '.' '[' field_name_list ']' 801 815 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 802 816 | field_name ARROW field 803 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild <Expression>( $3 ) ) ); }817 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild( $3 ) ) ); } 804 818 | field_name ARROW '[' field_name_list ']' 805 819 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } … … 843 857 switch ( $1 ) { 844 858 case OperKinds::AddressOf: 845 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild <Expression>( $2 ) ) );859 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild( $2 ) ) ); 846 860 break; 847 861 case OperKinds::PointTo: … … 849 863 break; 850 864 case OperKinds::And: 851 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild <Expression>( $2 ) ) ) );865 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild( $2 ) ) ) ); 852 866 break; 853 867 default: … … 858 872 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); } 859 873 | ICR unary_expression 860 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::Incr, $2 ) ); }874 { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); } 861 875 | DECR unary_expression 862 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::Decr, $2 ) ); }876 { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); } 863 877 | SIZEOF unary_expression 864 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild <Expression>( $2 ) ) ); }878 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); } 865 879 | SIZEOF '(' type_no_function ')' 866 880 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); } 867 881 | ALIGNOF unary_expression // GCC, variable alignment 868 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild <Expression>( $2 ) ) ); }882 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild( $2 ) ) ); } 869 883 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 870 884 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } … … 901 915 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 902 916 | '(' VIRTUAL ')' cast_expression // CFA 903 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild <Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }917 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); } 904 918 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 905 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild <Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }919 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); } 906 920 | '(' RETURN type_no_function ')' cast_expression // CFA 907 921 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } … … 1092 1106 assignment_expression 1093 1107 | comma_expression ',' assignment_expression 1094 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild <Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1108 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1095 1109 ; 1096 1110 … … 1230 1244 constant_expression { $$ = $1; } 1231 1245 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1232 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild <Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1246 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1233 1247 | subrange // CFA, subrange 1234 1248 ; … … 1298 1312 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); } 1299 1313 | FOR '(' ')' statement %prec THEN // CFA => for ( ;; ) 1300 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }1314 { $$ = new StatementNode( build_for( new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( $4 ) ) ); } 1301 1315 | FOR '(' ')' statement ELSE statement // CFA 1302 1316 { 1303 $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) );1317 $$ = new StatementNode( build_for( new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( $4 ) ) ); 1304 1318 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1305 1319 } … … 1335 1349 for_control_expression: 1336 1350 ';' comma_expression_opt ';' comma_expression_opt 1337 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }1351 { $$ = new ForCtrl( nullptr, $2, $4 ); } 1338 1352 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1339 { $$ = new ForCtrl( $1, $3, $5 ); } 1353 { 1354 StatementNode * init = $1 ? new StatementNode( new ExprStmt( maybeMoveBuild( $1 ) ) ) : nullptr; 1355 $$ = new ForCtrl( init, $3, $5 ); 1356 } 1340 1357 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1341 { $$ = new ForCtrl( $1, $2, $4 ); }1358 { $$ = new ForCtrl( new StatementNode( $1 ), $2, $4 ); } 1342 1359 1343 1360 | '@' ';' comma_expression // CFA, empty loop-index 1344 { $$ = new ForCtrl( (ExpressionNode *)nullptr, $3, nullptr ); }1361 { $$ = new ForCtrl( nullptr, $3, nullptr ); } 1345 1362 | '@' ';' comma_expression ';' comma_expression // CFA, empty loop-index 1346 { $$ = new ForCtrl( (ExpressionNode *)nullptr, $3, $5 ); }1363 { $$ = new ForCtrl( nullptr, $3, $5 ); } 1347 1364 1348 1365 | comma_expression // CFA, anonymous loop-index … … 1732 1749 asm_operand: // GCC 1733 1750 string_literal '(' constant_expression ')' 1734 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild <Expression>( $3 ) ) ); }1751 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild( $3 ) ) ); } 1735 1752 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1736 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild <Expression>( $6 ) ) ); }1753 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild( $6 ) ) ); } 1737 1754 ; 1738 1755 … … 2038 2055 basic_type_specifier 2039 2056 | sue_type_specifier 2040 {2041 // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2042 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2043 // printf( "\tattr %s\n", attr->name.c_str() );2044 // } // for2045 }2046 2057 | type_type_specifier 2047 2058 ; … … 2383 2394 '{' field_declaration_list_opt '}' type_parameters_opt 2384 2395 { 2385 // printf( "aggregate_type1 %s\n", $3.str->c_str() );2386 // if ( $2 )2387 // for ( Attribute * attr: reverseIterate( $2->attributes ) ) {2388 // printf( "copySpecifiers12 %s\n", attr->name.c_str() );2389 // } // for2390 2396 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2391 // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2392 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2393 // printf( "aggregate_type3 %s\n", attr->name.c_str() );2394 // } // for2395 2397 } 2396 2398 | aggregate_key attribute_list_opt TYPEDEFname // unqualified type name … … 2401 2403 '{' field_declaration_list_opt '}' type_parameters_opt 2402 2404 { 2403 // printf( "AGG3\n" );2404 2405 DeclarationNode::newFromTypedef( $3 ); 2405 2406 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); … … 2412 2413 '{' field_declaration_list_opt '}' type_parameters_opt 2413 2414 { 2414 // printf( "AGG4\n" );2415 2415 DeclarationNode::newFromTypeGen( $3, nullptr ); 2416 2416 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); … … 2439 2439 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and 2440 2440 // delete newFromTypeGen. 2441 $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 ); 2442 $3->type->symbolic.name = nullptr; 2443 $3->type->symbolic.actuals = nullptr; 2444 delete $3; 2441 if ( $3->type->kind == TypeData::SymbolicInst && ! $3->type->symbolic.isTypedef ) { 2442 $$ = $3->addQualifiers( $2 ); 2443 } else { 2444 $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 ); 2445 $3->type->symbolic.name = nullptr; // copied to $$ 2446 $3->type->symbolic.actuals = nullptr; 2447 delete $3; 2448 } 2445 2449 } 2446 2450 ; … … 2779 2783 type_no_function: // sizeof, alignof, cast (constructor) 2780 2784 cfa_abstract_declarator_tuple // CFA 2781 | type_specifier 2785 | type_specifier // cannot be type_specifier_nobody, e.g., (struct S {}){} is a thing 2782 2786 | type_specifier abstract_declarator 2783 2787 { $$ = $2->addType( $1 ); } … … 2843 2847 { $$ = $3; } 2844 2848 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2845 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild <Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }2849 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); } 2846 2850 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2847 2851 { $$ = $4; } … … 3231 3235 subrange: 3232 3236 constant_expression '~' constant_expression // CFA, integer subrange 3233 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild <Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }3237 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 3234 3238 ; 3235 3239
Note: See TracChangeset
for help on using the changeset viewer.