Changeset 6d49ea3 for src/SynTree


Ignore:
Timestamp:
Aug 17, 2017, 5:37:20 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:
274ce8c
Parents:
936e9f4
Message:

second attempt, add declarations into if conditional

Location:
src/SynTree
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Mutator.cc

    r936e9f4 r6d49ea3  
    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 : Mon Jul 24 16:32:00 2017
    13 // Update Count     : 25
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 15:39:37 2017
     13// Update Count     : 27
    1414//
    1515
     
    114114
    115115Statement *Mutator::mutate( IfStmt *ifStmt ) {
     116        mutateAll( ifStmt->get_initialization(), *this );
    116117        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
    117118        ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
  • src/SynTree/Statement.cc

    r936e9f4 r6d49ea3  
    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 : Mon Aug 14 12:26:00 2017
    13 // Update Count     : 65
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 16:17:20 2017
     13// Update Count     : 67
    1414//
    1515
     
    3232using std::endl;
    3333
    34 Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {}
     34Statement::Statement( std::list<Label> labels ) : labels( labels ) {}
    3535
    3636void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {}
     
    3838Statement::~Statement() {}
    3939
    40 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
     40ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {}
    4141
    4242ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    8888const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    8989
    90 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) :
    91         Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) {
     90BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) :
     91        Statement( labels ), originalTarget( target ), target( target ), computedTarget( NULL ), type( type ) {
    9292        //actually this is a syntactic error signaled by the parser
    9393        if ( type == BranchStmt::Goto && target.empty() )
     
    9595}
    9696
    97 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) :
    98         Statement( labels ), computedTarget( _computedTarget ), type( _type ) {
     97BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) :
     98        Statement( labels ), computedTarget( computedTarget ), type( type ) {
    9999        if ( type != BranchStmt::Goto || computedTarget == 0 )
    100100                throw SemanticError("Computed target not valid in branch statement");
     
    105105}
    106106
    107 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {}
     107ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {}
    108108
    109109ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    122122}
    123123
    124 IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
    125         Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
     124IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
     125        Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    126126
    127127IfStmt::IfStmt( const IfStmt & other ) :
    128         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
     128        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
     129        cloneAll( other.initialization, initialization );
     130}
    129131
    130132IfStmt::~IfStmt() {
     133        deleteAll( initialization );
    131134        delete condition;
    132135        delete thenPart;
     
    139142        condition->print( os, indent + 4 );
    140143
     144        if ( !initialization.empty() ) {
     145                os << string( indent + 2, ' ' ) << "initialization: \n";
     146                for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     147                        os << string( indent + 4, ' ' );
     148                        (*it)->print( os, indent + 4 );
     149                }
     150                os << endl;
     151        }
     152
    141153        os << string( indent+2, ' ' ) << "... then: " << endl;
    142154
     
    151163}
    152164
    153 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
    154         Statement( _labels ), condition( _condition ), statements( _statements ) {
     165SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):
     166        Statement( labels ), condition( condition ), statements( statements ) {
    155167}
    156168
     
    179191}
    180192
    181 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
    182         Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
     193CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
     194        Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    183195        if ( isDefault() && condition != 0 )
    184196                throw SemanticError("default with conditions");
     
    216228}
    217229
    218 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
    219         Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
     230WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ):
     231        Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) {
    220232}
    221233
     
    238250}
    239251
    240 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    241         Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
     252ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
     253        Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    242254}
    243255
     
    317329}
    318330
    319 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
    320         Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) {
     331TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
     332        Statement( labels ), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    321333}
    322334
     
    351363}
    352364
    353 CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) :
    354         Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) {
     365CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
     366        Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    355367}
    356368
     
    389401
    390402
    391 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
     403FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) {
    392404        assert( labels.empty() ); // finally statement cannot be labeled
    393405}
  • src/SynTree/Statement.h

    r936e9f4 r6d49ea3  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 16:28:55 2017
    13 // Update Count     : 70
     12// Last Modified On : Thu Aug 17 15:37:53 2017
     13// Update Count     : 72
    1414//
    1515
     
    127127class IfStmt : public Statement {
    128128  public:
    129         std::list<Statement *> initialization;
    130129        Expression *condition;
    131130        Statement *thenPart;
    132131        Statement *elsePart;
    133 
    134         IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
     132        std::list<Statement *> initialization;
     133
     134        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart,
     135                        std::list<Statement *> initialization = std::list<Statement *>() );
    135136        IfStmt( const IfStmt &other );
    136137        virtual ~IfStmt();
    137138
    138139        std::list<Statement *> &get_initialization() { return initialization; }
    139         void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    140140        Expression *get_condition() { return condition; }
    141141        void set_condition( Expression *newValue ) { condition = newValue; }
     
    239239
    240240        std::list<Statement *> &get_initialization() { return initialization; }
    241         void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    242241        Expression *get_condition() { return condition; }
    243242        void set_condition( Expression *newValue ) { condition = newValue; }
  • src/SynTree/Visitor.cc

    r936e9f4 r6d49ea3  
    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 : Mon Jul 24 16:30:00 2017
    13 // Update Count     : 27
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 15:39:38 2017
     13// Update Count     : 29
    1414//
    1515
     
    9999
    100100void Visitor::visit( IfStmt *ifStmt ) {
     101        acceptAll( ifStmt->get_initialization(), *this );
    101102        maybeAccept( ifStmt->get_condition(), *this );
    102103        maybeAccept( ifStmt->get_thenPart(), *this );
Note: See TracChangeset for help on using the changeset viewer.