[cfe-dev] Is there anyway I can add some custom information to the AST?

Nathan James via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 4 09:33:52 PDT 2020


Hi Yafei,

You can use the Attribute system to decorate AST nodes, they can also
be loaded via plugins. See `clang/examples/Attrbiute/` to see how they
are created and registered.

Then you can add an attribute to the class decl, for example
> class [[convert]] MyVector {};

Hope this helps,
Nathan James

On Sun, 2020-07-05 at 00:05 +0800, Yafei Liu via cfe-dev wrote:
> Hi, all.
> I'm writing some tools to convert a C++ class to something else, and
> I want to add  some custom information to the AST.
> 
> At first, I decided to add some comments to mark some classes, but I
> found that the AST does not contain comments.
> 
> Secondly, I want to customize an attribute, but I found that it needs
> to recompile the Clang, I didn't find a "plug-in" way.  Since my
> tools are designed for public usage, a customized compiler is not
> very considerable.
> 
> Currently I have to force the user to declare their class names and
> field names with some special rules, but this is not very acceptable
> to me.
> 
> So anyone knows if there's a better way to add some custom
> information to the AST?
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list