CLANG-QUERY(1)

πŸ“¦
version 15.0.7 Β· 3 versions
, in ubuntu jammy

✨ NAME ✨

okay bestie, gather round πŸ’– this is clang-query β€” the manual page for clang-query 15. she's a little tool that lets you poke at clang's AST and ask it questions, and honestly? iconic behavior. no cap.


πŸŽ€ DESCRIPTION πŸŽ€

so here's the vibe check, fr fr β€” this is how you run her:

USAGE: clang-query [options] <source0> [... <sourceN>]

like. you give her options, you give her source files, she does her thing. periodt. πŸ”₯

below is the full menu of options, no skips, no skimming, we're reading the whole thing together πŸ’…


πŸ’– OPTIONS πŸ’–

Generic Options

these ones are the universal, everybody-gets-them options ✨

  • --help β€” shows you all the available options (and if that's not enough, --help-hidden shows you even more πŸ™ˆ)
  • --help-list β€” shows you a list of all the available options (and yeah, --help-list-hidden gives you the bigger, secret-menu version πŸ‘‘)
  • --version β€” prints out what version of this program you're running, in case you need receipts 🧾

clang-query options

now THIS is the main character section 🌟 the ones that are actually specific to clang-query:

  • -c <command> β€” specify a command to run
  • --extra-arg=<string> β€” an additional argument to append to the compiler command line 🫢
  • --extra-arg-before=<string> β€” an additional argument to prepend to the compiler command line (yes bestie, before the others, order matters ✨)
  • -f <file> β€” read commands from a file
  • -p <string> β€” build path
  • --preload=<file> β€” preload commands from a file and then start interactive mode πŸ¦‹
  • --use-color β€” use colors in the detailed AST output. If it's not set, colors will be used if the terminal connected to standard output supports colors. so like, she checks the vibe of your terminal first πŸ’…

πŸ—‚οΈ about -p <build-path>

-p <build-path> is the thing you use to read a compile command database.

for example, it can be a CMake build directory in which a file named compile_commands.json exists β€” and to get that output you use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option πŸ’–. When no build path is specified, a search for compile_commands.json will be attempted through all parent paths of the first input file. See: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree.

ngl bestie, that link is your bestie too. go read it. 🫢

πŸ“ about <source0> ... <sourceN>

<source0> ... β€” this is where you specify the paths of your source files. these paths get looked up in the compile command database, okay?

here's the tea tho, and it's kinda strict 😭:

  • If the path of a file is absolute, it needs to point into CMake's source tree.
  • If the path is relative, the current working directory needs to be in the CMake source tree, and the file must be in a subdirectory of the current working directory.
  • "./" prefixes in the relative files will be automatically removed β€” cute, she does that for you πŸ’…
  • but the rest of a relative path must be a suffix of a path in the compile command database. no wiggle room, that's just the rules. periodt.

that's the whole page bestie, you ate it πŸ’–

signing off with the receipts: this was clang-query 15, dated July 2023, and the manual page is officially known as CLANG-QUERY(1) πŸŽ€βœ¨ love u, go query some ASTs 🌸

πŸ“¦ where this page comes from