<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Some more info about the answer from my previous reply if you want a more direct approach you can do something like:<div class=""><div class=""><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"> </div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00157" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  157</span> <span class="keyword" style="color: rgb(0, 128, 0);">static</span> <span class="keywordtype" style="color: rgb(96, 64, 32);">bool</span> isAnnotatedToAllowDirectAssignment(<span class="keyword" style="color: rgb(0, 128, 0);">const</span> <a class="code" href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html" style="color: rgb(70, 101, 162); text-decoration: none;">Decl</a> *D) {</div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00158" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  158</span>   <span class="keywordflow" style="color: rgb(224, 128, 0);">for</span> (<span class="keyword" style="color: rgb(0, 128, 0);">const</span> <span class="keyword" style="color: rgb(0, 128, 0);">auto</span> *Ann : D-><a class="code" href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a9c0ac8ddf9155de0b95eeeb18034e50f" style="color: rgb(70, 101, 162); text-decoration: none;">specific_attrs</a><AnnotateAttr>())</div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00159" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  159</span>     <span class="keywordflow" style="color: rgb(224, 128, 0);">if</span> (Ann->getAnnotation() ==</div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00160" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  160</span>         <span class="stringliteral" style="color: rgb(0, 32, 128);">"objc_allow_direct_instance_variable_assignment"</span>)</div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00161" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  161</span>       <span class="keywordflow" style="color: rgb(224, 128, 0);">return</span> <span class="keyword" style="color: rgb(0, 128, 0);">true</span>;</div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00162" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  162</span>   <span class="keywordflow" style="color: rgb(224, 128, 0);">return</span> <span class="keyword" style="color: rgb(0, 128, 0);">false</span>;</div><div class="line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition-property: background-color, box-shadow; transition-duration: 0.5s; background-color: rgb(251, 252, 253);"><a name="l00163" style="color: rgb(61, 87, 140);" class=""></a><span class="lineno" style="-webkit-user-select: none; padding-right: 4px; text-align: right; border-right-width: 2px; border-right-style: solid; border-right-color: rgb(0, 255, 0); background-color: rgb(232, 232, 232); white-space: pre;">  163</span> }</div></div><div class=""><div style="text-indent: -53px;" class=""><font face="monospace, fixed" size="2" class=""><span style="white-space: pre-wrap; background-color: rgb(251, 252, 253);" class="">```</span></font></div><div>Of course wrapping this in a custom matcher and modified according to your needs, the example was take from `DirectlvarAssignment Checker` [1].</div><div><br class=""></div><div>[1] <a href="https://clang.llvm.org/doxygen/DirectIvarAssignment_8cpp_source.html" class="">https://clang.llvm.org/doxygen/DirectIvarAssignment_8cpp_source.html</a></div><div><br class=""><blockquote type="cite" class=""><div class="">On 5 Jul 2020, at 11:39, Andi-Bogdan Postelnicu <<a href="mailto:andi@mozilla.com" class="">andi@mozilla.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="content-isolator__container"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">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].</div><div class="">I would suggest to wrapp this in a custom matcher.</div><div class=""><br class=""></div><div class="">Hope this helps! </div><div class=""><br class=""></div><div class="">[1] <a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a1e0b6223e2547ac65ddbf4802117998b" class="">https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a1e0b6223e2547ac65ddbf4802117998b</a></div><div class="">[2] <a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a59463d45ab90b696a368b58d23eb49aa" class="">https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a59463d45ab90b696a368b58d23eb49aa</a><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 5 Jul 2020, at 11:25, Yafei Liu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">For example I have a struct:</div><div class=""><pre style="color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(43,43,43)" class=""><span style="color:rgb(204,120,50)" class="">struct </span>[[clang::annotate(<span style="color:rgb(106,135,89)" class="">"example"</span>)]] ExampleStruct {<br class="">  <span style="color:rgb(204,120,50)" class="">int </span>i<span style="color:rgb(204,120,50)" class="">;<br class=""></span><span style="color:rgb(204,120,50)" class="">  float </span>f<span style="color:rgb(204,120,50)" class="">;<br class=""></span><span style="color:rgb(204,120,50)" class="">  double </span>d<span style="color:rgb(204,120,50)" class="">;<br class=""></span><span style="color:rgb(204,120,50)" class="">  int</span>* ip<span style="color:rgb(204,120,50)" class="">;<br class=""></span><span style="color:rgb(204,120,50)" class="">  </span>uint32_t ii<span style="color:rgb(204,120,50)" class="">;<br class=""></span>}<span style="color:rgb(204,120,50)" class="">;</span></pre>Currently I use the matcher like this:</div><div class=""><pre style="color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(43,43,43)" class=""><span style="color:rgb(181,182,227)" class="">clang</span>::<span style="color:rgb(181,182,227)" class="">ast_matchers</span>::cxxRecordDecl<span style="color:rgb(95,140,138)" class="">(</span><span style="color:rgb(181,182,227)" class="">clang</span>::<span style="color:rgb(181,182,227)" class="">ast_matchers</span>::hasDefinition()<span style="color:rgb(204,120,50)" class="">,<br class=""></span><span style="color:rgb(204,120,50)" class="">    </span><span style="color:rgb(181,182,227)" class="">clang</span>::<span style="color:rgb(181,182,227)" class="">ast_matchers</span>::hasAttr(<span style="color:rgb(181,182,227)" class="">clang</span>::<span style="color:rgb(181,182,227)" class="">attr</span>::<span style="color:rgb(152,118,170);font-style:italic" class="">Annotate</span>)<span style="color:rgb(95,140,138)" class="">)</span>.bind(<span style="color:rgb(106,135,89)" class="">"example_struct"</span>)<span style="color:rgb(204,120,50)" class="">;</span></pre><b class=""></b><i class=""></i><u class=""></u><sub class=""></sub><sup class=""></sup><strike class=""></strike><br class=""></div><div class="">Can I go further by making the matcher check if the annotate is "example"?</div></div></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></div></body></html>