|
| 1 | +package izumi.reflect.dottyreflection |
| 2 | + |
| 3 | +import scala.quoted.Quotes |
| 4 | + |
| 5 | +trait InspectorBase extends ReflectionUtil { |
| 6 | + |
| 7 | + val qctx: Quotes |
| 8 | + import qctx.reflect._ |
| 9 | + |
| 10 | + protected def shift: Int |
| 11 | + |
| 12 | + // FIXME reimplement TrivialMacroLogger on Scala 3 |
| 13 | + inline def debug: debug = valueOf[debug] |
| 14 | + final type debug = false |
| 15 | + |
| 16 | + // println instead of report.info because report.info eats all the subsequent report.info's after first. |
| 17 | + inline final protected def logStart(inline s: String): Unit = { |
| 18 | + inline if (debug) println(" " * shift + currentPositionStr + s) |
| 19 | + } |
| 20 | + |
| 21 | + inline final protected def log(inline s: String): Unit = { |
| 22 | + inline if (debug) println(" " * shift + currentPositionStr + " -> " + s) |
| 23 | + } |
| 24 | + |
| 25 | + inline final protected def logTpeAttrs[T](inline typeRepr: TypeRepr): Unit = { |
| 26 | + inline if (debug) { |
| 27 | + val tree = TypeTree.of(using typeRepr.asType) |
| 28 | + val symbol = tree.symbol |
| 29 | + System |
| 30 | + .err.println( |
| 31 | + currentPositionStr + ": " + |
| 32 | + s"Attrs[${tree.show}]: type=${symbol.isType}, term=${symbol.isTerm}, packageDef=${symbol.isPackageDef}, classDef=${symbol.isClassDef}, typeDef=${symbol.isValDef}, defdef=${symbol.isDefDef}, bind=${symbol.isBind}, nosymbol=${symbol.isNoSymbol}" |
| 33 | + ) |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + private def currentPositionStr: String = { |
| 38 | + val pos = qctx.reflect.Position.ofMacroExpansion |
| 39 | + s"${pos.sourceFile.name}:${pos.endLine}" |
| 40 | + } |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +object InspectorBase { |
| 45 | + |
| 46 | + private[reflect] inline def ifDebug[A](inline f: => Unit): Unit = { |
| 47 | + inline if (valueOf[InspectorBase#debug]) { |
| 48 | +//[error] ^^^^^^^^^^^^^ |
| 49 | +//[error] izumi.reflect.dottyreflection.InspectorBase is not a legal path |
| 50 | +//[error] since it has a member InternalTypeRefOrParamRef with possibly conflicting bounds Object{def underlying(ctx: Any): Nothing} <: ... <: Object{def underlying(ctx: Nothing): Matchable} |
| 51 | + f |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private[reflect] inline def log(inline shift: Int, s: String): Unit = { |
| 56 | + inline if (valueOf[InspectorBase#debug]) println(" " * shift + " -> " + s) |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments