]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/types/TEffectAst.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/types/TEffectAst.java
new file mode 100644 (file)
index 0000000..094fa14
--- /dev/null
@@ -0,0 +1,79 @@
+package org.simantics.scl.compiler.internal.parsing.types;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;\r
+import org.simantics.scl.compiler.internal.types.TypeElaborationContext;\r
+import org.simantics.scl.compiler.types.Type;\r
+import org.simantics.scl.compiler.types.Types;\r
+import org.simantics.scl.compiler.types.kinds.Kind;\r
+import org.simantics.scl.compiler.types.kinds.Kinds;\r
+\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
+\r
+\r
+public class TEffectAst extends TypeAst {\r
+    public final TypeAst[] effects;\r
+    public final TypeAst type;\r
+    \r
+    public TEffectAst(TypeAst effect, TypeAst type) {\r
+        this.effects = new TypeAst[] {effect};\r
+        this.type = type;\r
+    }\r
+    \r
+    public TEffectAst(TypeAst[] effects, TypeAst type) {\r
+        this.effects = effects;\r
+        this.type = type;\r
+    }\r
+    \r
+    public TEffectAst(ArrayList<TypeAst> effects, TypeAst type) {\r
+        this(effects.toArray(new TypeAst[effects.size()]), type);\r
+    }\r
+\r
+    @Override\r
+    public void toString(StringBuilder b) {\r
+        b.append('<');\r
+        boolean first = true;\r
+        for(TypeAst effect : effects) {\r
+            if(first)\r
+                first = false;\r
+            else\r
+                b.append(",");\r
+            effect.toString(b);\r
+        }\r
+        b.append("> ");\r
+        b.append(type);\r
+    }\r
+\r
+    @Override\r
+    public Type toType(TypeTranslationContext context, Kind expectedKind) {\r
+        context.unify(location, Kinds.STAR, expectedKind);\r
+        return Types.functionE(\r
+                Types.PUNIT,\r
+                TFunctionAst.toEffect(context, effects),\r
+                type.toType(context, Kinds.STAR));\r
+    }\r
+    \r
+    @Override\r
+    public Type toType(TypeElaborationContext context) {\r
+        return Types.functionE(\r
+                Types.PUNIT,\r
+                TFunctionAst.toEffect(context, effects),\r
+                type.toType(context));\r
+    }\r
+\r
+    @Override\r
+    public int getPrecedence() {\r
+        return 0;\r
+    }\r
+\r
+    @Override\r
+    public void collectReferences(TObjectIntHashMap<String> typeNameMap,\r
+            TIntHashSet set) {\r
+        for(TypeAst effect : effects)\r
+            effect.collectReferences(typeNameMap, set);\r
+        type.collectReferences(typeNameMap, set);\r
+    }\r
+}\r