Ignore:
Timestamp:
Sep 24, 2016, 12:08:02 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
9c23f31
Parents:
1b772749
Message:

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r1b772749 r2298f728  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 18:12:21 2016
    13 // Update Count     : 1978
     12// Last Modified On : Sat Sep 24 11:30:40 2016
     13// Update Count     : 1991
    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 ) );
     
    389390                {
    390391                        Token fn;
    391                         fn.str = new std::string( "?{}" ); // location undefined
     392                        fn.str = new string( "?{}" );                           // location undefined
    392393                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) );
    393394                }
     
    666667                {
    667668                        Token fn;
    668                         fn.str = new std::string( "^?{}" ); // location undefined
     669                        fn.str = new string( "^?{}" );                          // location undefined
    669670                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    670671                }
     
    14671468aggregate_name:
    14681469        aggregate_key '{' field_declaration_list '}'
    1469                 { $$ = DeclarationNode::newAggregate( $1, new std::string( "" ), nullptr, $3, true ); }
     1470                { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); }
    14701471        | aggregate_key no_attr_identifier_or_type_name
    14711472                {
    14721473                        typedefTable.makeTypedef( *$2 );
    1473                         $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );
     1474                        $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false );
    14741475                }
    14751476        | aggregate_key no_attr_identifier_or_type_name
     
    14781479                { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); }
    14791480        | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    1480                 { $$ = DeclarationNode::newAggregate( $1, new std::string( "" ), $3, $6, false ); }
     1481                { $$ = DeclarationNode::newAggregate( $1, nullptr, $3, $6, false ); }
    14811482        | aggregate_key typegen_name                                            // CFA, S/R conflict
    14821483                { $$ = $2; }
     
    15591560enum_name:
    15601561        enum_key '{' enumerator_list comma_opt '}'
    1561                 { $$ = DeclarationNode::newEnum( new std::string( "" ), $3 ); }
     1562                { $$ = DeclarationNode::newEnum( nullptr, $3 ); }
    15621563        | enum_key no_attr_identifier_or_type_name
    15631564                {
     
    25202521abstract_function:
    25212522        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
    2522                 { $$ = DeclarationNode::newFunction( new std::string( "" ), nullptr, $3, nullptr ); }
     2523                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
    25232524        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25242525                { $$ = $2->addParamList( $6 ); }
     
    25892590abstract_parameter_function:
    25902591        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
    2591                 { $$ = DeclarationNode::newFunction( new std::string( "" ), nullptr, $3, nullptr ); }
     2592                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
    25922593        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25932594                { $$ = $2->addParamList( $6 ); }
     
    27932794                // empty (void) function return type.
    27942795        '[' ']' type_specifier
    2795                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2796                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    27962797        | '[' ']' multi_array_dimension type_specifier
    2797                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2798                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    27982799        | multi_array_dimension type_specifier
    27992800                { $$ = $2->addNewArray( $1 ); }
    28002801        | '[' ']' new_abstract_ptr
    2801                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2802                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    28022803        | '[' ']' multi_array_dimension new_abstract_ptr
    2803                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2804                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    28042805        | multi_array_dimension new_abstract_ptr
    28052806                { $$ = $2->addNewArray( $1 ); }
     
    28132814new_abstract_function:                                                                  // CFA
    28142815        '[' ']' '(' new_parameter_type_list_opt ')'
    2815         { $$ = DeclarationNode::newFunction( new std::string( "" ), DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
     2816                { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    28162817        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
    2817                 { $$ = DeclarationNode::newFunction( new std::string( "" ), $1, $4, nullptr ); }
     2818                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28182819        | new_function_return '(' push new_parameter_type_list_opt pop ')'
    2819                 { $$ = DeclarationNode::newFunction( new std::string( "" ), $1, $4, nullptr ); }
     2820                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28202821        ;
    28212822
     
    28522853
    28532854void yyerror( const char * ) {
    2854         std::cout << "Error ";
     2855        cout << "Error ";
    28552856        if ( yyfilename ) {
    2856                 std::cout << "in file " << yyfilename << " ";
     2857                cout << "in file " << yyfilename << " ";
    28572858        } // if
    2858         std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;
     2859        cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;
    28592860}
    28602861
Note: See TracChangeset for help on using the changeset viewer.