diff options
| author | Jiuyang Liu | 2021-05-28 00:09:21 +0800 |
|---|---|---|
| committer | GitHub | 2021-05-28 00:09:21 +0800 |
| commit | 82764bbd498ef116614ff8f84a5842b6aee2f6b1 (patch) | |
| tree | 93f36a8534553a16a8a96e72e6fbbcf78ae62fe1 /src/main/scala/firrtl/annotations/Annotation.scala | |
| parent | 26a8e9c88cf31c38a09a7f67700ec3244fa45237 (diff) | |
| parent | 2014fccab2e878c3a0dbd6d0dd1a2affa359798e (diff) | |
Merge branch 'master' into update/sbt-scalafix-0.9.28
Diffstat (limited to 'src/main/scala/firrtl/annotations/Annotation.scala')
| -rw-r--r-- | src/main/scala/firrtl/annotations/Annotation.scala | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main/scala/firrtl/annotations/Annotation.scala b/src/main/scala/firrtl/annotations/Annotation.scala index b5c9c7e0..08555a84 100644 --- a/src/main/scala/firrtl/annotations/Annotation.scala +++ b/src/main/scala/firrtl/annotations/Annotation.scala @@ -5,6 +5,8 @@ package annotations import firrtl.options.StageUtils +import scala.collection.Traversable + case class AnnotationException(message: String) extends Exception(message) /** Base type of auxiliary information */ @@ -23,18 +25,19 @@ trait Annotation extends Product { * @param ls * @return */ - private def extractComponents(ls: scala.collection.Traversable[_]): Seq[Target] = { - ls.collect { + private def extractComponents(ls: Traversable[_]): Traversable[Target] = { + ls.flatMap { case c: Target => Seq(c) - case o: Product => extractComponents(o.productIterator.toIterable) case x: scala.collection.Traversable[_] => extractComponents(x) - }.foldRight(Seq.empty[Target])((seq, c) => c ++ seq) + case o: Product => extractComponents(o.productIterator.toIterable) + case _ => Seq() + } } /** Returns all [[firrtl.annotations.Target Target]] members in this annotation * @return */ - def getTargets: Seq[Target] = extractComponents(productIterator.toSeq) + def getTargets: Seq[Target] = extractComponents(productIterator.toIterable).toSeq } /** If an Annotation does not target any [[Named]] thing in the circuit, then all updates just @@ -42,12 +45,17 @@ trait Annotation extends Product { */ trait NoTargetAnnotation extends Annotation { def update(renames: RenameMap): Seq[NoTargetAnnotation] = Seq(this) + + override def getTargets: Seq[Target] = Seq.empty } /** An Annotation that targets a single [[Named]] thing */ trait SingleTargetAnnotation[T <: Named] extends Annotation { val target: T + // we can implement getTargets more efficiently since we know that we have exactly one target + override def getTargets: Seq[Target] = Seq(target) + /** Create another instance of this Annotation */ def duplicate(n: T): Annotation @@ -100,6 +108,8 @@ trait MultiTargetAnnotation extends Annotation { */ def targets: Seq[Seq[Target]] + override def getTargets: Seq[Target] = targets.flatten + /** Create another instance of this Annotation * * The inner Seqs correspond to the renames of the inner Seqs of targets |
