[PATCH] Add debug method to visualize complex source locations

Kim Gräsman kim.grasman at gmail.com
Fri May 17 04:20:10 PDT 2013


Hi Manuel,

I think the new structure works even with the intimidating location in
the example.

I wonder if it would help even more if you included a source text
fragment from every location?

I know I would use this to snapshot where a given location is when
doing AST traversals, and I think more context makes it easier to find
my bearings.

Why are there leading colons in all line/col dumps? Should there be a
leading filename/file ID?

Thanks,
- Kim

On Fri, May 17, 2013 at 11:43 AM, Manuel Klimek <klimek at google.com> wrote:
> I played around a bit after trying to understand Argyrios' adaptions for
> makeFileCharRange, and came up with this:
>
> Pastebin:
> http://pastebin.com/g4ny0vbq
>
> Pasted into mail (will probalby not format well in most mail programs):
> Loc
> |-Expansion
> | |-ExpansionStart
> | | |-ExpansionStart
> | | | |-ExpansionStart :4:1,
> | | | |-ExpansionEnd   :4:16,
> | | | `-Spelling       :3:16,
> | | |-ExpansionEnd
> | | | |-ExpansionStart :4:1,
> | | | |-ExpansionEnd   :4:16,
> | | | `-Spelling       :3:19,
> | | `-Spelling       :2:14,
> | |-ExpansionEnd
> | | |-ExpansionStart
> | | | |-ExpansionStart :4:1,
> | | | |-ExpansionEnd   :4:16,
> | | | `-Spelling       :3:16,
> | | |-ExpansionEnd
> | | | |-ExpansionStart :4:1,
> | | | |-ExpansionEnd   :4:16,
> | | | `-Spelling       :3:19,
> | | `-Spelling       :2:17,
> | `-Spelling       :1:14,
> `-Spelling
>   |-Expansion
>   | |-ExpansionStart
>   | | |-ExpansionStart :4:1,
>   | | |-ExpansionEnd   :4:16,
>   | | `-Spelling       :3:16,
>   | |-ExpansionEnd
>   | | |-ExpansionStart :4:1,
>   | | |-ExpansionEnd   :4:16,
>   | | `-Spelling       :3:19,
>   | `-Spelling       :2:16,
>   `-Spelling
>     |-Expansion
>     | |-ExpansionStart :4:1,
>     | |-ExpansionEnd   :4:16,
>     | `-Spelling       :3:18,
>     `-Spelling
>       |-Expansion
>       | |-ExpansionStart
>       | | |-ExpansionStart
>       | | | |-ExpansionStart :4:3,
>       | | | |-ExpansionEnd   :4:15,
>       | | | `-Spelling       :3:16,
>       | | |-ExpansionEnd
>       | | | |-ExpansionStart :4:3,
>       | | | |-ExpansionEnd   :4:15,
>       | | | `-Spelling       :3:19,
>       | | `-Spelling       :2:14,
>       | |-ExpansionEnd
>       | | |-ExpansionStart
>       | | | |-ExpansionStart :4:3,
>       | | | |-ExpansionEnd   :4:15,
>       | | | `-Spelling       :3:16,
>       | | |-ExpansionEnd
>       | | | |-ExpansionStart :4:3,
>       | | | |-ExpansionEnd   :4:15,
>       | | | `-Spelling       :3:19,
>       | | `-Spelling       :2:17,
>       | `-Spelling       :1:14,
>       `-Spelling
>         |-Expansion
>         | |-ExpansionStart
>         | | |-ExpansionStart :4:3,
>         | | |-ExpansionEnd   :4:15,
>         | | `-Spelling       :3:16,
>         | |-ExpansionEnd
>         | | |-ExpansionStart :4:3,
>         | | |-ExpansionEnd   :4:15,
>         | | `-Spelling       :3:19,
>         | `-Spelling       :2:16,
>         `-Spelling
>           |-Expansion
>           | |-ExpansionStart :4:3,
>           | |-ExpansionEnd   :4:15,
>           | `-Spelling       :3:18,
>           `-Spelling
>             |-Expansion
>             | |-ExpansionStart
>             | | |-ExpansionStart :4:7,
>             | | |-ExpansionEnd   :4:13,
>             | | `-Spelling       :2:14,
>             | |-ExpansionEnd
>             | | |-ExpansionStart :4:7,
>             | | |-ExpansionEnd   :4:13,
>             | | `-Spelling       :2:17,
>             | `-Spelling       :1:14,
>             `-Spelling
>               |-Expansion
>               | |-ExpansionStart :4:7,
>               | |-ExpansionEnd   :4:13,
>               | `-Spelling       :2:16,
>               `-Spelling
>                 |-Expansion
>                 | |-ExpansionStart
>                 | | |-ExpansionStart :4:9,
>                 | | |-ExpansionEnd   :4:12,
>                 | | `-Spelling       :2:14,
>                 | |-ExpansionEnd
>                 | | |-ExpansionStart :4:9,
>                 | | |-ExpansionEnd   :4:12,
>                 | | `-Spelling       :2:17,
>                 | `-Spelling       :1:14,
>                 `-Spelling
>                   |-Expansion
>                   | |-ExpansionStart :4:9,
>                   | |-ExpansionEnd   :4:12,
>                   | `-Spelling       :2:16,
>                   `-Spelling       :4:11
>
>
> On Wed, May 8, 2013 at 8:49 PM, Manuel Klimek <klimek at google.com> wrote:
>>
>> On Wed, May 8, 2013 at 6:42 PM, Chandler Carruth <chandlerc at google.com>
>> wrote:
>>>
>>>
>>> On Wed, May 8, 2013 at 5:36 PM, Manuel Klimek <klimek at google.com> wrote:
>>>>
>>>> In preparation for some docs on source locations I want to write I came
>>>> up
>>>> with the little helper method that visualizes source locations as a
>>>> tree.
>>>> This is especially helpful when you have many nested levels of macro
>>>> expansions.
>>>>
>>>> Example output:
>>>> (SP=(:6:14),
>>>>  EX=(SP=(:2:14),
>>>>      ES=(:6:8),
>>>>      EE=(:6:15)))
>>>>
>>>> SP = spelling
>>>> EX = expansion (if there's only a single location)
>>>> ES/EE = expansion start, expansion end (in case there's a range)
>>>>
>>>> Feel free to bikeshed about the details :D
>>>
>>>
>>> Two high-level questions unrelated to the code itself:
>>>
>>> 1) Should we visualize these trees in roughly the same tree-ish syntax as
>>> AST trees? Or is it useful to visualize them on a single line *inside* the
>>> AST tree?
>>
>>
>> I'm all for bike shed color ideas: can you create a paste with how you
>> want it to look? (I tried a few things, and they all looked bad - I'm no
>> good at that :P)
>>
>>>
>>> 2) Is there a way to make this part of the testing of source locations
>>> which is currently done mostly through c-index-test's testing of the writing
>>> out of cursor details from libclang?
>>
>>
>> Not sure - I really want a format that's for users; I'd be happy to create
>> something more machine-readable (JSON for example), so we can use it in
>> tests, though.
>>
>>> One nit-picky detail: please don't use the initialisms.... At least, not
>>> *these*. I see SP, EX, and ES in this syntax and I think "wait, is this a
>>> stack machine asm chunk?? some other weird assembly language?" before my
>>> mind returns to sanity. ;]
>>
>>
>> Just tell me what to use :) I don't have strong feelings about anything
>> here - the main problem is that with 4- or 5-layer macros, this can quickly
>> go deep and become unwieldy if names start getting too long (as you know me
>> I of course started with "SpellingLocation" etc :)
>>
>> Cheers,
>> /Manuel
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list