]> gerrit.simantics Code Review - simantics/platform.git/blob
ef73ea6af1ec0745071c22c452bee333e1535866
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.modules;\r
2 \r
3 import gnu.trove.map.hash.THashMap;\r
4 \r
5 import java.util.ArrayList;\r
6 \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
18 \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
31     long locatable;\r
32     public String documentation;\r
33     \r
34     public TypeClass(long loc, TPred[] context, TCon name, String javaName, TVar[] parameters,\r
35             Fundep[] fundeps) {\r
36         super(Kinds.STAR);\r
37         this.locatable = loc;\r
38         this.context = context;        \r
39         this.name = name;\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
49     }\r
50 \r
51     /*\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
56             if(i>0)\r
57                 b.append(", ");\r
58             context[i].toString(tuc);\r
59             b.append(context[i]);\r
60         }\r
61         b.append(") => ");\r
62         b.append(class_.toString(tuc));\r
63         b.append(" where\n");\r
64         methods.forEachValue(new TObjectProcedure<TypeClassMethod>() {            \r
65             @Override\r
66             public boolean execute(TypeClassMethod method) {\r
67                 b.append("    ");\r
68                 b.append(method.name);\r
69                 b.append(" :: ");\r
70                 b.append(method.baseType.toString(tuc));\r
71                 b.append('\n');\r
72                 return true;\r
73             }\r
74         });\r
75     }\r
76     */\r
77     \r
78     @Override\r
79     public TypeDesc construct(JavaTypeTranslator translator, Type[] parameters) {\r
80         return typeDesc;\r
81     }\r
82 \r
83     public void setDocumentation(String documentation) {\r
84         this.documentation = documentation;\r
85     }\r
86 }\r