Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixNames.cc

    r2fd0de0 r0c577f7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FixNames.cc -- Adjustments to typed declarations.
     7// FixNames.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 20 11:49:00 2022
    13 // Update Count     : 24
     12// Last Modified On : Fri Oct 29 15:49:00 2021
     13// Update Count     : 23
    1414//
    1515
     
    8787
    8888/// Does work with the main function and scopeLevels.
    89 class FixNames_new final {
     89class FixNames_new : public ast::WithGuards {
    9090        int scopeLevel = 1;
    9191
     
    103103
    104104        const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) {
     105                // This store is used to ensure a maximum of one call to mutate.
     106                ast::FunctionDecl * mutDecl = nullptr;
     107
     108                if ( shouldSetScopeLevel( functionDecl ) ) {
     109                        mutDecl = ast::mutate( functionDecl );
     110                        mutDecl->scopeLevel = scopeLevel;
     111                }
     112
    105113                if ( FixMain::isMain( functionDecl ) ) {
    106                         auto mutDecl = ast::mutate( functionDecl );
    107 
    108                         if ( shouldSetScopeLevel( mutDecl ) ) {
    109                                 mutDecl->scopeLevel = scopeLevel;
    110                         }
     114                        if ( !mutDecl ) { mutDecl = ast::mutate( functionDecl ); }
    111115
    112116                        int nargs = mutDecl->params.size();
     
    120124                                )
    121125                        );
    122 
    123                         return mutDecl;
    124                 } else if ( shouldSetScopeLevel( functionDecl ) ) {
    125                         return ast::mutate_field( functionDecl, &ast::FunctionDecl::scopeLevel, scopeLevel );
    126                 } else {
    127                         return functionDecl;
    128126                }
     127                return mutDecl ? mutDecl : functionDecl;
    129128        }
    130129
    131130        void previsit( const ast::CompoundStmt * ) {
    132                 scopeLevel += 1;
    133         }
    134 
    135         void postvisit( const ast::CompoundStmt * ) {
    136                 scopeLevel -= 1;
     131                GuardValue( scopeLevel ) += 1;
    137132        }
    138133};
Note: See TracChangeset for help on using the changeset viewer.