Skip to content

Commit

Permalink
two ASM-based classes in fjbg.jar allow using standard asm 4.0 jars
Browse files Browse the repository at this point in the history
  • Loading branch information
magarciaEPFL committed Apr 4, 2012
1 parent ef8deaa commit cebc82d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -1578,7 +1578,7 @@ LIBRARIES (MSIL, FJBG maybe later)
<javac
srcdir="${src.dir}/fjbg"
destdir="${build-libs.dir}/classes/fjbg"
classpath="${build-libs.dir}/classes/fjbg"
classpath="${build-libs.dir}/classes/fjbg:${lib.dir}/extra/asm-4.0.jar:${lib.dir}/extra/asm-util-4.0.jar"
includes="**/*.java"
debug="true"
target="1.5" source="1.4">
Expand Down
23 changes: 6 additions & 17 deletions src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
Expand Up @@ -302,17 +302,6 @@ abstract class GenJVM extends SubComponent with BytecodeWriters {
sym.isModuleClass && !sym.isImplClass && !sym.isLifted
}

/*
* For this to work, add the following to asm.Attribute:
*
* protected Attribute(final String type, final byte[] value) {
* this.type = type;
* this.value = value;
* }
*
*/
class CustomAttr(name: String, b: Array[Byte]) extends asm.Attribute(name, b) { }

// -----------------------------------------------------------------------------------------
// finding the least upper bound in agreement with the bytecode verifier (given two internal names handed by ASM)
// Background:
Expand Down Expand Up @@ -477,10 +466,10 @@ abstract class GenJVM extends SubComponent with BytecodeWriters {
cw
}

def createJAttribute(name: String, b: Array[Byte], offset: Int, len: Int): CustomAttr = {
def createJAttribute(name: String, b: Array[Byte], offset: Int, len: Int): org.objectweb.asm.CustomAttr = {
val dest = new Array[Byte](len);
System.arraycopy(b, offset, dest, 0, len);
new CustomAttr(name, dest)
new org.objectweb.asm.CustomAttr(name, dest)
}

// -----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -784,10 +773,10 @@ abstract class GenJVM extends SubComponent with BytecodeWriters {
// Run the signature parser to catch bogus signatures.
val isValidSignature = wrap {
// Alternative: scala.tools.reflect.SigParser (frontend to sun.reflect.generics.parser.SignatureParser)
import asm.util.CheckMethodAdapter
if (sym.isMethod) { CheckMethodAdapter checkMethodSignature sig } // requires asm-util.jar
else if (sym.isTerm) { CheckMethodAdapter checkFieldSignature sig }
else { CheckMethodAdapter checkClassSignature sig }
import org.objectweb.asm.util.SignatureChecker
if (sym.isMethod) { SignatureChecker checkMethodSignature sig } // requires asm-util.jar
else if (sym.isTerm) { SignatureChecker checkFieldSignature sig }
else { SignatureChecker checkClassSignature sig }
}

if(!isValidSignature) {
Expand Down
24 changes: 24 additions & 0 deletions src/fjbg/org/objectweb/asm/CustomAttr.java
@@ -0,0 +1,24 @@
/* NSC -- new Scala compiler
* Copyright 2005-2012 LAMP/EPFL
*/

package org.objectweb.asm;

import org.objectweb.asm.Attribute;

/**
* A subclass of ASM's Attribute for the sole purpose of accessing a protected field there.
*
*/
public class CustomAttr extends Attribute {

public CustomAttr(final String type, final byte[] value) {
super(type);
/* The next line depends on asm-4.0.jar ie the shrinked version.
When using, say, asm-debug-all-4.0.jar, the assignment should read `super.value = value;` */
super.b = value;
}

}


47 changes: 47 additions & 0 deletions src/fjbg/org/objectweb/asm/util/SignatureChecker.java
@@ -0,0 +1,47 @@
/* NSC -- new Scala compiler
* Copyright 2005-2012 LAMP/EPFL
*/

package org.objectweb.asm.util;

import org.objectweb.asm.util.CheckMethodAdapter;
import org.objectweb.asm.MethodVisitor;

/**
* A subclass of ASM's CheckMethodAdapter for the sole purpose of accessing some protected methods there.
*
*/
public class SignatureChecker extends CheckMethodAdapter {

public SignatureChecker(final MethodVisitor mv) {
super(mv);
}

/**
* Checks a class signature.
*
* @param signature a string containing the signature that must be checked.
*/
public static void checkClassSignature(final String signature) {
CheckMethodAdapter.checkClassSignature(signature);
}

/**
* Checks a method signature.
*
* @param signature a string containing the signature that must be checked.
*/
public static void checkMethodSignature(final String signature) {
CheckMethodAdapter.checkMethodSignature(signature);
}

/**
* Checks a field signature.
*
* @param signature a string containing the signature that must be checked.
*/
public static void checkFieldSignature(final String signature) {
CheckMethodAdapter.checkFieldSignature(signature);
}

}

0 comments on commit cebc82d

Please sign in to comment.