1 package org.simantics.scl.compiler.common.datatypes;
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;
11 public class Constructor implements Typed {
12 public static final Constructor[] EMPTY_ARRAY = new Constructor[0];
14 public final long loc;
16 public final TypeConstructor dataType;
17 public final Name name;
18 public final Type[] parameterTypes;
19 public final String javaName;
21 public final TVar[] typeVariables;
22 public final Type type;
24 public String[] fieldNames;
26 public String[] recordFieldNames;
28 public Constructor(long loc,
29 TypeConstructor dataType, Name name, Type[] parameters,
31 ClassBuilder.checkClassName(javaName);
33 this.dataType = dataType;
35 this.parameterTypes = parameters;
36 this.javaName = javaName;
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);
46 public Type getType() {
50 public TVar[] getTypeVariables() {
54 public Type[] getParameterTypes() {
55 return parameterTypes;
58 public Type getReturnType() {