Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r4ed70597 rfaddbd8  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 26 16:45:44 2016
    13 // Update Count     : 1964
     12// Last Modified On : Wed Oct  5 14:10:46 2016
     13// Update Count     : 2002
    1414//
    1515
     
    5454#include "TypeData.h"
    5555#include "LinkageSpec.h"
     56using namespace std;
    5657
    5758extern DeclarationNode * parseTree;
     
    5960extern TypedefTable typedefTable;
    6061
    61 std::stack< LinkageSpec::Spec > linkageStack;
    62 
    63 void appendStr( std::string *to, std::string *from ) {
     62stack< LinkageSpec::Spec > linkageStack;
     63
     64void appendStr( string *to, string *from ) {
    6465        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    6566        to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     
    195196%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
    196197%type<en> field field_list
     198%type<tok> field_name
    197199
    198200%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    359361                { $$ = $2; }
    360362        | '(' compound_statement ')'                                            // GCC, lambda expression
    361         { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
     363                { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
    362364        ;
    363365
     
    377379                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    378380        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
     381        | postfix_expression '.' INTEGERconstant
    379382        | postfix_expression ARROW no_attr_identifier
    380383                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    389392                {
    390393                        Token fn;
    391                         fn.str = new std::string( "?{}" ); // location undefined
    392                         $$ = 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 ) ) ) );
    393396                }
    394397        ;
     
    412415
    413416field:                                                                                                  // CFA, tuple field selector
    414         no_attr_identifier
    415                 { $$ = new ExpressionNode( build_varref( $1 ) ); }
     417        field_name
    416418                // ambiguity with .0 so space required after field-selection, e.g.
    417419                //   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
    419422                { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); }
    420         | no_attr_identifier '.' '[' push field_list pop ']'
     423        | field_name '.' '[' push field_list pop ']'
    421424                { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) ) ); }
    422         | no_attr_identifier ARROW field
     425        | field_name ARROW field
    423426                { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) ) ); }
    424         | no_attr_identifier ARROW '[' push field_list pop ']'
     427        | field_name ARROW '[' push field_list pop ']'
    425428                { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) ) ); }
     429        ;
     430
     431field_name:
     432        no_attr_identifier
     433        | INTEGERconstant
    426434        ;
    427435
     
    666674                {
    667675                        Token fn;
    668                         fn.str = new std::string( "^?{}" ); // location undefined
     676                        fn.str = new string( "^?{}" );                          // location undefined
    669677                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    670678                }
     
    896904                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    897905        | 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 ) ) ); }
    899907        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    900908                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
     
    968976                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    969977        | '[' constant_expression ']' string_literal '(' constant_expression ')'
    970         { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
     978                { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    971979        ;
    972980
     
    13631371                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
    13641372        | LONG
    1365                 { $$ = DeclarationNode::newModifier( DeclarationNode::Long ); }
     1373                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    13661374        | SHORT
    1367                 { $$ = DeclarationNode::newModifier( DeclarationNode::Short ); }
     1375                { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
    13681376        | SIGNED
    1369                 { $$ = DeclarationNode::newModifier( DeclarationNode::Signed ); }
     1377                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
    13701378        | UNSIGNED
    1371                 { $$ = DeclarationNode::newModifier( DeclarationNode::Unsigned ); }
     1379                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
    13721380        | VOID
    13731381                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    13751383                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
    13761384        | COMPLEX                                                                                       // C99
    1377                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Complex ); }
     1385                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
    13781386        | IMAGINARY                                                                                     // C99
    1379                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
     1387                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
    13801388        | VALIST                                                                                        // GCC, __builtin_va_list
    13811389                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
     
    14671475aggregate_name:
    14681476        aggregate_key '{' field_declaration_list '}'
    1469                 { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3, true ); }
     1477                { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); }
    14701478        | aggregate_key no_attr_identifier_or_type_name
    14711479                {
    14721480                        typedefTable.makeTypedef( *$2 );
    1473                         $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );
     1481                        $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false );
    14741482                }
    14751483        | aggregate_key no_attr_identifier_or_type_name
    14761484                { typedefTable.makeTypedef( *$2 ); }
    14771485                '{' field_declaration_list '}'
    1478                 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5, true ); }
     1486                { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); }
    14791487        | 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 ); }
    14811489        | aggregate_key typegen_name                                            // CFA, S/R conflict
    14821490                { $$ = $2; }
     
    15591567enum_name:
    15601568        enum_key '{' enumerator_list comma_opt '}'
    1561                 { $$ = DeclarationNode::newEnum( 0, $3 ); }
     1569                { $$ = DeclarationNode::newEnum( nullptr, $3 ); }
    15621570        | enum_key no_attr_identifier_or_type_name
    15631571                {
     
    18491857type_class:                                                                                             // CFA
    18501858        OTYPE
    1851                 { $$ = DeclarationNode::Type; }
     1859                { $$ = DeclarationNode::Otype; }
    18521860        | DTYPE
    18531861                { $$ = DeclarationNode::Ftype; }
     
    20042012                {
    20052013                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2006                         linkage = LinkageSpec::fromString( *$2 );
     2014                        linkage = LinkageSpec::linkageCheck( $2 );
    20072015                }
    20082016          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
     
    25202528abstract_function:
    25212529        '(' 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 ); }
    25232531        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25242532                { $$ = $2->addParamList( $6 ); }
     
    25892597abstract_parameter_function:
    25902598        '(' 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 ); }
    25922600        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25932601                { $$ = $2->addParamList( $6 ); }
     
    27932801                // empty (void) function return type.
    27942802        '[' ']' type_specifier
    2795                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2803                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    27962804        | '[' ']' 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 ) ); }
    27982806        | multi_array_dimension type_specifier
    27992807                { $$ = $2->addNewArray( $1 ); }
    28002808        | '[' ']' new_abstract_ptr
    2801                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2809                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    28022810        | '[' ']' 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 ) ); }
    28042812        | multi_array_dimension new_abstract_ptr
    28052813                { $$ = $2->addNewArray( $1 ); }
     
    28132821new_abstract_function:                                                                  // CFA
    28142822        '[' ']' '(' new_parameter_type_list_opt ')'
    2815                 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0 ); }
     2823                { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    28162824        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
    2817                 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
     2825                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28182826        | new_function_return '(' push new_parameter_type_list_opt pop ')'
    2819                 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
     2827                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28202828        ;
    28212829
     
    28522860
    28532861void yyerror( const char * ) {
    2854         std::cout << "Error ";
     2862        cout << "Error ";
    28552863        if ( yyfilename ) {
    2856                 std::cout << "in file " << yyfilename << " ";
     2864                cout << "in file " << yyfilename << " ";
    28572865        } // 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;
    28592867}
    28602868
Note: See TracChangeset for help on using the changeset viewer.