<div dir="ltr">Hi Andi-Bogdan, do you mean I should do the checking in the MatchCallback, as long as this cannot be done in a matcher?</div><br><div class="gmail_quote"><div class="gmail_attr" dir="ltr">On Sun, Jul 5, 2020 at 4:50 PM Andi-Bogdan Postelnicu <<a href="mailto:andi@mozilla.com">andi@mozilla.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div style="overflow-wrap: break-word;">Some more info about the answer from my previous reply if you want a more direct approach you can do something like:<div><div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"> </div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00157" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 157</span> <span style="color:rgb(0,128,0)">static</span> <span style="color:rgb(96,64,32)">bool</span> isAnnotatedToAllowDirectAssignment(<span style="color:rgb(0,128,0)">const</span> <a style="color:rgb(70,101,162);text-decoration:none" href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html" target="_blank">Decl</a> *D) {</div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00158" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 158</span> <span style="color:rgb(224,128,0)">for</span> (<span style="color:rgb(0,128,0)">const</span> <span style="color:rgb(0,128,0)">auto</span> *Ann : D-><a style="color:rgb(70,101,162);text-decoration:none" href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a9c0ac8ddf9155de0b95eeeb18034e50f" target="_blank">specific_attrs</a><AnnotateAttr>())</div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00159" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 159</span> <span style="color:rgb(224,128,0)">if</span> (Ann->getAnnotation() ==</div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00160" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 160</span> <span style="color:rgb(0,32,128)">"objc_allow_direct_instance_variable_assignment"</span>)</div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00161" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 161</span> <span style="color:rgb(224,128,0)">return</span> <span style="color:rgb(0,128,0)">true</span>;</div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00162" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 162</span> <span style="color:rgb(224,128,0)">return</span> <span style="color:rgb(0,128,0)">false</span>;</div><div style="margin:0px;line-height:1;padding-bottom:0px;padding-left:53px;font-family:monospace,fixed;font-size:13px;white-space:pre-wrap;min-height:13px;font-stretch:normal;background-color:rgb(251,252,253)"><a name="m_-1691174028348913477_l00163" style="color:rgb(61,87,140)"></a><span style="text-align:right;padding-right:4px;border-right-color:rgb(0,255,0);border-right-width:2px;border-right-style:solid;white-space:pre-wrap;background-color:rgb(232,232,232)"> 163</span> }</div></div><div><div><font face="monospace, fixed" size="2"><span style="white-space:pre-wrap;background-color:rgb(251,252,253)">```</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></div><div>[1] <a href="https://clang.llvm.org/doxygen/DirectIvarAssignment_8cpp_source.html" target="_blank">https://clang.llvm.org/doxygen/DirectIvarAssignment_8cpp_source.html</a></div><div><br><blockquote type="cite"><div>On 5 Jul 2020, at 11:39, Andi-Bogdan Postelnicu <<a href="mailto:andi@mozilla.com" target="_blank">andi@mozilla.com</a>> wrote:</div><br><div><div><div style="overflow-wrap: break-word;">Hello,<div><br></div><div>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>I would suggest to wrapp this in a custom matcher.</div><div><br></div><div>Hope this helps! </div><div><br></div><div>[1] <a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a1e0b6223e2547ac65ddbf4802117998b" target="_blank">https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a1e0b6223e2547ac65ddbf4802117998b</a></div><div>[2] <a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a59463d45ab90b696a368b58d23eb49aa" target="_blank">https://clang.llvm.org/doxygen/classclang_1_1Decl.html#a59463d45ab90b696a368b58d23eb49aa</a><br><div><br><blockquote type="cite"><div>On 5 Jul 2020, at 11:25, Yafei Liu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>For example I have a struct:</div><div><pre style="color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(43,43,43)"><span style="color:rgb(204,120,50)">struct </span>[[clang::annotate(<span style="color:rgb(106,135,89)">"example"</span>)]] ExampleStruct {<br> <span style="color:rgb(204,120,50)">int </span>i<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"> float </span>f<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"> double </span>d<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"> int</span>* ip<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"> </span>uint32_t ii<span style="color:rgb(204,120,50)">;<br></span>}<span style="color:rgb(204,120,50)">;</span></pre>Currently I use the matcher like this:</div><div><pre style="color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(43,43,43)"><span style="color:rgb(181,182,227)">clang</span>::<span style="color:rgb(181,182,227)">ast_matchers</span>::cxxRecordDecl<span style="color:rgb(95,140,138)">(</span><span style="color:rgb(181,182,227)">clang</span>::<span style="color:rgb(181,182,227)">ast_matchers</span>::hasDefinition()<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)"> </span><span style="color:rgb(181,182,227)">clang</span>::<span style="color:rgb(181,182,227)">ast_matchers</span>::hasAttr(<span style="color:rgb(181,182,227)">clang</span>::<span style="color:rgb(181,182,227)">attr</span>::<span style="color:rgb(152,118,170);font-style:italic">Annotate</span>)<span style="color:rgb(95,140,138)">)</span>.bind(<span style="color:rgb(106,135,89)">"example_struct"</span>)<span style="color:rgb(204,120,50)">;</span></pre><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br></div><div>Can I go further by making the matcher check if the annotate is "example"?</div></div></div></div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div></div></blockquote></div>