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%2Finternal%2Fcodegen%2Futils%2FCodeBuilderUtils.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Futils%2FCodeBuilderUtils.java;h=ec44be75a1531adf48204c4d78653c09c87cb340;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java new file mode 100644 index 000000000..ec44be75a --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java @@ -0,0 +1,238 @@ +package org.simantics.scl.compiler.internal.codegen.utils; + +import java.util.Arrays; + +import org.cojen.classfile.TypeDesc; +import org.objectweb.asm.Label; +import org.objectweb.asm.Opcodes; +import org.simantics.scl.compiler.internal.codegen.references.Val; +import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator; +import org.simantics.scl.compiler.types.Type; + +public class CodeBuilderUtils { + + /** + * Creates fields c0,...,c{N-1} to the given class, where c is fieldNamePrefix and N is the length of types. + * Creates also a constructor for the fields. + * @param classFile + * @param fieldModifiers + * @param fieldNamePrefix + * @param types + */ + public static void makeRecord(ClassBuilder classBuilder, String recordName, int fieldModifiers, String fieldNamePrefix, TypeDesc[] types, + boolean generateEqualsAndHashCode) { + // Create fields + for(int i=0;i 0) { + tsmb.newObject(TypeDesc.forClass(StringBuilder.class)); + tsmb.dup(); + tsmb.invokeConstructor("java/lang/StringBuilder", Constants.EMPTY_TYPEDESC_ARRAY); + + // build string + tsmb.loadConstant("(" + recordName); + StringBuilder_appendString(tsmb); + for(int i=0;i