<div dir="ltr">CC @klimek @alexfh @djasper<div><br></div><div>There are some differences in behaviour of clang-query and ast matchers in code. I also don't know why and I would like to know.</div><div><br></div><div>Piotr</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 1, 2016 at 6:15 AM, Farzad Sadeghi via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">i have the following ASTMatcher:<br>
`functionDecl(forEachDescendant(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")),<br>
unless(hasDescendant(declRefExpr(to(varDecl(anything()))))))<br>
).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"))).bind("scopeDaddy")`.<br>
it compiles and works fine both after building and running it and also<br>
in clang-query.<br>
i needed to make some changes to it so i wrote this one:<br>
`functionDecl(forEachDescendant(anyOf(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")),<br>
unless(hasDescendant(declRefExpr(to(varDecl(anything()))))))<br>
).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),<br>
callExpr(unless(hasAncestor(expr()))).bind("orphancall")))).bind("scopeDaddy")`<br>
when i run it in clang-query it runs without a problem but when i put<br>
that in my code and try to compile it, the compiler returns this:<br>
-----------------------------------------------------------------------------------------------------------------------------<br>
tokenizer.cpp: In constructor<br>
‘TokenizerASTConsumer::TokenizerASTConsumer(clang::Rewriter&)’:<br>
tokenizer.cpp:544:348: error: no match for call to ‘(const<br>
clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<clang::ast_matchers::internal::ForEachDescendantMatcher>)<br>
(clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcher<clang::Stmt>,<br>
clang::ast_matchers::internal::BindableMatcher<clang::Stmt> >)’<br>
 Decl(anything()))))))<br>
).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),<br>
callExpr(unless(hasAncestor(expr())))))).bind("sc<br>
<br>
                                                                    ^<br>
In file included from /usr/local/include/clang/ASTMatchers/ASTMatchers.h:52:0,<br>
                 from tokenizer.cpp:15:<br>
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1043:14:<br>
note: candidate: template<class T><br>
clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,<br>
FromTypes, ToTypes>::Adaptor<T><br>
clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,<br>
FromTypes, ToTypes>::operator()(const<br>
clang::ast_matchers::internal::Matcher<From>&) const [with T = T;<br>
ArgumentAdapterT =<br>
clang::ast_matchers::internal::ForEachDescendantMatcher; FromTypes =<br>
clang::ast_matchers::internal::TypeList<clang::Decl, clang::Stmt,<br>
clang::NestedNameSpecifier, clang::NestedNameSpecifierLoc,<br>
clang::QualType, clang::Type, clang::TypeLoc,<br>
clang::CXXCtorInitializer>; ToTypes =<br>
clang::ast_matchers::internal::TypeList<clang::Decl, clang::Stmt,<br>
clang::NestedNameSpecifier, clang::NestedNameSpecifierLoc,<br>
clang::TypeLoc, clang::QualType>]<br>
   Adaptor<T> operator()(const Matcher<T> &InnerMatcher) const {<br>
              ^<br>
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1043:14:<br>
note:   template argument deduction/substitution failed:<br>
tokenizer.cpp:544:348: note:<br>
‘clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcher<clang::Stmt>,<br>
clang::ast_matchers::internal::BindableMatcher<clang::Stmt> >’ is not<br>
derived from ‘const clang::ast_matchers::internal::Matcher<T>’<br>
 Decl(anything()))))))<br>
).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),<br>
callExpr(unless(hasAncestor(expr())))))).bind("sc<br>
 ------------------------------------------------------------------------------------------------------------------------------<br>
I've built my llvm and clang libraries from the SVN version 3.9.0<br>
using g++ and use g++ 5.3.1 to compile this code  .<br>
is the matcher wrong and clang-query fails to see that(even though it<br>
acts exactly as i intended it to) or it's something else?<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Farzad Sadeghi<br>
_______________________________________________<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/mailman/listinfo/cfe-dev</a><br>
</font></span></blockquote></div><br></div>