1 package org.simantics.scl.compiler.internal.parsing.types;
3 import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;
4 import org.simantics.scl.compiler.internal.types.TypeElaborationContext;
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.Kind;
9 import org.simantics.scl.compiler.types.kinds.Kinds;
11 import gnu.trove.map.hash.TObjectIntHashMap;
12 import gnu.trove.set.hash.TIntHashSet;
16 public class TForAllAst extends TypeAst {
17 public final String[] vars;
18 public final TypeAst type;
20 public TForAllAst(String[] vars, TypeAst type) {
26 public void toString(StringBuilder b) {
28 for(String var : vars) {
37 public Type toType(TypeTranslationContext context, Kind expectedKind) {
38 context.unify(location, Kinds.STAR, expectedKind);
39 TVar[] oldVars = new TVar[vars.length];
40 for(int i=0;i<vars.length;++i)
41 oldVars[i] = context.pushTypeVar(vars[i]);
42 Type result = type.toType(context, Kinds.STAR);
43 for(int i=vars.length-1;i>=0;--i)
44 result = Types.forAll(context.popTypeVar(vars[i], oldVars[i]), result);
49 public Type toType(TypeElaborationContext context) {
50 TVar[] oldVars = new TVar[vars.length];
51 for(int i=0;i<vars.length;++i)
52 oldVars[i] = context.push(vars[i]);
53 Type result = type.toType(context);
54 for(int i=vars.length-1;i>=0;--i)
55 result = Types.forAll(context.pop(vars[i], oldVars[i]), result);
60 public int getPrecedence() {
65 public void collectReferences(TObjectIntHashMap<String> typeNameMap,
67 type.collectReferences(typeNameMap, set);