]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.scl.compiler.internal.types.ast;
2
3 import org.simantics.scl.compiler.internal.types.TypeElaborationContext;
4 import org.simantics.scl.compiler.types.TVar;
5 import org.simantics.scl.compiler.types.Type;
6 import org.simantics.scl.compiler.types.Types;
7 import org.simantics.scl.compiler.types.exceptions.SCLTypeParseException;
8
9
10
11 public class TForAllAst extends TypeAst {
12     public final String[] vars;
13     public final TypeAst type;
14     
15     public TForAllAst(String[] vars, TypeAst type) {
16         this.vars = vars;
17         this.type = type;
18     }
19     
20     @Override
21     public void toString(StringBuilder b) {
22         b.append("forall");
23         for(String var : vars) {
24             b.append(' ');
25             b.append(var);
26         }
27         b.append(". ");
28         type.toString(b);
29     }
30
31     @Override
32     public Type toType(TypeElaborationContext context) throws SCLTypeParseException {
33         TVar[] oldVars = new TVar[vars.length];
34         for(int i=0;i<vars.length;++i)
35             oldVars[i] = context.push(vars[i]);
36         Type result = type.toType(context);
37         for(int i=vars.length-1;i>=0;--i)
38             result = Types.forAll(context.pop(vars[i], oldVars[i]), result);
39         return result;
40     }
41     
42     @Override
43     public int getPrecedence() {
44         return 2;
45     }
46 }