Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r20519b7 r6d49ea3  
    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
    14 //
    15 
    16 #include <list>
    17 #include <algorithm>
    18 #include <cassert>
    19 
    20 #include "ParseNode.h"
    21 #include "SynTree/Statement.h"
    22 #include "SynTree/Expression.h"
    23 #include "parserutility.h"
    24 #include "Common/utility.h"
     12// Last Modified On : Thu Aug 17 16:01:31 2017
     13// Update Count     : 345
     14//
     15
     16#include <cassert>                 // for assert, safe_dynamic_cast, assertf
     17#include <list>                    // for list
     18#include <memory>                  // for unique_ptr
     19#include <string>                  // for string
     20
     21#include "Common/SemanticError.h"  // for SemanticError
     22#include "Common/utility.h"        // for maybeMoveBuild, maybeBuild
     23#include "ParseNode.h"             // for StatementNode, ExpressionNode, bui...
     24#include "SynTree/Expression.h"    // for Expression, ConstantExpr
     25#include "SynTree/Label.h"         // for Label, noLabels
     26#include "SynTree/Declaration.h"
     27#include "SynTree/Statement.h"     // for Statement, BranchStmt, CaseStmt
     28#include "parserutility.h"         // for notZeroExpr
     29
     30class Declaration;
    2531
    2632using namespace std;
     
    7480}
    7581
    76 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
     82Statement *build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
    7783        Statement *thenb, *elseb = 0;
    7884        std::list< Statement * > branches;
     
    8793                elseb = branches.front();
    8894        } // if
    89         return new IfStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), thenb, elseb );
     95       
     96        std::list< Statement * > init;
     97        if ( ctl->init != 0 ) {
     98                buildMoveList( ctl->init, init );
     99        } // if
     100
     101        Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) );
     102        delete ctl;
     103        return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );
    90104}
    91105
Note: See TracChangeset for help on using the changeset viewer.