]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/types/TPlainEffectAst.java
New SCL syntax <<effects>>
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / types / TPlainEffectAst.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.kinds.Kind;
9
10 import gnu.trove.map.hash.TObjectIntHashMap;
11 import gnu.trove.set.hash.TIntHashSet;
12
13
14
15 public class TPlainEffectAst extends TypeAst {
16     public final TypeAst[] effects;
17     
18     public TPlainEffectAst(TypeAst[] effects) {
19         this.effects = effects;
20     }
21     
22     public TPlainEffectAst(ArrayList<TypeAst> effects) {
23         this(effects.toArray(new TypeAst[effects.size()]));
24     }
25
26     @Override
27     public void toString(StringBuilder b) {
28         b.append("<<");
29         boolean first = true;
30         for(TypeAst effect : effects) {
31             if(first)
32                 first = false;
33             else
34                 b.append(",");
35             effect.toString(b);
36         }
37         b.append(">>");
38     }
39
40     @Override
41     public Type toType(TypeTranslationContext context, Kind expectedKind) {
42         return TFunctionAst.toEffect(context, effects);
43     }
44     
45     @Override
46     public Type toType(TypeElaborationContext context) {
47         return TFunctionAst.toEffect(context, effects);
48     }
49
50     @Override
51     public int getPrecedence() {
52         return 0;
53     }
54
55     @Override
56     public void collectReferences(TObjectIntHashMap<String> typeNameMap,
57             TIntHashSet set) {
58         for(TypeAst effect : effects)
59             effect.collectReferences(typeNameMap, set);
60     }
61 }