[cfe-dev] Using clang-query on the whole project

Kevin Funk kfunk at kde.org
Thu Jun 11 02:24:52 PDT 2015


I've found clang-query to be useful to query single files. Matching the Clang 
AST is easy enough and fast to learn. I don't see how to use clang-query on a 
whole project, though, which would be super useful.

A simple example where it's effectively useless: Assume some header "global.h" 
containing "struct Global {};", every file in the project includes this header.

Now the idiomatic way to run clang-query over all the files in the project:
  clang-query -p $BUILD $(find . -name "*.cpp")

Let's try to find record decls named "Global":
  match recordDecl(hasName("Global"), isDefinition())

=> You get one match per file / translation unit. But in fact, this is not 
really what you want. You want one match here.

So of course this is difficult: clang-query is TU-centric, while for a whole 
project you'd "somehow" want a global view over the source code and not have 
duplicate results for a query like above.

- Is it possible to get clang-query to behave like that?
  - Any research/pointers in that regard?
- Is it possible to filter duplicates in the results without external tools?

Thanks a lot for a great tool so far!

Kevin Funk | kfunk at kde.org | http://kfunk.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150611/03f745c4/attachment.sig>

More information about the cfe-dev mailing list