Why Printer Classes are private?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Why Printer Classes are private?

Eric Fiselier via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Why Printer Classes are private?

Eric Fiselier via cfe-dev
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.


2017-10-18 12:53 GMT-07:00 Roman Popov <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Why Printer Classes are private?

Eric Fiselier via cfe-dev
Hi Roman,

On 18 October 2017 at 14:35, Roman Popov via cfe-dev <[hidden email]> 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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Why Printer Classes are private?

Eric Fiselier via cfe-dev
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 interest. 

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 <[hidden email]>:
Hi Roman,

On 18 October 2017 at 14:35, Roman Popov via cfe-dev <[hidden email]> 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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Why Printer Classes are private?

Eric Fiselier via cfe-dev


On 18 October 2017 at 17:07, Roman Popov <[hidden email]> 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:

 



2017-10-18 16:30 GMT-07:00 Alex L <[hidden email]>:
Hi Roman,

On 18 October 2017 at 14:35, Roman Popov via cfe-dev <[hidden email]> 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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Why Printer Classes are private?

Eric Fiselier via cfe-dev
Unfortunately in addition to Visitors, DeclPrinter also has some hidden helper printXXX methods:  printTemplateParameters, printTemplateArguments, etc.... 
So even if we add PrintHelper to override some visitors, it won't have an access to those very useful helpers.  

This seems to me as a fundamental limitation of curiously recurring template pattern : unlike real dynamic dispatch, it allows only a single level of inheritance. 

Does anyone have any ideas how to allow customization of a DeclPrinter?

2017-10-19 9:46 GMT-07:00 Alex L <[hidden email]>:


On 18 October 2017 at 17:07, Roman Popov <[hidden email]> 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:

 



2017-10-18 16:30 GMT-07:00 Alex L <[hidden email]>:
Hi Roman,

On 18 October 2017 at 14:35, Roman Popov via cfe-dev <[hidden email]> 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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev






_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev