Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Commit 1fa441c

Browse files
committed
Upgrade ASM to 5.0.2
This commit is a squashed version of all commits in PR #3747. For future upgrades, consult the README and check the commits in https://github.com/scala/scala/pull/3747/commits There's one bug in ASM 5.0.2 that breaks scalac: http://forge.ow2.org/tracker/?func=detail&aid=317200&group_id=23&atid=100023 This bug is fixed in ASM trunk, the patch has been merged into this commit. A future upgrade of ASM should contain the fix.
1 parent ddb7994 commit 1fa441c

Some content is hidden

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

64 files changed

+3825
-294
lines changed

README

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Version 5.0.2, SVN r1741, tags/ASM_5_0_2
2+
3+
Git SVN repo: https://github.com/lrytz/asm
4+
- git svn howto: https://github.com/lrytz/asm/issues/1
5+
6+
Upgrading ASM
7+
-------------
8+
9+
Start by deleting all source files in src/asm/ and copy the ones from the latest ASM release.
10+
11+
Excluded Files (don't copy):
12+
- package.html files
13+
- org/objectweb/asm/commons
14+
- org/objectweb/asm/optimizer
15+
- org/objectweb/asm/xml
16+
17+
Re-packaging and cosmetic changes:
18+
- convert line endings (there are some CRLF)
19+
find src/asm/scala/tools/asm -name '*.java' | xargs dos2unix
20+
- change package clauses
21+
find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/package org\.objectweb\.asm/package scala.tools.asm/'
22+
- update imports
23+
find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/import org\.objectweb\.asm/import scala.tools.asm/'
24+
- update @links, @associates
25+
find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/@link org\.objectweb\.asm/@link scala.tools.asm/'
26+
find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/@associates org\.objectweb\.asm/@associates scala.tools.asm/'
27+
- remove trailing whitespace
28+
find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/[ ]*$//'
29+
30+
Actual changes: check the git log for [asm-cherry-pick] after the previous upgrade.

src/main/java/scala/tools/asm/AnnotationVisitor.java

Lines changed: 4 additions & 4 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;

src/main/java/scala/tools/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/main/java/scala/tools/asm/ByteVector.java

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,14 @@ public ByteVector putLong(final long l) {
204204
* automatically enlarged if necessary.
205205
*
206206
* @param s
207-
* a String.
207+
* a String whose UTF8 encoded length must be less than 65536.
208208
* @return this byte vector.
209209
*/
210210
public ByteVector putUTF8(final String s) {
211211
int charLength = s.length();
212+
if (charLength > 65535) {
213+
throw new IllegalArgumentException();
214+
}
212215
int len = length;
213216
if (len + 2 + charLength > data.length) {
214217
enlarge(2 + charLength);
@@ -227,38 +230,68 @@ public ByteVector putUTF8(final String s) {
227230
if (c >= '\001' && c <= '\177') {
228231
data[len++] = (byte) c;
229232
} else {
230-
int byteLength = i;
231-
for (int j = i; j < charLength; ++j) {
232-
c = s.charAt(j);
233-
if (c >= '\001' && c <= '\177') {
234-
byteLength++;
235-
} else if (c > '\u07FF') {
236-
byteLength += 3;
237-
} else {
238-
byteLength += 2;
239-
}
240-
}
241-
data[length] = (byte) (byteLength >>> 8);
242-
data[length + 1] = (byte) byteLength;
243-
if (length + 2 + byteLength > data.length) {
244-
length = len;
245-
enlarge(2 + byteLength);
246-
data = this.data;
247-
}
248-
for (int j = i; j < charLength; ++j) {
249-
c = s.charAt(j);
250-
if (c >= '\001' && c <= '\177') {
251-
data[len++] = (byte) c;
252-
} else if (c > '\u07FF') {
253-
data[len++] = (byte) (0xE0 | c >> 12 & 0xF);
254-
data[len++] = (byte) (0x80 | c >> 6 & 0x3F);
255-
data[len++] = (byte) (0x80 | c & 0x3F);
256-
} else {
257-
data[len++] = (byte) (0xC0 | c >> 6 & 0x1F);
258-
data[len++] = (byte) (0x80 | c & 0x3F);
259-
}
260-
}
261-
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);
262295
}
263296
}
264297
length = len;

0 commit comments

Comments
 (0)