]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/StandardTypeConstructor.java
Merge "Ensure GetElementClassRequest is not constructed without elementFactory"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / types / StandardTypeConstructor.java
1 package org.simantics.scl.compiler.internal.codegen.types;
2
3 import org.cojen.classfile.TypeDesc;
4 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
5 import org.simantics.scl.compiler.types.TCon;
6 import org.simantics.scl.compiler.types.TVar;
7 import org.simantics.scl.compiler.types.Type;
8 import org.simantics.scl.compiler.types.kinds.Kind;
9
10 public class StandardTypeConstructor extends TypeConstructor {
11     private TypeDesc typeDesc; // null, if trivial data type (one constructor with one parameter)
12     public boolean external;
13     
14     public StandardTypeConstructor(TCon con, Kind kind) {
15         super(con, kind);
16     }
17     
18     public StandardTypeConstructor(TCon con, Kind kind, TypeDesc typeDesc) {
19         this(con, kind);
20         this.typeDesc = typeDesc;
21     }
22     
23     public StandardTypeConstructor(TCon con, Kind kind, TypeDesc typeDesc, String documentation) {
24         this(con, kind);
25         this.typeDesc = typeDesc;
26         this.documentation = documentation;
27     }
28     
29     public StandardTypeConstructor(TCon name, TVar[] parameters, TypeDesc typeDesc) {
30         super(name, parameters);
31         this.typeDesc = typeDesc;
32     }
33
34     public void setTypeDesc(TypeDesc typeDesc) {
35         this.typeDesc = typeDesc;
36     }
37     
38     public TypeDesc getTypeDesc() {
39         return typeDesc;
40     }
41
42     @Override
43     public TypeDesc construct(JavaTypeTranslator translator, Type[] parameters) {
44         if(typeDesc == null)
45             typeDesc = translator.toTypeDesc(constructors[0].parameterTypes[0]);
46         return typeDesc;
47     }
48 }