]> gerrit.simantics Code Review - simantics/platform.git/blob
bd563120bd49770a159cb2339e1f6ad445606d9b
[simantics/platform.git] /
1 package org.simantics.scl.compiler.internal.types;
2
3 import gnu.trove.map.hash.THashMap;
4
5 import org.simantics.scl.compiler.types.TVar;
6 import org.simantics.scl.compiler.types.Type;
7 import org.simantics.scl.compiler.types.Types;
8 import org.simantics.scl.compiler.types.kinds.Kinds;
9 import org.simantics.scl.compiler.types.util.ITypeEnvironment;
10
11 public class TypeElaborationContext {
12
13     THashMap<String, TVar> vars; 
14     ITypeEnvironment environment;
15         
16     public TypeElaborationContext(
17             THashMap<String, TVar> vars,
18             ITypeEnvironment environment) {
19         this.vars = vars;
20         this.environment = environment;
21     }
22     
23     public TypeElaborationContext(ITypeEnvironment environment) {
24         this(new THashMap<String, TVar>(), environment);
25     }
26
27     public TVar resolveTypeVariable(String varName) {
28         TVar var = vars.get(varName);
29         if(var == null) {
30             var = Types.var(Kinds.STAR /* FIXME */);
31             vars.put(varName, var);
32         }
33         return var;
34     }
35
36     public TVar push(String varName) {
37         return vars.put(varName, Types.var(Kinds.STAR /* FIXME */)); 
38     }
39
40     public TVar pop(String varName, TVar oldVar) {
41         if(oldVar == null)
42             return vars.remove(varName);
43         else
44             return vars.put(varName, oldVar);
45     }
46     
47     public Type resolveTypeConstructor(String name) {
48         return environment.resolve(null, name);
49     }
50
51     public Type resolveTypeConstructor(String namespace, String name) {
52         return environment.resolve(namespace, name);
53     }
54
55 }