diff options
| author | Jack | 2021-12-18 08:27:38 +0000 |
|---|---|---|
| committer | Jack | 2021-12-18 08:27:38 +0000 |
| commit | dd9ad534771247ac16eaa47eb9794102736b5102 (patch) | |
| tree | d4566d317cb8526b79017de1e438aea8217dd1d4 /macros/src | |
| parent | 440edc4436fb3a8a4175ae425a0d31c4997ee60f (diff) | |
| parent | f50f74f583fba7b98e550c440df091e559ce32b8 (diff) | |
Merge branch 'master' into 3.5-release
Diffstat (limited to 'macros/src')
| -rw-r--r-- | macros/src/main/scala/chisel3/internal/InstantiableMacro.scala | 25 | ||||
| -rw-r--r-- | macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala | 14 |
2 files changed, 29 insertions, 10 deletions
diff --git a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala index 1d374198..18c6c7aa 100644 --- a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala +++ b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala @@ -14,17 +14,24 @@ private[chisel3] object instantiableMacro { def processBody(stats: Seq[Tree]): (Seq[Tree], Iterable[Tree]) = { val extensions = scala.collection.mutable.ArrayBuffer.empty[Tree] extensions += q"implicit val mg = new chisel3.internal.MacroGenerated{}" + // 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)") + 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)") + 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)") + extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)") Seq(x) - case other => Seq(other) + case other => + Seq(other) } (resultStats, extensions) } @@ -38,17 +45,19 @@ private[chisel3] object instantiableMacro { val defname = TypeName(tpname + c.freshName()) val instname = TypeName(tpname + c.freshName()) val (newStats, extensions) = processBody(stats) + val argTParams = tparams.map(_.name) (q""" $mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents with chisel3.experimental.hierarchy.IsInstantiable { $self => ..$newStats } """, - Seq(q"""implicit class $defname(module: chisel3.experimental.hierarchy.Definition[$tpname]) { ..$extensions }""", - q"""implicit class $instname(module: chisel3.experimental.hierarchy.Instance[$tpname]) { ..$extensions } """), + Seq(q"""implicit class $defname[..$tparams](___module: chisel3.experimental.hierarchy.Definition[$tpname[..$argTParams]]) { ..$extensions }""", + q"""implicit class $instname[..$tparams](___module: chisel3.experimental.hierarchy.Instance[$tpname[..$argTParams]]) { ..$extensions } """), tpname) case q"$mods trait $tpname[..$tparams] extends { ..$earlydefns } with ..$parents { $self => ..$stats }" => val defname = TypeName(tpname + c.freshName()) val instname = TypeName(tpname + c.freshName()) val (newStats, extensions) = processBody(stats) + val argTParams = tparams.map(_.name) (q"$mods trait $tpname[..$tparams] extends { ..$earlydefns } with ..$parents with chisel3.experimental.hierarchy.IsInstantiable { $self => ..$newStats }", - Seq(q"""implicit class $defname(module: chisel3.experimental.hierarchy.Definition[$tpname]) { ..$extensions }""", - q"""implicit class $instname(module: chisel3.experimental.hierarchy.Instance[$tpname]) { ..$extensions } """), + Seq(q"""implicit class $defname[..$tparams](___module: chisel3.experimental.hierarchy.Definition[$tpname[..$argTParams]]) { ..$extensions }""", + q"""implicit class $instname[..$tparams](___module: chisel3.experimental.hierarchy.Instance[$tpname[..$argTParams]]) { ..$extensions } """), tpname) } val newObj = objOpt match { diff --git a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala index a8a7e8d5..ac3e236c 100644 --- a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala +++ b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala @@ -165,7 +165,12 @@ object SourceInfoTransform class SourceInfoTransform(val c: Context) extends AutoSourceTransform { import c.universe._ - def noArg(): c.Tree = { + def noArg: c.Tree = { + q"$thisObj.$doFuncTerm($implicitSourceInfo, $implicitCompileOptions)" + } + + /** Necessary for dummy methods to auto-apply their arguments to this macro */ + def noArgDummy(dummy: c.Tree*): c.Tree = { q"$thisObj.$doFuncTerm($implicitSourceInfo, $implicitCompileOptions)" } @@ -224,7 +229,12 @@ object SourceInfoWhiteboxTransform class SourceInfoWhiteboxTransform(val c: whitebox.Context) extends AutoSourceTransform { import c.universe._ - def noArg(): c.Tree = { + def noArg: c.Tree = { + q"$thisObj.$doFuncTerm($implicitSourceInfo, $implicitCompileOptions)" + } + + /** Necessary for dummy methods to auto-apply their arguments to this macro */ + def noArgDummy(dummy: c.Tree*): c.Tree = { q"$thisObj.$doFuncTerm($implicitSourceInfo, $implicitCompileOptions)" } |
