diff options
| author | mergify[bot] | 2022-01-26 19:52:36 +0000 |
|---|---|---|
| committer | GitHub | 2022-01-26 19:52:36 +0000 |
| commit | db0fe3fb23c3f50be0aeb859b19cb96967e15186 (patch) | |
| tree | 44b12e6c4b67df118194f0bcda2dcbbf49d57712 /macros/src/main/scala/chisel3/internal | |
| parent | a737281f670aa34152ce971b57f926ecc9307a8c (diff) | |
Expand supported val modifiers for @public (#2365) (#2367)
(cherry picked from commit 13fb4595b3b21beadaad5ba5c5d131138099d6e1)
Co-authored-by: Adam Izraelevitz <adam.izraelevitz@sifive.com>
Diffstat (limited to 'macros/src/main/scala/chisel3/internal')
| -rw-r--r-- | macros/src/main/scala/chisel3/internal/InstantiableMacro.scala | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala index d66b51ac..a001b284 100644 --- a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala +++ b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala @@ -16,21 +16,25 @@ private[chisel3] object instantiableMacro { // Note the triple `_` prefixing `module` is to avoid conflicts if a user marks a 'val module' // with @public; in this case, the lookup code is ambiguous between the generated `def module` // function and the argument to the generated implicit class. - val resultStats = stats.flatMap { - case x @ q"@public val $tpname: $tpe = $name" if tpname.toString() == name.toString() => - extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)") - Nil - case x @ q"@public val $tpname: $tpe = $_" => - extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)") - Seq(x) - case x @ q"@public val $tpname: $tpe" => - extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)") - Seq(x) - case x @ q"@public lazy val $tpname: $tpe = $_" => - extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)") - Seq(x) - case other => - Seq(other) + val resultStats = stats.flatMap { stat => + stat match { + case hasPublic: ValOrDefDef if hasPublic.mods.annotations.toString.contains("new public()") => + hasPublic match { + case aDef: DefDef => + c.error(aDef.pos, s"Cannot mark a def as @public") + Nil + // For now, we only omit protected/private vals + case aVal: ValDef + if aVal.mods.hasFlag(c.universe.Flag.PRIVATE) || aVal.mods.hasFlag(c.universe.Flag.PROTECTED) => + c.error(aVal.pos, s"Cannot mark a private or protected val as @public") + Nil + case aVal: ValDef => + extensions += atPos(aVal.pos)(q"def ${aVal.name} = ___module._lookup(_.${aVal.name})") + if (aVal.name.toString == aVal.children.last.toString) Nil else Seq(aVal) + case other => Seq(other) + } + case other => Seq(other) + } } (resultStats, extensions) } |
