Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r8cc5cb0 r413ad05  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 11 18:02:57 2016
    13 // Update Count     : 1861
     12// Last Modified On : Fri Aug 26 16:45:44 2016
     13// Update Count     : 1964
    1414//
    1515
     
    4343#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
    45 extern char *yytext;
    4645
    4746#undef __GNUC_MINOR__
     
    5655#include "LinkageSpec.h"
    5756
    58 DeclarationNode *theTree = 0;                                                   // the resulting parse tree
    59 LinkageSpec::Type linkage = LinkageSpec::Cforall;
    60 std::stack< LinkageSpec::Type > linkageStack;
    61 TypedefTable typedefTable;
    62 
    63 void appendStr( std::string &to, std::string *from ) {
     57extern DeclarationNode * parseTree;
     58extern LinkageSpec::Spec linkage;
     59extern TypedefTable typedefTable;
     60
     61std::stack< LinkageSpec::Spec > linkageStack;
     62
     63void appendStr( std::string *to, std::string *from ) {
    6464        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    65         to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) );
     65        to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
    6666} // appendStr
    6767%}
     
    126126        InitializerNode *in;
    127127        OperKinds op;
     128        std::string *str;
    128129        bool flag;
    129130}
     
    131132%type<tok> identifier  no_01_identifier  no_attr_identifier zero_one
    132133%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name
    133 %type<constant> string_literal_list
     134%type<constant> string_literal
     135%type<str> string_literal_list
    134136
    135137// expressions
     
    143145%type<en> constant_expression                   assignment_expression           assignment_expression_opt
    144146%type<en> comma_expression                              comma_expression_opt
    145 //%type<en> argument_expression_list            argument_expression                     for_control_expression          assignment_opt
    146147%type<en> argument_expression_list              argument_expression                     assignment_opt
    147148%type<fctl> for_control_expression
     
    162163%type<sn> case_value_list                               case_label                                      case_label_list
    163164%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    164 %type<pn> handler_list                                  handler_clause                          finally_clause
     165%type<sn> handler_list                                  handler_clause                          finally_clause
    165166
    166167// declarations
     
    224225%type<decl> paren_identifier paren_type
    225226
    226 %type<decl> storage_class storage_class_name storage_class_list
     227%type<decl> storage_class storage_class_list
    227228
    228229%type<decl> sue_declaration_specifier sue_type_specifier
     
    297298
    298299push:
    299                 {
    300                         typedefTable.enterScope();
    301                 }
     300                { typedefTable.enterScope(); }
    302301        ;
    303302
    304303pop:
    305                 {
    306                         typedefTable.leaveScope();
    307                 }
     304                { typedefTable.leaveScope(); }
    308305        ;
    309306
     
    312309constant:
    313310                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    314 INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
     311        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    315312        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    316313        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     
    338335        ;
    339336
     337string_literal:
     338        string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
     339        ;
     340
    340341string_literal_list:                                                                    // juxtaposed strings are concatenated
    341         STRINGliteral                                                           { $$ = build_constantStr( *$1 ); }
     342        STRINGliteral                                                           { $$ = $1; } // conversion from tok to str
    342343        | string_literal_list STRINGliteral
    343344                {
    344                         appendStr( $1->get_constant()->get_value(), $2 );
     345                        appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
    345346                        delete $2;                                                                      // allocated by lexer
    346                         $$ = $1;
     347                        $$ = $1;                                                                        // conversion from tok to str
    347348                }
    348349        ;
     
    371372        | postfix_expression '(' argument_expression_list ')'
    372373                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    373         // ambiguity with .0 so space required after field-selection, e.g.
     374                // ambiguity with .0 so space required after field-selection, e.g.
    374375                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    375376        | postfix_expression '.' no_attr_identifier
     
    389390                        Token fn;
    390391                        fn.str = new std::string( "?{}" ); // location undefined
    391                         $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_link( $3 ) ) );
     392                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) );
    392393                }
    393394        ;
     
    396397        argument_expression
    397398        | argument_expression_list ',' argument_expression
    398                 { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
     399                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    399400        ;
    400401
     
    407408field_list:                                                                                             // CFA, tuple field selector
    408409        field
    409         | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_link( $3 ); }
     410        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    410411        ;
    411412
     
    413414        no_attr_identifier
    414415                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    415         // ambiguity with .0 so space required after field-selection, e.g.
     416                // ambiguity with .0 so space required after field-selection, e.g.
    416417                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    417418        | no_attr_identifier '.' field
     
    431432        | constant
    432433                { $$ = $1; }
    433         | string_literal_list
     434        | string_literal
    434435                { $$ = new ExpressionNode( $1 ); }
    435436        | EXTENSION cast_expression                                                     // GCC
     
    607608assignment_operator:
    608609        '='                                                                                     { $$ = OperKinds::Assign; }
     610        | ATassign                                                                      { $$ = OperKinds::AtAssn; }
    609611        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
    610612        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     
    627629                { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    628630        | '[' push ',' tuple_expression_list pop ']'
    629                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_link( $4 ) ) ); }
     631                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
    630632        | '[' push assignment_expression ',' tuple_expression_list pop ']'
    631                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) ); }
     633                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
    632634        ;
    633635
     
    635637        assignment_expression_opt
    636638        | tuple_expression_list ',' assignment_expression_opt
    637                 { $$ = (ExpressionNode *)$1->set_link( $3 ); }
     639                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    638640        ;
    639641
     
    665667                        Token fn;
    666668                        fn.str = new std::string( "^?{}" ); // location undefined
    667                         $$ = new StatementNode2( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_link( $4 ) ) ) ) );
     669                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    668670                }
    669671        ;
     
    679681compound_statement:
    680682        '{' '}'
    681                 { $$ = new CompoundStmtNode( (StatementNode *)0 ); }
     683                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    682684        | '{'
    683685                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     
    686688          local_label_declaration_opt                                           // GCC, local labels
    687689          block_item_list pop '}'                                                       // C99, intermix declarations and statements
    688                 { $$ = new CompoundStmtNode( $5 ); }
     690                { $$ = new StatementNode( build_compound( $5 ) ); }
    689691        ;
    690692
     
    692694        block_item
    693695        | block_item_list push block_item
    694                 { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } }
     696                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    695697        ;
    696698
     
    700702        | EXTENSION declaration                                                         // GCC
    701703                {       // mark all fields in list
    702                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
     704                        for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    703705                                iter->set_extension( true );
    704706                        $$ = new StatementNode( $2 );
     
    712714        statement
    713715        | statement_list statement
    714                 { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } }
     716                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    715717        ;
    716718
    717719expression_statement:
    718720        comma_expression_opt ';'
    719                 { $$ = new StatementNode2( build_expr( $1 ) ); }
     721                { $$ = new StatementNode( build_expr( $1 ) ); }
    720722        ;
    721723
     
    723725        IF '(' comma_expression ')' statement                           %prec THEN
    724726                // explicitly deal with the shift/reduce conflict on if/else
    725                 { $$ = new StatementNode2( build_if( $3, $5, nullptr ) ); }
     727                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    726728        | IF '(' comma_expression ')' statement ELSE statement
    727                 { $$ = new StatementNode2( build_if( $3, $5, $7 ) ); }
     729                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    728730        | SWITCH '(' comma_expression ')' case_clause           // CFA
    729                 { $$ = new StatementNode2( build_switch( $3, $5 ) ); }
     731                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    730732        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    731733                {
    732                         StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) );
     734                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
    733735                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    734736                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     
    736738                        // therefore, are removed from the grammar even though C allows it. The change also applies to choose
    737739                        // statement.
    738                         $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
     740                        $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    739741                }
    740742        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    741                 { $$ = new StatementNode2( build_switch( $3, $5 ) ); }
     743                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    742744        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    743745                {
    744                         StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) );
    745                         $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
     746                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     747                        $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    746748                }
    747749        ;
     
    758760
    759761case_value_list:                                                                                // CFA
    760         //case_value                                                                    { $$ = new StatementNode( StatementNode::Case, $1, 0 ); }
    761         case_value                                                                      { $$ = new StatementNode2( build_case( $1 ) ); }
     762        case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
    762763                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
    763         | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_link( new StatementNode2( build_case( $3 ) ) ) ); }
     764        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
    764765        ;
    765766
    766767case_label:                                                                                             // CFA
    767768        CASE case_value_list ':'                                        { $$ = $2; }
    768         | DEFAULT ':'                                                           { $$ = new StatementNode2( build_default() ); }
     769        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
    769770                // A semantic check is required to ensure only one default clause per switch/choose statement.
    770771        ;
     
    772773case_label_list:                                                                                // CFA
    773774        case_label
    774         | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_link( $2 )); }
     775        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
    775776        ;
    776777
    777778case_clause:                                                                                    // CFA
    778         case_label_list statement                                       { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
     779        case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    779780        ;
    780781
     
    787788switch_clause_list:                                                                             // CFA
    788789        case_label_list statement_list
    789                 { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
     790                { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    790791        | switch_clause_list case_label_list statement_list
    791                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); }
     792                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
    792793        ;
    793794
     
    802803                { $$ = $1->append_last_case( $2 ); }
    803804        | case_label_list statement_list fall_through_opt
    804                 { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); }
     805                { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    805806        | choose_clause_list case_label_list fall_through
    806                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
     807                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    807808        | choose_clause_list case_label_list statement_list fall_through_opt
    808                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); }
     809                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    809810        ;
    810811
    811812fall_through_opt:                                                                               // CFA
    812813        // empty
    813                 { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
     814                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
    814815        | fall_through
    815816        ;
     
    824825iteration_statement:
    825826        WHILE '(' comma_expression ')' statement
    826                 { $$ = new StatementNode2( build_while( $3, $5 ) ); }
     827                { $$ = new StatementNode( build_while( $3, $5 ) ); }
    827828        | DO statement WHILE '(' comma_expression ')' ';'
    828                 { $$ = new StatementNode2( build_while( $5, $2 ) ); }
     829                { $$ = new StatementNode( build_while( $5, $2 ) ); }
    829830        | FOR '(' push for_control_expression ')' statement
    830                 { $$ = new StatementNode2( build_for( $4, $6 ) ); }
     831                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    831832        ;
    832833
     
    840841jump_statement:
    841842        GOTO IDENTIFIER ';'
    842                 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Goto ) ); }
     843                { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }
    843844        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    844845                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
    845846                // whereas normal operator precedence yields goto (*i)+3;
    846                 { $$ = new StatementNode2( build_computedgoto( $3 ) ); }
     847                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
    847848        | CONTINUE ';'
    848849                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    849                 { $$ = new StatementNode2( build_branch( "", BranchStmt::Continue ) ); }
     850                { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }
    850851        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    851852                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    852853                // the target of the transfer appears only at the start of an iteration statement.
    853                 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
     854                { $$ = new StatementNode( build_branch( $2, BranchStmt::Continue ) ); }
    854855        | BREAK ';'
    855856                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    856                 { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); }
     857                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }
    857858        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    858859                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    859860                // the target of the transfer appears only at the start of an iteration statement.
    860                 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
     861                { $$ = new StatementNode( build_branch( $2, BranchStmt::Break ) ); }
    861862        | RETURN comma_expression_opt ';'
    862                 { $$ = new StatementNode2( build_return( $2 ) ); }
     863                { $$ = new StatementNode( build_return( $2 ) ); }
    863864        | THROW assignment_expression_opt ';'                           // handles rethrow
    864                 { $$ = new StatementNode2( build_throw( $2 ) ); }
     865                { $$ = new StatementNode( build_throw( $2 ) ); }
    865866        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
    866                 { $$ = new StatementNode2( build_throw( $2 ) ); }
     867                { $$ = new StatementNode( build_throw( $2 ) ); }
    867868        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
    868                 { $$ = new StatementNode2( build_throw( $2 ) ); }
     869                { $$ = new StatementNode( build_throw( $2 ) ); }
    869870        ;
    870871
    871872exception_statement:
    872873        TRY compound_statement handler_list
    873                 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
     874                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
    874875        | TRY compound_statement finally_clause
    875                 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
     876                { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
    876877        | TRY compound_statement handler_list finally_clause
    877                 {
    878                         $3->set_link( $4 );
    879                         $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 ))));
    880                 }
     878                { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
    881879        ;
    882880
    883881handler_list:
    884                 // There must be at least one catch clause
    885882        handler_clause
    886883                // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
    887884        | CATCH '(' ELLIPSIS ')' compound_statement
    888                 { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
     885                { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    889886        | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
    890                 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
     887                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    891888        | CATCHRESUME '(' ELLIPSIS ')' compound_statement
    892                 { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
     889                { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    893890        | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
    894                 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
     891                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    895892        ;
    896893
    897894handler_clause:
    898895        CATCH '(' push push exception_declaration pop ')' compound_statement pop
    899                 { $$ = StatementNode::newCatchStmt( $5, $8 ); }
     896                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    900897        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
    901                 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
     898        { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
    902899        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    903                 { $$ = StatementNode::newCatchStmt( $5, $8 ); }
     900                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    904901        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    905                 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
     902                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
    906903        ;
    907904
     
    909906        FINALLY compound_statement
    910907                {
    911                         $$ = new StatementNode( StatementNode::Finally, 0, $2 );
    912                         std::cout << "Just created a finally node" << std::endl;
     908                        $$ = new StatementNode( build_finally( $2 ) );
    913909                }
    914910        ;
     
    937933
    938934asm_statement:
    939         ASM asm_volatile_opt '(' string_literal_list ')' ';'
    940                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); }
    941         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
    942                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); }
    943         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    944                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); }
    945         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    946                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); }
    947         | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    948                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); }
     935        ASM asm_volatile_opt '(' string_literal ')' ';'
     936                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
     937        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
     938                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
     939        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
     940                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
     941        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
     942                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
     943        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
     944                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
    949945        ;
    950946
     
    965961        asm_operand
    966962        | asm_operands_list ',' asm_operand
    967                 { $$ = (ExpressionNode *)$1->set_link( $3 ); }
     963                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    968964        ;
    969965
    970966asm_operand:                                                                                    // GCC
    971         string_literal_list '(' constant_expression ')'
    972                 { $$ = new ExpressionNode( build_asm( 0, $1, $3 ) ); }
    973         | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
    974         { $$ = new ExpressionNode( build_asm( $2, $4, $6 ) ); }
     967        string_literal '(' constant_expression ')'
     968                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
     969        | '[' constant_expression ']' string_literal '(' constant_expression ')'
     970        { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    975971        ;
    976972
     
    978974        // empty
    979975                { $$ = 0; }                                                                             // use default argument
    980         | string_literal_list
     976        | string_literal
    981977                { $$ = new ExpressionNode( $1 ); }
    982         | asm_clobbers_list_opt ',' string_literal_list
    983         { $$ = (ExpressionNode *)$1->set_link( new ExpressionNode( $3 ) ); }
     978        | asm_clobbers_list_opt ',' string_literal
     979                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    984980        ;
    985981
    986982label_list:
    987983        no_attr_identifier
    988                 { $$ = new LabelNode(); $$->append_label( $1 ); }
     984                {
     985                        $$ = new LabelNode(); $$->labels.push_back( *$1 );
     986                        delete $1;                                                                      // allocated by lexer
     987                }
    989988        | label_list ',' no_attr_identifier
    990                 { $$ = $1; $1->append_label( $3 ); }
     989                {
     990                        $$ = $1; $1->labels.push_back( *$3 );
     991                        delete $3;                                                                      // allocated by lexer
     992                }
    991993        ;
    992994
     
    12861288        type_qualifier_name
    12871289        | attribute
    1288         //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
     1290                //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
    12891291        ;
    12901292
     
    13311333
    13321334storage_class:
    1333         storage_class_name
    1334         ;
    1335 
    1336 storage_class_name:
    13371335        EXTERN
    13381336                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }
     
    13441342                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); }
    13451343        | INLINE                                                                                        // C99
    1346                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
     1344                //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
     1345                { $$ = new DeclarationNode; $$->isInline = true; }
    13471346        | FORTRAN                                                                                       // C99
    13481347                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); }
    13491348        | NORETURN                                                                                      // C11
    1350                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); }
     1349                //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); }
     1350                { $$ = new DeclarationNode; $$->isNoreturn = true; }
    13511351        | THREADLOCAL                                                                           // C11
    13521352                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); }
     
    15041504        | EXTENSION field_declaring_list ';'                            // GCC
    15051505                {       // mark all fields in list
    1506                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
     1506                        for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    15071507                                iter->set_extension( true );
    15081508                        $$ = $2;
     
    17501750        | initializer
    17511751        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    1752         | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_link( $3 ) ); }
     1752        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    17531753        | initializer_list ',' designation initializer
    1754                 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); }
     1754                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    17551755        ;
    17561756
     
    17741774        designator
    17751775        | designator_list designator
    1776                 { $$ = (ExpressionNode *)( $1->set_link( $2 ) ); }
     1776                { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
    17771777        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    17781778        ;
     
    18801880        | assignment_expression
    18811881        | type_name_list ',' type_name
    1882                 { $$ = (ExpressionNode *)( $1->set_link( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
     1882                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
    18831883        | type_name_list ',' assignment_expression
    1884                 { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
     1884                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    18851885        ;
    18861886
     
    19811981                {}                                                                                              // empty input file
    19821982        | external_definition_list
    1983                 {
    1984                         if ( theTree ) {
    1985                                 theTree->appendList( $1 );
    1986                         } else {
    1987                                 theTree = $1;
    1988                         }
    1989                 }
     1983                { parseTree = parseTree != nullptr ? parseTree->appendList( $1 ) : $1;  }
    19901984        ;
    19911985
     
    19931987        external_definition
    19941988        | external_definition_list push external_definition
    1995                 { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }
     1989                { $$ = $1 != nullptr ? $1->appendList( $3 ) : $3; }
    19961990        ;
    19971991
     
    20092003        | EXTERN STRINGliteral
    20102004                {
    2011                         linkageStack.push( linkage );
     2005                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    20122006                        linkage = LinkageSpec::fromString( *$2 );
    20132007                }
     
    20202014        | EXTENSION external_definition
    20212015                {       // mark all fields in list
    2022                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
     2016                        for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    20232017                                iter->set_extension( true );
    20242018                        $$ = $2;
     
    21212115asm_name_opt:                                                                                   // GCC
    21222116        // empty
    2123         | ASM '(' string_literal_list ')' attribute_list_opt
     2117        | ASM '(' string_literal_list ')' attribute_list_opt { delete $3; }     // FIX ME: unimplemented
    21242118        ;
    21252119
     
    21502144        // empty
    21512145        | any_word
    2152         | any_word '(' comma_expression_opt ')'
     2146        | any_word '(' comma_expression_opt ')' { delete $3; } // FIX ME: unimplemented
    21532147        ;
    21542148
    21552149any_word:                                                                                               // GCC
    2156         identifier_or_type_name {}
    2157         | storage_class_name {}
    2158         | basic_type_name {}
    2159         | type_qualifier {}
     2150        identifier_or_type_name { delete $1; }                          // FIX ME: unimplemented
     2151        | storage_class { delete $1; }                                          // FIX ME: unimplemented
     2152        | basic_type_name { delete $1; }                                        // FIX ME: unimplemented
     2153        | type_qualifier { delete $1; }                                         // FIX ME: unimplemented
    21602154        ;
    21612155
     
    28552849// ----end of grammar----
    28562850
     2851extern char *yytext;
     2852
    28572853void yyerror( const char * ) {
    28582854        std::cout << "Error ";
Note: See TracChangeset for help on using the changeset viewer.