Changeset 936e9f4 for src


Ignore:
Timestamp:
Aug 16, 2017, 6:31:41 PM (7 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:
21f0aa8, 6d49ea3
Parents:
fcc88a4
Message:

first attempt, add declarations into "if" conditional

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    rfcc88a4 r936e9f4  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Aug 10 16:54:00 2017
    13 // Update Count     : 789
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Aug 16 16:46:48 2017
     13// Update Count     : 794
    1414//
    1515
     
    376376Statement * build_expr( ExpressionNode * ctl );
    377377
     378struct IfCtl {
     379        IfCtl( DeclarationNode * decl, ExpressionNode * condition ) :
     380                init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
     381
     382        StatementNode * init;
     383        ExpressionNode * condition;
     384};
     385
    378386struct ForCtl {
    379387        ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
     
    387395};
    388396
    389 Statement * build_if( ExpressionNode * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
     397Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
    390398Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );
    391399Statement * build_case( ExpressionNode * ctl );
  • src/Parser/StatementNode.cc

    rfcc88a4 r936e9f4  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 11 21:23:15 2017
    13 // Update Count     : 331
     12// Last Modified On : Wed Aug 16 16:39:43 2017
     13// Update Count     : 340
    1414//
    1515
     
    7979}
    8080
    81 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
     81Statement *build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
    8282        Statement *thenb, *elseb = 0;
    8383        std::list< Statement * > branches;
     
    9292                elseb = branches.front();
    9393        } // if
    94         return new IfStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), thenb, elseb );
     94       
     95        std::list< Statement * > init;
     96        if ( ctl->init != 0 ) {
     97                buildMoveList( ctl->init, init );
     98        } // if
     99
     100        return new IfStmt( noLabels, notZeroExpr(
     101                                                           /*ctl->condition
     102                                                                 ?*/ maybeMoveBuild< Expression >(ctl->condition)
     103                                                                 /*: new VariableExpr( init.end() )*/ )
     104                                                   , thenb, elseb );
     105        // ret->initialization = init;
     106        // delete ctl;
     107        // assert( ret );
     108        // return ret;
    95109}
    96110
  • src/Parser/parser.yy

    rfcc88a4 r936e9f4  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  4 13:33:00 2017
    13 // Update Count     : 2475
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Aug 16 18:09:14 2017
     13// Update Count     : 2485
    1414//
    1515
     
    9898        StatementNode * sn;
    9999        ConstantExpr * constant;
     100        IfCtl * ifctl;
    100101        ForCtl * fctl;
    101102        LabelNode * label;
     
    175176%type<en> comma_expression                              comma_expression_opt
    176177%type<en> argument_expression_list              argument_expression                     default_initialize_opt
     178%type<ifctl> if_control_expression
    177179%type<fctl> for_control_expression
    178180%type<en> subrange
     
    794796
    795797selection_statement:
    796         IF '(' comma_expression ')' statement                           %prec THEN
     798        IF '(' if_control_expression ')' statement                              %prec THEN
    797799                // explicitly deal with the shift/reduce conflict on if/else
    798800                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    799         | IF '(' comma_expression ')' statement ELSE statement
     801        | IF '(' if_control_expression ')' statement ELSE statement
    800802                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    801803        | SWITCH '(' comma_expression ')' case_clause           // CFA
     
    819821                }
    820822        ;
     823
     824if_control_expression:
     825        comma_expression
     826                { $$ = new IfCtl( nullptr, $1 ); }
     827        | c_declaration                                                                         // no semi-coln
     828                { $$ = new IfCtl( $1, nullptr ); }
     829        | cfa_declaration                                                                       // no semi-colon
     830                { $$ = new IfCtl( $1, nullptr ); }
     831        | declaration comma_expression
     832                { $$ = new IfCtl( $1, $2 ); }
     833        ;
    821834
    822835// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
     
    10971110
    10981111KR_declaration_list:
    1099         c_declaration
    1100         | KR_declaration_list push c_declaration
     1112        c_declaration ';'
     1113        | KR_declaration_list push c_declaration ';'
    11011114                { $$ = $1->appendList( $3 ); }
    11021115        ;
     
    11171130        ;
    11181131
    1119 declaration:                                                                                    // CFA, new & old style declarations
    1120         cfa_declaration
    1121         | c_declaration
     1132declaration:                                                                                    // old & new style declarations
     1133        c_declaration ';'
     1134        | cfa_declaration ';'                                                           // CFA
    11221135        ;
    11231136
     
    11341147
    11351148cfa_declaration:                                                                                // CFA
    1136         cfa_variable_declaration pop ';'
    1137         | cfa_typedef_declaration pop ';'
    1138         | cfa_function_declaration pop ';'
    1139         | type_declaring_list pop ';'
    1140         | trait_specifier pop ';'
     1149        cfa_variable_declaration pop
     1150        | cfa_typedef_declaration pop
     1151        | cfa_function_declaration pop
     1152        | type_declaring_list pop
     1153        | trait_specifier pop
    11411154        ;
    11421155
     
    13381351
    13391352c_declaration:
    1340         declaration_specifier declaring_list pop ';'
     1353        declaration_specifier declaring_list pop
    13411354                {
    13421355                        $$ = distAttr( $1, $2 );
    13431356                }
    1344         | typedef_declaration pop ';'
    1345         | typedef_expression pop ';'                                            // GCC, naming expression type
    1346         | sue_declaration_specifier pop ';'
     1357        | typedef_declaration pop
     1358        | typedef_expression pop                                                        // GCC, naming expression type
     1359        | sue_declaration_specifier pop
    13471360        ;
    13481361
  • src/SynTree/Statement.h

    rfcc88a4 r936e9f4  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug  3 14:08:00 2017
    13 // Update Count     : 69
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Aug 16 16:28:55 2017
     13// Update Count     : 70
    1414//
    1515
     
    127127class IfStmt : public Statement {
    128128  public:
     129        std::list<Statement *> initialization;
    129130        Expression *condition;
    130131        Statement *thenPart;
     
    135136        virtual ~IfStmt();
    136137
     138        std::list<Statement *> &get_initialization() { return initialization; }
     139        void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    137140        Expression *get_condition() { return condition; }
    138141        void set_condition( Expression *newValue ) { condition = newValue; }
Note: See TracChangeset for help on using the changeset viewer.