diff options
author | Nathan James <n.james93@hotmail.co.uk> | 2021-04-28 11:21:34 +0100 |
---|---|---|
committer | Nathan James <n.james93@hotmail.co.uk> | 2021-04-28 11:21:35 +0100 |
commit | 858a9583e1fed24aa57e5f2769f4117883264ceb (patch) | |
tree | a1321e12d9919616c525b3e76b8579e97a5bcdab /clang-tools-extra/clang-query | |
parent | 3ea4bc78428f34211a9fb6843871803a2ac58183 (diff) | |
download | llvm-858a9583e1fed24aa57e5f2769f4117883264ceb.zip llvm-858a9583e1fed24aa57e5f2769f4117883264ceb.tar.gz llvm-858a9583e1fed24aa57e5f2769f4117883264ceb.tar.bz2 |
[clang-query] Add check to prevent setting srcloc when no introspection is available.
Checks if introspection support is available set output kind parser.
If it isn't present the auto complete will not suggest `srcloc` and an error query will be reported if a user tries to access it.
Reviewed By: steveire
Differential Revision: https://reviews.llvm.org/D101365
Diffstat (limited to 'clang-tools-extra/clang-query')
-rw-r--r-- | clang-tools-extra/clang-query/Query.h | 1 | ||||
-rw-r--r-- | clang-tools-extra/clang-query/QueryParser.cpp | 27 |
2 files changed, 17 insertions, 11 deletions
diff --git a/clang-tools-extra/clang-query/Query.h b/clang-tools-extra/clang-query/Query.h index 38be291..f96bf19 100644 --- a/clang-tools-extra/clang-query/Query.h +++ b/clang-tools-extra/clang-query/Query.h @@ -149,6 +149,7 @@ struct SetExclusiveOutputQuery : Query { QS.DiagOutput = false; QS.DetailedASTOutput = false; QS.PrintOutput = false; + QS.SrcLocOutput = false; QS.*Var = true; return true; } diff --git a/clang-tools-extra/clang-query/QueryParser.cpp b/clang-tools-extra/clang-query/QueryParser.cpp index b444162..b80ad04 100644 --- a/clang-tools-extra/clang-query/QueryParser.cpp +++ b/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 @@ QueryRef QueryParser::parseSetBool(bool QuerySession::*Var) { 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 @@ template <typename QueryType> QueryRef QueryParser::parseSetOutputKind() { 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"); |