]> gerrit.simantics Code Review - simantics/platform.git/blob
1bb40c5faa2acb72e3fa0e8f1856767d811c226e
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.contexts;
2
3 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
4 import org.simantics.scl.compiler.elaboration.expressions.Expression;
5 import org.simantics.scl.compiler.elaboration.expressions.Variable;
6 import org.simantics.scl.compiler.types.TVar;
7 import org.simantics.scl.compiler.types.Type;
8
9 import gnu.trove.map.hash.THashMap;
10
11 public class ReplaceContext {
12     public final THashMap<TVar, Type> EMPTY_VARIABLE_MAP = new THashMap<TVar, Type>(); 
13     
14     public THashMap<TVar, Type> tvarMap;
15     public THashMap<Variable, Expression> varMap;
16     public final TypingContext typingContext;
17     public boolean inPattern;
18     
19     public ReplaceContext(THashMap<TVar, Type> tvarMap,
20             THashMap<Variable, Expression> varMap,
21             TypingContext typingContext) {
22         this.tvarMap = tvarMap;
23         this.varMap = varMap;
24         this.typingContext = typingContext;
25         this.inPattern = false;
26     }
27     
28     public ReplaceContext(Variable[] from, Variable[] to) {
29         this.tvarMap = EMPTY_VARIABLE_MAP;        
30         this.typingContext = null;
31         this.inPattern = false;
32         varMap = new THashMap<Variable, Expression>(from.length);
33         for(int i=0;i<from.length;++i)
34             varMap.put(from[i], new EVariable(to[i]));
35     }
36     
37     public ReplaceContext(TypingContext typingContext) {
38         this(new THashMap<TVar, Type>(), new THashMap<Variable, Expression>(), typingContext);
39     }
40 }