]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/types/TEffectAst.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / types / TEffectAst.java
1 package org.simantics.scl.compiler.internal.parsing.types;\r
2 \r
3 import java.util.ArrayList;\r
4 \r
5 import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;\r
6 import org.simantics.scl.compiler.internal.types.TypeElaborationContext;\r
7 import org.simantics.scl.compiler.types.Type;\r
8 import org.simantics.scl.compiler.types.Types;\r
9 import org.simantics.scl.compiler.types.kinds.Kind;\r
10 import org.simantics.scl.compiler.types.kinds.Kinds;\r
11 \r
12 import gnu.trove.map.hash.TObjectIntHashMap;\r
13 import gnu.trove.set.hash.TIntHashSet;\r
14 \r
15 \r
16 \r
17 public class TEffectAst extends TypeAst {\r
18     public final TypeAst[] effects;\r
19     public final TypeAst type;\r
20     \r
21     public TEffectAst(TypeAst effect, TypeAst type) {\r
22         this.effects = new TypeAst[] {effect};\r
23         this.type = type;\r
24     }\r
25     \r
26     public TEffectAst(TypeAst[] effects, TypeAst type) {\r
27         this.effects = effects;\r
28         this.type = type;\r
29     }\r
30     \r
31     public TEffectAst(ArrayList<TypeAst> effects, TypeAst type) {\r
32         this(effects.toArray(new TypeAst[effects.size()]), type);\r
33     }\r
34 \r
35     @Override\r
36     public void toString(StringBuilder b) {\r
37         b.append('<');\r
38         boolean first = true;\r
39         for(TypeAst effect : effects) {\r
40             if(first)\r
41                 first = false;\r
42             else\r
43                 b.append(",");\r
44             effect.toString(b);\r
45         }\r
46         b.append("> ");\r
47         b.append(type);\r
48     }\r
49 \r
50     @Override\r
51     public Type toType(TypeTranslationContext context, Kind expectedKind) {\r
52         context.unify(location, Kinds.STAR, expectedKind);\r
53         return Types.functionE(\r
54                 Types.PUNIT,\r
55                 TFunctionAst.toEffect(context, effects),\r
56                 type.toType(context, Kinds.STAR));\r
57     }\r
58     \r
59     @Override\r
60     public Type toType(TypeElaborationContext context) {\r
61         return Types.functionE(\r
62                 Types.PUNIT,\r
63                 TFunctionAst.toEffect(context, effects),\r
64                 type.toType(context));\r
65     }\r
66 \r
67     @Override\r
68     public int getPrecedence() {\r
69         return 0;\r
70     }\r
71 \r
72     @Override\r
73     public void collectReferences(TObjectIntHashMap<String> typeNameMap,\r
74             TIntHashSet set) {\r
75         for(TypeAst effect : effects)\r
76             effect.collectReferences(typeNameMap, set);\r
77         type.collectReferences(typeNameMap, set);\r
78     }\r
79 }\r