aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/fuchsia
diff options
context:
space:
mode:
authorJulie Hockett <juliehockett@google.com>2018-05-11 20:03:22 +0000
committerJulie Hockett <juliehockett@google.com>2018-05-11 20:03:22 +0000
commit6000066c7923293372d4df503548959719a6bc72 (patch)
treeb5fe8b4592d0c58f856f8b52e55978e7966e46be /clang-tidy/fuchsia
parent1e55d8af75a27352e766873ebff3b39b5b88d109 (diff)
Revert "[clang-tidy] Adding RestrictSystemIncludes check to Fuchsia module"
This reverts commit r332125 for a failing test. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@332131 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/fuchsia')
-rw-r--r--clang-tidy/fuchsia/CMakeLists.txt1
-rw-r--r--clang-tidy/fuchsia/FuchsiaTidyModule.cpp3
-rw-r--r--clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp118
-rw-r--r--clang-tidy/fuchsia/RestrictSystemIncludesCheck.h48
4 files changed, 0 insertions, 170 deletions
diff --git a/clang-tidy/fuchsia/CMakeLists.txt b/clang-tidy/fuchsia/CMakeLists.txt
index b69a5c06..c2ed2524 100644
--- a/clang-tidy/fuchsia/CMakeLists.txt
+++ b/clang-tidy/fuchsia/CMakeLists.txt
@@ -5,7 +5,6 @@ add_clang_library(clangTidyFuchsiaModule
FuchsiaTidyModule.cpp
MultipleInheritanceCheck.cpp
OverloadedOperatorCheck.cpp
- RestrictSystemIncludesCheck.cpp
StaticallyConstructedObjectsCheck.cpp
TrailingReturnCheck.cpp
VirtualInheritanceCheck.cpp
diff --git a/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
index 0d3bbfe7..67b3bc91 100644
--- a/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ b/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -14,7 +14,6 @@
#include "DefaultArgumentsCheck.h"
#include "MultipleInheritanceCheck.h"
#include "OverloadedOperatorCheck.h"
-#include "RestrictSystemIncludesCheck.h"
#include "StaticallyConstructedObjectsCheck.h"
#include "TrailingReturnCheck.h"
#include "VirtualInheritanceCheck.h"
@@ -37,8 +36,6 @@ public:
"fuchsia-multiple-inheritance");
CheckFactories.registerCheck<OverloadedOperatorCheck>(
"fuchsia-overloaded-operator");
- CheckFactories.registerCheck<RestrictSystemIncludesCheck>(
- "fuchsia-restrict-system-includes");
CheckFactories.registerCheck<StaticallyConstructedObjectsCheck>(
"fuchsia-statically-constructed-objects");
CheckFactories.registerCheck<TrailingReturnCheck>(
diff --git a/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp b/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
deleted file mode 100644
index 4817e904..00000000
--- a/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-//===--- RestrictSystemIncludesCheck.cpp - clang-tidy----------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "RestrictSystemIncludesCheck.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Lex/HeaderSearch.h"
-#include "clang/Lex/PPCallbacks.h"
-#include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Path.h"
-#include <cstring>
-
-namespace clang {
-namespace tidy {
-namespace fuchsia {
-
-class RestrictedIncludesPPCallbacks : public PPCallbacks {
-public:
- explicit RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check,
- SourceManager &SM)
- : Check(Check), SM(SM) {}
-
- void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
- StringRef FileName, bool IsAngled,
- CharSourceRange FilenameRange, const FileEntry *File,
- StringRef SearchPath, StringRef RelativePath,
- const Module *Imported,
- SrcMgr::CharacteristicKind FileType) override;
- void EndOfMainFile() override;
-
-private:
- struct IncludeDirective {
- IncludeDirective() = default;
- IncludeDirective(SourceLocation Loc, CharSourceRange Range,
- StringRef Filename, StringRef FullPath, bool IsInMainFile)
- : Loc(Loc), Range(Range), IncludeFile(Filename), IncludePath(FullPath),
- IsInMainFile(IsInMainFile) {}
-
- SourceLocation Loc; // '#' location in the include directive
- CharSourceRange Range; // SourceRange for the file name
- std::string IncludeFile; // Filename as a string
- std::string IncludePath; // Full file path as a string
- bool IsInMainFile; // Whether or not the include is in the main file
- };
-
- using FileIncludes = llvm::SmallVector<IncludeDirective, 8>;
- llvm::SmallDenseMap<FileID, FileIncludes> IncludeDirectives;
-
- RestrictSystemIncludesCheck &Check;
- SourceManager &SM;
-};
-
-void RestrictedIncludesPPCallbacks::InclusionDirective(
- SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
- StringRef SearchPath, StringRef RelativePath, const Module *Imported,
- SrcMgr::CharacteristicKind FileType) {
- if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) {
- SmallString<256> FullPath;
- llvm::sys::path::append(FullPath, SearchPath);
- llvm::sys::path::append(FullPath, RelativePath);
- // Bucket the allowed include directives by the id of the file they were
- // declared in.
- IncludeDirectives[SM.getFileID(HashLoc)].emplace_back(
- HashLoc, FilenameRange, FileName, FullPath.str(),
- SM.isInMainFile(HashLoc));
- }
-}
-
-void RestrictedIncludesPPCallbacks::EndOfMainFile() {
- for (const auto &Bucket : IncludeDirectives) {
- const FileIncludes &FileDirectives = Bucket.second;
-
- // Emit fixits for all restricted includes.
- for (const auto &Include : FileDirectives) {
- // Fetch the length of the include statement from the start to just after
- // the newline, for finding the end (including the newline).
- unsigned ToLen = std::strcspn(SM.getCharacterData(Include.Loc), "\n") + 1;
- CharSourceRange ToRange = CharSourceRange::getCharRange(
- Include.Loc, Include.Loc.getLocWithOffset(ToLen));
-
- if (!Include.IsInMainFile) {
- auto D = Check.diag(
- Include.Loc,
- "system include %0 not allowed, transitively included from %1");
- D << Include.IncludeFile << SM.getFilename(Include.Loc);
- D << FixItHint::CreateRemoval(ToRange);
- continue;
- }
- auto D = Check.diag(Include.Loc, "system include %0 not allowed");
- D << Include.IncludeFile;
- D << FixItHint::CreateRemoval(ToRange);
- }
- }
-}
-
-void RestrictSystemIncludesCheck::registerPPCallbacks(
- CompilerInstance &Compiler) {
- Compiler.getPreprocessor().addPPCallbacks(
- llvm::make_unique<RestrictedIncludesPPCallbacks>(
- *this, Compiler.getSourceManager()));
-}
-
-void RestrictSystemIncludesCheck::storeOptions(
- ClangTidyOptions::OptionMap &Opts) {
- Options.store(Opts, "Includes", AllowedIncludes);
-}
-
-} // namespace fuchsia
-} // namespace tidy
-} // namespace clang
diff --git a/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h b/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
deleted file mode 100644
index d4e5ac1e..00000000
--- a/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
+++ /dev/null
@@ -1,48 +0,0 @@
-//===--- RestrictSystemIncludesCheck.h - clang-tidy---------- ----*- C++-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
-
-#include "../ClangTidy.h"
-#include "../ClangTidyDiagnosticConsumer.h"
-#include "../utils/OptionsUtils.h"
-
-namespace clang {
-namespace tidy {
-namespace fuchsia {
-
-/// Checks for allowed includes and suggests removal of any others. If no
-/// includes are specified, the check will exit without issuing any warnings.
-///
-/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
-class RestrictSystemIncludesCheck : public ClangTidyCheck {
-public:
- RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context),
- AllowedIncludes(Options.get("Includes", "*")),
- AllowedIncludesGlobList(AllowedIncludes) {}
-
- void registerPPCallbacks(CompilerInstance &Compiler) override;
- void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
- bool contains(StringRef FileName) {
- return AllowedIncludesGlobList.contains(FileName);
- }
-
-private:
- std::string AllowedIncludes;
- GlobList AllowedIncludesGlobList;
-};
-
-} // namespace fuchsia
-} // namespace tidy
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H