@@ -28,6 +28,7 @@ import dotty.tools.dotc.util.{Positions, DotClass}
28
28
import Decorators ._
29
29
import tpd ._
30
30
import scala .tools .asm
31
+ import NameOps ._
31
32
import StdNames .nme
32
33
33
34
class DottyBackendInterface ()(implicit ctx : Context ) extends BackendInterface {
@@ -138,12 +139,13 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
138
139
val PartialFunctionClass : Symbol = defn.PartialFunctionClass
139
140
val AbstractPartialFunctionClass : Symbol = defn.AbstractPartialFunctionClass
140
141
val String_valueOf : Symbol = defn.String_valueOf_Object
142
+ lazy val Predef_classOf : Symbol = ctx.requiredMethod(toDenot(defn.ScalaPredefModule ).moduleClass.asClass, nme.classOf )
141
143
142
144
lazy val AnnotationRetentionAttr = ctx.requiredClass(" java.lang.annotation.Retention" )
143
145
lazy val AnnotationRetentionSourceAttr = ctx.requiredClass(" java.lang.annotation.RetentionPolicy" ).linkedClass.requiredValue(" SOURCE" )
144
146
lazy val AnnotationRetentionClassAttr = ctx.requiredClass(" java.lang.annotation.RetentionPolicy" ).linkedClass.requiredValue(" CLASS" )
145
147
lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass(" java.lang.annotation.RetentionPolicy" ).linkedClass.requiredValue(" RUNTIME" )
146
-
148
+ lazy val JavaAnnotationClass = ctx.requiredClass( " java.lang.annotation.Annotation " )
147
149
148
150
149
151
def boxMethods : Map [Symbol , Symbol ] = defn.ScalaValueClasses .map{x =>
@@ -235,13 +237,34 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
235
237
case ClazzTag => av.visit(name, const.typeValue.toTypeKind(bcodeStore)(innerClasesStore).toASMType)
236
238
case EnumTag =>
237
239
val edesc = innerClasesStore.typeDescriptor(const.tpe.asInstanceOf [bcodeStore.int.Type ]) // the class descriptor of the enumeration class.
238
- val evalue = const.symbolValue.name.toString // value the actual enumeration value.
240
+ val evalue = const.symbolValue.name.toString // value the actual enumeration value.
239
241
av.visitEnum(name, edesc, evalue)
240
242
}
243
+ case t : TypeApply if (t.fun.symbol == Predef_classOf ) =>
244
+ av.visit(name, t.args.head.tpe.classSymbol.denot.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType)
245
+ case t : Select =>
246
+ if (t.symbol.denot.is(Flags .Enum )) {
247
+ val edesc = innerClasesStore.typeDescriptor(t.tpe.asInstanceOf [bcodeStore.int.Type ]) // the class descriptor of the enumeration class.
248
+ val evalue = t.symbol.name.toString // value the actual enumeration value.
249
+ av.visitEnum(name, edesc, evalue)
250
+ } else {
251
+ assert(toDenot(t.symbol).name.toTermName.defaultGetterIndex >= 0 ) // this should be default getter. do not emmit.
252
+ }
253
+ case t : SeqLiteral =>
254
+ val arrAnnotV : AnnotationVisitor = av.visitArray(name)
255
+ for (arg <- t.elems) { emitArgument(arrAnnotV, null , arg, bcodeStore)(innerClasesStore) }
256
+ arrAnnotV.visitEnd()
257
+
241
258
case Apply (fun, args) if (fun.symbol == defn.ArrayClass .primaryConstructor ||
242
259
(toDenot(fun.symbol).owner == defn.ArrayClass .linkedClass && fun.symbol.name == nme_apply)) =>
243
260
val arrAnnotV : AnnotationVisitor = av.visitArray(name)
244
- val flatArgs = args.flatMap {
261
+
262
+ var actualArgs = if (fun.tpe.isInstanceOf [ImplicitMethodType ]) {
263
+ // generic array method, need to get implicit argument out of the way
264
+ fun.asInstanceOf [Apply ].args
265
+ } else args
266
+
267
+ val flatArgs = actualArgs.flatMap {
245
268
case t : tpd.SeqLiteral => t.elems
246
269
case e => List (e)
247
270
}
@@ -258,14 +281,14 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
258
281
for(arg <- BCodeAsmCommon.arrEncode(sb)) { arrAnnotV.visit(name, arg) }
259
282
arrAnnotV.visitEnd()
260
283
} // for the lazy val in ScalaSigBytes to be GC'ed, the invoker of emitAnnotations() should hold the ScalaSigBytes in a method-local var that doesn't escape.
261
-
262
- case NestedAnnotArg(annInfo ) =>
263
- val AnnotationInfo( typ, args, assocs) = annInfo
264
- assert(args.isEmpty, args )
284
+ */
285
+ case t @ Apply (constr, args) if t.tpe.derivesFrom( JavaAnnotationClass ) =>
286
+ val typ = t.tpe.classSymbol.denot.info
287
+ val assocs = assocsFromApply(t )
265
288
val desc = innerClasesStore.typeDescriptor(typ.asInstanceOf [bcodeStore.int.Type ]) // the class descriptor of the nested annotation class
266
- val nestedVisitor = av.visitAnnotation(name, desc)
289
+ val nestedVisitor = av.visitAnnotation(name, desc)
267
290
emitAssocs(nestedVisitor, assocs, bcodeStore)(innerClasesStore)
268
- */ }
291
+ }
269
292
}
270
293
271
294
override def emitAnnotations (cw : asm.ClassVisitor , annotations : List [Annotation ], bcodeStore : BCodeHelpers )(innerClasesStore : bcodeStore.BCInnerClassGen ) {
@@ -486,21 +509,23 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
486
509
implicit def annotHelper (a : Annotation ): AnnotationHelper = new AnnotationHelper {
487
510
def atp : Type = a.tree.tpe
488
511
489
- def assocs : List [(Name , Tree )] = {
490
- a.tree match {
491
- case Apply (fun, args) =>
492
- fun.tpe.widen match {
493
- case MethodType (names, _) =>
494
- names zip args
495
- }
496
- }
497
- }
512
+ def assocs : List [(Name , Tree )] = assocsFromApply(a.tree)
498
513
499
514
def symbol : Symbol = a.tree.symbol
500
515
501
516
def args : List [Tree ] = List .empty // those arguments to scala-defined annotations. they are never emmited
502
517
}
503
518
519
+ def assocsFromApply (tree : Tree ) = {
520
+ tree match {
521
+ case Apply (fun, args) =>
522
+ fun.tpe.widen match {
523
+ case MethodType (names, _) =>
524
+ names zip args
525
+ }
526
+ }
527
+ }
528
+
504
529
505
530
implicit def nameHelper (n : Name ): NameHelper = new NameHelper {
506
531
def toTypeName : Name = n.toTypeName
0 commit comments