[cfe-dev] How to match clang::attr::Annotate with specific value?
Andi-Bogdan Postelnicu via cfe-dev
cfe-dev at lists.llvm.org
Sun Jul 5 01:50:33 PDT 2020
Some more info about the answer from my previous reply if you want a more direct approach you can do something like:
<> 157 static bool isAnnotatedToAllowDirectAssignment(const Decl <https://clang.llvm.org/doxygen/classclang_1_1Decl.html> *D) {
<> 158 for (const auto *Ann : D->specific_attrs <https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a9c0ac8ddf9155de0b95eeeb18034e50f><AnnotateAttr>())
<> 159 if (Ann->getAnnotation() ==
<> 160 "objc_allow_direct_instance_variable_assignment")
<> 161 return true;
<> 162 return false;
<> 163 }
```
Of course wrapping this in a custom matcher and modified according to your needs, the example was take from `DirectlvarAssignment Checker` [1].
[1] https://clang.llvm.org/doxygen/DirectIvarAssignment_8cpp_source.html <https://clang.llvm.org/doxygen/DirectIvarAssignment_8cpp_source.html>
> On 5 Jul 2020, at 11:39, Andi-Bogdan Postelnicu <andi at mozilla.com> wrote:
>
> Hello,
>
> Yes of course you can do that, you can first interrogate Decl::hasAttrs [1], and if that’s true you can get the AttrVec [2].
> I would suggest to wrapp this in a custom matcher.
>
> Hope this helps!
>
> [1] https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a1e0b6223e2547ac65ddbf4802117998b <https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a1e0b6223e2547ac65ddbf4802117998b>
> [2] https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a59463d45ab90b696a368b58d23eb49aa <https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a59463d45ab90b696a368b58d23eb49aa>
>
>> On 5 Jul 2020, at 11:25, Yafei Liu via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
>>
>> For example I have a struct:
>> struct [[clang::annotate("example")]] ExampleStruct {
>> int i;
>> float f;
>> double d;
>> int* ip;
>> uint32_t ii;
>> };
>> Currently I use the matcher like this:
>> clang::ast_matchers::cxxRecordDecl(clang::ast_matchers::hasDefinition(),
>> clang::ast_matchers::hasAttr(clang::attr::Annotate)).bind("example_struct");
>>
>> Can I go further by making the matcher check if the annotate is "example"?
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200705/9ff7a0fe/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200705/9ff7a0fe/attachment-0001.sig>
More information about the cfe-dev
mailing list