Ignore:
Timestamp:
Jul 24, 2024, 6:59:16 PM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
151c8db, 5aeb1a9, d02d223
Parents:
1ad112a5 (diff), b6923b17 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/HoistControlDecls.cpp

    r1ad112a5 r878b1385  
    99// Author           : Andrew Beach
    1010// Created On       : Fri Dec  3 15:34:00 2021
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  1 18:59:47 2022
    13 // Update Count     : 25
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jul 24 12:00:00 2024
     13// Update Count     : 3
    1414//
    1515
     
    2323namespace ControlStruct {
    2424
     25namespace {
     26
    2527template<typename StmtT>
    2628const Stmt * hoist( const StmtT * stmt ) {
    27         // If no hoisting is needed, then make no changes.
    28 
    29         if ( stmt->inits.size() == 0 ) {                                        // no declarations ?
     29        // If no hoisting is needed (no declaration), then make no changes.
     30        if ( stmt->inits.size() == 0 ) {
    3031                // if ( /* no conditional declarations */ ...  ) ...
    3132                return stmt;
    32         } // if
     33        }
    3334
    34         // Put hoist declarations and modified statement in a compound statement.
    35 
    36         CompoundStmt * block = new CompoundStmt( stmt->location ); // create empty compound statement
     35        StmtT * mutStmt = mutate( stmt );
     36        CompoundStmt * block = new CompoundStmt( stmt->location );
    3737        //    {}
    3838
    39         for ( const Stmt * next : stmt->inits ) {                       // link conditional declarations into compound
     39        //    Label: if ( int x = f(), y = g(); ... ) ...
     40        // link declarations into compound statement
     41        for ( const Stmt * next : mutStmt->inits ) {
    4042                block->kids.push_back( next );
    4143        }
    42         //    if ( int x = f(), y = g(); ... ) ...
    43         // link declarations into compound statement
    4444        //    {
    4545        //         int x = f();
    4646        //         int y = g();
    4747        //    }
     48        mutStmt->inits.clear();
     49        //    Label: if ( ... ) ...
    4850
    49         StmtT * mutStmt = mutate( stmt );                                       // create mutate handle to change statement
    50         mutStmt->inits.clear();                                                         // remove declarations
     51        block->labels.swap( mutStmt->labels );
     52        //    Label: {
     53        //        int x = f();
     54        //        int y = g();
     55        //    }
    5156        //    if ( ... ) ...
    5257
    53         block->kids.push_back( mutStmt );                                       // link modified statement into compound
    54         //    {
     58        block->kids.push_back( mutStmt );
     59        //    Label: {
    5560        //        int x = f();
    5661        //        int y = g();
     
    7378};
    7479
     80} // namespace
     81
    7582// Hoist initialization out of for statements.
    7683void hoistControlDecls( TranslationUnit & translationUnit ) {
Note: See TracChangeset for help on using the changeset viewer.