Re: Re: Setting positions for annotation generated trees

Torsten Schmits <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
Hi Eugene,

it's actually a pretty straightforward problem and my current solution 
works really well.
The use case is an annotated object containing several case classes as 
schematic for database/app models that are expanded into several classes 
and objects each. The original tree is discarded completely, so 
effectively, I'm turning a single file into another, which contains a 
single object hosting all of the model classes.
Just before the final reification, I simple recurse into the result tree 
and set the offset by calculating the child tree size using 
'showCode().length', then applying a crude heuristic to handle templates 
and other internal structures.
This yields adequate precision for error messages, but I assume that the 
compiler must be capable of doing that perfectly.
I actually just thought about just discarding the macro expansion and 
compiling the file containing the debug output as regular source; that 
ought to be the pragmatic approach…

On Monday, 17 August 2015 00:58:57 UTC+2, Eugene Burmako wrote:
>
> Hi!
>
> Good error messages for macro expansions are hard, because it's usually 
> hard to automatically classify/position parts of expansions. However, it 
> might very well be that there's a heuristics that works for an important 
> class of use cases.
>
> Could you give an example of how you would the compiler to calculate the 
> positions for your use case? 
>
> Cheers,
> Eugene
>
> On 16 August 2015 at 18:07, Torsten Schmits <[email protected] 
> <javascript:>> wrote:
>
>>
>> update 2: Noticed that I could cast internal.util.Position to 
>> c.universe.Position, and similarly for SourceFile.
>> Creating those from scratch led to a completely satisfactory result, 
>> although using `atPos` somehow screws it up, while it works great when 
>> reflecting `setPos`.
>> Anyhoo, I still have to calculate the positions manually, would be nice 
>> to have this done by the compiler.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "scala-language" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.