1 package org.simantics.scl.compiler.elaboration.modules;
\r
3 import java.util.ArrayList;
\r
5 import org.cojen.classfile.TypeDesc;
\r
6 import org.simantics.scl.compiler.common.datatypes.Constructor;
\r
7 import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
\r
8 import org.simantics.scl.compiler.types.TCon;
\r
9 import org.simantics.scl.compiler.types.TVar;
\r
10 import org.simantics.scl.compiler.types.Type;
\r
11 import org.simantics.scl.compiler.types.Types;
\r
12 import org.simantics.scl.compiler.types.kinds.KArrow;
\r
13 import org.simantics.scl.compiler.types.kinds.Kind;
\r
14 import org.simantics.scl.compiler.types.kinds.Kinds;
\r
16 public abstract class TypeConstructor {
\r
20 public TVar[] parameters;
\r
23 public Constructor[] constructors = Constructor.EMPTY_ARRAY;
\r
24 public String documentation;
\r
27 * A data type is open if it can be constructed without
\r
28 * constructors listed above.
\r
30 public boolean isOpen = true;
\r
32 public TypeConstructor(Kind kind) {
\r
36 public TypeConstructor(TCon name, Kind kind) {
\r
40 ArrayList<TVar> vars = new ArrayList<TVar>(2);
\r
41 for(Kind cur = kind; cur instanceof KArrow;) {
\r
42 KArrow arrow = (KArrow)cur;
\r
43 vars.add(Types.var(arrow.domain));
\r
46 this.parameters = vars.toArray(new TVar[vars.size()]);
\r
47 this.type = Types.apply(name, parameters);
\r
50 public TypeConstructor(TCon name, TVar ... parameters) {
\r
51 setType(name, parameters);
\r
52 Kind kind = Kinds.STAR;
\r
53 for(int i = parameters.length-1;i>=0;--i)
\r
54 kind = Kinds.arrow(parameters[i].getKind(), kind);
\r
58 public void setType(TCon name, TVar ... parameters) {
\r
60 this.parameters = parameters;
\r
61 this.type = Types.apply(name, parameters);
\r
64 public void setConstructors(Constructor ... constructors) {
\r
65 this.constructors = constructors;
\r
68 public abstract TypeDesc construct(JavaTypeTranslator translator, Type[] parameters);
\r
70 public void setDocumentation(String documentation) {
\r
71 this.documentation = documentation;
\r