[PATCH] D158055: [clang][AST] Added some missing setter methods
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 11:25:11 PDT 2023
aaron.ballman added a comment.
In D158055#4594863 <https://reviews.llvm.org/D158055#4594863>, @strimo378 wrote:
> Yes, I have a need for these setters :) but I cannot decide if the LLVM project in general or other people could profit from it.
>
> I am working on a C++-to-C transpiler based on clang. Other clang-based tool typically modify the intput file based on FileLocation information. In contrast, I follow a constructive approach with AST print. The transpiler is organized in many small passes that transform the clang AST until at the end I can output the C code via AST print. Some notable passes are
>
> - Remove unused AST decls (simplifies AST for non-trivial input)
> - Resolve templates (is also useful standalone to remove templates from a C++ program)
> - Resolve namespaces
> - Move nested records
> - Convert methods to functions
> - etc.
>
> For transforming the AST, I often need to replace Types and regenerate the corresponding TypeLoc. I tried for over one year to recreate AST nodes when a setter methods was missing but that caused a lot of work and instabilities for maintaining cross references. For that reason, I now insert a new setter method when needed and until now surprising less setter methods are missing.
>
> For me it takes 5-10 min per version upgrade to port the changes, so it is not a big deal for me if you refuse them. I have some other AST modification in place for removing templates information but nothing complex...
Thank you for the detailed explanation! I think we should probably skip adding these until there's an in-tree need for them. Given that we don't want the AST to be mutable once it's been constructed, I think adding setters gives the wrong impression and we should continue to use `friend` to give limited access to interfaces that need the mutability.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158055/new/
https://reviews.llvm.org/D158055
More information about the cfe-commits
mailing list