Changeset b6923b17 for src/ControlStruct


Ignore:
Timestamp:
Jul 24, 2024, 12:22:52 PM (5 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
878b1385, a03ed29
Parents:
35c792f
Message:

Fixed goto labelled loop. I had to reorder some passes. Updated control declaration hoisting (including comments and correcting update count). Added test, moved more tests into ctrl-flow.

Location:
src/ControlStruct
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/HoistControlDecls.cpp

    r35c792f rb6923b17  
    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 ) {
  • src/ControlStruct/HoistControlDecls.hpp

    r35c792f rb6923b17  
    99// Author           : Andrew Beach
    1010// Created On       : Fri Dec  3 15:31:00 2021
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:25:07 2022
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jul 24 12:04:00 2024
    1313// Update Count     : 3
    1414//
     
    2121
    2222namespace ControlStruct {
     23
    2324/// Hoist declarations out of control flow statements into compound statement.
    24 /// Must happen before auto-gen routines are added.
     25/// Must happen before auto-gen routines are added and after loop control
     26/// flow is resolved.
    2527void hoistControlDecls( ast::TranslationUnit & translationUnit );
     28
    2629} // namespace ControlStruct
    2730
Note: See TracChangeset for help on using the changeset viewer.