-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add -print-lines #3523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -print-lines #3523
Conversation
Example output for class Foo {
def foo = {
3 + 6 +
7 + 8 +
9
"asdfdsfdsfdsgfsg" +
"asdfdsfdsfdsgfsg" +
"asdfdsf654765dsfdsgfsg" +
"asdfdsfdsfdsgfsg" +
"asdfdsfd7645767sfdsgfsg" +
"dfdsgfgdfhtrtyuu6" +
"asdfdsfdsfdsgfsg" +
"asdf53453dsfdsfdsgfsg"
}
def bar =
foo
println(
"2"
)
List(1, 2, 3).
max
}
We use line ranges to ensure all lines from the source are accounted in each line of type checked code. |
This is interesting, but why not tweak the pretty-printer so that it uses the source line number to decide where to put newlines instead of the -pagewidth setting? Then the output line numbers and source line numbers would be exactly the same. |
That was my initial approach. But while implementing it I stumbled upon several issues. The first is that it was hard to maintain a pleasing formatting while adding the new lines on each new source line. Making this work correctly would require a fair amount of work and possibly and possibly some major changes in the pretty printer. The second and most important reason is that there is no linear correspondence between the source lines and the code in the trees. For example, the synthetic 1 ::
2 ::
Nil The positions will be reversed which would make it impossible to print source line by source line. We could try to reverse engineer all desugared tree just to try to keep line numbers, but I feel that it would be a can of worms and that we would lose useful information about how the code is desugared/typed. We still can combine this with |
@@ -155,7 +171,7 @@ object Texts { | |||
def lines(xs: Traversable[Text]) = Vertical(xs.toList.reverse) | |||
} | |||
|
|||
case class Str(s: String) extends Text { | |||
case class Str(s: String, startLine: Int = Int.MaxValue, endLine: Int = -1) extends Text { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a special purpose class Lines
with a special instance NoLine
. I think it is weird to use Int.MaxValue
and -1
as special values. You can even make it a value class that wraps a Long
like Position
if performance matters here.
a897319
to
48da50e
Compare
48da50e
to
ca34ba0
Compare
@@ -694,4 +705,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { | |||
} | |||
|
|||
override def plain = new PlainPrinter(_ctx) | |||
|
|||
def withPos(txt: Text, pos: SourcePosition): Text = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private?
This can be used with
dotc -decompiler -print-lines ...
ordotc -Xprint
.