clang-query is a tool that performs tree pattern matching against a C++ parse tree. As such, it is useful for finding call sites in the condor code. Consider the following problem. We want to find all the places in the source code where vector::reserve is called. We can't just grep for "reserve", as other classes have methods named reserve. In the worst case, there may even be a #define for reserve, further obfuscating the call sites.

Prerequisites include

  1. Installation of clang
  2. Existing of a compile_commands.json file in the root of the condor source tree. Note that cmake can produce this, and the default "configure_uw" script includes the command to generate this as a side-effect of compiling.
  3. An in-source build. I'm sure there's a way to work around this, but I haven't found it.

Given the above, clang-query can find source code matches when run like this

clang-query -f file_with_pattern source_file.cpp

The magic, of course, is in the pattern. Here is an example pattern that finds all calls to "reserve" from the vector class"

let bind-root true
let m1 cxxMemberCallExpr( callee(cxxMethodDecl(hasName("reserve"))), thisPointerType(namedDecl(hasName("vector"))))
m m1

In theory, clang-query can take an arbitrary number of source file arguments, but in my experience, it crashes after some large number, so I feed it files one at a time, grepping them out of the compile_commands.json database, like so

grep '"file":' compile_commands.json  | tr -d '"' | awk '{print $2}' | xargs -n 1 clang-query -f findVectors