[PATCH] D101365: [clang-query] Add check to prevent setting srcloc when no introspection is available.
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 27 07:18:13 PDT 2021
njames93 updated this revision to Diff 340835.
njames93 added a comment.
Cleanup.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101365/new/
https://reviews.llvm.org/D101365
Files:
clang-tools-extra/clang-query/QueryParser.cpp
Index: clang-tools-extra/clang-query/QueryParser.cpp
===================================================================
--- clang-tools-extra/clang-query/QueryParser.cpp
+++ clang-tools-extra/clang-query/QueryParser.cpp
@@ -11,6 +11,7 @@
#include "QuerySession.h"
#include "clang/ASTMatchers/Dynamic/Parser.h"
#include "clang/Basic/CharInfo.h"
+#include "clang/Tooling/NodeIntrospection.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include <set>
@@ -104,17 +105,19 @@
template <typename QueryType> QueryRef QueryParser::parseSetOutputKind() {
StringRef ValStr;
- unsigned OutKind = LexOrCompleteWord<unsigned>(this, ValStr)
- .Case("diag", OK_Diag)
- .Case("print", OK_Print)
- .Case("detailed-ast", OK_DetailedAST)
- .Case("srcloc", OK_SrcLoc)
- .Case("dump", OK_DetailedAST)
- .Default(~0u);
+ bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
+ unsigned OutKind =
+ LexOrCompleteWord<unsigned>(this, ValStr)
+ .Case("diag", OK_Diag)
+ .Case("print", OK_Print)
+ .Case("detailed-ast", OK_DetailedAST)
+ .Case("srcloc", OK_SrcLoc, /*IsCompletion=*/HasIntrospection)
+ .Case("dump", OK_DetailedAST)
+ .Default(~0u);
if (OutKind == ~0u) {
- return new InvalidQuery(
- "expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr +
- "'");
+ return new InvalidQuery("expected 'diag', 'print', 'detailed-ast'" +
+ StringRef(HasIntrospection ? ", 'srcloc'" : "") +
+ " or 'dump', got '" + ValStr + "'");
}
switch (OutKind) {
@@ -125,7 +128,9 @@
case OK_Print:
return new QueryType(&QuerySession::PrintOutput);
case OK_SrcLoc:
- return new QueryType(&QuerySession::SrcLocOutput);
+ if (HasIntrospection)
+ return new QueryType(&QuerySession::SrcLocOutput);
+ return new InvalidQuery("'srcloc' output support is not available.");
}
llvm_unreachable("Invalid output kind");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101365.340835.patch
Type: text/x-patch
Size: 2167 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210427/4925217b/attachment.bin>
More information about the cfe-commits
mailing list