FileDocCategorySizeDatePackage
ASMifierCodeVisitor.javaAPI DocGlassfish v2 API8677Thu Mar 02 11:51:18 GMT 2006oracle.toplink.libraries.asm.util

ASMifierCodeVisitor

public class ASMifierCodeVisitor extends PrintCodeVisitor
A {@link PrintCodeVisitor} that prints the ASM code that generates the code it visits.
author
Eric Bruneton, Eugene Kuleshov

Fields Summary
private final HashMap
labelNames
The label names. This map associate String values to Label keys.
Constructors Summary
public ASMifierCodeVisitor()
Constructs a new {@link ASMifierCodeVisitor} object.

    this.labelNames = new HashMap();
  
Methods Summary
private voidappendLabel(oracle.toplink.libraries.asm.Label l)
Appends the name of the given label to {@link #buf buf}. The given label must already have a name. One way to ensure this is to always call {@link #declareLabel declared} before calling this method.

param
l a label.

    buf.append((String)labelNames.get(l));
  
private voiddeclareLabel(oracle.toplink.libraries.asm.Label l)
Appends a declaration of the given label to {@link #buf buf}. This declaration is of the form "Label lXXX = new Label();". Does nothing if the given label has already been declared.

param
l a label.

    String name = (String)labelNames.get(l);
    if (name == null) {
      name = "l" + labelNames.size();
      labelNames.put(l, name);
      buf.append("Label ")
        .append(name)
        .append(" = new Label();\n");
    }
  
public voidprintAttribute(oracle.toplink.libraries.asm.Attribute attr)

    if (attr instanceof ASMifiable) {
      buf.append("// CODE ATTRIBUTE\n");
      ((ASMifiable)attr).asmify(buf, "cv", labelNames);
    } else {
      buf.append("// WARNING! skipped a non standard code attribute of type \"");
      buf.append(attr.type).append("\"\n");
    }
  
public voidprintFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)

    buf.append("cv.visitFieldInsn(")
      .append(OPCODES[opcode])
      .append(", ");
    ASMifierClassVisitor.appendConstant(buf, owner);
    buf.append(", ");
    ASMifierClassVisitor.appendConstant(buf, name);
    buf.append(", ");
    ASMifierClassVisitor.appendConstant(buf, desc);
    buf.append(");\n");
  
public voidprintIincInsn(int var, int increment)

    buf.append("cv.visitIincInsn(")
      .append(var)
      .append(", ")
      .append(increment)
      .append(");\n");
  
public voidprintInsn(int opcode)

    buf.append("cv.visitInsn(").
      append(OPCODES[opcode]).
      append(");\n");
  
public voidprintIntInsn(int opcode, int operand)

    buf.append("cv.visitIntInsn(").
      append(OPCODES[opcode]).
      append(", ").
      append(operand).
      append(");\n");
  
public voidprintJumpInsn(int opcode, oracle.toplink.libraries.asm.Label label)

    declareLabel(label);
    buf.append("cv.visitJumpInsn(")
      .append(OPCODES[opcode])
      .append(", ");
    appendLabel(label);
    buf.append(");\n");
  
public voidprintLabel(oracle.toplink.libraries.asm.Label label)

    declareLabel(label);
    buf.append("cv.visitLabel(");
    appendLabel(label);
    buf.append(");\n");
  
public voidprintLdcInsn(java.lang.Object cst)

    buf.append("cv.visitLdcInsn(");
    ASMifierClassVisitor.appendConstant(buf, cst);
    buf.append(");\n");
  
public voidprintLineNumber(int line, oracle.toplink.libraries.asm.Label start)

    buf.append("cv.visitLineNumber(")
      .append(line)
      .append(", ");
    appendLabel(start);
    buf.append(");\n");
  
public voidprintLocalVariable(java.lang.String name, java.lang.String desc, oracle.toplink.libraries.asm.Label start, oracle.toplink.libraries.asm.Label end, int index)

    buf.append("cv.visitLocalVariable(");
    ASMifierClassVisitor.appendConstant(buf, name);
    buf.append(", ");
    ASMifierClassVisitor.appendConstant(buf, desc);
    buf.append(", ");
    appendLabel(start);
    buf.append(", ");
    appendLabel(end);
    buf.append(", ").append(index).append(");\n");
  
public voidprintLookupSwitchInsn(oracle.toplink.libraries.asm.Label dflt, int[] keys, oracle.toplink.libraries.asm.Label[] labels)

    for (int i = 0; i < labels.length; ++i) {
      declareLabel(labels[i]);
    }
    declareLabel(dflt);

    buf.append("cv.visitLookupSwitchInsn(");
    appendLabel(dflt);
    buf.append(", new int[] {");
    for (int i = 0; i < keys.length; ++i) {
      buf.append(i == 0 ? " " : ", ").append(keys[i]);
    }
    buf.append(" }, new Label[] {");
    for (int i = 0; i < labels.length; ++i) {
      buf.append(i == 0 ? " " : ", ");
      appendLabel(labels[i]);
    }
    buf.append(" });\n");
  
public voidprintMaxs(int maxStack, int maxLocals)

    buf.append("cv.visitMaxs(")
      .append(maxStack)
      .append(", ")
      .append(maxLocals)
      .append(");\n");
  
public voidprintMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)

    buf.append("cv.visitMethodInsn(")
      .append(OPCODES[opcode])
      .append(", ");
    ASMifierClassVisitor.appendConstant(buf, owner);
    buf.append(", ");
    ASMifierClassVisitor.appendConstant(buf, name);
    buf.append(", ");
    ASMifierClassVisitor.appendConstant(buf, desc);
    buf.append(");\n");
  
public voidprintMultiANewArrayInsn(java.lang.String desc, int dims)

    buf.append("cv.visitMultiANewArrayInsn(");
    ASMifierClassVisitor.appendConstant(buf, desc);
    buf.append(", ")
      .append(dims)
      .append(");\n");
  
public voidprintTableSwitchInsn(int min, int max, oracle.toplink.libraries.asm.Label dflt, oracle.toplink.libraries.asm.Label[] labels)

    for (int i = 0; i < labels.length; ++i) {
      declareLabel(labels[i]);
    }
    declareLabel(dflt);

    buf.append("cv.visitTableSwitchInsn(")
      .append(min)
      .append(", ")
      .append(max)
      .append(", ");
    appendLabel(dflt);
    buf.append(", new Label[] {");
    for (int i = 0; i < labels.length; ++i) {
      buf.append(i == 0 ? " " : ", ");
      appendLabel(labels[i]);
    }
    buf.append(" });\n");
  
public voidprintTryCatchBlock(oracle.toplink.libraries.asm.Label start, oracle.toplink.libraries.asm.Label end, oracle.toplink.libraries.asm.Label handler, java.lang.String type)

    buf.append("cv.visitTryCatchBlock(");
    appendLabel(start);
    buf.append(", ");
    appendLabel(end);
    buf.append(", ");
    appendLabel(handler);
    buf.append(", ");
    ASMifierClassVisitor.appendConstant(buf, type);
    buf.append(");\n");
  
public voidprintTypeInsn(int opcode, java.lang.String desc)

    buf.append("cv.visitTypeInsn(").
      append(OPCODES[opcode]).
      append(", ");
    ASMifierClassVisitor.appendConstant(buf, desc);
    buf.append(");\n");
  
public voidprintVarInsn(int opcode, int var)

    buf.append("cv.visitVarInsn(").
      append(OPCODES[opcode]).
      append(", ").
      append(var).
      append(");\n");