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