Changeset 17cb385 for src/ControlStruct


Ignore:
Timestamp:
Feb 2, 2022, 7:51:30 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
941e14a
Parents:
fc72696c (diff), 4e7171f (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/ControlStruct
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ForExprMutator.cc

    rfc72696c r17cb385  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 11 22:26:52 2019
    13 // Update Count     : 14
     12// Last Modified On : Tue Feb  1 09:26:12 2022
     13// Update Count     : 16
    1414//
    1515
     
    4545                return hoist( forStmt, forStmt->initialization );
    4646        }
    47         Statement * ForExprMutator::postmutate( WhileStmt * whileStmt ) {
    48                 return hoist( whileStmt, whileStmt->initialization );
     47        Statement * ForExprMutator::postmutate( WhileDoStmt * whileDoStmt ) {
     48                return hoist( whileDoStmt, whileDoStmt->initialization );
    4949        }
    5050} // namespace ControlStruct
  • src/ControlStruct/ForExprMutator.h

    rfc72696c r17cb385  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 30 09:14:46 2022
    13 // Update Count     : 6
     12// Last Modified On : Tue Feb  1 09:18:50 2022
     13// Update Count     : 7
    1414//
    1515
     
    1818class IfStmt;
    1919class ForStmt;
    20 class WhileStmt;
     20class WhileDoStmt;
    2121class Statement;
    2222
     
    2626                Statement * postmutate( IfStmt * );
    2727                Statement * postmutate( ForStmt * );
    28                 Statement * postmutate( WhileStmt * );
     28                Statement * postmutate( WhileDoStmt * );
    2929        };
    3030} // namespace ControlStruct
  • src/ControlStruct/HoistControlDecls.cpp

    rfc72696c r17cb385  
    1010// Created On       : Fri Dec  3 15:34:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 18:52:35 2022
    13 // Update Count     : 23
     12// Last Modified On : Tue Feb  1 18:59:47 2022
     13// Update Count     : 25
    1414//
    1515
     
    3535
    3636        CompoundStmt * block = new CompoundStmt( stmt->location ); // create empty compound statement
    37         //    {
    38         //    }
     37        //    {}
    3938
    4039        for ( const Stmt * next : stmt->inits ) {                       // link conditional declarations into compound
     
    6968                return hoist<ForStmt>( stmt );
    7069        }
    71         const Stmt * postvisit( const WhileStmt * stmt ) {
    72                 return hoist<WhileStmt>( stmt );
     70        const Stmt * postvisit( const WhileDoStmt * stmt ) {
     71                return hoist<WhileDoStmt>( stmt );
    7372        }
    7473};
  • src/ControlStruct/LabelFixer.cc

    rfc72696c r17cb385  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:28:31 2022
    13 // Update Count     : 161
     12// Last Modified On : Tue Feb  1 09:12:09 2022
     13// Update Count     : 162
    1414//
    1515
     
    2929bool LabelFixer::Entry::insideLoop() {
    3030        return ( dynamic_cast< ForStmt * > ( definition ) ||
    31                 dynamic_cast< WhileStmt * > ( definition )  );
     31                dynamic_cast< WhileDoStmt * > ( definition )  );
    3232}
    3333
  • src/ControlStruct/LabelGeneratorNew.cpp

    rfc72696c r17cb385  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 18:51:10 2022
    13 // Update Count     : 71
     12// Last Modified On : Wed Feb  2 09:11:17 2022
     13// Update Count     : 72
    1414//
    1515
     
    2828        static int current = 0;
    2929
    30         assert( ( (void)"CFA internal error: parameter statement cannot be null pointer", stmt ) );
     30        assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" );
    3131
    3232        enum { size = 128 };
    3333        char buf[size];                                                                         // space to build label
    3434        int len = snprintf( buf, size, "__L%d__%s", current++, suffix.c_str() );
    35         assert( ( (void)"CFA Internal error: buffer overflow creating label", len < size ) );
     35        assertf( len < size, "CFA Internal error: buffer overflow creating label" );
    3636
    3737        // What does this do?
    3838        if ( ! stmt->labels.empty() ) {
    3939                len = snprintf( buf + len, size - len, "_%s__", stmt->labels.front().name.c_str() );
    40                 assert( ( (void)"CFA Internal error: buffer overflow creating label", len < size - len ) );
     40                assertf( len < size - len, "CFA Internal error: buffer overflow creating label" );
    4141        } // if
    4242
  • src/ControlStruct/MLEMutator.cc

    rfc72696c r17cb385  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jan 22 11:50:00 2020
    13 // Update Count     : 223
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Feb  1 09:26:28 2022
     13// Update Count     : 225
    1414//
    1515
     
    3939        namespace {
    4040                bool isLoop( const MultiLevelExitMutator::Entry & e ) {
    41                         return dynamic_cast< WhileStmt * >( e.get_controlStructure() )
     41                        return dynamic_cast< WhileDoStmt * >( e.get_controlStructure() )
    4242                                || dynamic_cast< ForStmt * >( e.get_controlStructure() );
    4343                }
     
    295295        }
    296296
    297         void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {
    298                 return prehandleLoopStmt( whileStmt );
     297        void MultiLevelExitMutator::premutate( WhileDoStmt * whileDoStmt ) {
     298                return prehandleLoopStmt( whileDoStmt );
    299299        }
    300300
     
    303303        }
    304304
    305         Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {
    306                 return posthandleLoopStmt( whileStmt );
     305        Statement * MultiLevelExitMutator::postmutate( WhileDoStmt * whileDoStmt ) {
     306                return posthandleLoopStmt( whileDoStmt );
    307307        }
    308308
  • src/ControlStruct/MLEMutator.h

    rfc72696c r17cb385  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jan 22 11:50:00 2020
    13 // Update Count     : 48
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Feb  1 09:27:24 2022
     13// Update Count     : 50
    1414//
    1515
     
    4242                void premutate( CompoundStmt *cmpndStmt );
    4343                Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException );
    44                 void premutate( WhileStmt *whileStmt );
    45                 Statement * postmutate( WhileStmt *whileStmt );
     44                void premutate( WhileDoStmt *whileDoStmt );
     45                Statement * postmutate( WhileDoStmt *whileDoStmt );
    4646                void premutate( ForStmt *forStmt );
    4747                Statement * postmutate( ForStmt *forStmt );
     
    6767                                stmt( stmt ), breakExit( breakExit ), contExit( contExit ) {}
    6868
    69                         explicit Entry( WhileStmt *stmt, Label breakExit, Label contExit ) :
     69                        explicit Entry( WhileDoStmt *stmt, Label breakExit, Label contExit ) :
    7070                                stmt( stmt ), breakExit( breakExit ), contExit( contExit ) {}
    7171
  • src/ControlStruct/MultiLevelExit.cpp

    rfc72696c r17cb385  
    1010// Created On       : Mon Nov  1 13:48:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:35:08 2022
    13 // Update Count     : 28
     12// Last Modified On : Tue Feb  1 18:48:47 2022
     13// Update Count     : 29
    1414//
    1515
     
    4040
    4141        enum Kind {
    42                 ForStmtK, WhileStmtK, CompoundStmtK, IfStmtK, CaseStmtK, SwitchStmtK, TryStmtK
     42                ForStmtK, WhileDoStmtK, CompoundStmtK, IfStmtK, CaseStmtK, SwitchStmtK, TryStmtK
    4343        } kind;
    4444
     
    5353        Entry( const ForStmt * stmt, Label breakExit, Label contExit ) :
    5454                stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( ForStmtK ) {}
    55         Entry( const WhileStmt * stmt, Label breakExit, Label contExit ) :
    56                 stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( WhileStmtK ) {}
     55        Entry( const WhileDoStmt * stmt, Label breakExit, Label contExit ) :
     56                stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( WhileDoStmtK ) {}
    5757        Entry( const CompoundStmt *stmt, Label breakExit ) :
    5858                stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( CompoundStmtK ) {}
     
    6666                stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( TryStmtK ) {}
    6767
    68         bool isContTarget() const { return kind <= WhileStmtK; }
     68        bool isContTarget() const { return kind <= WhileDoStmtK; }
    6969        bool isBreakTarget() const { return kind != CaseStmtK; }
    7070        bool isFallTarget() const { return kind == CaseStmtK; }
    7171        bool isFallDefaultTarget() const { return kind == SwitchStmtK; }
    7272
    73         Label useContExit() { assert( kind <= WhileStmtK ); return useTarget(secondTarget); }
     73        // These routines set a target as being "used" by a BranchStmt
     74        Label useContExit() { assert( kind <= WhileDoStmtK ); return useTarget(secondTarget); }
    7475        Label useBreakExit() { assert( kind != CaseStmtK ); return useTarget(firstTarget); }
    7576        Label useFallExit() { assert( kind == CaseStmtK );  return useTarget(firstTarget); }
    7677        Label useFallDefaultExit() { assert( kind == SwitchStmtK ); return useTarget(secondTarget); }
    7778
    78         bool isContUsed() const { assert( kind <= WhileStmtK ); return secondTarget.used; }
     79        // These routines check if a specific label for a statement is used by a BranchStmt
     80        bool isContUsed() const { assert( kind <= WhileDoStmtK ); return secondTarget.used; }
    7981        bool isBreakUsed() const { assert( kind != CaseStmtK ); return firstTarget.used; }
    8082        bool isFallUsed() const { assert( kind == CaseStmtK ); return firstTarget.used; }
     
    110112        const CompoundStmt * previsit( const CompoundStmt * );
    111113        const BranchStmt * postvisit( const BranchStmt * );
    112         void previsit( const WhileStmt * );
    113         const WhileStmt * postvisit( const WhileStmt * );
     114        void previsit( const WhileDoStmt * );
     115        const WhileDoStmt * postvisit( const WhileDoStmt * );
    114116        void previsit( const ForStmt * );
    115117        const ForStmt * postvisit( const ForStmt * );
     
    164166        const CompoundStmt * stmt ) {
    165167        visit_children = false;
     168
     169        // if the stmt is labelled then generate a label to check in postvisit if the label is used
    166170        bool isLabeled = !stmt->labels.empty();
    167171        if ( isLabeled ) {
     
    217221}
    218222
     223// This routine updates targets on enclosing control structures to indicate which
     224//     label is used by the BranchStmt that is passed
    219225const BranchStmt * MultiLevelExitCore::postvisit( const BranchStmt * stmt ) {
    220226        vector<Entry>::reverse_iterator targetEntry =
    221227                enclosing_control_structures.rend();
     228
     229        // Labels on different stmts require different approaches to access
    222230        switch ( stmt->kind ) {
    223231          case BranchStmt::Goto:
     
    253261                  break;
    254262          }
     263          // handle fallthrough in case/switch stmts
    255264          case BranchStmt::FallThrough: {
    256265                  targetEntry = findEnclosingControlStructure( isFallthroughTarget );
     
    333342}
    334343
    335 void MultiLevelExitCore::previsit( const WhileStmt * stmt ) {
     344void MultiLevelExitCore::previsit( const WhileDoStmt * stmt ) {
    336345        return prehandleLoopStmt( stmt );
    337346}
    338347
    339 const WhileStmt * MultiLevelExitCore::postvisit( const WhileStmt * stmt ) {
     348const WhileDoStmt * MultiLevelExitCore::postvisit( const WhileDoStmt * stmt ) {
    340349        return posthandleLoopStmt( stmt );
    341350}
     
    530539        }
    531540
     541        // if continue is used insert a continue label into the back of the body of the loop
    532542        if ( entry.isContUsed() ) {
    533543                CompoundStmt * new_body = new CompoundStmt( body->location );
     544                // {}
    534545                new_body->kids.push_back( body );
     546                // {
     547                //  body
     548                // }
    535549                new_body->kids.push_back(
    536550                        labelledNullStmt( body->location, entry.useContExit() ) );
     551                // {
     552                //  body
     553                //  ContinueLabel: {}
     554                // }
    537555                return new_body;
    538556        }
     
    548566        Label contLabel = newLabel( "loopContinue", loopStmt );
    549567        enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel );
     568        // labels are added temporarily to see if they are used and then added permanently in postvisit if ther are used
     569        // children will tag labels as being used during their traversal which occurs before postvisit
     570
     571        // GuardAction calls the lambda after the node is done being visited
    550572        GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
    551573}
     
    560582        return mutate_field(
    561583                loopStmt, &LoopNode::body, mutateLoop( loopStmt->body, entry ) );
     584        // this call to mutate_field compares loopStmt->body and the result of mutateLoop
     585        //              if they are the same the node isn't mutated, if they differ then the new mutated node is returned
     586        //              the stmts will only differ if a label is used
    562587}
    563588
Note: See TracChangeset for help on using the changeset viewer.