[cfe-dev] Getting meta-data into Clang's AST
cnuernber at gmail.com
Fri Jul 2 13:59:32 PDT 2010
OK, now I know what you mean by attributes; these won't work for me.
You meant things like _cdecl and such, correct?
I am going to try to use the generator to generate a portion of the
translation layer from a complex representation of a problem back to a
simple one. I need to be able to note type and variable names at the
minimum and perhaps more. Thus comments would be more appropriate.
So what is the best way to go forward? Should I merge this patch back
into my system? I believe this is still doable.
On Fri, Jul 2, 2010 at 11:29 AM, chris nuernberger <cnuernber at gmail.com> wrote:
> OK, lets look at attributes for a second.
> What are they? A google search for clang attributes of course doesn't
> turn up much.
> Really, if I could embed arbitrary text in an attribute associated
> with a member variable this would do it; I could design a small DSL to
> do what I need. Does this sound feasible, even if this text is
> somewhat verbose?
> If not, the changelist about the comments looks pretty involved; I
> will want to discuss that further but I am really hoping that
> attributes will do.
> On Fri, Jul 2, 2010 at 11:22 AM, Douglas Gregor <dgregor at apple.com> wrote:
>> On Jul 2, 2010, at 10:03 AM, chris nuernberger wrote:
>>> I completed (quite easily) the first part of my task which was to get
>>> clang to parse some c++ objects and write out some serialization
>>> mappings for them.
>>> Now I have seemingly much harder task which is to parse some c++
>>> objects and not only get their binary layout
>> ASTRecordLayout has that information.
>>> but also to be able to
>>> read some pretty arbitrary meta data about each member.
>>> Is there a recommended way to add in meta data to the Clang AST from
>>> the parser?
>> Attributes, pragmas, and comments are the typical approaches. I would recommend *not* using pragmas, because associating them with specific declarations is a real pain. Attributes are okay for lightweight metadata, and in the future it'll be far easier to add your own attributes. Comments give the most flexibility, although you'll still need to solve the problem of associating a comment with the declaration(s) it applies to.
>>> I noticed comments seem to be completely stripped; is
>>> this the case or did I mis-read something?
>> Yes, this is the case, although it was actually a recent chang. See
>> where I ripped out our handling of comments because they were completely unused. I'm not opposed to bringing comments back if they're actually going to be used for something real *cough* Doxygen parsing *cough*.
>>> Comments would be ideal as the other compilers for these objects will
>>> then definitely ignore the data, but I could also declare a special
>>> objects with string constants or something like that; assuming it
>>> didn't change the binary layout of the object.
>>> Has anyone done something like this before?
>> Not in Clang, but it's fairly common to use comments for metadata.
>> - Doug
> A foolish consistency is the hobgoblin of little minds - Emerson
A foolish consistency is the hobgoblin of little minds - Emerson
More information about the cfe-dev