Ignore:
Timestamp:
Mar 6, 2018, 12:11:11 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
520145b, e5d4e5c, e6c5e79
Parents:
094476d (diff), 1feb535f (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

    r094476d rcaa649b  
    104104bool TypeSubstitution::empty() const {
    105105        return typeEnv.empty() && varEnv.empty();
     106}
     107
     108namespace {
     109        struct EnvTrimmer {
     110                TypeSubstitution * env, * newEnv;
     111                EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
     112                void previsit( TypeDecl * tyDecl ) {
     113                        // transfer known bindings for seen type variables
     114                        if ( Type * t = env->lookup( tyDecl->name ) ) {
     115                                newEnv->add( tyDecl->name, t );
     116                        }
     117                }
     118        };
     119} // namespace
     120
     121/// reduce environment to just the parts that are referenced in a given expression
     122TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, TypeSubstitution * env ) {
     123        if ( env ) {
     124                TypeSubstitution * newEnv = new TypeSubstitution();
     125                PassVisitor<EnvTrimmer> trimmer( env, newEnv );
     126                expr->accept( trimmer );
     127                return newEnv;
     128        }
     129        return nullptr;
    106130}
    107131
Note: See TracChangeset for help on using the changeset viewer.