]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/datatypes/Constructor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / common / datatypes / Constructor.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/datatypes/Constructor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/datatypes/Constructor.java
new file mode 100755 (executable)
index 0000000..88a4555
--- /dev/null
@@ -0,0 +1,61 @@
+package org.simantics.scl.compiler.common.datatypes;
+
+import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
+import org.simantics.scl.compiler.internal.codegen.utils.ClassBuilder;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.util.Typed;
+
+public class Constructor implements Typed {
+    public static final Constructor[] EMPTY_ARRAY = new Constructor[0];
+    
+    public final long loc;
+    
+    public final TypeConstructor dataType;
+    public final Name name;
+    public final Type[] parameterTypes;
+    public final String javaName;
+    
+    public final TVar[] typeVariables;
+    public final Type type;
+
+    public String[] fieldNames;
+
+    public String[] recordFieldNames;
+    
+    public Constructor(long loc,
+            TypeConstructor dataType, Name name, Type[] parameters,
+            String javaName) {
+        ClassBuilder.checkClassName(javaName);
+        this.loc = loc;
+        this.dataType = dataType;
+        this.name = name;
+        this.parameterTypes = parameters;
+        this.javaName = javaName;
+        
+        Type currentType = dataType.type;
+        for(int i=parameterTypes.length-1;i>=0;--i)
+            currentType = Types.function(parameterTypes[i], currentType);
+        this.typeVariables = Types.freeVars(currentType).toArray(TVar.EMPTY_ARRAY); 
+        this.type = Types.closure(currentType, typeVariables);
+    }
+
+    @Override
+    public Type getType() {
+        return type;
+    }    
+    
+    public TVar[] getTypeVariables() {
+        return typeVariables;
+    }
+    
+    public Type[] getParameterTypes() {
+        return parameterTypes;
+    }
+    
+    public Type getReturnType() {
+        return dataType.type;
+    }
+}