Changes in / [878b1385:1ad112a5]


Ignore:
Files:
4 added
6 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/HoistControlDecls.cpp

    r878b1385 r1ad112a5  
    99// Author           : Andrew Beach
    1010// Created On       : Fri Dec  3 15:34:00 2021
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 24 12:00:00 2024
    13 // Update Count     : 3
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Feb  1 18:59:47 2022
     13// Update Count     : 25
    1414//
    1515
     
    2323namespace ControlStruct {
    2424
    25 namespace {
    26 
    2725template<typename StmtT>
    2826const Stmt * hoist( const StmtT * stmt ) {
    29         // If no hoisting is needed (no declaration), then make no changes.
    30         if ( stmt->inits.size() == 0 ) {
     27        // If no hoisting is needed, then make no changes.
     28
     29        if ( stmt->inits.size() == 0 ) {                                        // no declarations ?
    3130                // if ( /* no conditional declarations */ ...  ) ...
    3231                return stmt;
    33         }
     32        } // if
    3433
    35         StmtT * mutStmt = mutate( stmt );
    36         CompoundStmt * block = new CompoundStmt( stmt->location );
     34        // Put hoist declarations and modified statement in a compound statement.
     35
     36        CompoundStmt * block = new CompoundStmt( stmt->location ); // create empty compound statement
    3737        //    {}
    3838
    39         //    Label: if ( int x = f(), y = g(); ... ) ...
    40         // link declarations into compound statement
    41         for ( const Stmt * next : mutStmt->inits ) {
     39        for ( const Stmt * next : stmt->inits ) {                       // link conditional declarations into compound
    4240                block->kids.push_back( next );
    4341        }
     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 ( ... ) ...
    5048
    51         block->labels.swap( mutStmt->labels );
    52         //    Label: {
    53         //        int x = f();
    54         //        int y = g();
    55         //    }
     49        StmtT * mutStmt = mutate( stmt );                                       // create mutate handle to change statement
     50        mutStmt->inits.clear();                                                         // remove declarations
    5651        //    if ( ... ) ...
    5752
    58         block->kids.push_back( mutStmt );
    59         //    Label: {
     53        block->kids.push_back( mutStmt );                                       // link modified statement into compound
     54        //    {
    6055        //        int x = f();
    6156        //        int y = g();
     
    7873};
    7974
    80 } // namespace
    81 
    8275// Hoist initialization out of for statements.
    8376void hoistControlDecls( TranslationUnit & translationUnit ) {
  • src/ControlStruct/HoistControlDecls.hpp

    r878b1385 r1ad112a5  
    99// Author           : Andrew Beach
    1010// Created On       : Fri Dec  3 15:31:00 2021
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 24 12:04:00 2024
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jan 31 22:25:07 2022
    1313// Update Count     : 3
    1414//
     
    2121
    2222namespace ControlStruct {
    23 
    2423/// Hoist declarations out of control flow statements into compound statement.
    25 /// Must happen before auto-gen routines are added and after loop control
    26 /// flow is resolved.
     24/// Must happen before auto-gen routines are added.
    2725void hoistControlDecls( ast::TranslationUnit & translationUnit );
    28 
    2926} // namespace ControlStruct
    3027
  • src/main.cpp

    r878b1385 r1ad112a5  
    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 );
    335333                PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit );
    336334
     
    344342                PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit );
    345343                PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit );
     344                PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit );
    346345
    347346                if ( symtabp ) {
     
    357356
    358357                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 );
  • tests/Makefile.am

    r878b1385 r1ad112a5  
    208208
    209209SYNTAX_ONLY_CODE = expression typedefRedef variableDeclarator switch numericConstants identFuncDeclarator \
    210         init1 limits nested-types cast ctrl-flow/labelledExit array quasiKeyword include/stdincludes include/includes builtins/sync warnings/self-assignment concurrency/waitfor/parse
     210        init1 limits nested-types cast labelledExit array quasiKeyword include/stdincludes include/includes builtins/sync warnings/self-assignment concurrency/waitfor/parse
    211211${SYNTAX_ONLY_CODE} : % : %.cfa ${CFACCBIN}
    212212        ${CFACOMPILE_SYNTAX}
Note: See TracChangeset for help on using the changeset viewer.