]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/datatypes/Constructor.java
Fixed multiple issues causing dangling references to discarded queries
[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.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;
11
12 public class Constructor implements Typed {
13     public static final Constructor[] EMPTY_ARRAY = new Constructor[0];
14     
15     public final long loc;
16     
17     public final TypeConstructor dataType;
18     public final Name name;
19     public final Type[] parameterTypes;
20     public final String javaName;
21     
22     public final TVar[] typeVariables;
23     public final Type type;
24
25     public ComponentAccess[] componentAccesses;
26
27     public String[] recordFieldNames;
28     
29     public Constructor(long loc,
30             TypeConstructor dataType, Name name, Type[] parameters,
31             String javaName) {
32         ClassBuilder.checkClassName(javaName);
33         this.loc = loc;
34         this.dataType = dataType;
35         this.name = name;
36         this.parameterTypes = parameters;
37         this.javaName = javaName;
38         
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);
44     }
45
46     @Override
47     public Type getType() {
48         return type;
49     }    
50     
51     public TVar[] getTypeVariables() {
52         return typeVariables;
53     }
54     
55     public Type[] getParameterTypes() {
56         return parameterTypes;
57     }
58     
59     public Type getReturnType() {
60         return dataType.type;
61     }
62 }