Skip to content

Commit 398431a

Browse files
committed
Merge pull request #90 from samuelgruetter/java8-classfiles
ClassfileParser: Java8 bytecode (fixes #83)
2 parents a7d47ab + f40007e commit 398431a

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ object Flags {
342342
/** Symbol is a Java-style varargs method */
343343
final val JavaVarargs = termFlag(38, "<varargs>")
344344

345+
/** Symbol is a Java default method */
346+
final val DefaultMethod = termFlag(39, "<defaultmethod>")
347+
345348
// Flags following this one are not pickled
346349

347350
/** Denotation is in train of being loaded and completed, used to catch cyclic dependencies */

src/dotty/tools/dotc/core/pickling/ClassfileConstants.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ object ClassfileConstants {
6868
final val CONSTANT_INTFMETHODREF = 11
6969
final val CONSTANT_NAMEANDTYPE = 12
7070

71+
final val CONSTANT_METHODHANDLE = 15
72+
final val CONSTANT_METHODTYPE = 16
73+
final val CONSTANT_INVOKEDYNAMIC = 18
74+
7175
// tags describing the type of a literal in attribute values
7276
final val BYTE_TAG = 'B'
7377
final val CHAR_TAG = 'C'

src/dotty/tools/dotc/core/pickling/ClassfileParser.scala

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,16 @@ class ClassfileParser(
392392
case ENUM_TAG =>
393393
val t = pool.getType(index)
394394
val n = pool.getName(in.nextChar)
395-
val s = t.typeSymbol.companionModule.decls.lookup(n)
396-
assert(s != NoSymbol, t)
397-
if (skip) None else Some(Literal(Constant(s)))
395+
val module = t.typeSymbol.companionModule
396+
val s = module.info.decls.lookup(n)
397+
if (skip) {
398+
None
399+
} else if (s != NoSymbol) {
400+
Some(Literal(Constant(s)))
401+
} else {
402+
ctx.warning(s"""While parsing annotations in ${in.file}, could not find $n in enum $module.\nThis is likely due to an implementation restriction: an annotation argument cannot refer to a member of the annotated class (SI-7014).""")
403+
None
404+
}
398405
case ARRAY_TAG =>
399406
val arr = new ArrayBuffer[Tree]()
400407
var hasError = false
@@ -489,6 +496,13 @@ class ClassfileParser(
489496
case tpnme.ExceptionsATTR =>
490497
parseExceptions(attrLen)
491498

499+
case tpnme.CodeATTR =>
500+
if (sym.owner is Flags.Interface) {
501+
sym.setFlag(Flags.DefaultMethod)
502+
ctx.log(s"$sym in ${sym.owner} is a java8+ default method.")
503+
}
504+
in.skip(attrLen)
505+
492506
case _ =>
493507
}
494508
in.bp = end
@@ -759,10 +773,13 @@ class ClassfileParser(
759773
(in.nextByte.toInt: @switch) match {
760774
case CONSTANT_UTF8 | CONSTANT_UNICODE =>
761775
in.skip(in.nextChar)
762-
case CONSTANT_CLASS | CONSTANT_STRING =>
776+
case CONSTANT_CLASS | CONSTANT_STRING | CONSTANT_METHODTYPE =>
763777
in.skip(2)
778+
case CONSTANT_METHODHANDLE =>
779+
in.skip(3)
764780
case CONSTANT_FIELDREF | CONSTANT_METHODREF | CONSTANT_INTFMETHODREF
765-
| CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT =>
781+
| CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT
782+
| CONSTANT_INVOKEDYNAMIC =>
766783
in.skip(4)
767784
case CONSTANT_LONG | CONSTANT_DOUBLE =>
768785
in.skip(8)

0 commit comments

Comments
 (0)