Changeset 0bd3faf for src/InitTweak


Ignore:
Timestamp:
Nov 13, 2023, 1:40:12 PM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
6ea85b22
Parents:
25f2798
Message:

Removed forward declarations missed in the BaseSyntaxNode removal. Removed code and modified names to support two versions of the ast.

Location:
src/InitTweak
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r25f2798 r0bd3faf  
    2727
    2828namespace InitTweak {
    29         class GlobalFixer_new : public ast::WithShortCircuiting {
     29        class GlobalFixer : public ast::WithShortCircuiting {
    3030        public:
    3131                void previsit (const ast::ObjectDecl *);
     
    4242
    4343        void fixGlobalInit(ast::TranslationUnit & translationUnit, bool inLibrary) {
    44                 ast::Pass<GlobalFixer_new> fixer;
     44                ast::Pass<GlobalFixer> fixer;
    4545                accept_all(translationUnit, fixer);
    4646
     
    7373        }
    7474
    75         void GlobalFixer_new::previsit(const ast::ObjectDecl * objDecl) {
     75        void GlobalFixer::previsit(const ast::ObjectDecl * objDecl) {
    7676                auto mutDecl = mutate(objDecl);
    7777                assertf(mutDecl == objDecl, "Global object decl must be unique");
  • src/InitTweak/FixInitNew.cpp

    r25f2798 r0bd3faf  
    917917                                        // static variables with the same name in different functions.
    918918                                        // Note: it isn't sufficient to modify only the mangleName, because
    919                                         // then subsequent Indexer passes can choke on seeing the object's name
     919                                        // then subsequent SymbolTable passes can choke on seeing the object's name
    920920                                        // if another object has the same name and type. An unfortunate side-effect
    921921                                        // of renaming the object is that subsequent NameExprs may fail to resolve,
     
    11691169                                arg2 = new ast::MemberExpr(funcDecl->location, field, new ast::VariableExpr(funcDecl->location, function->params.back() ) );
    11701170                        }
    1171                         InitExpander_new srcParam( arg2 );
     1171                        InitExpander srcParam( arg2 );
    11721172                        // cast away reference type and construct field.
    11731173                        ast::Expr * thisExpr = new ast::CastExpr(funcDecl->location, new ast::VariableExpr(funcDecl->location, thisParam ), thisParam->get_type()->stripReferences());
  • src/InitTweak/GenInit.cc

    r25f2798 r0bd3faf  
    4646namespace {
    4747
    48 #       warning Remove the _New suffix after the conversion is complete.
    49 
    5048        // Outer pass finds declarations, for their type could wrap a type that needs hoisting
    51         struct HoistArrayDimension_NoResolve_New final :
     49        struct HoistArrayDimension_NoResolve final :
    5250                        public ast::WithDeclsToAdd<>, public ast::WithShortCircuiting,
    5351                        public ast::WithGuards, public ast::WithConstTranslationUnit,
    54                         public ast::WithVisitorRef<HoistArrayDimension_NoResolve_New>,
     52                        public ast::WithVisitorRef<HoistArrayDimension_NoResolve>,
    5553                        public ast::WithSymbolTableX<ast::SymbolTable::ErrorDetection::IgnoreErrors> {
    5654
     
    5957                                public ast::WithShortCircuiting, public ast::WithGuards {
    6058
    61                         HoistArrayDimension_NoResolve_New * outer;
    62                         HoistDimsFromTypes( HoistArrayDimension_NoResolve_New * outer ) : outer(outer) {}
     59                        HoistArrayDimension_NoResolve * outer;
     60                        HoistDimsFromTypes( HoistArrayDimension_NoResolve * outer ) : outer(outer) {}
    6361
    6462                        // Only intended for visiting through types.
     
    211209
    212210
    213         struct ReturnFixer_New final :
     211        struct ReturnFixer final :
    214212                        public ast::WithStmtsToAdd<>, ast::WithGuards, ast::WithShortCircuiting {
    215213                void previsit( const ast::FunctionDecl * decl );
     
    219217        };
    220218
    221         void ReturnFixer_New::previsit( const ast::FunctionDecl * decl ) {
     219        void ReturnFixer::previsit( const ast::FunctionDecl * decl ) {
    222220                if (decl->linkage == ast::Linkage::Intrinsic) visit_children = false;
    223221                GuardValue( funcDecl ) = decl;
    224222        }
    225223
    226         const ast::ReturnStmt * ReturnFixer_New::previsit(
     224        const ast::ReturnStmt * ReturnFixer::previsit(
    227225                        const ast::ReturnStmt * stmt ) {
    228226                auto & returns = funcDecl->returns;
     
    265263
    266264        void genInit( ast::TranslationUnit & transUnit ) {
    267                 ast::Pass<HoistArrayDimension_NoResolve_New>::run( transUnit );
    268                 ast::Pass<ReturnFixer_New>::run( transUnit );
     265                ast::Pass<HoistArrayDimension_NoResolve>::run( transUnit );
     266                ast::Pass<ReturnFixer>::run( transUnit );
    269267        }
    270268
    271269        void fixReturnStatements( ast::TranslationUnit & transUnit ) {
    272                 ast::Pass<ReturnFixer_New>::run( transUnit );
    273         }
    274 
    275         bool ManagedTypes_new::isManaged( const ast::Type * type ) const {
     270                ast::Pass<ReturnFixer>::run( transUnit );
     271        }
     272
     273        bool ManagedTypes::isManaged( const ast::Type * type ) const {
    276274                // references are never constructed
    277275                if ( dynamic_cast< const ast::ReferenceType * >( type ) ) return false;
     
    292290        }
    293291
    294         bool ManagedTypes_new::isManaged( const ast::ObjectDecl * objDecl ) const {
     292        bool ManagedTypes::isManaged( const ast::ObjectDecl * objDecl ) const {
    295293                const ast::Type * type = objDecl->type;
    296294                while ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
     
    302300        }
    303301
    304         void ManagedTypes_new::handleDWT( const ast::DeclWithType * dwt ) {
     302        void ManagedTypes::handleDWT( const ast::DeclWithType * dwt ) {
    305303                // if this function is a user-defined constructor or destructor, mark down the type as "managed"
    306304                if ( ! dwt->linkage.is_overrideable && CodeGen::isCtorDtor( dwt->name ) ) {
     
    313311        }
    314312
    315         void ManagedTypes_new::handleStruct( const ast::StructDecl * aggregateDecl ) {
     313        void ManagedTypes::handleStruct( const ast::StructDecl * aggregateDecl ) {
    316314                // don't construct members, but need to take note if there is a managed member,
    317315                // because that means that this type is also managed
     
    329327        }
    330328
    331         void ManagedTypes_new::beginScope() { managedTypes.beginScope(); }
    332         void ManagedTypes_new::endScope() { managedTypes.endScope(); }
     329        void ManagedTypes::beginScope() { managedTypes.beginScope(); }
     330        void ManagedTypes::endScope() { managedTypes.endScope(); }
    333331
    334332        ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg) {
    335333                assertf(objDecl, "genCtorDtor passed null objDecl");
    336                 InitExpander_new srcParam(arg);
     334                InitExpander srcParam(arg);
    337335                return SymTab::genImplicitCall(srcParam, new ast::VariableExpr(loc, objDecl), loc, fname, objDecl);
    338336        }
     
    341339        // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor for each
    342340        // constructable object
    343         InitExpander_new srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr };
     341        InitExpander srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr };
    344342        ast::ptr< ast::Expr > dstParam = new ast::VariableExpr(loc, objDecl);
    345343
  • src/InitTweak/GenInit.h

    r25f2798 r0bd3faf  
    3737        ast::ConstructorInit * genCtorInit( const CodeLocation & loc, const ast::ObjectDecl * objDecl );
    3838
    39         class ManagedTypes_new {
     39        class ManagedTypes final {
    4040        public:
    4141                bool isManaged( const ast::ObjectDecl * objDecl ) const ; // determine if object is managed
  • src/InitTweak/InitTweak.cc

    r25f2798 r0bd3faf  
    3939namespace InitTweak {
    4040        namespace {
    41                 struct HasDesignations_new : public ast::WithShortCircuiting {
     41                struct HasDesignations : public ast::WithShortCircuiting {
    4242                        bool result = false;
    4343
     
    5757                };
    5858
    59                 struct InitDepthChecker_new {
     59                struct InitDepthChecker {
    6060                        bool result = true;
    6161                        const ast::Type * type;
    6262                        int curDepth = 0, maxDepth = 0;
    63                         InitDepthChecker_new( const ast::Type * type ) : type( type ) {
     63                        InitDepthChecker( const ast::Type * type ) : type( type ) {
    6464                                const ast::Type * t = type;
    6565                                while ( auto at = dynamic_cast< const ast::ArrayType * >( t ) ) {
     
    7878                };
    7979
    80                 struct InitFlattener_new : public ast::WithShortCircuiting {
     80                struct InitFlattener : public ast::WithShortCircuiting {
    8181                        std::vector< ast::ptr< ast::Expr > > argList;
    8282
     
    9090
    9191        bool isDesignated( const ast::Init * init ) {
    92                 ast::Pass<HasDesignations_new> finder;
     92                ast::Pass<HasDesignations> finder;
    9393                maybe_accept( init, finder );
    9494                return finder.core.result;
     
    9696
    9797        bool checkInitDepth( const ast::ObjectDecl * objDecl ) {
    98                 ast::Pass<InitDepthChecker_new> checker( objDecl->type );
     98                ast::Pass<InitDepthChecker> checker( objDecl->type );
    9999                maybe_accept( objDecl->init.get(), checker );
    100100                return checker.core.result;
     
    102102
    103103std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ) {
    104         ast::Pass< InitFlattener_new > flattener;
     104        ast::Pass< InitFlattener > flattener;
    105105        maybe_accept( init, flattener );
    106106        return std::move( flattener.core.argList );
    107107}
    108108
    109 class InitExpander_new::ExpanderImpl {
     109class InitExpander::ExpanderImpl {
    110110public:
    111111        virtual ~ExpanderImpl() = default;
     
    137137        template< typename Out >
    138138        void build(
    139                 ast::UntypedExpr * callExpr, const InitExpander_new::IndexList & indices,
     139                ast::UntypedExpr * callExpr, const InitExpander::IndexList & indices,
    140140                const ast::Init * init, Out & out
    141141        ) {
     
    183183        }
    184184
    185         class InitImpl_new final : public InitExpander_new::ExpanderImpl {
     185        class InitImpl final : public InitExpander::ExpanderImpl {
    186186                ast::ptr< ast::Init > init;
    187187        public:
    188                 InitImpl_new( const ast::Init * i ) : init( i ) {}
    189 
    190                 std::vector< ast::ptr< ast::Expr > > next( InitExpander_new::IndexList & ) override {
     188                InitImpl( const ast::Init * i ) : init( i ) {}
     189
     190                std::vector< ast::ptr< ast::Expr > > next( InitExpander::IndexList & ) override {
    191191                        return makeInitList( init );
    192192                }
    193193
    194194                ast::ptr< ast::Stmt > buildListInit(
    195                         ast::UntypedExpr * callExpr, InitExpander_new::IndexList & indices
     195                        ast::UntypedExpr * callExpr, InitExpander::IndexList & indices
    196196                ) override {
    197197                        // If array came with an initializer list, initialize each element. We may have more
     
    215215        };
    216216
    217         class ExprImpl_new final : public InitExpander_new::ExpanderImpl {
     217        class ExprImpl final : public InitExpander::ExpanderImpl {
    218218                ast::ptr< ast::Expr > arg;
    219219        public:
    220                 ExprImpl_new( const ast::Expr * a ) : arg( a ) {}
     220                ExprImpl( const ast::Expr * a ) : arg( a ) {}
    221221
    222222                std::vector< ast::ptr< ast::Expr > > next(
    223                         InitExpander_new::IndexList & indices
     223                        InitExpander::IndexList & indices
    224224                ) override {
    225225                        if ( ! arg ) return {};
     
    237237
    238238                ast::ptr< ast::Stmt > buildListInit(
    239                         ast::UntypedExpr *, InitExpander_new::IndexList &
     239                        ast::UntypedExpr *, InitExpander::IndexList &
    240240                ) override {
    241241                        return {};
     
    244244} // anonymous namespace
    245245
    246 InitExpander_new::InitExpander_new( const ast::Init * init )
    247 : expander( new InitImpl_new{ init } ), crnt(), indices() {}
    248 
    249 InitExpander_new::InitExpander_new( const ast::Expr * expr )
    250 : expander( new ExprImpl_new{ expr } ), crnt(), indices() {}
    251 
    252 std::vector< ast::ptr< ast::Expr > > InitExpander_new::operator* () { return crnt; }
    253 
    254 InitExpander_new & InitExpander_new::operator++ () {
     246InitExpander::InitExpander( const ast::Init * init )
     247: expander( new InitImpl{ init } ), crnt(), indices() {}
     248
     249InitExpander::InitExpander( const ast::Expr * expr )
     250: expander( new ExprImpl{ expr } ), crnt(), indices() {}
     251
     252std::vector< ast::ptr< ast::Expr > > InitExpander::operator* () { return crnt; }
     253
     254InitExpander & InitExpander::operator++ () {
    255255        crnt = expander->next( indices );
    256256        return *this;
     
    259259/// builds statement which has the same semantics as a C-style list initializer (for array
    260260/// initializers) using callExpr as the base expression to perform initialization
    261 ast::ptr< ast::Stmt > InitExpander_new::buildListInit( ast::UntypedExpr * callExpr ) {
     261ast::ptr< ast::Stmt > InitExpander::buildListInit( ast::UntypedExpr * callExpr ) {
    262262        return expander->buildListInit( callExpr, indices );
    263263}
    264264
    265 void InitExpander_new::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) {
     265void InitExpander::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) {
    266266        indices.emplace_back( index );
    267267        indices.emplace_back( dimension );
    268268}
    269269
    270 void InitExpander_new::clearArrayIndices() { indices.clear(); }
    271 
    272 bool InitExpander_new::addReference() {
     270void InitExpander::clearArrayIndices() { indices.clear(); }
     271
     272bool InitExpander::addReference() {
    273273        for ( ast::ptr< ast::Expr > & expr : crnt ) {
    274274                expr = new ast::AddressExpr{ expr };
     
    308308        }
    309309
    310         struct CallFinder_new final {
     310        struct CallFinder final {
    311311                std::vector< const ast::Expr * > matches;
    312312                const std::vector< std::string > names;
    313313
    314                 CallFinder_new( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {}
     314                CallFinder( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {}
    315315
    316316                void handleCallExpr( const ast::Expr * expr ) {
     
    326326
    327327        std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ) {
    328                 ast::Pass< CallFinder_new > finder{ std::vector< std::string >{ "?{}", "^?{}" } };
     328                ast::Pass< CallFinder > finder{ std::vector< std::string >{ "?{}", "^?{}" } };
    329329                maybe_accept( stmt, finder );
    330330                return std::move( finder.core.matches );
     
    381381        }
    382382
    383         struct ConstExprChecker_new : public ast::WithShortCircuiting {
     383        struct ConstExprChecker : public ast::WithShortCircuiting {
    384384                // most expressions are not const expr
    385385                void previsit( const ast::Expr * ) { result = false; visit_children = false; }
     
    426426        bool isConstExpr( const ast::Expr * expr ) {
    427427                if ( expr ) {
    428                         ast::Pass<ConstExprChecker_new> checker;
     428                        ast::Pass<ConstExprChecker> checker;
    429429                        expr->accept( checker );
    430430                        return checker.core.result;
     
    435435        bool isConstExpr( const ast::Init * init ) {
    436436                if ( init ) {
    437                         ast::Pass<ConstExprChecker_new> checker;
     437                        ast::Pass<ConstExprChecker> checker;
    438438                        init->accept( checker );
    439439                        return checker.core.result;
     
    486486        }
    487487
    488 }
     488} // namespace InitTweak
  • src/InitTweak/InitTweak.h

    r25f2798 r0bd3faf  
    7979        void addDataSectionAttribute( ast::ObjectDecl * objDecl );
    8080
    81         class InitExpander_new {
     81        class InitExpander final {
    8282        public:
    8383                using IndexList = std::vector< ast::ptr< ast::Expr > >;
     
    9292        public:
    9393                /// Expand by stepping through init to get each list of arguments
    94                 InitExpander_new( const ast::Init * init );
     94                InitExpander( const ast::Init * init );
    9595
    9696                /// Always expand to expression
    97                 InitExpander_new( const ast::Expr * expr );
     97                InitExpander( const ast::Expr * expr );
    9898
    9999                std::vector< ast::ptr< ast::Expr > > operator* ();
    100                 InitExpander_new & operator++ ();
     100                InitExpander & operator++ ();
    101101
    102102                /// builds statement which has the same semantics as a C-style list initializer (for array
     
    111111                bool addReference();
    112112        };
    113 } // namespace
     113} // namespace InitTweak
    114114
    115115// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.