Skip to content

ClassfileParser: Java8 bytecode (fixes #83) #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ object Flags {
/** Symbol is a Java-style varargs method */
final val JavaVarargs = termFlag(38, "<varargs>")

/** Symbol is a Java default method */
final val DefaultMethod = termFlag(39, "<defaultmethod>")

// Flags following this one are not pickled

/** Denotation is in train of being loaded and completed, used to catch cyclic dependencies */
Expand Down
4 changes: 4 additions & 0 deletions src/dotty/tools/dotc/core/pickling/ClassfileConstants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ object ClassfileConstants {
final val CONSTANT_INTFMETHODREF = 11
final val CONSTANT_NAMEANDTYPE = 12

final val CONSTANT_METHODHANDLE = 15
final val CONSTANT_METHODTYPE = 16
final val CONSTANT_INVOKEDYNAMIC = 18

// tags describing the type of a literal in attribute values
final val BYTE_TAG = 'B'
final val CHAR_TAG = 'C'
Expand Down
27 changes: 22 additions & 5 deletions src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,16 @@ class ClassfileParser(
case ENUM_TAG =>
val t = pool.getType(index)
val n = pool.getName(in.nextChar)
val s = t.typeSymbol.companionModule.decls.lookup(n)
assert(s != NoSymbol, t)
if (skip) None else Some(Literal(Constant(s)))
val module = t.typeSymbol.companionModule
val s = module.info.decls.lookup(n)
if (skip) {
None
} else if (s != NoSymbol) {
Some(Literal(Constant(s)))
} else {
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).""")
None
}
case ARRAY_TAG =>
val arr = new ArrayBuffer[Tree]()
var hasError = false
Expand Down Expand Up @@ -489,6 +496,13 @@ class ClassfileParser(
case tpnme.ExceptionsATTR =>
parseExceptions(attrLen)

case tpnme.CodeATTR =>
if (sym.owner is Flags.Interface) {
sym.setFlag(Flags.DefaultMethod)
ctx.log(s"$sym in ${sym.owner} is a java8+ default method.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is log worthy, one can see this on the flags of the method later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added this because scalac also logs it

}
in.skip(attrLen)

case _ =>
}
in.bp = end
Expand Down Expand Up @@ -759,10 +773,13 @@ class ClassfileParser(
(in.nextByte.toInt: @switch) match {
case CONSTANT_UTF8 | CONSTANT_UNICODE =>
in.skip(in.nextChar)
case CONSTANT_CLASS | CONSTANT_STRING =>
case CONSTANT_CLASS | CONSTANT_STRING | CONSTANT_METHODTYPE =>
in.skip(2)
case CONSTANT_METHODHANDLE =>
in.skip(3)
case CONSTANT_FIELDREF | CONSTANT_METHODREF | CONSTANT_INTFMETHODREF
| CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT =>
| CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT
| CONSTANT_INVOKEDYNAMIC =>
in.skip(4)
case CONSTANT_LONG | CONSTANT_DOUBLE =>
in.skip(8)
Expand Down