Changeset 5518719


Ignore:
Timestamp:
Jan 21, 2020, 6:14:40 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
9d6317f
Parents:
26fd986 (diff), 5cdeecd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/LabelFixer.cc

    r26fd986 r5518719  
    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 : Mon Mar 11 22:26:02 2019
    13 // Update Count     : 159
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Jan 21 10:32:00 2020
     13// Update Count     : 160
    1414//
    1515
     
    2121#include "ControlStruct/LabelGenerator.h"  // for LabelGenerator
    2222#include "LabelFixer.h"
    23 #include "MLEMutator.h"                    // for MLEMutator
     23#include "MLEMutator.h"                    // for MultiLevelExitMutator
    2424#include "SynTree/Declaration.h"           // for FunctionDecl
    2525#include "SynTree/Expression.h"            // for NameExpr, Expression, Unty...
     
    4444
    4545        void LabelFixer::postvisit( FunctionDecl * functionDecl ) {
    46                 PassVisitor<MLEMutator> mlemut( resolveJumps(), generator );
    47                 functionDecl->acceptMutator( mlemut );
     46                PassVisitor<MultiLevelExitMutator> mlem( resolveJumps(), generator );
     47                functionDecl->acceptMutator( mlem );
    4848        }
    4949
  • src/ControlStruct/MLEMutator.cc

    r26fd986 r5518719  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jan 16 15:33:00 2020
    13 // Update Count     : 221
     12// Last Modified On : Tue Jan 21 10:33:00 2020
     13// Update Count     : 222
    1414//
    1515
     
    3333
    3434namespace ControlStruct {
    35         MLEMutator::~MLEMutator() {
     35        MultiLevelExitMutator::~MultiLevelExitMutator() {
    3636                delete targetTable;
    3737                targetTable = 0;
    3838        }
    3939        namespace {
    40                 bool isLoop( const MLEMutator::Entry & e ) { return dynamic_cast< WhileStmt * >( e.get_controlStructure() ) || dynamic_cast< ForStmt * >( e.get_controlStructure() ); }
    41                 bool isSwitch( const MLEMutator::Entry & e ) { return dynamic_cast< SwitchStmt *>( e.get_controlStructure() ); }
    42 
    43                 bool isBreakTarget( const MLEMutator::Entry & e ) { return isLoop( e ) || isSwitch( e ) || dynamic_cast< CompoundStmt *>( e.get_controlStructure() ); }
    44                 bool isContinueTarget( const MLEMutator::Entry & e ) { return isLoop( e ); }
    45                 bool isFallthroughTarget( const MLEMutator::Entry & e ) { return dynamic_cast< CaseStmt *>( e.get_controlStructure() );; }
    46                 bool isFallthroughDefaultTarget( const MLEMutator::Entry & e ) { return isSwitch( e ); }
     40                bool isLoop( const MultiLevelExitMutator::Entry & e ) {
     41                        return dynamic_cast< WhileStmt * >( e.get_controlStructure() )
     42                                || dynamic_cast< ForStmt * >( e.get_controlStructure() );
     43                }
     44                bool isSwitch( const MultiLevelExitMutator::Entry & e ) {
     45                        return dynamic_cast< SwitchStmt *>( e.get_controlStructure() );
     46                }
     47
     48                bool isBreakTarget( const MultiLevelExitMutator::Entry & e ) {
     49                        return isLoop( e ) || isSwitch( e )
     50                                || dynamic_cast< CompoundStmt *>( e.get_controlStructure() );
     51                }
     52                bool isContinueTarget( const MultiLevelExitMutator::Entry & e ) {
     53                        return isLoop( e );
     54                }
     55                bool isFallthroughTarget( const MultiLevelExitMutator::Entry & e ) {
     56                        return dynamic_cast< CaseStmt *>( e.get_controlStructure() );
     57                }
     58                bool isFallthroughDefaultTarget( const MultiLevelExitMutator::Entry & e ) {
     59                        return isSwitch( e );
     60                }
    4761        } // namespace
    4862
     
    5064        // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the
    5165        // body of statements
    52         void MLEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
     66        void MultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
    5367                SemanticErrorException errors;
    5468
     
    8195        }
    8296
    83         void MLEMutator::premutate( CompoundStmt *cmpndStmt ) {
     97        void MultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) {
    8498                visit_children = false;
    8599                bool labeledBlock = !(cmpndStmt->labels.empty());
     
    118132                        }
    119133                }
    120                 assertf( false, "Could not find label '%s' on statement %s", originalTarget.get_name().c_str(), toString( stmt ).c_str() );
    121         }
    122 
    123 
    124         Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ) {
     134                assertf( false, "Could not find label '%s' on statement %s",
     135                        originalTarget.get_name().c_str(), toString( stmt ).c_str() );
     136        }
     137
     138
     139        Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt )
     140                        throw ( SemanticErrorException ) {
    125141                std::string originalTarget = branchStmt->originalTarget;
    126142
     
    230246        }
    231247
    232         Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     248        Statement *MultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
    233249                // only generate these when needed
    234250                if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop;
     
    253269
    254270        template< typename LoopClass >
    255         void MLEMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
     271        void MultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
    256272                // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine
    257273                // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested
     
    264280
    265281        template< typename LoopClass >
    266         Statement * MLEMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
     282        Statement * MultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
    267283                assert( ! enclosingControlStructures.empty() );
    268284                Entry &e = enclosingControlStructures.back();
     
    275291        }
    276292
    277         void MLEMutator::premutate( WhileStmt * whileStmt ) {
     293        void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {
    278294                return prehandleLoopStmt( whileStmt );
    279295        }
    280296
    281         void MLEMutator::premutate( ForStmt * forStmt ) {
     297        void MultiLevelExitMutator::premutate( ForStmt * forStmt ) {
    282298                return prehandleLoopStmt( forStmt );
    283299        }
    284300
    285         Statement * MLEMutator::postmutate( WhileStmt * whileStmt ) {
     301        Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {
    286302                return posthandleLoopStmt( whileStmt );
    287303        }
    288304
    289         Statement * MLEMutator::postmutate( ForStmt * forStmt ) {
     305        Statement * MultiLevelExitMutator::postmutate( ForStmt * forStmt ) {
    290306                return posthandleLoopStmt( forStmt );
    291307        }
    292308
    293         void MLEMutator::premutate( IfStmt * ifStmt ) {
     309        void MultiLevelExitMutator::premutate( IfStmt * ifStmt ) {
    294310                // generate a label for breaking out of a labeled if
    295311                bool labeledBlock = !(ifStmt->get_labels().empty());
     
    301317        }
    302318
    303         Statement * MLEMutator::postmutate( IfStmt * ifStmt ) {
     319        Statement * MultiLevelExitMutator::postmutate( IfStmt * ifStmt ) {
    304320                bool labeledBlock = !(ifStmt->get_labels().empty());
    305321                if ( labeledBlock ) {
     
    311327        }
    312328
    313         void MLEMutator::premutate( TryStmt * tryStmt ) {
     329        void MultiLevelExitMutator::premutate( TryStmt * tryStmt ) {
    314330                // generate a label for breaking out of a labeled if
    315331                bool labeledBlock = !(tryStmt->get_labels().empty());
     
    321337        }
    322338
    323         Statement * MLEMutator::postmutate( TryStmt * tryStmt ) {
     339        Statement * MultiLevelExitMutator::postmutate( TryStmt * tryStmt ) {
    324340                bool labeledBlock = !(tryStmt->get_labels().empty());
    325341                if ( labeledBlock ) {
     
    331347        }
    332348
    333         void MLEMutator::premutate( FinallyStmt * ) {
     349        void MultiLevelExitMutator::premutate( FinallyStmt * ) {
    334350                GuardAction([this, old = std::move(enclosingControlStructures)]() {
    335351                        enclosingControlStructures = std::move(old);
     
    338354        }
    339355
    340         void MLEMutator::premutate( CaseStmt *caseStmt ) {
     356        void MultiLevelExitMutator::premutate( CaseStmt *caseStmt ) {
    341357                visit_children = false;
    342358
     
    377393        }
    378394
    379         void MLEMutator::premutate( SwitchStmt *switchStmt ) {
     395        void MultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) {
    380396                // generate a label for breaking out of a labeled switch
    381397                Label brkLabel = generator->newLabel("switchBreak", switchStmt);
     
    403419        }
    404420
    405         Statement * MLEMutator::postmutate( SwitchStmt * switchStmt ) {
     421        Statement * MultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) {
    406422                Entry &e = enclosingControlStructures.back();
    407423                assert ( e == switchStmt );
  • src/ControlStruct/MLEMutator.h

    r26fd986 r5518719  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jan 16 12:46:00 2020
    13 // Update Count     : 46
     12// Last Modified On : Tue Jan 21 10:33:00 2020
     13// Update Count     : 47
    1414//
    15 
    16 // Can anyone figure out what MLE stands for?
    1715
    1816#pragma once
     
    3230        class LabelGenerator;
    3331
    34         class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting, public WithGuards {
     32        class MultiLevelExitMutator : public WithVisitorRef<MultiLevelExitMutator>,
     33                        public WithShortCircuiting, public WithGuards {
    3534          public:
    3635                class Entry;
    37                 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
    38                 ~MLEMutator();
     36                MultiLevelExitMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) :
     37                        targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
     38                ~MultiLevelExitMutator();
    3939
    4040                void premutate( CompoundStmt *cmpndStmt );
  • src/SynTree/Statement.cc

    r26fd986 r5518719  
    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 Jan 10 14:20:47 2020
    13 // Update Count     : 70
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jan 20 16:03:00 2020
     13// Update Count     : 71
    1414//
    1515
     
    101101
    102102
    103 const char * BranchStmt::brType[] = { "Goto", "Break", "Continue" };
     103const char * BranchStmt::brType[] = {
     104        "Goto", "Break", "Continue", "Fall Through", "Fall Through Default",
     105};
    104106
    105107BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
     
    119121
    120122void BranchStmt::print( std::ostream & os, Indenter indent ) const {
     123        assert(type < 5);
    121124        os << "Branch (" << brType[type] << ")" << endl ;
    122125        if ( target != "" ) os << indent+1 << "with target: " << target << endl;
Note: See TracChangeset for help on using the changeset viewer.