Changeset 49c9773 for src/InitTweak


Ignore:
Timestamp:
Jun 1, 2017, 10:58:24 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
acd738aa, d3ed39f
Parents:
6065b3aa (diff), b1d4d60 (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:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r6065b3aa r49c9773  
    2020#include <unordered_map>
    2121#include <unordered_set>
     22
    2223#include "InitTweak.h"
    2324#include "GenInit.h"
    2425#include "FixInit.h"
    2526#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"
    2631#include "ResolvExpr/Resolver.h"
    2732#include "ResolvExpr/typeops.h"
     33#include "SymTab/Autogen.h"
     34#include "SymTab/Indexer.h"
     35#include "SynTree/AddStmtVisitor.h"
     36#include "SynTree/Attribute.h"
    2837#include "SynTree/Declaration.h"
    29 #include "SynTree/Type.h"
    3038#include "SynTree/Expression.h"
    31 #include "SynTree/Attribute.h"
    32 #include "SynTree/Statement.h"
    3339#include "SynTree/Initializer.h"
    3440#include "SynTree/Mutator.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
     41#include "SynTree/Statement.h"
     42#include "SynTree/Type.h"
    4143#include "Tuples/Tuples.h"
    4244
     
    5456                typedef std::unordered_map< int, int > UnqCount;
    5557
    56                 class InsertImplicitCalls final : public GenPoly::PolyMutator {
     58                class InsertImplicitCalls {
    5759                public:
    5860                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     
    6163
    6264                        InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {}
    63                         typedef GenPoly::PolyMutator Parent;
    64                         using Parent::mutate;
    65                         virtual Expression * mutate( ApplicationExpr * appExpr ) override;
    66                         virtual Expression * mutate( StmtExpr * stmtExpr ) override;
     65
     66                        Expression * postmutate( ApplicationExpr * appExpr );
     67                        void premutate( StmtExpr * stmtExpr );
    6768
    6869                        // collects environments for relevant nodes
    6970                        EnvMap & envMap;
     71                        TypeSubstitution * env; //Magically populated by the PassVisitor
    7072                };
    7173
     
    190192                };
    191193
    192                 class FixInit final : public GenPoly::PolyMutator {
     194                class FixInit {
    193195                  public:
    194196                        /// expand each object declaration to use its constructor after it is declared.
    195197                        static void fixInitializers( std::list< Declaration * > &translationUnit );
    196198
    197                         typedef GenPoly::PolyMutator Parent;
    198                         using Parent::mutate;
    199                         virtual DeclarationWithType * mutate( ObjectDecl *objDecl ) override;
     199                        DeclarationWithType * postmutate( ObjectDecl *objDecl );
    200200
    201201                        std::list< Declaration * > staticDtorDecls;
     202                        std::list< Statement * > stmtsToAddAfter; // found by PassVisitor
    202203                };
    203204
     
    300301        namespace {
    301302                void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) {
    302                         InsertImplicitCalls inserter( envMap );
     303                        PassVisitor<InsertImplicitCalls> inserter( envMap );
    303304                        mutateAll( translationUnit, inserter );
    304305                }
     
    310311
    311312                void FixInit::fixInitializers( std::list< Declaration * > & translationUnit ) {
    312                         FixInit fixer;
     313                        PassVisitor<FixInit> fixer;
    313314
    314315                        // can't use mutateAll, because need to insert declarations at top-level
     
    318319                                try {
    319320                                        *i = maybeMutate( *i, fixer );
    320                                         translationUnit.splice( i, fixer.staticDtorDecls );
     321                                        translationUnit.splice( i, fixer.pass.staticDtorDecls );
    321322                                } catch( SemanticError &e ) {
    322323                                        e.set_location( (*i)->location );
     
    350351                }
    351352
    352                 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) {
    353                         appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) );
     353                Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) {
    354354                        assert( appExpr );
    355355
     
    393393                }
    394394
    395                 Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {
     395                void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) {
    396396                        assert( env );
    397397                        envMap[stmtExpr] = env;
    398                         return Parent::mutate( stmtExpr );
    399398                }
    400399
     
    696695                }
    697696
    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 ) );
     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)
    702699                        if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) {
    703700                                // 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.