Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r658fafe4 r7f5566b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // StatementNode.cc --
     7// StatementNode.cc -- 
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 17:21:02 2016
    13 // Update Count     : 133
     12// Last Modified On : Thu Jul 30 14:39:39 2015
     13// Update Count     : 130
    1414//
    1515
     
    2222#include "SynTree/Expression.h"
    2323#include "parseutility.h"
    24 #include "Common/utility.h"
     24#include "utility.h"
    2525
    2626using namespace std;
    2727
    2828const char *StatementNode::StType[] = {
    29         "Exp",   "If",       "Switch", "Case",    "Default",  "Choose",   "Fallthru",
    30         "While", "Do",       "For",
     29        "Exp",   "If",       "Switch", "Case",    "Default",  "Choose",   "Fallthru", 
     30        "While", "Do",       "For", 
    3131        "Goto",  "Continue", "Break",  "Return",  "Throw",
    3232        "Try",   "Catch",    "Finally", "Asm",
     
    6262StatementNode::StatementNode( Type t, ExpressionNode *ctrl_label, StatementNode *block ) : type( t ), control( ctrl_label ), block( block ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {
    6363        this->control = ( t == Default ) ? 0 : control;
    64 }
     64} 
    6565
    6666StatementNode::StatementNode( Type t, string *target ) : type( t ), control( 0 ), block( 0 ), labels( 0 ), target( target ), decl( 0 ), isCatchRest ( false ) {}
     
    7474
    7575StatementNode * StatementNode::newCatchStmt( DeclarationNode *d, StatementNode *s, bool catchRestP ) {
    76         StatementNode *ret = new StatementNode( StatementNode::Catch, 0, s );
     76        StatementNode *ret = new StatementNode( StatementNode::Catch, 0, s ); 
    7777        ret->addDeclaration( d );
    7878        ret->setCatchRest( catchRestP );
     
    101101StatementNode *StatementNode::add_label( const std::string *l ) {
    102102        if ( l != 0 ) {
    103                 labels.push_front( *l );
     103                labels.push_front( *l ); 
    104104                delete l;
    105105        } // if
     
    107107}
    108108
    109 // StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) {
    110 //      if ( control && e )
    111 //              control->add_to_list( e ); // xxx - check this
    112 //      return this;
    113 // }
     109StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) {
     110        if ( control && e )
     111                control->add_to_list( e ); // xxx - check this
     112        return this;
     113}
    114114
    115115StatementNode *StatementNode::append_block( StatementNode *stmt ) {
     
    156156                        control->print( os, indent );
    157157                        os << endl;
    158                 } else
     158                } else 
    159159                        os << string( indent, ' ' ) << "Null Statement" << endl;
    160160                break;
     
    177177                if ( block ) {
    178178                        os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
    179                         block->printList( os, indent + 2 * ParseNode::indent_by );
     179                        block->printList( os, indent + 2 * ParseNode::indent_by ); 
    180180                } // if
    181181                if ( target ) {
     
    222222                                branches.pop_front();
    223223                        } // if
    224                         return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb );
     224                        return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb );
    225225                }
    226226          case While:
    227227                assert( branches.size() == 1 );
    228                 return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() );
     228                return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front() );
    229229          case Do:
    230230                assert( branches.size() == 1 );
    231                 return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true );
     231                return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front(), true );
    232232          case For:
    233233                {
     
    244244                        Expression *cond = 0;
    245245                        if ( ctl->get_condition() != 0 )
    246                                 cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) );
     246                                cond = notZeroExpr( ctl->get_condition()->build() );
    247247
    248248                        Expression *incr = 0;
    249249                        if ( ctl->get_change() != 0 )
    250                                 incr = maybeBuild<Expression>(ctl->get_change());
     250                                incr = ctl->get_change()->build();
    251251
    252252                        return new ForStmt( labs, init, cond, incr, branches.front() );
    253253                }
    254254          case Switch:
    255                 return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches );
    256           case Case:
    257                 return new CaseStmt( labs, maybeBuild<Expression>(get_control()), branches );
     255                return new SwitchStmt( labs, get_control()->build(), branches );
     256          case Choose:
     257                return new ChooseStmt( labs, get_control()->build(), branches );
     258          case Fallthru:
     259                return new FallthruStmt( labs );
     260          case Case:
     261                return new CaseStmt( labs, get_control()->build(), branches );
    258262          case Default:
    259263                return new CaseStmt( labs, 0, branches, true );
     
    262266                        if ( get_target() == "" ) {                                     // computed goto
    263267                                assert( get_control() != 0 );
    264                                 return new BranchStmt( labs, maybeBuild<Expression>(get_control()), BranchStmt::Goto );
     268                                return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto );
    265269                        } // if
    266270
     
    390394                os << string( indent + ParseNode::indent_by, ' ' ) << "Goto Labels:" << endl;
    391395                os << string( indent + 2 * ParseNode::indent_by, ' ' );
    392                 for ( std::list<Label>::const_iterator i = gotolabels.begin();; ) {
     396                for ( std::list<std::string>::const_iterator i = gotolabels.begin();; ) {
    393397                        os << *i;
    394398                        i++;
     
    417421}
    418422
     423
     424void NullStmtNode::print( ostream &os, int indent ) const {
     425        os << string( indent, ' ' ) << "Null Statement:" << endl;
     426}
     427
     428Statement *NullStmtNode::build() const {
     429        return new NullStmt;
     430}
     431
    419432// Local Variables: //
    420433// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.