Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    raff3af4 r0661678  
    2020#include <unordered_map>
    2121#include <unordered_set>
    22 
    2322#include "InitTweak.h"
    2423#include "GenInit.h"
    2524#include "FixInit.h"
    2625#include "FixGlobalInit.h"
    27 #include "CodeGen/GenType.h"  // for warning/error messages
    28 #include "Common/PassVisitor.h"
    29 #include "GenPoly/DeclMutator.h"
    30 #include "GenPoly/PolyMutator.h"
    3126#include "ResolvExpr/Resolver.h"
    3227#include "ResolvExpr/typeops.h"
    33 #include "SymTab/Autogen.h"
    34 #include "SymTab/Indexer.h"
    35 #include "SynTree/AddStmtVisitor.h"
     28#include "SynTree/Declaration.h"
     29#include "SynTree/Type.h"
     30#include "SynTree/Expression.h"
    3631#include "SynTree/Attribute.h"
    37 #include "SynTree/Declaration.h"
    38 #include "SynTree/Expression.h"
     32#include "SynTree/Statement.h"
    3933#include "SynTree/Initializer.h"
    4034#include "SynTree/Mutator.h"
    41 #include "SynTree/Statement.h"
    42 #include "SynTree/Type.h"
     35#include "SymTab/Indexer.h"
     36#include "SymTab/Autogen.h"
     37#include "GenPoly/PolyMutator.h"
     38#include "GenPoly/DeclMutator.h"
     39#include "SynTree/AddStmtVisitor.h"
     40#include "CodeGen/GenType.h"  // for warning/error messages
    4341#include "Tuples/Tuples.h"
    4442
     
    5654                typedef std::unordered_map< int, int > UnqCount;
    5755
    58                 class InsertImplicitCalls {
     56                class InsertImplicitCalls final : public GenPoly::PolyMutator {
    5957                public:
    6058                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     
    6361
    6462                        InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {}
    65 
    66                         Expression * postmutate( ApplicationExpr * appExpr );
    67                         void premutate( StmtExpr * stmtExpr );
     63                        typedef GenPoly::PolyMutator Parent;
     64                        using Parent::mutate;
     65                        virtual Expression * mutate( ApplicationExpr * appExpr ) override;
     66                        virtual Expression * mutate( StmtExpr * stmtExpr ) override;
    6867
    6968                        // collects environments for relevant nodes
    7069                        EnvMap & envMap;
    71                         TypeSubstitution * env; //Magically populated by the PassVisitor
    7270                };
    7371
     
    192190                };
    193191
    194                 class FixInit {
     192                class FixInit final : public GenPoly::PolyMutator {
    195193                  public:
    196194                        /// expand each object declaration to use its constructor after it is declared.
    197195                        static void fixInitializers( std::list< Declaration * > &translationUnit );
    198196
    199                         DeclarationWithType * postmutate( ObjectDecl *objDecl );
     197                        typedef GenPoly::PolyMutator Parent;
     198                        using Parent::mutate;
     199                        virtual DeclarationWithType * mutate( ObjectDecl *objDecl ) override;
    200200
    201201                        std::list< Declaration * > staticDtorDecls;
    202                         std::list< Statement * > stmtsToAddAfter; // found by PassVisitor
    203202                };
    204203
     
    301300        namespace {
    302301                void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) {
    303                         PassVisitor<InsertImplicitCalls> inserter( envMap );
     302                        InsertImplicitCalls inserter( envMap );
    304303                        mutateAll( translationUnit, inserter );
    305304                }
     
    311310
    312311                void FixInit::fixInitializers( std::list< Declaration * > & translationUnit ) {
    313                         PassVisitor<FixInit> fixer;
     312                        FixInit fixer;
    314313
    315314                        // can't use mutateAll, because need to insert declarations at top-level
     
    319318                                try {
    320319                                        *i = maybeMutate( *i, fixer );
    321                                         translationUnit.splice( i, fixer.pass.staticDtorDecls );
     320                                        translationUnit.splice( i, fixer.staticDtorDecls );
    322321                                } catch( SemanticError &e ) {
    323322                                        e.set_location( (*i)->location );
     
    351350                }
    352351
    353                 Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) {
     352                Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) {
     353                        appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) );
    354354                        assert( appExpr );
    355355
     
    393393                }
    394394
    395                 void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) {
     395                Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {
    396396                        assert( env );
    397397                        envMap[stmtExpr] = env;
     398                        return Parent::mutate( stmtExpr );
    398399                }
    399400
     
    695696                }
    696697
    697                 DeclarationWithType *FixInit::postmutate( ObjectDecl *objDecl ) {
    698                         // since this removes the init field from objDecl, it must occur after children are mutated (i.e. postmutate)
     698                DeclarationWithType *FixInit::mutate( ObjectDecl *objDecl ) {
     699                        // first recursively handle pieces of ObjectDecl so that they aren't missed by other visitors when the init
     700                        // is removed from the ObjectDecl
     701                        objDecl = dynamic_cast< ObjectDecl * >( Parent::mutate( objDecl ) );
    699702                        if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) {
    700703                                // a decision should have been made by the resolver, so ctor and init are not both non-NULL
Note: See TracChangeset for help on using the changeset viewer.