njames93 created this revision. njames93 added reviewers: steveire, aaron.ballman. njames93 requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo 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,23 @@ 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); + unsigned OutKind = + LexOrCompleteWord<unsigned>(this, ValStr) + .Case("diag", OK_Diag) + .Case("print", OK_Print) + .Case("detailed-ast", OK_DetailedAST) + .Case("srcloc", OK_SrcLoc, + /*IsCompletion=*/ + tooling::NodeIntrospection::hasIntrospectionSupport()) + .Case("dump", OK_DetailedAST) + .Default(~0u); if (OutKind == ~0u) { return new InvalidQuery( - "expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + - "'"); + "expected 'diag', 'print', 'detailed-ast'" + + StringRef(tooling::NodeIntrospection::hasIntrospectionSupport() + ? ", 'srcloc'" + : "") + + " or 'dump', got '" + ValStr + "'"); } switch (OutKind) { @@ -125,7 +132,9 @@ case OK_Print: return new QueryType(&QuerySession::PrintOutput); case OK_SrcLoc: - return new QueryType(&QuerySession::SrcLocOutput); + if (tooling::NodeIntrospection::hasIntrospectionSupport()) + return new QueryType(&QuerySession::SrcLocOutput); + return new InvalidQuery("'srcloc' output support is not available."); } llvm_unreachable("Invalid output kind");
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,23 @@ 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); + unsigned OutKind = + LexOrCompleteWord<unsigned>(this, ValStr) + .Case("diag", OK_Diag) + .Case("print", OK_Print) + .Case("detailed-ast", OK_DetailedAST) + .Case("srcloc", OK_SrcLoc, + /*IsCompletion=*/ + tooling::NodeIntrospection::hasIntrospectionSupport()) + .Case("dump", OK_DetailedAST) + .Default(~0u); if (OutKind == ~0u) { return new InvalidQuery( - "expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + - "'"); + "expected 'diag', 'print', 'detailed-ast'" + + StringRef(tooling::NodeIntrospection::hasIntrospectionSupport() + ? ", 'srcloc'" + : "") + + " or 'dump', got '" + ValStr + "'"); } switch (OutKind) { @@ -125,7 +132,9 @@ case OK_Print: return new QueryType(&QuerySession::PrintOutput); case OK_SrcLoc: - return new QueryType(&QuerySession::SrcLocOutput); + if (tooling::NodeIntrospection::hasIntrospectionSupport()) + return new QueryType(&QuerySession::SrcLocOutput); + return new InvalidQuery("'srcloc' output support is not available."); } llvm_unreachable("Invalid output kind");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits