Changes in / [274ce8c:8f6dfe7]


Ignore:
Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ForExprMutator.cc

    r274ce8c r8f6dfe7  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:32:46 2017
    13 // Update Count     : 11
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:14:44 2015
     13// Update Count     : 10
    1414//
    1515
     
    2121
    2222namespace ControlStruct {
    23         Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
    24                 std::list<Statement *> &init = ifStmt->get_initialization();
    25                 if ( init.size() == 0 ) {
    26                         return ifStmt;
    27                 } // if
    28 
    29                 // create compound statement, move initializers outside, leave _for_ as-is
    30                 CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    31                 std::list<Statement *> &stmts = block->get_kids();
    32                 stmts.splice( stmts.end(), init );
    33 
    34                 // add for to the new block
    35                 stmts.push_back( ifStmt );
    36                 return block;
    37         }
    38 
    3923        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    4024                // hoist any initializer declarations to make them C89 (rather than C99)
     
    4731                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    4832                std::list<Statement *> &stmts = block->get_kids();
    49                 stmts.splice( stmts.end(), init );
     33                for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) {
     34                        stmts.push_back( *it );
     35                }       // for
    5036
    5137                // add for to the new block
    5238                stmts.push_back( forStmt );
     39                forStmt->set_initialization( std::list<Statement *>() );
    5340                return block;
    5441        }
  • src/ControlStruct/ForExprMutator.h

    r274ce8c r8f6dfe7  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:32:48 2017
    13 // Update Count     : 5
     12// Last Modified On : Sat Jul 22 09:17:08 2017
     13// Update Count     : 4
    1414//
    1515
    1616#pragma once
    1717
    18 class IfStmt;
    1918class ForStmt;
    2019class Statement;
     
    2322        class ForExprMutator {
    2423          public:
    25                 Statement *postmutate( IfStmt * );
    2624                Statement *postmutate( ForStmt * );
    2725        };
  • src/Parser/StatementNode.cc

    r274ce8c r8f6dfe7  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:01:31 2017
    13 // Update Count     : 345
     12// Last Modified On : Wed Aug 16 16:39:43 2017
     13// Update Count     : 340
    1414//
    1515
     
    2424#include "SynTree/Expression.h"    // for Expression, ConstantExpr
    2525#include "SynTree/Label.h"         // for Label, noLabels
    26 #include "SynTree/Declaration.h"
    2726#include "SynTree/Statement.h"     // for Statement, BranchStmt, CaseStmt
    2827#include "parserutility.h"         // for notZeroExpr
     
    9998        } // if
    10099
    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 );
     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;
    104109}
    105110
  • src/Parser/parser.yy

    r274ce8c r8f6dfe7  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:52:12 2017
    13 // Update Count     : 2489
     12// Last Modified On : Wed Aug 16 18:09:14 2017
     13// Update Count     : 2485
    1414//
    1515
     
    796796
    797797selection_statement:
    798         IF '(' push if_control_expression ')' statement                         %prec THEN
     798        IF '(' if_control_expression ')' statement                              %prec THEN
    799799                // explicitly deal with the shift/reduce conflict on if/else
    800                 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
    801         | IF '(' push if_control_expression ')' statement ELSE statement
    802                 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
     800                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
     801        | IF '(' if_control_expression ')' statement ELSE statement
     802                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    803803        | SWITCH '(' comma_expression ')' case_clause           // CFA
    804804                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
     
    823823
    824824if_control_expression:
    825         comma_expression pop
     825        comma_expression
    826826                { $$ = new IfCtl( nullptr, $1 ); }
    827         | c_declaration                                                                         // no semi-colon
     827        | c_declaration                                                                         // no semi-coln
    828828                { $$ = new IfCtl( $1, nullptr ); }
    829829        | cfa_declaration                                                                       // no semi-colon
    830830                { $$ = new IfCtl( $1, nullptr ); }
    831         | declaration comma_expression                                          // semi-colon separated
     831        | declaration comma_expression
    832832                { $$ = new IfCtl( $1, $2 ); }
    833833        ;
  • src/SymTab/Indexer.cc

    r274ce8c r8f6dfe7  
    1010// Created On       : Sun May 17 21:37:33 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:08:40 2017
    13 // Update Count     : 20
     12// Last Modified On : Thu Mar 30 16:38:47 2017
     13// Update Count     : 19
    1414//
    1515
     
    351351                acceptAll( compoundStmt->get_kids(), *this );
    352352                leaveScope();
    353         }
    354 
    355         void Indexer::visit( IfStmt *ifStmt ) {
    356             // for statements introduce a level of scope
    357             enterScope();
    358             Visitor::visit( ifStmt );
    359             leaveScope();
    360353        }
    361354
  • src/SymTab/Indexer.h

    r274ce8c r8f6dfe7  
    1010// Created On       : Sun May 17 21:38:55 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:09:12 2017
    13 // Update Count     : 8
     12// Last Modified On : Sat Jul 22 09:46:34 2017
     13// Update Count     : 7
    1414//
    1515
     
    4545
    4646                virtual void visit( CompoundStmt *compoundStmt );
    47                 virtual void visit( IfStmt *ifStmt );
    4847                virtual void visit( ForStmt *forStmt );
    4948                virtual void visit( CatchStmt *catchStmt );
  • src/SynTree/Mutator.cc

    r274ce8c r8f6dfe7  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:39:37 2017
    13 // Update Count     : 27
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jul 24 16:32:00 2017
     13// Update Count     : 25
    1414//
    1515
     
    114114
    115115Statement *Mutator::mutate( IfStmt *ifStmt ) {
    116         mutateAll( ifStmt->get_initialization(), *this );
    117116        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
    118117        ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
  • src/SynTree/Statement.cc

    r274ce8c r8f6dfe7  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:17:20 2017
    13 // Update Count     : 67
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Aug 14 12:26:00 2017
     13// Update Count     : 65
    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, std::list<Statement *> initialization ):
    125         Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
     124IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
     125        Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
    126126
    127127IfStmt::IfStmt( const IfStmt & other ) :
    128         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
    129         cloneAll( other.initialization, initialization );
    130 }
     128        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
    131129
    132130IfStmt::~IfStmt() {
    133         deleteAll( initialization );
    134131        delete condition;
    135132        delete thenPart;
     
    142139        condition->print( os, indent + 4 );
    143140
    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 
    153141        os << string( indent+2, ' ' ) << "... then: " << endl;
    154142
     
    163151}
    164152
    165 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):
    166         Statement( labels ), condition( condition ), statements( statements ) {
     153SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
     154        Statement( _labels ), condition( _condition ), statements( _statements ) {
    167155}
    168156
     
    191179}
    192180
    193 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
    194         Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
     181CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
     182        Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
    195183        if ( isDefault() && condition != 0 )
    196184                throw SemanticError("default with conditions");
     
    228216}
    229217
    230 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ):
    231         Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) {
     218WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
     219        Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
    232220}
    233221
     
    250238}
    251239
    252 ForStmt::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 ) {
     240ForStmt::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_ ) {
    254242}
    255243
     
    329317}
    330318
    331 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
    332         Statement( labels ), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
     319TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
     320        Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) {
    333321}
    334322
     
    363351}
    364352
    365 CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
    366         Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
     353CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) :
     354        Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) {
    367355}
    368356
     
    401389
    402390
    403 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) {
     391FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
    404392        assert( labels.empty() ); // finally statement cannot be labeled
    405393}
  • src/SynTree/Statement.h

    r274ce8c r8f6dfe7  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:37:53 2017
    13 // Update Count     : 72
     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;
    131132        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 *>() );
     133
     134        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    136135        IfStmt( const IfStmt &other );
    137136        virtual ~IfStmt();
    138137
    139138        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; }
    241242        Expression *get_condition() { return condition; }
    242243        void set_condition( Expression *newValue ) { condition = newValue; }
  • src/SynTree/Visitor.cc

    r274ce8c r8f6dfe7  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:39:38 2017
    13 // Update Count     : 29
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jul 24 16:30:00 2017
     13// Update Count     : 27
    1414//
    1515
     
    9999
    100100void Visitor::visit( IfStmt *ifStmt ) {
    101         acceptAll( ifStmt->get_initialization(), *this );
    102101        maybeAccept( ifStmt->get_condition(), *this );
    103102        maybeAccept( ifStmt->get_thenPart(), *this );
Note: See TracChangeset for help on using the changeset viewer.