[clang-tools-extra] [clang-query] Load queries and matchers from file during REPL cycle (PR #90603)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon May 13 05:10:19 PDT 2024


================
@@ -281,5 +282,26 @@ const QueryKind SetQueryKind<bool>::value;
 const QueryKind SetQueryKind<OutputKind>::value;
 #endif
 
+bool FileQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
+  auto Buffer = llvm::MemoryBuffer::getFile(StringRef{File}.trim());
+  if (!Buffer) {
+    if (Prefix.has_value())
+      llvm::errs() << *Prefix << ": ";
+    llvm::errs() << "cannot open " << File << ": "
+                 << Buffer.getError().message() << "\n";
----------------
AaronBallman wrote:

I was thinking of pulling the information from the `ASTUnit` as that's how `MatchQuery` works, but then I realized this suggestion isn't fantastic because there's no source location to emit the diagnostic for. That got me looking at `InvalidQuery` and I see we emit directly to the passed `raw_ostream`, which is `llvm::outs()`.

Curiously, `runCommandsInFile()` emits to `llvm::errs()` instead, so we sometimes emit to the output stream and sometimes to the error stream. I'd say this case can continue to output to the error stream and maybe someday we should make this a bit more consistent across the tool.

https://github.com/llvm/llvm-project/pull/90603


More information about the cfe-commits mailing list