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