1 package org.simantics.scl.compiler.elaboration.modules;
\r
3 import gnu.trove.map.hash.THashMap;
\r
5 import java.util.ArrayList;
\r
7 import org.cojen.classfile.TypeDesc;
\r
8 import org.simantics.scl.compiler.constants.Constant;
\r
9 import org.simantics.scl.compiler.constants.JavaTypeClassSuper;
\r
10 import org.simantics.scl.compiler.elaboration.fundeps.Fundep;
\r
11 import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
\r
12 import org.simantics.scl.compiler.types.TCon;
\r
13 import org.simantics.scl.compiler.types.TPred;
\r
14 import org.simantics.scl.compiler.types.TVar;
\r
15 import org.simantics.scl.compiler.types.Type;
\r
16 import org.simantics.scl.compiler.types.Types;
\r
17 import org.simantics.scl.compiler.types.kinds.Kinds;
\r
19 public class TypeClass extends TypeConstructor {
\r
20 public final TPred[] context;
\r
21 public final TCon name;
\r
22 public final String javaName;
\r
23 public final TVar[] parameters;
\r
24 public final Fundep[] fundeps;
\r
25 public final TPred class_;
\r
26 public final ArrayList<String> methodNames = new ArrayList<String>();
\r
27 public final THashMap<String, TypeClassMethod> methods =
\r
28 new THashMap<String, TypeClassMethod>();
\r
29 public final Constant[] superGenerators;
\r
30 public final TypeDesc typeDesc;
\r
32 public String documentation;
\r
34 public TypeClass(long loc, TPred[] context, TCon name, String javaName, TVar[] parameters,
\r
37 this.locatable = loc;
\r
38 this.context = context;
\r
40 this.javaName = javaName;
\r
41 this.parameters = parameters;
\r
42 this.fundeps = fundeps;
\r
43 //this.typeDesc = TypeDesc.forClass(new JavaNamingPolicy(name.module).getTypeClassInterfaceName(name));
\r
44 this.typeDesc = TypeDesc.forClass(javaName);
\r
45 this.class_ = Types.pred(name, parameters);
\r
46 this.superGenerators = new Constant[context.length];
\r
47 for(int i=0;i<context.length;++i)
\r
48 superGenerators[i] = new JavaTypeClassSuper(i, javaName, "super" + i, context[i], class_);
\r
52 public void toString(final StringBuilder b) {
\r
53 final TypeUnparsingContext tuc = new TypeUnparsingContext();
\r
54 b.append("class (");
\r
55 for(int i=0;i<context.length;++i) {
\r
58 context[i].toString(tuc);
\r
59 b.append(context[i]);
\r
62 b.append(class_.toString(tuc));
\r
63 b.append(" where\n");
\r
64 methods.forEachValue(new TObjectProcedure<TypeClassMethod>() {
\r
66 public boolean execute(TypeClassMethod method) {
\r
68 b.append(method.name);
\r
70 b.append(method.baseType.toString(tuc));
\r
79 public TypeDesc construct(JavaTypeTranslator translator, Type[] parameters) {
\r
83 public void setDocumentation(String documentation) {
\r
84 this.documentation = documentation;
\r