[cfe-dev] Adding nodes to Clang's AST

Aleksei Sidorin via cfe-dev cfe-dev at lists.llvm.org
Mon Jan 9 08:54:58 PST 2017


Hello Ori,

You can create different kinds of nodes directly. For example, to create 
a new namespace, you will need to use code like this:

IdentifierInfo *IdInfo = Context.Idents.get("bar");
NamespaceDecl *NewNS = NamespaceDecl::Create(Context, 
Context.getTranslationUnitDecl(), false, StartLoc, IdLoc, IdInfo, OldDecl);

You can take a look at constructors of different Decl kinds (and static 
::Create() methods) in Decl.h and DeclCXX.h (and other Decl*.h) for more 
information.
To move a function to this namespace, you will need to set a new 
DeclContext for it:

FD->setDeclContext(NewNS);
FD->setLexicalDeclContext(NewNS);



09.01.2017 18:59, Ori Zaig via cfe-dev пишет:
>
> I need to insert new nodes to AST. For instance, adding a namespace to 
> a function: Turning this -
>
> |void foo();|
> ||
>
> into this -
>
> |namespace bar {|
> |    void foo();|
> |}|
>
> I want to edit the AST directly - I prefer not using source-to-source 
> compilation
>
> Tnx
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


-- 
Best regards,
Aleksei Sidorin
Software Engineer,
IMSWL-IMCG, SRR, Samsung Electronics

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170109/dc204dcb/attachment.html>


More information about the cfe-dev mailing list