]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/types/ast/TForAllAst.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / types / ast / TForAllAst.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/types/ast/TForAllAst.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/types/ast/TForAllAst.java
new file mode 100644 (file)
index 0000000..112f65b
--- /dev/null
@@ -0,0 +1,46 @@
+package org.simantics.scl.compiler.internal.types.ast;
+
+import org.simantics.scl.compiler.internal.types.TypeElaborationContext;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.exceptions.SCLTypeParseException;
+
+
+
+public class TForAllAst extends TypeAst {
+    public final String[] vars;
+    public final TypeAst type;
+    
+    public TForAllAst(String[] vars, TypeAst type) {
+        this.vars = vars;
+        this.type = type;
+    }
+    
+    @Override
+    public void toString(StringBuilder b) {
+        b.append("forall");
+        for(String var : vars) {
+            b.append(' ');
+            b.append(var);
+        }
+        b.append(". ");
+        type.toString(b);
+    }
+
+    @Override
+    public Type toType(TypeElaborationContext context) throws SCLTypeParseException {
+        TVar[] oldVars = new TVar[vars.length];
+        for(int i=0;i<vars.length;++i)
+            oldVars[i] = context.push(vars[i]);
+        Type result = type.toType(context);
+        for(int i=vars.length-1;i>=0;--i)
+            result = Types.forAll(context.pop(vars[i], oldVars[i]), result);
+        return result;
+    }
+    
+    @Override
+    public int getPrecedence() {
+        return 2;
+    }
+}