Merge "Trigger all drag start events from single place"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / common / datatypes / Constructor.java
1 package org.simantics.scl.compiler.common.datatypes;
2
3 import org.simantics.scl.compiler.common.names.Name;
4 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
5 import org.simantics.scl.compiler.internal.codegen.utils.ClassBuilder;
6 import org.simantics.scl.compiler.types.TVar;
7 import org.simantics.scl.compiler.types.Type;
8 import org.simantics.scl.compiler.types.Types;
9 import org.simantics.scl.compiler.types.util.Typed;
10
11 public class Constructor implements Typed {
12     public static final Constructor[] EMPTY_ARRAY = new Constructor[0];
13     
14     public final long loc;
15     
16     public final TypeConstructor dataType;
17     public final Name name;
18     public final Type[] parameterTypes;
19     public final String javaName;
20     
21     public final TVar[] typeVariables;
22     public final Type type;
23
24     public String[] fieldNames;
25
26     public String[] recordFieldNames;
27     
28     public Constructor(long loc,
29             TypeConstructor dataType, Name name, Type[] parameters,
30             String javaName) {
31         ClassBuilder.checkClassName(javaName);
32         this.loc = loc;
33         this.dataType = dataType;
34         this.name = name;
35         this.parameterTypes = parameters;
36         this.javaName = javaName;
37         
38         Type currentType = dataType.type;
39         for(int i=parameterTypes.length-1;i>=0;--i)
40             currentType = Types.function(parameterTypes[i], currentType);
41         this.typeVariables = Types.freeVars(currentType).toArray(TVar.EMPTY_ARRAY); 
42         this.type = Types.closure(currentType, typeVariables);
43     }
44
45     @Override
46     public Type getType() {
47         return type;
48     }    
49     
50     public TVar[] getTypeVariables() {
51         return typeVariables;
52     }
53     
54     public Type[] getParameterTypes() {
55         return parameterTypes;
56     }
57     
58     public Type getReturnType() {
59         return dataType.type;
60     }
61 }