1 package org.simantics.scl.compiler.internal.parsing.types;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;
6 import org.simantics.scl.compiler.internal.types.TypeElaborationContext;
7 import org.simantics.scl.compiler.types.Type;
8 import org.simantics.scl.compiler.types.Types;
9 import org.simantics.scl.compiler.types.kinds.Kind;
10 import org.simantics.scl.compiler.types.kinds.Kinds;
12 import gnu.trove.map.hash.TObjectIntHashMap;
13 import gnu.trove.set.hash.TIntHashSet;
17 public class TEffectAst extends TypeAst {
18 public final TypeAst[] effects;
19 public final TypeAst type;
21 public TEffectAst(TypeAst effect, TypeAst type) {
22 this.effects = new TypeAst[] {effect};
26 public TEffectAst(TypeAst[] effects, TypeAst type) {
27 this.effects = effects;
31 public TEffectAst(ArrayList<TypeAst> effects, TypeAst type) {
32 this(effects.toArray(new TypeAst[effects.size()]), type);
36 public void toString(StringBuilder b) {
39 for(TypeAst effect : effects) {
51 public Type toType(TypeTranslationContext context, Kind expectedKind) {
52 context.unify(location, Kinds.STAR, expectedKind);
53 return Types.functionE(
55 TFunctionAst.toEffect(context, effects),
56 type.toType(context, Kinds.STAR));
60 public Type toType(TypeElaborationContext context) {
61 return Types.functionE(
63 TFunctionAst.toEffect(context, effects),
64 type.toType(context));
68 public int getPrecedence() {
73 public void collectReferences(TObjectIntHashMap<String> typeNameMap,
75 for(TypeAst effect : effects)
76 effect.collectReferences(typeNameMap, set);
77 type.collectReferences(typeNameMap, set);