Changeset a03ed29 for src


Ignore:
Timestamp:
Jul 24, 2024, 7:11:32 PM (5 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
5aeb1a9
Parents:
e561551 (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:

conclude merge

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/HoistControlDecls.cpp

    re561551 ra03ed29  
    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

    re561551 ra03ed29  
    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
  • src/main.cpp

    re561551 ra03ed29  
    331331                PASS( "Fix Unique Ids", Validate::fixUniqueIds, transUnit );
    332332                PASS( "Implement Corun", Concurrency::implementCorun, transUnit );
     333                PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit );
     334                PASS( "Fix Labels", ControlStruct::fixLabels, transUnit );
    333335                PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit );
    334336
     
    342344                PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit );
    343345                PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit );
    344                 PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit );
    345346
    346347                if ( symtabp ) {
     
    356357
    357358                PASS( "Translate Throws", ControlStruct::translateThrows, transUnit );
    358                 PASS( "Fix Labels", ControlStruct::fixLabels, transUnit );
    359359                PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit  );
    360360                PASS( "Fix Names", CodeGen::fixNames, transUnit );
Note: See TracChangeset for help on using the changeset viewer.