[PATCH] Introduce clang-query tool.

Manuel Klimek klimek at google.com
Wed Nov 6 09:36:19 PST 2013


On Wed, Nov 6, 2013 at 9:29 AM, Samuel Benzaquen <sbenza at google.com> wrote:

>
>
> ================
> Comment at: clang-query/QueryParser.h:20
> @@ +19,3 @@
> +///
> +/// \return A reference to the parsed query object, which may be an
> +/// \c InvalidQuery if a parse error occurs.
> ----------------
> There should be a comment somewhere specifying the valid commands and
> their syntax.
> It could in the parser, or somewhere in ClangQuery.cpp (possibly printing
> it to the user with a --help option).
>
> ================
> Comment at: clang-query/Query.cpp:55-65
> @@ +54,13 @@
> +    CollectBoundNodes Collect(Matches);
> +    if (Matcher.canConvertTo<Decl>()) {
> +      DeclarationMatcher M = Matcher.convertTo<Decl>();
> +      if (QS.BindRoot)
> +        M = decl(M).bind("root");
> +      Finder.addMatcher(decl(forEachDescendant(M)), &Collect);
> +    } else if (Matcher.canConvertTo<Stmt>()) {
> +      StatementMatcher M = Matcher.convertTo<Stmt>();
> +      if (QS.BindRoot)
> +        M = stmt(M).bind("root");
> +      Finder.addMatcher(decl(forEachDescendant(M)), &Collect);
> +    }
> +    Finder.match(*AST->getASTContext().getTranslationUnitDecl(),
> ----------------
> Manuel Klimek wrote:
> > Yea, we really need addDynamicMatcher ...
> If I remember correctly, I added one, then we decide to remove it again.
> This tool would be the first use case that would require it.
>

Peter said that according to the review history it fell out of a patch
somehow :) I definitely think now is the time to add it, though, anyway :D


>
> ================
> Comment at: clang-query/Query.cpp:58
> @@ +57,3 @@
> +      if (QS.BindRoot)
> +        M = decl(M).bind("root");
> +      Finder.addMatcher(decl(forEachDescendant(M)), &Collect);
> ----------------
> You can bind at the DynTypedMatcher level using
> DynTypedMatcher::tryBind(). No need to do it for every type.
>
> ================
> Comment at: clang-query/Query.cpp:59
> @@ +58,3 @@
> +        M = decl(M).bind("root");
> +      Finder.addMatcher(decl(forEachDescendant(M)), &Collect);
> +    } else if (Matcher.canConvertTo<Stmt>()) {
> ----------------
> What is the purpose of forEachDescendant() here?
> Finder will recursively try to match the provided matchers already.
>
> Doing it this way will match the topmost node if something in it matches,
> instead of returning the actual node that matched.
>
>
> http://llvm-reviews.chandlerc.com/D2098
>
> BRANCH
>   clangquery
>
> ARCANIST PROJECT
>   clang-tools-extra
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131106/37a63ee4/attachment.html>


More information about the cfe-commits mailing list