diff options
author | Julie Hockett <juliehockett@google.com> | 2018-05-09 22:28:18 +0000 |
---|---|---|
committer | Julie Hockett <juliehockett@google.com> | 2018-05-09 22:28:18 +0000 |
commit | 22f9b1e0f683324a9212fecf10931d0565c3f59e (patch) | |
tree | 6f71e5f3112c6cdacafd0c5278f28c24cd3b17dd /clang-tidy/fuchsia | |
parent | 4e77effc3a17c5d8286fc3aa0637a47028dd0dd7 (diff) |
Revert "[clang-tidy] Adding RestrictSystemIncludes check to Fuchsia module"
This reverts commit r331930, which was landed by accident.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@331934 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/fuchsia')
-rw-r--r-- | clang-tidy/fuchsia/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 3 | ||||
-rw-r--r-- | clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp | 126 | ||||
-rw-r--r-- | clang-tidy/fuchsia/RestrictSystemIncludesCheck.h | 46 |
4 files changed, 0 insertions, 176 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 ee00cb21..00000000 --- a/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp +++ /dev/null @@ -1,126 +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 (!llvm::is_contained(Check.getAllowedIncludes(), 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() { - if (IncludeDirectives.empty()) - return; - - 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) { - // Do nothing if there are no restricted includes. - if (AllowedIncludes.empty()) - return; - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique<RestrictedIncludesPPCallbacks>( - *this, Compiler.getSourceManager())); -} - -void RestrictSystemIncludesCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "Includes", - utils::options::serializeStringList(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 07b47cca..00000000 --- a/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h +++ /dev/null @@ -1,46 +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 "../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( - utils::options::parseStringList(Options.get("Includes", ""))) {} - - void registerPPCallbacks(CompilerInstance &Compiler) override; - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; - const std::vector<std::string> &getAllowedIncludes() const { - return AllowedIncludes; - } - -private: - std::vector<std::string> AllowedIncludes; -}; - -} // namespace fuchsia -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H |