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

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 6 06:07:34 PDT 2020


Consider using the attribute ‘annotate’.    It doesn’t seem to be documented on our page unfortunately, but it applies to a declaration and takes an arbitrary string:  [[clang::annotate("asdf")]]

OR: __attribute__((annotate(“asdf”)))

From: cfe-dev <cfe-dev-bounces at lists.llvm.org> On Behalf Of Yafei Liu via cfe-dev
Sent: Saturday, July 4, 2020 9:06 AM
To: Clang Dev <cfe-dev at lists.llvm.org>
Subject: [cfe-dev] Is there anyway I can add some custom information to the AST?

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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200706/ceb7fc0d/attachment-0001.html>


More information about the cfe-dev mailing list