Changeset 2ec65ad
- Timestamp:
- Mar 1, 2018, 4:58:58 PM (7 years ago)
- 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:
- ee61248
- Parents:
- a8a2b0a
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Specialize.cc
ra8a2b0a r2ec65ad 200 200 } 201 201 202 struct EnvTrimmer {203 TypeSubstitution * env, * newEnv;204 EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}205 void previsit( TypeDecl * tyDecl ) {206 // transfer known bindings for seen type variables207 if ( Type * t = env->lookup( tyDecl->name ) ) {208 newEnv->add( tyDecl->name, t );209 }210 }211 };212 213 /// reduce environment to just the parts that are referenced in a given expression214 TypeSubstitution * trimEnv( ApplicationExpr * expr, TypeSubstitution * env ) {215 if ( env ) {216 TypeSubstitution * newEnv = new TypeSubstitution();217 PassVisitor<EnvTrimmer> trimmer( env, newEnv );218 expr->accept( trimmer );219 return newEnv;220 }221 return nullptr;222 }223 224 202 /// Generates a thunk that calls `actual` with type `funType` and returns its address 225 203 Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) { … … 265 243 } 266 244 267 appExpr-> set_env( trimEnv( appExpr, env ));245 appExpr->env = TypeSubstitution::newFromExpr( appExpr, env ); 268 246 if ( inferParams ) { 269 247 appExpr->get_inferParams() = *inferParams; -
src/SynTree/TypeSubstitution.cc
ra8a2b0a r2ec65ad 104 104 bool TypeSubstitution::empty() const { 105 105 return typeEnv.empty() && varEnv.empty(); 106 } 107 108 namespace { 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 122 TypeSubstitution * 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; 106 130 } 107 131 -
src/SynTree/TypeSubstitution.h
ra8a2b0a r2ec65ad 54 54 template< typename TypeInstListIterator > 55 55 void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ); 56 57 /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr 58 static TypeSubstitution * newFromExpr( Expression * expr, TypeSubstitution * env ); 56 59 57 60 void normalize();
Note: See TracChangeset
for help on using the changeset viewer.