diff options
author | Paul Phillips <paulp@improving.org> | 2013-04-20 12:25:03 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-04-20 14:58:09 -0700 |
commit | c4d0fd9998d96843cd9704d5610a29ab752ecb14 (patch) | |
tree | c8bf37f4c1e474b85c859593463a319ff1407104 /test/files/run | |
parent | 68c6ba7e59befa88b2f383dd7eca71a9329a8b6d (diff) | |
download | scala-c4d0fd9998d96843cd9704d5610a29ab752ecb14.tar.gz scala-c4d0fd9998d96843cd9704d5610a29ab752ecb14.tar.bz2 scala-c4d0fd9998d96843cd9704d5610a29ab752ecb14.zip |
-Yshow-member-pos, print the positions of members.
Here for instance is a command line which leverages the
output of this option to print the method bodies of all
methods called 'transformInfo' found under src. Given
1500 source files it accomplishes this in four seconds,
thanks to -Ystop-after:parser.
% scalac -Yshow-member-pos sed -Ystop-after:parser \
$(find src/compiler -name '*.scala') | \
grep transformInfo | sed 's/ # .*//;' | \
while read line; do echo "// $line" && gsed -n $line && echo; done
Or more simply, the start/end lines of each member of Random:
% scalac -Yshow-member-pos "" ./src/library/scala/util/Random.scala
./src/library/scala/util/Random.scala
20,134 class Random
33 def nextBoolean
38 def nextBytes
43 def nextDouble
48 def nextFloat
54 def nextGaussian
59 def nextInt
65 def nextInt
70 def nextLong
81,89 def nextString
82,86 def safeChar
83 val surrogateStart
84 val res
94,98 def nextPrintableChar
[snip]
It makes me sad I'm always in the position of having to hack
the compiler to do this sort of thing. All we need is something
like -Yinsert-phase:Foo where Foo is a class implementing a
(Phase, Tree) => Tree method, and the compiler runs all the
unit.bodies through it after each phase, and then one could
easily accomplish this in the privacy of one's own compiler.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/memberpos.check | 11 | ||||
-rw-r--r-- | test/files/run/memberpos.scala | 39 |
2 files changed, 50 insertions, 0 deletions
diff --git a/test/files/run/memberpos.check b/test/files/run/memberpos.check new file mode 100644 index 0000000000..e7d3534000 --- /dev/null +++ b/test/files/run/memberpos.check @@ -0,0 +1,11 @@ +newSource1 +2,4 class A +6,28 object A + 7,10 def bippy + 8 def hello + 11,27 class Dingo + 12,26 def foooooz + 22 val a +30 class B + 30 def f + diff --git a/test/files/run/memberpos.scala b/test/files/run/memberpos.scala new file mode 100644 index 0000000000..f2b79c0ec1 --- /dev/null +++ b/test/files/run/memberpos.scala @@ -0,0 +1,39 @@ +import scala.tools.partest._ + +// Simple sanity test for -Yshow-member-pos. +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp -Ystop-after:parser -Yshow-member-pos \"\" -d " + testOutput.path + override def show() = compile() + override def code = """ +class A(val a: Int = 1) { + +} + +object A { + def bippy = { + def hello = 55 + "" + hello + } + class Dingo { + def foooooz = /**** + + + + + + ****/ { + + + + val a = 1 + + + a + } + } +} + +class B { def f = 1 } + +""" +} |