================
@@ -0,0 +1,111 @@
+//===--- QueryCheck.cpp - clang-tidy 
--------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "QueryCheck.h"
+#include "../../clang-query/Query.h"
+#include "../../clang-query/QueryParser.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/Dynamic/VariantValue.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include <string>
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::custom {
+
+static SmallVector<ast_matchers::dynamic::DynTypedMatcher>
+parseQuery(const ClangTidyOptions::CustomCheckValue &V,
+           ClangTidyContext *Context) {
+  SmallVector<ast_matchers::dynamic::DynTypedMatcher> Matchers{};
+  clang::query::QuerySession QS({});
+  llvm::StringRef QueryStringRef{V.Query};
+  while (!QueryStringRef.empty()) {
+    query::QueryRef Q = query::QueryParser::parse(QueryStringRef, QS);
+    switch (Q->Kind) {
+    case query::QK_Match: {
+      const auto &MatchQuery = llvm::cast<query::MatchQuery>(*Q);
+      Matchers.push_back(MatchQuery.Matcher);
+      break;
+    }
+    case query::QK_Let: {
+      const auto &LetQuery = llvm::cast<query::LetQuery>(*Q);
+      LetQuery.run(llvm::errs(), QS);
+      break;
+    }
+    case query::QK_Invalid: {
+      const auto &InvalidQuery = llvm::cast<query::InvalidQuery>(*Q);
+      Context->configurationDiag(InvalidQuery.ErrStr, DiagnosticIDs::Error);
----------------
vbvictor wrote:

Could we also dump `QueryStringRef` here if it isn't provided in 
`InvalidQuery.ErrStr`

https://github.com/llvm/llvm-project/pull/131804
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to