Skip to content

Commit 3fb2e4a

Browse files
committed
upgrade asm4 to asm5
1 parent a17b6fd commit 3fb2e4a

File tree

123 files changed

+13656
-1157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+13656
-1157
lines changed

src/java/nginx/clojure/asm/AnnotationVisitor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class AnnotationVisitor {
4141

4242
/**
4343
* The ASM API version implemented by this visitor. The value of this field
44-
* must be one of {@link Opcodes#ASM4}.
44+
* must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
4545
*/
4646
protected final int api;
4747

@@ -56,7 +56,7 @@ public abstract class AnnotationVisitor {
5656
*
5757
* @param api
5858
* the ASM API version implemented by this visitor. Must be one
59-
* of {@link Opcodes#ASM4}.
59+
* of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
6060
*/
6161
public AnnotationVisitor(final int api) {
6262
this(api, null);
@@ -67,13 +67,13 @@ public AnnotationVisitor(final int api) {
6767
*
6868
* @param api
6969
* the ASM API version implemented by this visitor. Must be one
70-
* of {@link Opcodes#ASM4}.
70+
* of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
7171
* @param av
7272
* the annotation visitor to which this visitor must delegate
7373
* method calls. May be null.
7474
*/
7575
public AnnotationVisitor(final int api, final AnnotationVisitor av) {
76-
if (api != Opcodes.ASM4) {
76+
if (api != Opcodes.ASM4 && api != Opcodes.ASM5) {
7777
throw new IllegalArgumentException();
7878
}
7979
this.api = api;
@@ -89,7 +89,7 @@ public AnnotationVisitor(final int api, final AnnotationVisitor av) {
8989
* the actual value, whose type must be {@link Byte},
9090
* {@link Boolean}, {@link Character}, {@link Short},
9191
* {@link Integer} , {@link Long}, {@link Float}, {@link Double},
92-
* {@link String} or {@link Type} or OBJECT or ARRAY sort. This
92+
* {@link String} or {@link Type} of OBJECT or ARRAY sort. This
9393
* value can also be an array of byte, boolean, short, char, int,
9494
* long, float or double values (this is equivalent to using
9595
* {@link #visitArray visitArray} and visiting each array element

src/java/nginx/clojure/asm/AnnotationWriter.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ final class AnnotationWriter extends AnnotationVisitor {
104104
*/
105105
AnnotationWriter(final ClassWriter cw, final boolean named,
106106
final ByteVector bv, final ByteVector parent, final int offset) {
107-
super(Opcodes.ASM4);
107+
super(Opcodes.ASM5);
108108
this.cw = cw;
109109
this.named = named;
110110
this.bv = bv;
@@ -315,4 +315,57 @@ static void put(final AnnotationWriter[] panns, final int off,
315315
}
316316
}
317317
}
318+
319+
/**
320+
* Puts the given type reference and type path into the given bytevector.
321+
* LOCAL_VARIABLE and RESOURCE_VARIABLE target types are not supported.
322+
*
323+
* @param typeRef
324+
* a reference to the annotated type. See {@link TypeReference}.
325+
* @param typePath
326+
* the path to the annotated type argument, wildcard bound, array
327+
* element type, or static inner type within 'typeRef'. May be
328+
* <tt>null</tt> if the annotation targets 'typeRef' as a whole.
329+
* @param out
330+
* where the type reference and type path must be put.
331+
*/
332+
static void putTarget(int typeRef, TypePath typePath, ByteVector out) {
333+
switch (typeRef >>> 24) {
334+
case 0x00: // CLASS_TYPE_PARAMETER
335+
case 0x01: // METHOD_TYPE_PARAMETER
336+
case 0x16: // METHOD_FORMAL_PARAMETER
337+
out.putShort(typeRef >>> 16);
338+
break;
339+
case 0x13: // FIELD
340+
case 0x14: // METHOD_RETURN
341+
case 0x15: // METHOD_RECEIVER
342+
out.putByte(typeRef >>> 24);
343+
break;
344+
case 0x47: // CAST
345+
case 0x48: // CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
346+
case 0x49: // METHOD_INVOCATION_TYPE_ARGUMENT
347+
case 0x4A: // CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
348+
case 0x4B: // METHOD_REFERENCE_TYPE_ARGUMENT
349+
out.putInt(typeRef);
350+
break;
351+
// case 0x10: // CLASS_EXTENDS
352+
// case 0x11: // CLASS_TYPE_PARAMETER_BOUND
353+
// case 0x12: // METHOD_TYPE_PARAMETER_BOUND
354+
// case 0x17: // THROWS
355+
// case 0x42: // EXCEPTION_PARAMETER
356+
// case 0x43: // INSTANCEOF
357+
// case 0x44: // NEW
358+
// case 0x45: // CONSTRUCTOR_REFERENCE
359+
// case 0x46: // METHOD_REFERENCE
360+
default:
361+
out.put12(typeRef >>> 24, (typeRef & 0xFFFF00) >> 8);
362+
break;
363+
}
364+
if (typePath == null) {
365+
out.putByte(0);
366+
} else {
367+
int length = typePath.b[typePath.offset] * 2 + 1;
368+
out.putByteArray(typePath.b, typePath.offset, length);
369+
}
370+
}
318371
}

src/java/nginx/clojure/asm/ByteVector.java

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -230,41 +230,68 @@ public ByteVector putUTF8(final String s) {
230230
if (c >= '\001' && c <= '\177') {
231231
data[len++] = (byte) c;
232232
} else {
233-
int byteLength = i;
234-
for (int j = i; j < charLength; ++j) {
235-
c = s.charAt(j);
236-
if (c >= '\001' && c <= '\177') {
237-
byteLength++;
238-
} else if (c > '\u07FF') {
239-
byteLength += 3;
240-
} else {
241-
byteLength += 2;
242-
}
243-
}
244-
if (byteLength > 65535) {
245-
throw new IllegalArgumentException();
246-
}
247-
data[length] = (byte) (byteLength >>> 8);
248-
data[length + 1] = (byte) byteLength;
249-
if (length + 2 + byteLength > data.length) {
250-
length = len;
251-
enlarge(2 + byteLength);
252-
data = this.data;
253-
}
254-
for (int j = i; j < charLength; ++j) {
255-
c = s.charAt(j);
256-
if (c >= '\001' && c <= '\177') {
257-
data[len++] = (byte) c;
258-
} else if (c > '\u07FF') {
259-
data[len++] = (byte) (0xE0 | c >> 12 & 0xF);
260-
data[len++] = (byte) (0x80 | c >> 6 & 0x3F);
261-
data[len++] = (byte) (0x80 | c & 0x3F);
262-
} else {
263-
data[len++] = (byte) (0xC0 | c >> 6 & 0x1F);
264-
data[len++] = (byte) (0x80 | c & 0x3F);
265-
}
266-
}
267-
break;
233+
length = len;
234+
return encodeUTF8(s, i, 65535);
235+
}
236+
}
237+
length = len;
238+
return this;
239+
}
240+
241+
/**
242+
* Puts an UTF8 string into this byte vector. The byte vector is
243+
* automatically enlarged if necessary. The string length is encoded in two
244+
* bytes before the encoded characters, if there is space for that (i.e. if
245+
* this.length - i - 2 >= 0).
246+
*
247+
* @param s
248+
* the String to encode.
249+
* @param i
250+
* the index of the first character to encode. The previous
251+
* characters are supposed to have already been encoded, using
252+
* only one byte per character.
253+
* @param maxByteLength
254+
* the maximum byte length of the encoded string, including the
255+
* already encoded characters.
256+
* @return this byte vector.
257+
*/
258+
ByteVector encodeUTF8(final String s, int i, int maxByteLength) {
259+
int charLength = s.length();
260+
int byteLength = i;
261+
char c;
262+
for (int j = i; j < charLength; ++j) {
263+
c = s.charAt(j);
264+
if (c >= '\001' && c <= '\177') {
265+
byteLength++;
266+
} else if (c > '\u07FF') {
267+
byteLength += 3;
268+
} else {
269+
byteLength += 2;
270+
}
271+
}
272+
if (byteLength > maxByteLength) {
273+
throw new IllegalArgumentException();
274+
}
275+
int start = length - i - 2;
276+
if (start >= 0) {
277+
data[start] = (byte) (byteLength >>> 8);
278+
data[start + 1] = (byte) byteLength;
279+
}
280+
if (length + byteLength - i > data.length) {
281+
enlarge(byteLength - i);
282+
}
283+
int len = length;
284+
for (int j = i; j < charLength; ++j) {
285+
c = s.charAt(j);
286+
if (c >= '\001' && c <= '\177') {
287+
data[len++] = (byte) c;
288+
} else if (c > '\u07FF') {
289+
data[len++] = (byte) (0xE0 | c >> 12 & 0xF);
290+
data[len++] = (byte) (0x80 | c >> 6 & 0x3F);
291+
data[len++] = (byte) (0x80 | c & 0x3F);
292+
} else {
293+
data[len++] = (byte) (0xC0 | c >> 6 & 0x1F);
294+
data[len++] = (byte) (0x80 | c & 0x3F);
268295
}
269296
}
270297
length = len;

0 commit comments

Comments
 (0)