Ignore:
Timestamp:
Jan 22, 2018, 3:09:01 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
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:
e23d20b
Parents:
326cd2b (diff), 4bf3b2b (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 plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/TypeSubstitution.cc

    r326cd2b r9cdfb4d0  
    107107
    108108void TypeSubstitution::normalize() {
     109        PassVisitor<Substituter> sub( *this, true );
    109110        do {
    110                 subCount = 0;
    111                 freeOnly = true;
     111                sub.pass.subCount = 0;
     112                sub.pass.freeOnly = true;
    112113                for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    113                         i->second = i->second->acceptMutator( *this );
     114                        i->second = i->second->acceptMutator( sub );
    114115                }
    115         } while ( subCount );
    116 }
    117 
    118 Type * TypeSubstitution::mutate( TypeInstType *inst ) {
    119         BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
     116        } while ( sub.pass.subCount );
     117}
     118
     119Type * TypeSubstitution::Substituter::postmutate( TypeInstType *inst ) {
     120        BoundVarsType::const_iterator bound = boundVars.find( inst->name );
    120121        if ( bound != boundVars.end() ) return inst;
    121122
    122         TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
    123         if ( i == typeEnv.end() ) {
     123        TypeEnvType::const_iterator i = sub.typeEnv.find( inst->get_name() );
     124        if ( i == sub.typeEnv.end() ) {
    124125                return inst;
    125126        } else {
    126 ///         std::cout << "found " << inst->get_name() << ", replacing with ";
    127 ///         i->second->print( std::cout );
    128 ///         std::cout << std::endl;
     127///         std::cerr << "found " << inst->get_name() << ", replacing with ";
     128///         i->second->print( std::cerr );
     129///         std::cerr << std::endl;
    129130                subCount++;
    130                 Type *newtype = i->second->clone();
     131                Type * newtype = i->second->clone();
    131132                newtype->get_qualifiers() |= inst->get_qualifiers();
    132133                delete inst;
     
    135136}
    136137
    137 Expression * TypeSubstitution::mutate( NameExpr *nameExpr ) {
    138         VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() );
    139         if ( i == varEnv.end() ) {
     138Expression * TypeSubstitution::Substituter::postmutate( NameExpr * nameExpr ) {
     139        VarEnvType::const_iterator i = sub.varEnv.find( nameExpr->name );
     140        if ( i == sub.varEnv.end() ) {
    140141                return nameExpr;
    141142        } else {
     
    146147}
    147148
    148 template< typename TypeClass >
    149 Type *TypeSubstitution::handleType( TypeClass *type ) {
    150         ValueGuard<BoundVarsType> oldBoundVars( boundVars );
     149void TypeSubstitution::Substituter::premutate( Type * type ) {
     150        GuardValue( boundVars );
    151151        // bind type variables from forall-qualifiers
    152152        if ( freeOnly ) {
    153                 for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
    154                         boundVars.insert( (*tyvar )->get_name() );
     153                for ( Type::ForallList::const_iterator tyvar = type->forall.begin(); tyvar != type->forall.end(); ++tyvar ) {
     154                        boundVars.insert( (*tyvar)->name );
    155155                } // for
    156156        } // if
    157         Type *ret = Mutator::mutate( type );
    158         return ret;
    159157}
    160158
    161159template< typename TypeClass >
    162 Type *TypeSubstitution::handleAggregateType( TypeClass *type ) {
    163         ValueGuard<BoundVarsType> oldBoundVars( boundVars );
     160void TypeSubstitution::Substituter::handleAggregateType( TypeClass * type ) {
     161        GuardValue( boundVars );
    164162        // bind type variables from forall-qualifiers
    165163        if ( freeOnly ) {
    166                 for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
    167                         boundVars.insert( (*tyvar )->get_name() );
     164                for ( Type::ForallList::const_iterator tyvar = type->forall.begin(); tyvar != type->forall.end(); ++tyvar ) {
     165                        boundVars.insert( (*tyvar)->name );
    168166                } // for
    169167                // bind type variables from generic type instantiations
    170168                std::list< TypeDecl* > *baseParameters = type->get_baseParameters();
    171                 if ( baseParameters && ! type->get_parameters().empty() ) {
     169                if ( baseParameters && ! type->parameters.empty() ) {
    172170                        for ( std::list< TypeDecl* >::const_iterator tyvar = baseParameters->begin(); tyvar != baseParameters->end(); ++tyvar ) {
    173                                 boundVars.insert( (*tyvar)->get_name() );
     171                                boundVars.insert( (*tyvar)->name );
    174172                        } // for
    175173                } // if
    176174        } // if
    177         Type *ret = Mutator::mutate( type );
    178         return ret;
    179 }
    180 
    181 Type * TypeSubstitution::mutate( VoidType *voidType ) {
    182         return handleType( voidType );
    183 }
    184 
    185 Type * TypeSubstitution::mutate( BasicType *basicType ) {
    186         return handleType( basicType );
    187 }
    188 
    189 Type * TypeSubstitution::mutate( PointerType *pointerType ) {
    190         return handleType( pointerType );
    191 }
    192 
    193 Type * TypeSubstitution::mutate( ArrayType *arrayType ) {
    194         return handleType( arrayType );
    195 }
    196 
    197 Type * TypeSubstitution::mutate( FunctionType *functionType ) {
    198         return handleType( functionType );
    199 }
    200 
    201 Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) {
    202         return handleAggregateType( aggregateUseType );
    203 }
    204 
    205 Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) {
    206         return handleAggregateType( aggregateUseType );
    207 }
    208 
    209 Type * TypeSubstitution::mutate( EnumInstType *aggregateUseType ) {
    210         return handleType( aggregateUseType );
    211 }
    212 
    213 Type * TypeSubstitution::mutate( TraitInstType *aggregateUseType ) {
    214         return handleType( aggregateUseType );
    215 }
    216 
    217 Type * TypeSubstitution::mutate( TupleType *tupleType ) {
    218         return handleType( tupleType );
    219 }
    220 
    221 Type * TypeSubstitution::mutate( VarArgsType *varArgsType ) {
    222         return handleType( varArgsType );
    223 }
    224 
    225 Type * TypeSubstitution::mutate( ZeroType *zeroType ) {
    226         return handleType( zeroType );
    227 }
    228 
    229 Type * TypeSubstitution::mutate( OneType *oneType ) {
    230         return handleType( oneType );
     175}
     176
     177void TypeSubstitution::Substituter::premutate( StructInstType * aggregateUseType ) {
     178        handleAggregateType( aggregateUseType );
     179}
     180
     181void TypeSubstitution::Substituter::premutate( UnionInstType *aggregateUseType ) {
     182        handleAggregateType( aggregateUseType );
    231183}
    232184
Note: See TracChangeset for help on using the changeset viewer.