<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">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>> a écrit :<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 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>
<div class="elided-text"><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 <<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 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 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></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Seems like this query also matches function arguments. I suppose I have to use a condition saying that the previous or parent statement is catch? </div><div dir="auto"><br></div><div dir="auto">Matthieu</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="elided-text">
> --<br>
> "The Direct3D Graphics Pipeline" free book <<a href="http://tinyurl.com/d3d-pipeline" rel="noreferrer" target="_blank">http://tinyurl.com/d3d-<wbr>pipeline</a>><br>
> The Terminals Wiki <<a href="http://terminals-wiki.org" rel="noreferrer" target="_blank">http://terminals-wiki.org</a>><br>
> The Computer Graphics Museum <<a href="http://ComputerGraphicsMuseum.org" rel="noreferrer" target="_blank">http://<wbr>ComputerGraphicsMuseum.org</a>><br>
> Legalize Adulthood! (my blog) <<a href="http://LegalizeAdulthood.wordpress.com" rel="noreferrer" target="_blank">http://LegalizeAdulthood.<wbr>wordpress.com</a>><br>
> ______________________________<wbr>_________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</div></blockquote></div><br></div></div></div>