]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/SCLConstructor.java
Minor refactorings related to SCL constructors
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / SCLConstructor.java
index 9e8c7a0f2310c79b0bc28c26fc505bdb07ae394c..1491c71bd6582cb90c9154f4e478846c3e5f119a 100644 (file)
@@ -2,6 +2,8 @@ package org.simantics.scl.compiler.constants;
 
 import org.cojen.classfile.TypeDesc;
 import org.objectweb.asm.Label;
+import org.simantics.scl.compiler.constants.componentaccess.ComponentAccess;
+import org.simantics.scl.compiler.constants.componentaccess.FieldComponentAccess;
 import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
 import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
 import org.simantics.scl.compiler.internal.codegen.references.IVal;
@@ -18,40 +20,38 @@ import org.simantics.scl.compiler.types.Types;
 public class SCLConstructor extends FunctionValue {
     
     private static int MAX_FIELD_COUNT = Constants.MAX_TUPLE_LENGTH;
-    public static String[][] DEFAULT_FIELD_NAMES = new String[MAX_FIELD_COUNT+1][];
+    public static ComponentAccess[][] DEFAULT_FIELD_NAMES = new ComponentAccess[MAX_FIELD_COUNT+1][];
     
     static {
         for(int i=0;i<=MAX_FIELD_COUNT;++i) {
-            String[] fieldNames = new String[i];
+               ComponentAccess[] fieldNames = new ComponentAccess[i];
             for(int j=0;j<i;++j)
-                fieldNames[j] = "c" + j;
+                fieldNames[j] = new FieldComponentAccess("c" + j);
             DEFAULT_FIELD_NAMES[i] = fieldNames;
         }
     }
     
-    String name; // For debugging
-    String className;
-    String[] fieldNames;
+    private final String name; // For debugging
+    private final String className;
+    private final ComponentAccess[] componentAccesses;
     boolean onlyConstructor;
-    int constructorTag;
-    public final String[] recordFieldNames;
+    private final int constructorTag;
        
     public SCLConstructor(String name, String className, TVar[] typeParameters, int constructorTag,
-            Type returnType, String[] fieldNames, String[] recordFieldNames, Type... parameterTypes) {
+            Type returnType, ComponentAccess[] componentAccesses, Type... parameterTypes) {
         super(typeParameters, Types.NO_EFFECTS, returnType, parameterTypes);
         ClassBuilder.checkClassName(className);
         this.name = name;
         this.className = className;
-        this.fieldNames = fieldNames;
+        this.componentAccesses = componentAccesses;
         this.constructorTag = constructorTag;
-        this.recordFieldNames = recordFieldNames;
     }    
     
     public SCLConstructor(String name, String className, TVar[] typeParameters, int constructorTag,
             Type returnType,
             Type ... parameterTypes) {     
         this(name, className, typeParameters, constructorTag, returnType,
-                DEFAULT_FIELD_NAMES[parameterTypes.length], null, parameterTypes);
+                DEFAULT_FIELD_NAMES[parameterTypes.length], parameterTypes);
     }
     
     public void setOnlyConstructor(boolean onlyConstructor) {
@@ -118,7 +118,7 @@ public class SCLConstructor extends FunctionValue {
             
             if(!typeDesc.equals(TypeDesc.VOID)) {
                 mb.dup();
-                mb.loadField(MethodBuilder.getClassName(constructorType), fieldNames[i], typeDesc);                
+                componentAccesses[i].load(mb, MethodBuilder.getClassName(constructorType), typeDesc);
                 if(typeDesc == TypeDesc.OBJECT)
                     mb.unbox(contType);      
             }