[cfe-dev] Why Printer Classes are private?

Roman Popov via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 18 17:07:12 PDT 2017

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?

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

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

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/20171018/bd62390a/attachment.html>

More information about the cfe-dev mailing list