X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcommon%2Fdatatypes%2FConstructor.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcommon%2Fdatatypes%2FConstructor.java;h=88a45558f55658a4feb55c995753556674c1f8b5;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 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 index 000000000..88a45558f --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/datatypes/Constructor.java @@ -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; + } +}