[cfe-dev] Decls and Attrs

Aaron Ballman aaron at aaronballman.com
Thu Aug 15 05:54:34 PDT 2013


On Thu, Aug 15, 2013 at 5:00 AM, Vassil Vassilev
<vasil.georgiev.vasilev at cern.ch> wrote:
> On 08/14/2013 03:24 PM, Aaron Ballman wrote:
>>
>> Ah, no, I misunderstood your question.  Sorry about that!
>
> No problem.
>
>>
>> And no, there is no direct link from an attribute back to a decl.  For
>> instance, the attribute could be attached to a type or a stmt, as well
>> as a decl.
>
> IIUC, the policy is clang should/will generate just one attribute of a kind
> and this attribute will be reused, even though now the implementation seems
> doing it otherwise:
> grep -rni "new ([a-zA-Z].*) [a-zA-Z].*Attr(" clang/lib/ ...

No, clang will generate a new attribute each time one is processed in
SemaDeclAttr.cpp, et al (it doesn't memoize attributes), but by
convention this attribute is only attached to a single subject at a
time.

>> However, the Decl does not own its Attrs; the ASTContext does.  So you
>> could modify the ASTContext to tell you which Decls an Attr is
>> attached to if you only care about Decls.
>
> How I can do that? The only way that comes to my mind is iterating over all
> decls and asking for their attr...

Since ASTContext holds onto the list of attributes (and not the decl
itself), you can walk the list the AST is holding via
ASTContext::DeclAttrs.  So you would not have to walk all Decls, just
Decls that have Attrs.

~Aaron



More information about the cfe-dev mailing list