MCPcopy Index your code
hub / github.com/clojure/clojure / LocalVariablesSorter

Class LocalVariablesSorter

src/jvm/clojure/asm/commons/LocalVariablesSorter.java:48–351  ·  view source on GitHub ↗

A MethodVisitor that renumbers local variables in their order of appearance. This adapter allows one to easily add new local variables to a method. It may be used by inheriting from this class, but the preferred way of using it is via delegation: the next visitor in the chain can indeed add

Source from the content-addressed store, hash-verified

46 * @author Eric Bruneton
47 */
48public class LocalVariablesSorter extends MethodVisitor {
49
50 /** The type of the java.lang.Object class. */
51 private static final Type OBJECT_TYPE = Type.getObjectType("java/lang/Object");
52
53 /**
54 * The mapping from old to new local variable indices. A local variable at index i of size 1 is
55 * remapped to 'mapping[2*i]', while a local variable at index i of size 2 is remapped to
56 * 'mapping[2*i+1]'.
57 */
58 private int[] remappedVariableIndices = new int[40];
59
60 /**
61 * The local variable types after remapping. The format of this array is the same as in {@link
62 * MethodVisitor#visitFrame}, except that long and double types use two slots.
63 */
64 private Object[] remappedLocalTypes = new Object[20];
65
66 /** The index of the first local variable, after formal parameters. */
67 protected final int firstLocal;
68
69 /** The index of the next local variable to be created by {@link #newLocal}. */
70 protected int nextLocal;
71
72 /**
73 * Constructs a new {@link LocalVariablesSorter}. <i>Subclasses must not use this constructor</i>.
74 * Instead, they must use the {@link #LocalVariablesSorter(int, int, String, MethodVisitor)}
75 * version.
76 *
77 * @param access access flags of the adapted method.
78 * @param descriptor the method's descriptor (see {@link Type}).
79 * @param methodVisitor the method visitor to which this adapter delegates calls.
80 * @throws IllegalStateException if a subclass calls this constructor.
81 */
82 public LocalVariablesSorter(
83 final int access, final String descriptor, final MethodVisitor methodVisitor) {
84 this(Opcodes.ASM6, access, descriptor, methodVisitor);
85 if (getClass() != LocalVariablesSorter.class) {
86 throw new IllegalStateException();
87 }
88 }
89
90 /**
91 * Constructs a new {@link LocalVariablesSorter}.
92 *
93 * @param api the ASM API version implemented by this visitor. Must be one of {@link
94 * Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7_EXPERIMENTAL}.
95 * @param access access flags of the adapted method.
96 * @param descriptor the method's descriptor (see {@link Type}).
97 * @param methodVisitor the method visitor to which this adapter delegates calls.
98 */
99 protected LocalVariablesSorter(
100 final int api, final int access, final String descriptor, final MethodVisitor methodVisitor) {
101 super(api, methodVisitor);
102 nextLocal = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0;
103 for (Type argumentType : Type.getArgumentTypes(descriptor)) {
104 nextLocal += argumentType.getSize();
105 }

Callers

nothing calls this directly

Calls 1

getObjectTypeMethod · 0.95

Tested by

no test coverage detected