[cfe-dev] clang-qurery and compiler reacting differently to a matcher
Piotr Padlewski via cfe-dev
cfe-dev at lists.llvm.org
Sun Jul 3 08:53:03 PDT 2016
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
On Sat, Jul 2, 2016 at 1:35 PM, Farzad Sadeghi <thabogre at gmail.com> wrote:
> do you happen to know where i can see those differences?
>
> On 7/1/16, Piotr Padlewski <prazek at google.com> wrote:
> > 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
> >
> > On Fri, Jul 1, 2016 at 6:15 AM, Farzad Sadeghi via cfe-dev <
> > cfe-dev at lists.llvm.org> wrote:
> >
> >> 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::ArgumentAdaptingMatcherFunc<clang::ast_matchers::internal::ForEachDescendantMatcher>)
> >>
> >>
> (clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcher<clang::Stmt>,
> >> clang::ast_matchers::internal::BindableMatcher<clang::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<class T>
> >>
> >>
> clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
> >> FromTypes, ToTypes>::Adaptor<T>
> >>
> >>
> clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
> >> FromTypes, ToTypes>::operator()(const
> >> clang::ast_matchers::internal::Matcher<From>&) 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<T> operator()(const Matcher<T> &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::Matcher<clang::Stmt>,
> >> clang::ast_matchers::internal::BindableMatcher<clang::Stmt> >’ is not
> >> derived from ‘const clang::ast_matchers::internal::Matcher<T>’
> >> Decl(anything()))))))
> >>
> >>
> ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),
> >> callExpr(unless(hasAncestor(expr())))))).bind("sc
> >>
> >>
> >>
> ------------------------------------------------------------------------------------------------------------------------------
> >> 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?
> >>
> >>
> >>
> >> --
> >> Farzad Sadeghi
> >> _______________________________________________
> >> cfe-dev mailing list
> >> cfe-dev at lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> >>
> >
>
>
> --
> Farzad Sadeghi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160703/0e968b43/attachment.html>
More information about the cfe-dev
mailing list