Changes in src/Parser/parser.yy [4ed70597:faddbd8]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r4ed70597 rfaddbd8 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 26 16:45:44201613 // Update Count : 196412 // Last Modified On : Wed Oct 5 14:10:46 2016 13 // Update Count : 2002 14 14 // 15 15 … … 54 54 #include "TypeData.h" 55 55 #include "LinkageSpec.h" 56 using namespace std; 56 57 57 58 extern DeclarationNode * parseTree; … … 59 60 extern TypedefTable typedefTable; 60 61 61 st d::stack< LinkageSpec::Spec > linkageStack;62 63 void appendStr( st d::string *to, std::string *from ) {62 stack< LinkageSpec::Spec > linkageStack; 63 64 void appendStr( string *to, string *from ) { 64 65 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 65 66 to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) ); … … 195 196 %type<decl> field_declaration field_declaration_list field_declarator field_declaring_list 196 197 %type<en> field field_list 198 %type<tok> field_name 197 199 198 200 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 359 361 { $$ = $2; } 360 362 | '(' compound_statement ')' // GCC, lambda expression 361 { $$ = new ExpressionNode( build_valexpr( $2 ) ); }363 { $$ = new ExpressionNode( build_valexpr( $2 ) ); } 362 364 ; 363 365 … … 377 379 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } 378 380 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 381 | postfix_expression '.' INTEGERconstant 379 382 | postfix_expression ARROW no_attr_identifier 380 383 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } … … 389 392 { 390 393 Token fn; 391 fn.str = new std::string( "?{}" ); // location undefined392 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3) ) );394 fn.str = new std::string( "?{}" ); // location undefined - use location of '{'? 395 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 393 396 } 394 397 ; … … 412 415 413 416 field: // CFA, tuple field selector 414 no_attr_identifier 415 { $$ = new ExpressionNode( build_varref( $1 ) ); } 417 field_name 416 418 // ambiguity with .0 so space required after field-selection, e.g. 417 419 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 418 | no_attr_identifier '.' field 420 { $$ = new ExpressionNode( build_varref( $1 ) ); } 421 | field_name '.' field 419 422 { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); } 420 | no_attr_identifier'.' '[' push field_list pop ']'423 | field_name '.' '[' push field_list pop ']' 421 424 { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) ) ); } 422 | no_attr_identifierARROW field425 | field_name ARROW field 423 426 { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) ) ); } 424 | no_attr_identifierARROW '[' push field_list pop ']'427 | field_name ARROW '[' push field_list pop ']' 425 428 { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) ) ); } 429 ; 430 431 field_name: 432 no_attr_identifier 433 | INTEGERconstant 426 434 ; 427 435 … … 666 674 { 667 675 Token fn; 668 fn.str = new st d::string( "^?{}" );// location undefined676 fn.str = new string( "^?{}" ); // location undefined 669 677 $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) ); 670 678 } … … 896 904 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 897 905 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 898 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }906 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } 899 907 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 900 908 { $$ = new StatementNode( build_catch( $5, $8 ) ); } … … 968 976 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); } 969 977 | '[' constant_expression ']' string_literal '(' constant_expression ')' 970 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }978 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); } 971 979 ; 972 980 … … 1363 1371 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); } 1364 1372 | LONG 1365 { $$ = DeclarationNode::new Modifier( DeclarationNode::Long ); }1373 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); } 1366 1374 | SHORT 1367 { $$ = DeclarationNode::new Modifier( DeclarationNode::Short ); }1375 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); } 1368 1376 | SIGNED 1369 { $$ = DeclarationNode::new Modifier( DeclarationNode::Signed ); }1377 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); } 1370 1378 | UNSIGNED 1371 { $$ = DeclarationNode::new Modifier( DeclarationNode::Unsigned ); }1379 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); } 1372 1380 | VOID 1373 1381 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } … … 1375 1383 { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); } 1376 1384 | COMPLEX // C99 1377 { $$ = DeclarationNode::new BasicType( DeclarationNode::Complex ); }1385 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } 1378 1386 | IMAGINARY // C99 1379 { $$ = DeclarationNode::new BasicType( DeclarationNode::Imaginary ); }1387 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); } 1380 1388 | VALIST // GCC, __builtin_va_list 1381 1389 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } … … 1467 1475 aggregate_name: 1468 1476 aggregate_key '{' field_declaration_list '}' 1469 { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3, true ); }1477 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); } 1470 1478 | aggregate_key no_attr_identifier_or_type_name 1471 1479 { 1472 1480 typedefTable.makeTypedef( *$2 ); 1473 $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );1481 $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false ); 1474 1482 } 1475 1483 | aggregate_key no_attr_identifier_or_type_name 1476 1484 { typedefTable.makeTypedef( *$2 ); } 1477 1485 '{' field_declaration_list '}' 1478 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5, true ); }1486 { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); } 1479 1487 | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1480 { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6, false ); }1488 { $$ = DeclarationNode::newAggregate( $1, nullptr, $3, $6, false ); } 1481 1489 | aggregate_key typegen_name // CFA, S/R conflict 1482 1490 { $$ = $2; } … … 1559 1567 enum_name: 1560 1568 enum_key '{' enumerator_list comma_opt '}' 1561 { $$ = DeclarationNode::newEnum( 0, $3 ); }1569 { $$ = DeclarationNode::newEnum( nullptr, $3 ); } 1562 1570 | enum_key no_attr_identifier_or_type_name 1563 1571 { … … 1849 1857 type_class: // CFA 1850 1858 OTYPE 1851 { $$ = DeclarationNode:: Type; }1859 { $$ = DeclarationNode::Otype; } 1852 1860 | DTYPE 1853 1861 { $$ = DeclarationNode::Ftype; } … … 2004 2012 { 2005 2013 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2006 linkage = LinkageSpec:: fromString( *$2 );2014 linkage = LinkageSpec::linkageCheck( $2 ); 2007 2015 } 2008 2016 '{' external_definition_list_opt '}' // C++-style linkage specifier … … 2520 2528 abstract_function: 2521 2529 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2522 { $$ = DeclarationNode::newFunction( 0, 0, $3, 0); }2530 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2523 2531 | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2524 2532 { $$ = $2->addParamList( $6 ); } … … 2589 2597 abstract_parameter_function: 2590 2598 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2591 { $$ = DeclarationNode::newFunction( 0, 0, $3, 0); }2599 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2592 2600 | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2593 2601 { $$ = $2->addParamList( $6 ); } … … 2793 2801 // empty (void) function return type. 2794 2802 '[' ']' type_specifier 2795 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2803 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2796 2804 | '[' ']' multi_array_dimension type_specifier 2797 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2805 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2798 2806 | multi_array_dimension type_specifier 2799 2807 { $$ = $2->addNewArray( $1 ); } 2800 2808 | '[' ']' new_abstract_ptr 2801 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2809 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2802 2810 | '[' ']' multi_array_dimension new_abstract_ptr 2803 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2811 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2804 2812 | multi_array_dimension new_abstract_ptr 2805 2813 { $$ = $2->addNewArray( $1 ); } … … 2813 2821 new_abstract_function: // CFA 2814 2822 '[' ']' '(' new_parameter_type_list_opt ')' 2815 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0); }2823 { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 2816 2824 | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')' 2817 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0); }2825 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2818 2826 | new_function_return '(' push new_parameter_type_list_opt pop ')' 2819 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0); }2827 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2820 2828 ; 2821 2829 … … 2852 2860 2853 2861 void yyerror( const char * ) { 2854 std::cout << "Error ";2862 cout << "Error "; 2855 2863 if ( yyfilename ) { 2856 std::cout << "in file " << yyfilename << " ";2864 cout << "in file " << yyfilename << " "; 2857 2865 } // if 2858 std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;2866 cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl; 2859 2867 } 2860 2868
Note:
See TracChangeset
for help on using the changeset viewer.