i have the following ASTMatcher:
`functionDecl(forEachDescendant(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")),
unless(hasDescendant(declRefExpr(to(varDecl(anything()))))))
).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"))).bind("scopeDaddy")`.
it compiles and works fine both after building and running it and also
in clang-query.
i needed to make some changes to it so i wrote this one:
`functionDecl(forEachDescendant(anyOf(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")),
unless(hasDescendant(declRefExpr(to(varDecl(anything()))))))
).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),
callExpr(unless(hasAncestor(expr()))).bind("orphancall")))).bind("scopeDaddy")`
when i run it in clang-query it runs without a problem but when i put
that in my code and try to compile it, the compiler returns this:
CC @klimek @alexfh @djasper
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.
Piotr
For instance I remember that there were some bugs with autocomplition, like no autocomplition for booleanType from Type (but it worked when you typed it), or there was something that clang-query accepted, but it failed at compile time or vice versa.
There was also a problem with hasCastKind, that I have no idea how to pass valid arguments to it in clang-query.
Piotr
i have the following ASTMatcher:
functionDecl(forEachDescendant(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")), unless(hasDescendant(declRefExpr(to(varDecl(anything())))))) ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"))).bind("scopeDaddy")
.
it compiles and works fine both after building and running it and also
in clang-query.
i needed to make some changes to it so i wrote this one:
functionDecl(forEachDescendant(anyOf(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")), unless(hasDescendant(declRefExpr(to(varDecl(anything())))))) ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"), callExpr(unless(hasAncestor(expr()))).bind("orphancall")))).bind("scopeDaddy")
when i run it in clang-query it runs without a problem but when i put
that in my code and try to compile it, the compiler returns this:tokenizer.cpp: In constructor
‘TokenizerASTConsumer::TokenizerASTConsumer(clang::Rewriter&)’:
tokenizer.cpp:544:348: error: no match for call to ‘(const
clang::ast_matchers::internal::ArgumentAdaptingMatcherFuncclang::ast_matchers::internal::ForEachDescendantMatcher)
(clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcherclang::Stmt,
clang::ast_matchers::internal::BindableMatcherclang::Stmt >)’
Decl(anything()))))))
).bind(“callee”)),unless(hasAncestor(binaryOperator())))).bind(“expression”),
callExpr(unless(hasAncestor(expr())))))).bind("sc^
In file included from /usr/local/include/clang/ASTMatchers/ASTMatchers.h:52:0,
from tokenizer.cpp:15:
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1043:14:
note: candidate: template
clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
FromTypes, ToTypes>::Adaptor
clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
FromTypes, ToTypes>::operator()(const
clang::ast_matchers::internal::Matcher&) const [with T = T;
ArgumentAdapterT =
clang::ast_matchers::internal::ForEachDescendantMatcher; FromTypes =
clang::ast_matchers::internal::TypeList<clang::Decl, clang::Stmt,
clang::NestedNameSpecifier, clang::NestedNameSpecifierLoc,
clang::QualType, clang::Type, clang::TypeLoc,
clang::CXXCtorInitializer>; ToTypes =
clang::ast_matchers::internal::TypeList<clang::Decl, clang::Stmt,
clang::NestedNameSpecifier, clang::NestedNameSpecifierLoc,
clang::TypeLoc, clang::QualType>]
Adaptor operator()(const Matcher &InnerMatcher) const {
^
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1043:14:
note: template argument deduction/substitution failed:
tokenizer.cpp:544:348: note:
‘clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcherclang::Stmt,
clang::ast_matchers::internal::BindableMatcherclang::Stmt >’ is not
derived from ‘const clang::ast_matchers::internal::Matcher’
Decl(anything()))))))
).bind(“callee”)),unless(hasAncestor(binaryOperator())))).bind(“expression”),
callExpr(unless(hasAncestor(expr())))))).bind("scI’ve built my llvm and clang libraries from the SVN version 3.9.0
using g++ and use g++ 5.3.1 to compile this code .
is the matcher wrong and clang-query fails to see that(even though it
acts exactly as i intended it to) or it’s something else?
Hrm, for me with clang trunk this matcher compiles just fine.
(cfe-dev back in)
Are you using clang as the compiler?
I’m using g++ and the library built using g++. maybe that’s what’s causing this.
Yea, I’m using a recent enough clang. My system GCC is unfortunately super old (ubuntu LTS). The interesting part would be to reduce it so we can see which compiler has the bug.
(larger list back in, please reply-to all, not just me, thanks!
i just checked the matcher using clang++ and llvm-devel and
clang-devel that i just got from Fedora’s repository (3.7.0.). The
problem is when the four special Narrowing matchers (anyOf, allOf,
anything, unless) are passed as argument toforEachDescendant
.
Previously there were limits with return type deduction, which we do with expression templates that have a templated conversion operator. I think Sam (cc’ed) fixed that at some point. If this doesn’t work with gcc, it’s either a clang or gcc bug. We need to reduce this in a way that doesn’t require the AST matchers.
How can we do that?
I'm new to llvm so I need some tips/hints to be able to help.
How can we do that?
I’m new to llvm so I need some tips/hints to be able to help.
First, I’d try it with a newer GCC - perhaps this was a GCC bug that is already fixed.
I've built my llvm and clang libraries from the SVN version 3.9.0
using g++ and use g++ 5.3.1 to compile this code .
is the matcher wrong and clang-query fails to see that(even though it
acts exactly as i intended it to) or it's something else?
Also, could you please tell me the version of clang you used that
compiled the matcher plus how the libraries you used were built (with
clang or gcc)?
I tried the matcher with clang 3.7.0 (release build) and the libraries
(3.7.0) from fedora's repository and i got the same error.