Skip to content
Snippets Groups Projects
Commit 25621685 authored by Etienne Kneuss's avatar Etienne Kneuss Committed by Philippe Suter
Browse files

Compile productElements to every case class implementations

parent e383420e
No related branches found
No related tags found
No related merge requests found
package leon.codegen.runtime;
public interface CaseClass {
public abstract Object[] productElements();
}
......@@ -229,6 +229,8 @@ object CodeGeneration {
CLASS_ACC_ABSTRACT
).asInstanceOf[U2])
cf.addInterface("leon/codegen/runtime/CaseClass")
cf.addDefaultConstructor
cf.writeToFile(cName + ".class")
......@@ -280,6 +282,30 @@ object CodeGeneration {
cch.freeze
}
locally {
val pem = cf.addMethod("[java/lang/Object;", "productElements")
pem.setFlags((
METHOD_ACC_PUBLIC |
METHOD_ACC_FINAL
).asInstanceOf[U2])
val pech = pem.codeHandler
pech << Ldc(ccd.fields.size)
pech << NewArray("java/lang/Object")
for ((f, i) <- ccd.fields.zipWithIndex) {
pech << DUP
pech << Ldc(i)
pech << ALoad(0)
pech << GetField(cName, f.id.name, typeToJVM(f.tpe))
pech << AASTORE
}
pech << ARETURN
pech.freeze
}
// definition of equals
locally {
val emh = cf.addMethod("Z", "equals", "Ljava/lang/Object;")
......
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment