[cfe-dev] Insertion one AST node into another at particular location

Yitzhak Mandelbaum via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 21 12:32:30 PDT 2020


Do you need to use ASTImporter, or was that just a starting point?
LibTooling has a lot of support for editing code.  clang-tidy tends to be
the easiest place to start. Additionally, clang transformer can simplify
the code editing parts with "rewrite rules":
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Tooling/Transformer/RewriteRule.h


To your example, you'd write a matcher which identifies the node of
interest and then edit the code with something like
`insertAfter(node(IdBoundToInterestingNode), cat(...))`

On Fri, Aug 21, 2020 at 9:22 AM samins KAlex via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Can I use ASTImporter for add some loop into function CompoundStatement node exactly in particular source location (or after some AST node between left bracket and right bracket)?
>
>
> Importer(ToUnit->getASTContext(), ToUnit->getFileManager(), FromUnit->getASTContext(), FromUnit->getFileManager(),
>
> Also
> It seems, I need to get ASTContext object from node "to", because ASTImporter constructor takes ASTContext "from" and "to"? But how can I do it having only "from" and "to" nodes ?
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://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/20200821/dcc64a33/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3854 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200821/dcc64a33/attachment.bin>


More information about the cfe-dev mailing list