1 package org.simantics.scl.compiler.common.datatypes;
3 import org.simantics.scl.compiler.common.names.Name;
4 import org.simantics.scl.compiler.constants.componentaccess.ComponentAccess;
5 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
6 import org.simantics.scl.compiler.internal.codegen.utils.ClassBuilder;
7 import org.simantics.scl.compiler.types.TVar;
8 import org.simantics.scl.compiler.types.Type;
9 import org.simantics.scl.compiler.types.Types;
10 import org.simantics.scl.compiler.types.util.Typed;
12 public class Constructor implements Typed {
13 public static final Constructor[] EMPTY_ARRAY = new Constructor[0];
15 public final long loc;
17 public final TypeConstructor dataType;
18 public final Name name;
19 public final Type[] parameterTypes;
20 public final String javaName;
22 public final TVar[] typeVariables;
23 public final Type type;
25 public ComponentAccess[] componentAccesses;
27 public String[] recordFieldNames;
29 public Constructor(long loc,
30 TypeConstructor dataType, Name name, Type[] parameters,
32 ClassBuilder.checkClassName(javaName);
34 this.dataType = dataType;
36 this.parameterTypes = parameters;
37 this.javaName = javaName;
39 Type currentType = dataType.type;
40 for(int i=parameterTypes.length-1;i>=0;--i)
41 currentType = Types.function(parameterTypes[i], currentType);
42 this.typeVariables = Types.freeVars(currentType).toArray(TVar.EMPTY_ARRAY);
43 this.type = Types.closure(currentType, typeVariables);
47 public Type getType() {
51 public TVar[] getTypeVariables() {
55 public Type[] getParameterTypes() {
56 return parameterTypes;
59 public Type getReturnType() {