Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rfaddbd8 r4ed70597  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Oct  5 14:10:46 2016
    13 // Update Count     : 2002
     12// Last Modified On : Fri Aug 26 16:45:44 2016
     13// Update Count     : 1964
    1414//
    1515
     
    5454#include "TypeData.h"
    5555#include "LinkageSpec.h"
    56 using namespace std;
    5756
    5857extern DeclarationNode * parseTree;
     
    6059extern TypedefTable typedefTable;
    6160
    62 stack< LinkageSpec::Spec > linkageStack;
    63 
    64 void appendStr( string *to, string *from ) {
     61std::stack< LinkageSpec::Spec > linkageStack;
     62
     63void appendStr( std::string *to, std::string *from ) {
    6564        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    6665        to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     
    196195%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
    197196%type<en> field field_list
    198 %type<tok> field_name
    199197
    200198%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    361359                { $$ = $2; }
    362360        | '(' compound_statement ')'                                            // GCC, lambda expression
    363                 { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
     361        { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
    364362        ;
    365363
     
    379377                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    380378        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    381         | postfix_expression '.' INTEGERconstant
    382379        | postfix_expression ARROW no_attr_identifier
    383380                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    392389                {
    393390                        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 ) ) );
    396393                }
    397394        ;
     
    415412
    416413field:                                                                                                  // CFA, tuple field selector
    417         field_name
     414        no_attr_identifier
     415                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    418416                // ambiguity with .0 so space required after field-selection, e.g.
    419417                //   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
    422419                { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); }
    423         | field_name '.' '[' push field_list pop ']'
     420        | no_attr_identifier '.' '[' push field_list pop ']'
    424421                { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) ) ); }
    425         | field_name ARROW field
     422        | no_attr_identifier ARROW field
    426423                { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) ) ); }
    427         | field_name ARROW '[' push field_list pop ']'
     424        | no_attr_identifier ARROW '[' push field_list pop ']'
    428425                { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) ) ); }
    429         ;
    430 
    431 field_name:
    432         no_attr_identifier
    433         | INTEGERconstant
    434426        ;
    435427
     
    674666                {
    675667                        Token fn;
    676                         fn.str = new string( "^?{}" );                          // location undefined
     668                        fn.str = new std::string( "^?{}" ); // location undefined
    677669                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    678670                }
     
    904896                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    905897        | 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 ) ) ); }
    907899        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    908900                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
     
    976968                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    977969        | '[' constant_expression ']' string_literal '(' constant_expression ')'
    978                 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
     970        { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    979971        ;
    980972
     
    13711363                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
    13721364        | LONG
    1373                 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
     1365                { $$ = DeclarationNode::newModifier( DeclarationNode::Long ); }
    13741366        | SHORT
    1375                 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
     1367                { $$ = DeclarationNode::newModifier( DeclarationNode::Short ); }
    13761368        | SIGNED
    1377                 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
     1369                { $$ = DeclarationNode::newModifier( DeclarationNode::Signed ); }
    13781370        | UNSIGNED
    1379                 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
     1371                { $$ = DeclarationNode::newModifier( DeclarationNode::Unsigned ); }
    13801372        | VOID
    13811373                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    13831375                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
    13841376        | COMPLEX                                                                                       // C99
    1385                 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     1377                { $$ = DeclarationNode::newBasicType( DeclarationNode::Complex ); }
    13861378        | IMAGINARY                                                                                     // C99
    1387                 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
     1379                { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
    13881380        | VALIST                                                                                        // GCC, __builtin_va_list
    13891381                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
     
    14751467aggregate_name:
    14761468        aggregate_key '{' field_declaration_list '}'
    1477                 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); }
     1469                { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3, true ); }
    14781470        | aggregate_key no_attr_identifier_or_type_name
    14791471                {
    14801472                        typedefTable.makeTypedef( *$2 );
    1481                         $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false );
     1473                        $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );
    14821474                }
    14831475        | aggregate_key no_attr_identifier_or_type_name
    14841476                { typedefTable.makeTypedef( *$2 ); }
    14851477                '{' field_declaration_list '}'
    1486                 { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); }
     1478                { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5, true ); }
    14871479        | 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 ); }
    14891481        | aggregate_key typegen_name                                            // CFA, S/R conflict
    14901482                { $$ = $2; }
     
    15671559enum_name:
    15681560        enum_key '{' enumerator_list comma_opt '}'
    1569                 { $$ = DeclarationNode::newEnum( nullptr, $3 ); }
     1561                { $$ = DeclarationNode::newEnum( 0, $3 ); }
    15701562        | enum_key no_attr_identifier_or_type_name
    15711563                {
     
    18571849type_class:                                                                                             // CFA
    18581850        OTYPE
    1859                 { $$ = DeclarationNode::Otype; }
     1851                { $$ = DeclarationNode::Type; }
    18601852        | DTYPE
    18611853                { $$ = DeclarationNode::Ftype; }
     
    20122004                {
    20132005                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2014                         linkage = LinkageSpec::linkageCheck( $2 );
     2006                        linkage = LinkageSpec::fromString( *$2 );
    20152007                }
    20162008          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
     
    25282520abstract_function:
    25292521        '(' 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 ); }
    25312523        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25322524                { $$ = $2->addParamList( $6 ); }
     
    25972589abstract_parameter_function:
    25982590        '(' 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 ); }
    26002592        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    26012593                { $$ = $2->addParamList( $6 ); }
     
    28012793                // empty (void) function return type.
    28022794        '[' ']' type_specifier
    2803                 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
     2795                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    28042796        | '[' ']' 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 ) ); }
    28062798        | multi_array_dimension type_specifier
    28072799                { $$ = $2->addNewArray( $1 ); }
    28082800        | '[' ']' new_abstract_ptr
    2809                 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
     2801                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
    28102802        | '[' ']' 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 ) ); }
    28122804        | multi_array_dimension new_abstract_ptr
    28132805                { $$ = $2->addNewArray( $1 ); }
     
    28212813new_abstract_function:                                                                  // CFA
    28222814        '[' ']' '(' new_parameter_type_list_opt ')'
    2823                 { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
     2815                { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0 ); }
    28242816        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
    2825                 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
     2817                { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
    28262818        | new_function_return '(' push new_parameter_type_list_opt pop ')'
    2827                 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
     2819                { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
    28282820        ;
    28292821
     
    28602852
    28612853void yyerror( const char * ) {
    2862         cout << "Error ";
     2854        std::cout << "Error ";
    28632855        if ( yyfilename ) {
    2864                 cout << "in file " << yyfilename << " ";
     2856                std::cout << "in file " << yyfilename << " ";
    28652857        } // 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;
    28672859}
    28682860
Note: See TracChangeset for help on using the changeset viewer.