diff options
Diffstat (limited to 'macros/src/main/scala/chisel3/internal/RuntimeDeprecationTransform.scala')
| -rw-r--r-- | macros/src/main/scala/chisel3/internal/RuntimeDeprecationTransform.scala | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/macros/src/main/scala/chisel3/internal/RuntimeDeprecationTransform.scala b/macros/src/main/scala/chisel3/internal/RuntimeDeprecationTransform.scala index e7eb7162..ff41bd30 100644 --- a/macros/src/main/scala/chisel3/internal/RuntimeDeprecationTransform.scala +++ b/macros/src/main/scala/chisel3/internal/RuntimeDeprecationTransform.scala @@ -3,7 +3,7 @@ package chisel3.internal import scala.reflect.macros.whitebox.Context -import scala.annotation.{StaticAnnotation, compileTimeOnly} +import scala.annotation.{compileTimeOnly, StaticAnnotation} import scala.language.experimental.macros // Workaround for https://github.com/sbt/sbt/issues/3966 @@ -14,24 +14,34 @@ class RuntimeDeprecatedTransform(val c: Context) { /** Adds a Builder.deprecated(...) call based on the contents of a plain @deprecated annotation. */ def runtimeDeprecated(annottees: c.Tree*): c.Tree = { - val transformed = annottees.map(annottee => annottee match { - case q"$mods def $tname[..$tparams](...$paramss): $tpt = $expr" => { - val Modifiers(_, _, annotations) = mods - val annotationMessage = annotations.collect { // get all messages from deprecated annotations - case q"new deprecated($desc, $since)" => desc - } match { // ensure there's only one and return it - case msg :: Nil => msg - case _ => c.abort(c.enclosingPosition, s"@chiselRuntimeDeprecated annotion must be used with exactly one @deprecated annotation, got annotations $annotations") - } - val message = s"$tname is deprecated: $annotationMessage" - val transformedExpr = q""" { + val transformed = annottees.map(annottee => + annottee match { + case q"$mods def $tname[..$tparams](...$paramss): $tpt = $expr" => { + val Modifiers(_, _, annotations) = mods + val annotationMessage = annotations.collect { // get all messages from deprecated annotations + case q"new deprecated($desc, $since)" => desc + } match { // ensure there's only one and return it + case msg :: Nil => msg + case _ => + c.abort( + c.enclosingPosition, + s"@chiselRuntimeDeprecated annotion must be used with exactly one @deprecated annotation, got annotations $annotations" + ) + } + val message = s"$tname is deprecated: $annotationMessage" + val transformedExpr = q""" { _root_.chisel3.internal.Builder.deprecated($message) $expr } """ - q"$mods def $tname[..$tparams](...$paramss): $tpt = $transformedExpr" + q"$mods def $tname[..$tparams](...$paramss): $tpt = $transformedExpr" + } + case other => + c.abort( + c.enclosingPosition, + s"@chiselRuntimeDeprecated annotion may only be used on defs, got ${showCode(other)}" + ) } - case other => c.abort(c.enclosingPosition, s"@chiselRuntimeDeprecated annotion may only be used on defs, got ${showCode(other)}") - }) + ) q"..$transformed" } } |
