使用-Xprint
flagscalac
可以得到不同编译器阶段的输出,例如,给出以下内容Foo.scala
object Foo {
val x = 42
}
然后scalac -Xprint:jvm Foo.scala
输出
package <empty> {
object Foo extends Object {
<static> private[this] val x: Int = _;
<stable> <accessor> def x(): Int = Foo.this.x;
def <init>(): Foo.type = {
Foo.super.<init>();
Foo.this.x = 42;
()
}
}
}
如何编译阶段本身,也就是我们说我们有源文件,jvmphase.scala
像这样
package <empty> { ...
包含阶段源代码而不是原始的香草Scala源代码,那么如何实现类似于以下内容的代码scalac jvmphase.scala
?
“编译阶段的编译输出”听起来很奇怪。从字面上看,编译器将编译源文件。编译器阶段的输出不再是源(尽管scalac -Xprint:...
尝试以类似方式打印它)。例如jvm
阶段在erasure
阶段之后。除了原始源代码的编译结果之外,尚不清楚在“编译编译器阶段的输出”时期望得到什么。
如果要在阶段之间进行更改,则应该创建编译器插件。
https://docs.scala-lang.org/overviews/plugins/index.html
https://dotty.epfl.ch/docs/reference/changed-features/compiler-plugins.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句