[clang-tools-extra] create new clang-tidy check to add namespaces to symbol references (PR #70621)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 30 08:02:17 PDT 2023


================
@@ -0,0 +1,840 @@
+//===--- UseExplicitNamespacesCheck.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 "UseExplicitNamespacesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/Lexer.h"
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+bool isTransparentNamespace(const NamespaceDecl *decl) {
+  return decl->isInline() || decl->isAnonymousNamespace();
+}
+
+std::string getIdentifierString(const IdentifierInfo *identifier) {
+  return (identifier) ? identifier->getNameStart() : "(nullptr)";
+}
+
+std::string getMatchContext(const char *match, const DynTypedNode &node) {
+  std::stringstream out;
+  out << match << "(" << node.getNodeKind().asStringRef().str() << ")";
+  return out.str();
+}
+
+std::string trueFalseString(bool value) { return value ? "true" : "false"; }
+
+UseExplicitNamespacesCheck::UseExplicitNamespacesCheck(
+    StringRef Name, ClangTidyContext *Context)
+    : ClangTidyCheck(Name, Context),
+      limitToPattern(Options.get("LimitToPattern", "")),
+      onlyExpandUsingNamespace(Options.get("OnlyExpandUsingNamespace", true)),
+      diagnosticLevel(Options.get("DiagnosticLevel", 0)) {
+  auto limitString = limitToPattern.str();
----------------
EugeneZelenko wrote:

Please do not use `auto` unless type is explicitly spelled in same statement or iterator. Same in other places.

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


More information about the cfe-commits mailing list