[cfe-dev] Why Printer Classes are private?

Alex L via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 19 09:46:49 PDT 2017


On 18 October 2017 at 17:07, Roman Popov <ripopov at gmail.com> wrote:

> Hi Alex,
> I can probably look into it if I have time and will feel myself confident
> enough. I've started learning Clang just recently (and my background is HW
> design, not programming).
>
> Meanwhile I've found a workaround to do what I've needed originally:
> Instead of printing nodes in a special way, I create Replacements for
> them, then use a temporary Rewriter to apply replacements and get back text
> I wanted to print.
>

> Probably it was supposed to be always done like that?
>

I think that it's definitely a viable option.


>
> The only problem is the case when I don't have parts of AST in original
> source code. For example when I deal with template instantiations. In that
> case I will have to emit implicit template specializations in overlay
> filesystem, reparse TU again, and then create replacements for nodes of
> interest.
>

> So If I had a capability to customize AST pretty-printer, I won't need to
> re-parse source code multiple times.
>

Personally I would be interested in adding such a customization to the
DeclPrinter for some of my work as well. I'm not currently working on, but
I might get to it in a couple of weeks. However if you think that you would
benefit from such a customization now, I would recommend you to look into
providing patches for such customization. If you are interested in learning
more about contributing to Clang feel free to take a look at the
documentation that we have:
http://llvm.org/docs/GettingStarted.html



>
>
>
> 2017-10-18 16:30 GMT-07:00 Alex L <arphaman at gmail.com>:
>
>> Hi Roman,
>>
>> On 18 October 2017 at 14:35, Roman Popov via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>
>>> In StmtPrinter there is a PrintHelper that can be used to override
>>> printing of some nodes. I guess PrintHelper was introduced for someone
>>> like me that wanted to override some StmtPrinter visitors.
>>> But DeclPrinter does not supports PrintHelper for some reason.
>>>
>>
>> It's possible that nobody else needed a customized DeclPrinter before, so
>> it wasn't necessary to add a helper for it.
>> I think that it would make sense to add a helper class for DeclPrinter if
>> there's a good enough justification for it. Would you be interested in
>> working on a patch for such a helper class?
>>
>> Alex
>>
>>
>>
>>>
>>>
>>> 2017-10-18 12:53 GMT-07:00 Roman Popov <ripopov at gmail.com>:
>>>
>>>> Hello,
>>>> I want to redefine some visitors in DeclPrinter and StmtPrinter, but
>>>> they are not exported over Clang API. Why is that?
>>>>
>>>> Currently I have to copy-paste them into my tool. But this
>>>> unfortunately leads to some duplication.
>>>>
>>>> -Roman
>>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171019/8c808763/attachment.html>


More information about the cfe-dev mailing list