Changeset 145f1fc


Ignore:
Timestamp:
Jul 15, 2015, 2:59:57 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
1ab4ce2, 2794fff, e45215c
Parents:
85c4ef0
Message:

modified ForStmt? to have a list of statements for the initialization portion, and reverted to hoisting the initialization

Location:
src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r85c4ef0 r145f1fc  
    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 : Fri Jun 26 16:52:58 2015
    13 // Update Count     : 144
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:47:42 2015
     13// Update Count     : 177
    1414//
    1515
     
    3838        int CodeGenerator::tabsize = 4;
    3939
    40         // the kinds of statements that would ideally be separated by more whitespace
     40        // the kinds of statements that would ideally be followed by whitespace
    4141        bool wantSpacing( Statement * stmt) {
    4242                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
     
    588588
    589589        void CodeGenerator::visit( ForStmt *forStmt ) {
    590                 output << "for (";
    591 
    592                 if ( forStmt->get_initialization() != 0 )
    593                         forStmt->get_initialization()->accept( *this );
    594                 else
    595                         output << ";";
    596                
     590                // initialization is always hoisted, so don't
     591                // bother doing anything with that
     592                output << "for (;";
     593
    597594                if ( forStmt->get_condition() != 0 )
    598595                        forStmt->get_condition()->accept( *this );
  • src/ControlStruct/ForExprMutator.cc

    r85c4ef0 r145f1fc  
    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 : Tue May 19 15:31:47 2015
    13 // Update Count     : 2
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:14:44 2015
     13// Update Count     : 10
    1414//
    1515
     
    2222                // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)
    2323                forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );
    24                 if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {
    25                         // create compound statement, move initializer declaration outside, leave _for_ as-is
    26                         CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    27                         std::list<Statement *> &stmts = block->get_kids();
    2824
    29                         stmts.push_back( decl );
    30                         forStmt->set_initialization( 0 );
    31                         stmts.push_back( forStmt );
     25                std::list<Statement *> &init = forStmt->get_initialization();
     26                if ( init.size() == 0 ) {
     27                        return forStmt;
     28                } // if
    3229
    33                         return block;
    34                 } // if
     30                // create compound statement, move initializers outside, leave _for_ as-is
     31                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     32                std::list<Statement *> &stmts = block->get_kids();
     33                for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) {
     34                        stmts.push_back( *it );
     35                }       // for
     36
     37                // add for to the new block
     38                stmts.push_back( forStmt );
     39                forStmt->set_initialization( std::list<Statement *>() );
     40                return block;
    3541
    3642                return forStmt;
  • src/ControlStruct/Mutate.cc

    r85c4ef0 r145f1fc  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 03 23:08:43 2015
    13 // Update Count     : 5
     12// Last Modified On : Wed Jul 15 14:50:04 2015
     13// Update Count     : 7
    1414//
    1515
     
    3636namespace ControlStruct {
    3737        void mutate( std::list< Declaration * > translationUnit ) {
    38                 // ForExprMutator formut;
     38                // hoist initialization out of for statements
     39                ForExprMutator formut;
    3940
    4041                // normalizes label definitions and generates multi-level
     
    5152                // LabelTypeChecker lbl;
    5253
    53                 // mutateAll( translationUnit, formut );
     54                mutateAll( translationUnit, formut );
    5455                acceptAll( translationUnit, lfix );
    5556                mutateAll( translationUnit, chmut );
  • src/GenPoly/PolyMutator.cc

    r85c4ef0 r145f1fc  
    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 : Tue May 19 07:45:50 2015
    13 // Update Count     : 1
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:50:58 2015
     13// Update Count     : 3
    1414//
    1515
     
    9292        Statement * PolyMutator::mutate(ForStmt *forStmt) {
    9393                forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
    94                 forStmt->set_initialization(  maybeMutate( forStmt->get_initialization(), *this ) );
     94                mutateAll( forStmt->get_initialization(), *this );
    9595                forStmt->set_condition(  mutateExpression( forStmt->get_condition() ) );
    9696                forStmt->set_increment(  mutateExpression( forStmt->get_increment() ) );
  • src/Parser/StatementNode.cc

    r85c4ef0 r145f1fc  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 14:59:41 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 23:25:41 2015
    13 // Update Count     : 19
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:20:44 2015
     13// Update Count     : 21
    1414//
    1515
     
    271271                        assert( ctl != 0 );
    272272
    273                         Statement *stmt = 0;
    274                         if ( ctl->get_init() != 0 )
    275                                 stmt = ctl->get_init()->build();
     273                        std::list<Statement *> init;
     274                        if ( ctl->get_init() != 0 ) {
     275                                buildList( ctl->get_init(), init );
     276                        }
    276277
    277278                        Expression *cond = 0;
     
    283284                                incr = ctl->get_change()->build();
    284285
    285                         return new ForStmt( labs, stmt, cond, incr, branches.front() );
     286                        return new ForStmt( labs, init, cond, incr, branches.front() );
    286287                }
    287288          case Switch:
  • src/ResolvExpr/Resolver.cc

    r85c4ef0 r145f1fc  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  3 16:18:20 2015
    13 // Update Count     : 159
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:54:04 2015
     13// Update Count     : 167
    1414//
    1515
     
    226226
    227227        void Resolver::visit( ForStmt *forStmt ) {
    228             // SymTab::Indexer::visit( forStmt );
    229                 Expression *newExpr;
    230             // for statements introduce a level of scope
    231             enterScope();
    232             maybeAccept( forStmt->get_initialization(), *this );
     228                SymTab::Indexer::visit( forStmt );
     229
    233230                if ( forStmt->get_condition() ) {
    234                         newExpr = findSingleExpression( forStmt->get_condition(), *this );
     231                        Expression * newExpr = findSingleExpression( forStmt->get_condition(), *this );
    235232                        delete forStmt->get_condition();
    236233                        forStmt->set_condition( newExpr );
    237234                } // if
    238  
     235               
    239236                if ( forStmt->get_increment() ) {
    240                         newExpr = findVoidExpression( forStmt->get_increment(), *this );
     237                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
    241238                        delete forStmt->get_increment();
    242239                        forStmt->set_increment( newExpr );
    243240                } // if
    244 
    245             maybeAccept( forStmt->get_condition(), *this );
    246             maybeAccept( forStmt->get_increment(), *this );
    247             maybeAccept( forStmt->get_body(), *this );
    248             leaveScope();
    249241        }
    250242
  • src/SymTab/AddVisit.h

    r85c4ef0 r145f1fc  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 16:14:32 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 16:16:38 2015
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:26:17 2015
     13// Update Count     : 4
    1414//
    1515
     
    5757        inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
    5858                addVisitStatement( forStmt->get_body(), visitor );
    59                 maybeAccept( forStmt->get_initialization(), visitor );
     59                acceptAll( forStmt->get_initialization(), visitor );
    6060                maybeAccept( forStmt->get_condition(), visitor );
    6161                maybeAccept( forStmt->get_increment(), visitor );
  • src/SymTab/Validate.cc

    r85c4ef0 r145f1fc  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jul 13 14:38:19 2015
    13 // Update Count     : 184
     12// Last Modified On : Tue Jul 14 12:27:54 2015
     13// Update Count     : 186
    1414//
    1515
     
    530530                init->get_args().push_back( new NameExpr( "0" ) );
    531531                Statement *initStmt = new ExprStmt( noLabels, init );
    532  
     532                std::list<Statement *> initList;
     533                initList.push_back( initStmt );
     534
    533535                UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
    534536                cond->get_args().push_back( new VariableExpr( index ) );
     
    555557                assignExpr->get_args().push_back( srcIndex );
    556558 
    557                 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
     559                *out++ = new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, assignExpr ) );
    558560        }
    559561
  • src/SynTree/Mutator.cc

    r85c4ef0 r145f1fc  
    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 : Mon May 18 10:10:46 2015
    13 // Update Count     : 1
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:31:39 2015
     13// Update Count     : 2
    1414//
    1515
     
    109109
    110110Statement *Mutator::mutate( ForStmt *forStmt ) {
    111         forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) );
     111        mutateAll( forStmt->get_initialization(), *this );
    112112        forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );
    113113        forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );
  • src/SynTree/Statement.cc

    r85c4ef0 r145f1fc  
    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 : Mon Jun 29 17:37:10 2015
    13 // Update Count     : 22
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:57:40 2015
     13// Update Count     : 27
    1414//
    1515
     
    192192}
    193193
    194 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
     194ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    195195        Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
    196196}
    197197
    198198ForStmt::~ForStmt() {
    199         delete initialization;
     199        deleteAll( initialization );
    200200        delete condition;
    201201        delete increment;
     
    213213
    214214        os << string( indent + 2, ' ' ) << "initialization: \n";
    215         if ( initialization != 0 )
    216                 initialization->print( os, indent + 4 );
     215        for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     216                (*it)->print( os, indent + 4 );
     217        }
    217218
    218219        os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
  • src/SynTree/Statement.h

    r85c4ef0 r145f1fc  
    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 : Tue Jun 23 11:44:27 2015
    13 // Update Count     : 20
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:14:54 2015
     13// Update Count     : 24
    1414//
    1515
     
    199199class ForStmt : public Statement {
    200200  public:
    201         ForStmt( std::list<Label> labels, Statement *initialization = 0,
     201        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    202202             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    203203        virtual ~ForStmt();
    204204
    205         Statement *get_initialization() { return initialization; }
    206         void set_initialization( Statement *newValue ) { initialization = newValue; }
     205        std::list<Statement *> &get_initialization() { return initialization; }
     206        void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    207207        Expression *get_condition() { return condition; }
    208208        void set_condition( Expression *newValue ) { condition = newValue; }
     
    217217        virtual void print( std::ostream &os, int indent = 0 ) const;
    218218  private:
    219         Statement *initialization;
     219        std::list<Statement *> initialization;
    220220        Expression *condition;
    221221        Expression *increment;
  • src/SynTree/Visitor.cc

    r85c4ef0 r145f1fc  
    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 : Mon May 18 11:14:51 2015
    13 // Update Count     : 2
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:31:03 2015
     13// Update Count     : 3
    1414//
    1515
     
    9494
    9595void Visitor::visit( ForStmt *forStmt ) {
    96         // ForStmt still needs to be fixed
    97         maybeAccept( forStmt->get_initialization(), *this );
     96        acceptAll( forStmt->get_initialization(), *this );
    9897        maybeAccept( forStmt->get_condition(), *this );
    9998        maybeAccept( forStmt->get_increment(), *this );
Note: See TracChangeset for help on using the changeset viewer.