1 package org.simantics.scl.compiler.elaboration.modules;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.common.names.Name;
5 import org.simantics.scl.compiler.constants.Constant;
6 import org.simantics.scl.compiler.constants.JavaTypeClassMethod;
7 import org.simantics.scl.compiler.types.Type;
8 import org.simantics.scl.compiler.types.Types;
9 import org.simantics.scl.compiler.types.util.MultiFunction;
11 public class TypeClassMethod {
18 Name defaultImplementation;
21 public TypeClassMethod(TypeClass typeClass, String name, String javaName,
22 Type baseType, int arity, long location) {
23 if(typeClass == null) throw new NullPointerException();
24 if(name == null) throw new NullPointerException();
25 if(javaName == null) throw new NullPointerException();
26 if(baseType == null) throw new NullPointerException();
27 this.typeClass = typeClass;
29 this.javaName = javaName;
30 this.baseType = baseType;
32 this.location = location;
35 public void setDefaultImplementation(Name defaultImplementation) {
36 if(this.defaultImplementation != null)
37 throw new InternalCompilerError("Default method implementation already defined");
38 this.defaultImplementation = defaultImplementation;
41 public Name getDefaultImplementation() {
42 return defaultImplementation;
45 public String getName() {
49 public String getJavaName() {
53 public Type getBaseType() {
57 public int getArity() {
61 public Type getType() {
62 return Types.closure(Types.constrained(
67 public TypeClass getTypeClass() {
71 public SCLValue createValue() {
72 String moduleName = typeClass.name.module;
73 SCLValue value = new SCLValue(Name.create(moduleName, name));
74 MultiFunction mfun = Types.matchFunction(baseType);
75 Type[] parameterTypes = new Type[mfun.parameterTypes.length + 1];
76 System.arraycopy(mfun.parameterTypes, 0, parameterTypes, 1, mfun.parameterTypes.length);
77 parameterTypes[0] = typeClass.class_;
78 // FIXME totally incorrect type for the method
79 Constant constant = new JavaTypeClassMethod(
86 value.setValue(constant);
87 value.setType(getType());