RFC: Tree-based refactorings with Clang

Hi everyone,

We would like to propose a new way of writing refactorings on top of the Clang infrastructure. Our is to have nice APIs that hide tedious tasks, like dealing with macros or adding parentheses around changed expressions.

Design is discussed in detail here:

https://docs.google.com/document/d/161XftOcF-ut1pGQr5ci9kXd_y0jRQl3y9sVyvuEkLDc/edit?usp=sharing

Please let us know what you think either by adding comments to the document or directly in this thread.
Eager to hear your thoughts!

Hi Ilya,

This looks awesome!

I am just curious - since the expected workflow is to always start with ASTMatchers do you plan to provide utilities to overcome limitations of AST you mention?

- Different ASTs for the same syntax
- Same ASTs for the different syntactic constructs

For example - do you plan to implement some functionality for separating a set of AST nodes based on their syntactic nature?

Thanks.

Jan

Is it possible for you to repost the design document to the mailing list so that it’s archived?

Hi Ilya,

This looks awesome!

I am just curious - since the expected workflow is to always start with ASTMatchers do you plan to provide utilities to overcome limitations of AST you mention?

Syntax trees are actually independent of matchers, an input to build them is a clang AST and one can find syntax tree nodes for the corresponding AST nodes afterwards.
The matchers are just another way to find interesting AST nodes, so we can use the same mechanism to map from the AST node (found by the matcher) to the syntax tree node.

I guess the confusing part of the document was the FAQ section about ASTMatchers, I’ve changed it to make it clear ASTMatchers are not planned as the only input source.

For example - do you plan to implement some functionality for separating a set of AST nodes based on their syntactic nature?

No plans to do this and it feels like building the syntax tree might be an overkill to solve this. Intuition is that this should be solvable with a switch on the AST node types.
That said, this is something that would definitely pop up while implementing the syntax trees.

Is it possible for you to repost the design document to the mailing list so that it’s archived?

Sure! Attaching the document to this letter in pdf format.

Tree-based refactorings with Clang.pdf (297 KB)