<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-03-16 19:59 GMT+00:00 Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Mar 16, 2018 at 3:40 PM, Matthieu Brucher via cfe-dev<br>
<<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
><br>
><br>
> Le 12 mars 2018 17:59, "Aaron Ballman via cfe-dev" <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
> a écrit :<br>
><br>
> I believe the matcher you're looking for is:<br>
> varDecl(hasType(references(<wbr>qualType(isConstQualified())))<wbr>)<br>
><br>
> For example, given:<br>
><br>
> void f1() {<br>
> try {<br>
> } catch (int &e) {<br>
> }<br>
> }<br>
><br>
> void f2() {<br>
> try {<br>
> } catch (const int &e) {<br>
> }<br>
> }<br>
><br>
> produces:<br>
><br>
> clang-query> match<br>
> varDecl(hasType(references(<wbr>qualType(isConstQualified())))<wbr>)<br>
><br>
> Match #1:<br>
><br>
> C:\Users\Aaron\Desktop\test.<wbr>cpp:9:12: note: "root" binds here<br>
> } catch (const int &e) {<br>
> ^~~~~~~~~~~~<br>
> 1 match.<br>
><br>
> ~Aaron<br>
><br>
> On Mon, Mar 12, 2018 at 2:12 AM, Richard via cfe-dev<br>
> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
>> [Please reply *only* to the list and do not include my email directly<br>
>> in the To: or Cc: of your reply; otherwise I will not see your reply.<br>
>> Thanks.]<br>
>><br>
>> In article<br>
>> <<a href="mailto:CAHCaCkKdVLA-Mvg6i8BLAURRAeFfq5_GSGc6NmY3bEjRPpXq3Q@mail.gmail.com">CAHCaCkKdVLA-<wbr>Mvg6i8BLAURRAeFfq5_<wbr>GSGc6NmY3bEjRPpXq3Q@mail.<wbr>gmail.com</a>>,<br>
>> Matthieu Brucher via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> writes:<br>
>><br>
>>> 2018-03-11 21:26 GMT+00:00 Richard via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>>:<br>
>>><br>
>>> > Have you tried prototyping with clang-query?<br>
>>> ><br>
>>><br>
>>> I know how to use it to create the query, but that's it. And even then, I<br>
>>> can only do basic query, as I don't know where to find documentation on<br>
>>> the<br>
>>> specifics.<br>
>>> It's possible to use for "dematching"? The ideal would be to select all<br>
>>> catch statements that are not const&, but there are no example anywhere<br>
>>> on<br>
>>> that kind of selection.<br>
>><br>
>> I confess that I find the type related matchers confusing and I'm<br>
>> never quite sure how to use them. If you look at the matcher<br>
>> reference <<a href="http://clang.llvm.org/docs/LibASTMatchersReference.html" rel="noreferrer" target="_blank">http://clang.llvm.org/docs/<wbr>LibASTMatchersReference.html</a>><br>
>> you'll see a matcher for isExceptionVariable which is how you match<br>
>> variable declarations in a catch statement. (Maybe the matcher name<br>
>> here isn't the best.)<br>
>><br>
>> c:\tmp<br>
>> > copy con: tmp.cpp<br>
>> #include <stdexcept><br>
>><br>
>> void f()<br>
>> {<br>
>> try {<br>
>> g();<br>
>> } catch (std::exception &e) {<br>
>> throw;<br>
>> }<br>
>> }<br>
>> ^Z<br>
>> 1 file(s) copied.<br>
>><br>
>> c:\tmp<br>
>> > clang-query tmp.cpp --<br>
>> clang-query> match varDecl(isExceptionVariable())<br>
>><br>
>> Match #1:<br>
>><br>
>> c:\tmp\tmp.cpp:9:12: note: "root" binds here<br>
>> } catch (std::exception &e) {<br>
>> ^~~~~~~~~~~~~~~~~<br>
>> 1 match.<br>
>> clang-query><br>
>><br>
>> The part that always confuses me about the matchers is how to modify<br>
>> matchers that find statements or declarations to qualify the matches<br>
>> by aspects of the associated type.<br>
>><br>
>> Here we want to narrow the varDecl() so that the type of the variable<br>
>> is reference but not reference to const. Frankly, I have never<br>
>> figured out how to do that in clang-query and I'd love for someone to<br>
>> enlighten me :)<br>
><br>
><br>
> Seems like this query also matches function arguments. I suppose I have to<br>
> use a condition saying that the previous or parent statement is catch?<br>
<br>
</div></div>It will match all variable declarations. For just catch arguments, I<br>
think you will want:<br>
<br>
varDecl(isExceptionVariable(),<br>
hasType(references(qualType(<wbr>isConstQualified()))))<br></blockquote><div><br></div><div>I really have to look at the ast_matchers functions (because I just noticed that this is where these are!).</div><div><br></div><div>Thanks a lot! </div></div><div><br></div><div>Regards,</div><div><br></div><div>Matthieu</div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Quantitative analyst, Ph.D.<br>Blog: <a href="http://blog.audio-tk.com/" target="_blank">http://blog.audio-tk.com/</a><br>LinkedIn: <a href="http://www.linkedin.com/in/matthieubrucher" target="_blank">http://www.linkedin.com/in/matthieubrucher</a></div></div></div></div></div>
</div></div>