-Yrangepos doesn't seam to have any effect: positions of ValDef, DefDef nodes still 'OffsetPosition' instead of 'RangePosition'

52 views
Skip to first unread message

Amos Wenger

unread,
Mar 26, 2012, 4:25:08 PM3/26/12
to scala-internals
It's all in the title, really: I thought using the -Yrangepos compiler
option would make ValDef.pos an instance of RangePosition, that gives
start and end positions, instead of an OffsetPosition, which is just
an offset in the file without size info.

Here's an example of how I'm trying to retrieve positions:

https://github.com/nddrylliog/scala-readability/blob/9278db58ccc4ab2c46fc3d1902b15813336568bb/src/main/scala/readability/ExtractionComponent.scala#L46

Getting the start and end of AST nodes like these would really help
with extracting interesting
chunks of codes from big codebases, which is what I'm looking to do in
the first place.

Any ideas?

Hubert Plociniczak

unread,
Mar 27, 2012, 3:51:43 AM3/27/12
to scala-i...@googlegroups.com


A few things about rangepos:
- if you try to run any code with 'scalac -Ybrowse:typer -Yrangepos
FILE.scala' you will see that most of the trees have range positions.
- some don't, yes, that's a bit unfortunate but we are trying to improve
on that - actually whenever you find such in Yrangepos mode it is
possible that it is a bug. The situation has improved dramatically from
2.9 to 2.10.0-snapshots.
- syntactic trees are often assigned offset positions (this is something
you might be experiencing but I would have to see an example)
- for the compiler we only care if range positions are valid up to (and
including) typer. after that, we don't care. You are running your tool
after refchecks from what I can see, this can interfere with a couple of
transformations that happen in refchecks which can manipulate/assign
range- or offset- positions.
- if you haven't done so already, have a look at the top comments in
https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
for more info on range positions.

That said, I would be happy to have look at any code examples that you
think should have range positions and they don't.

Thanks,
hubert

Paul Phillips

unread,
Mar 27, 2012, 6:39:20 AM3/27/12
to scala-i...@googlegroups.com
On Mon, Mar 26, 2012 at 1:25 PM, Amos Wenger <amosw...@gmail.com> wrote:
> Getting the start and end of AST nodes like these would really help
> with extracting interesting
> chunks of codes from big codebases, which is what I'm looking to do in
> the first place.

You might want to look at

https://github.com/paulp/scala/branches/topic/positions

where among other things I added a sourceCode method to Position.

Reply all
Reply to author
Forward
0 new messages