Skip to content

Commit 2e8f5c5

Browse files
committed
Remove positionHelper and annotHelper
1 parent d82ee36 commit 2e8f5c5

File tree

3 files changed

+15
-47
lines changed

3 files changed

+15
-47
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
327327

328328
// TODO needed? for(ann <- m.annotations) { ann.symbol.initialize }
329329
val jgensig = getStaticForwarderGenericSignature(m, module)
330-
val (throws, others) = symHelper(m).annotations partition (annotHelper(_).symbol == defn.ThrowsAnnot)
330+
val (throws, others) = symHelper(m).annotations partition (_.tree.symbol == defn.ThrowsAnnot)
331331
val thrownExceptions: List[String] = getExceptions(throws)
332332

333333
val jReturnType = toTypeKind(methodInfo.resultType)

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ trait BCodeSkelBuilder extends BCodeHelpers {
433433
case _ => false } )
434434
}
435435
def lineNumber(tree: Tree): Unit = {
436-
if (!emitLines || !positionHelper(tree.span).isDefined) return;
437-
val nr = positionHelper(positionHelper(tree.span).finalPosition).line
436+
if (!emitLines || !tree.span.exists) return;
437+
val nr = sourcePos(tree.span).line + 1
438438
if (nr != lastEmittedLineNr) {
439439
lastEmittedLineNr = nr
440440
lastInsn match {
@@ -486,7 +486,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
486486
def initJMethod(flags: Int, paramAnnotations: List[List[Annotation]]): Unit = {
487487

488488
val jgensig = getGenericSignature(methSymbol, claszSymbol)
489-
val (excs, others) = symHelper(methSymbol).annotations partition (annotHelper(_).symbol == defn.ThrowsAnnot)
489+
val (excs, others) = symHelper(methSymbol).annotations partition (_.tree.symbol == defn.ThrowsAnnot)
490490
val thrownExceptions: List[String] = getExceptions(excs)
491491

492492
val bytecodeName =

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
130130
}
131131

132132
def isRuntimeVisible(annot: Annotation): Boolean =
133-
if (toDenot(annotHelper(annot).atp.typeSymbol).hasAnnotation(AnnotationRetentionAttr))
133+
if (toDenot(annot.tree.tpe.typeSymbol).hasAnnotation(AnnotationRetentionAttr))
134134
retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr
135135
else {
136136
// SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the
@@ -141,12 +141,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
141141

142142
def shouldEmitAnnotation(annot: Annotation): Boolean = {
143143
annot.symbol.isJavaDefined &&
144-
retentionPolicyOf(annot) != AnnotationRetentionSourceAttr &&
145-
annot.args.isEmpty
144+
retentionPolicyOf(annot) != AnnotationRetentionSourceAttr
146145
}
147146

148147
private def retentionPolicyOf(annot: Annotation): Symbol =
149-
annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr).
148+
annot.tree.tpe.typeSymbol.getAnnotation(AnnotationRetentionAttr).
150149
flatMap(_.argumentConstant(0).map(_.symbolValue)).getOrElse(AnnotationRetentionClassAttr)
151150

152151
private def normalizeArgument(arg: Tree): Tree = arg match {
@@ -234,8 +233,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
234233
def emitAnnotations(cw: asm.ClassVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
235234
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
236235
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
237-
val typ = annot.atp
238-
val assocs = annot.assocs
236+
val typ = annot.tree.tpe
237+
val assocs = assocsFromApply(annot.tree)
239238
val av = cw.visitAnnotation(innerClasesStore.typeDescriptor(typ.asInstanceOf[bcodeStore.int.Type]), isRuntimeVisible(annot))
240239
emitAssocs(av, assocs, bcodeStore)(innerClasesStore)
241240
}
@@ -251,8 +250,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
251250
def emitAnnotations(mw: asm.MethodVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
252251
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
253252
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
254-
val typ = annot.atp
255-
val assocs = annot.assocs
253+
val typ = annot.tree.tpe
254+
val assocs = assocsFromApply(annot.tree)
256255
val av = mw.visitAnnotation(innerClasesStore.typeDescriptor(typ.asInstanceOf[bcodeStore.int.Type]), isRuntimeVisible(annot))
257256
emitAssocs(av, assocs, bcodeStore)(innerClasesStore)
258257
}
@@ -261,8 +260,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
261260
def emitAnnotations(fw: asm.FieldVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
262261
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
263262
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
264-
val typ = annot.atp
265-
val assocs = annot.assocs
263+
val typ = annot.tree.tpe
264+
val assocs = assocsFromApply(annot.tree)
266265
val av = fw.visitAnnotation(innerClasesStore.typeDescriptor(typ.asInstanceOf[bcodeStore.int.Type]), isRuntimeVisible(annot))
267266
emitAssocs(av, assocs, bcodeStore)(innerClasesStore)
268267
}
@@ -274,8 +273,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
274273
if (annotationss forall (_.isEmpty)) return
275274
for ((annots, idx) <- annotationss.zipWithIndex;
276275
annot <- annots) {
277-
val typ = annot.atp
278-
val assocs = annot.assocs
276+
val typ = annot.tree.tpe
277+
val assocs = assocsFromApply(annot.tree)
279278
val pannVisitor: asm.AnnotationVisitor = jmethod.visitParameterAnnotation(idx, innerClasesStore.typeDescriptor(typ.asInstanceOf[bcodeStore.int.Type]), isRuntimeVisible(annot))
280279
emitAssocs(pannVisitor, assocs, bcodeStore)(innerClasesStore)
281280
}
@@ -472,24 +471,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
472471
def sourceFileFor(cu: CompilationUnit): String = cu.source.file.name
473472

474473

475-
476-
implicit def positionHelper(a: Position): PositionHelper = new PositionHelper {
477-
def isDefined: Boolean = a.exists
478-
def line: Int = sourcePos(a).line + 1
479-
def finalPosition: Position = a
480-
}
481-
482-
483-
implicit def annotHelper(a: Annotation): AnnotationHelper = new AnnotationHelper {
484-
def atp: Type = a.tree.tpe
485-
486-
def assocs: List[(Name, Tree)] = assocsFromApply(a.tree)
487-
488-
def symbol: Symbol = a.tree.symbol
489-
490-
def args: List[Tree] = List.empty // those arguments to scala-defined annotations. they are never emitted
491-
}
492-
493474
def assocsFromApply(tree: Tree): List[(Name, Tree)] = {
494475
tree match {
495476
case Block(_, expr) => assocsFromApply(expr)
@@ -970,12 +951,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
970951
}
971952

972953

973-
abstract class PositionHelper {
974-
def isDefined: Boolean
975-
def finalPosition: Position
976-
def line: Int
977-
}
978-
979954
abstract class ConstantHelper {
980955
def tag: ConstantTag
981956
def longValue: Long
@@ -1182,13 +1157,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11821157
def getPrimitive(sym: Symbol): Int
11831158
}
11841159

1185-
abstract class AnnotationHelper{
1186-
def atp: Type
1187-
def symbol: Symbol
1188-
def args: List[Tree]
1189-
def assocs: List[(Name, /* ClassfileAnnotArg*/ Object)]
1190-
}
1191-
11921160
abstract class Caches {
11931161
def recordCache[T <: Clearable](cache: T): T
11941162
def newWeakMap[K, V](): collection.mutable.WeakHashMap[K, V]

0 commit comments

Comments
 (0)