[clang-tools-extra] r245052 - [clang-tidy] Move IncludeSorter.* and IncludeInserter.* to clang-tidy/utils/
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 07:31:32 PDT 2015
Author: alexfh
Date: Fri Aug 14 09:31:31 2015
New Revision: 245052
URL: http://llvm.org/viewvc/llvm-project?rev=245052&view=rev
Log:
[clang-tidy] Move IncludeSorter.* and IncludeInserter.* to clang-tidy/utils/
This is better structurally and it also fixes a linker error in the configure
build.
Added:
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
- copied unchanged from r245042, clang-tools-extra/trunk/clang-tidy/IncludeInserter.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h
- copied unchanged from r245042, clang-tools-extra/trunk/clang-tidy/IncludeInserter.h
clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.cpp
- copied unchanged from r245042, clang-tools-extra/trunk/clang-tidy/IncludeSorter.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.h
- copied, changed from r245042, clang-tools-extra/trunk/clang-tidy/IncludeSorter.h
Removed:
clang-tools-extra/trunk/clang-tidy/IncludeInserter.cpp
clang-tools-extra/trunk/clang-tidy/IncludeInserter.h
clang-tools-extra/trunk/clang-tidy/IncludeSorter.cpp
clang-tools-extra/trunk/clang-tidy/IncludeSorter.h
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h
clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp
Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=245052&r1=245051&r2=245052&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Aug 14 09:31:31 2015
@@ -7,8 +7,6 @@ add_clang_library(clangTidy
ClangTidyModule.cpp
ClangTidyDiagnosticConsumer.cpp
ClangTidyOptions.cpp
- IncludeInserter.cpp
- IncludeSorter.cpp
DEPENDS
ClangSACheckers
Removed: clang-tools-extra/trunk/clang-tidy/IncludeInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/IncludeInserter.cpp?rev=245051&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/IncludeInserter.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/IncludeInserter.cpp (removed)
@@ -1,84 +0,0 @@
-//===-------- IncludeInserter.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 "IncludeInserter.h"
-
-namespace clang {
-namespace tidy {
-
-class IncludeInserterCallback : public PPCallbacks {
-public:
- explicit IncludeInserterCallback(IncludeInserter *Inserter)
- : Inserter(Inserter) {}
- // Implements PPCallbacks::InclusionDerective(). Records the names and source
- // locations of the inclusions in the main source file being processed.
- void InclusionDirective(SourceLocation HashLocation,
- const Token & /*include_token*/,
- StringRef FileNameRef, bool IsAngled,
- CharSourceRange FileNameRange,
- const FileEntry * /*IncludedFile*/,
- StringRef /*SearchPath*/, StringRef /*RelativePath*/,
- const Module * /*ImportedModule*/) override {
- Inserter->AddInclude(FileNameRef, IsAngled, HashLocation,
- FileNameRange.getEnd());
- }
-
-private:
- IncludeInserter *Inserter;
-};
-
-IncludeInserter::IncludeInserter(const SourceManager &SourceMgr,
- const LangOptions &LangOpts,
- IncludeSorter::IncludeStyle Style)
- : SourceMgr(SourceMgr), LangOpts(LangOpts), Style(Style) {}
-
-IncludeInserter::~IncludeInserter() {}
-
-std::unique_ptr<PPCallbacks> IncludeInserter::CreatePPCallbacks() {
- return llvm::make_unique<IncludeInserterCallback>(this);
-}
-
-llvm::Optional<FixItHint>
-IncludeInserter::CreateIncludeInsertion(FileID FileID, StringRef Header,
- bool IsAngled) {
- // We assume the same Header will never be included both angled and not
- // angled.
- if (!InsertedHeaders.insert(std::make_pair(FileID, std::set<std::string>()))
- .second) {
- return llvm::None;
- }
- if (IncludeSorterByFile.find(FileID) == IncludeSorterByFile.end()) {
- // This may happen if there have been no preprocessor directives in this
- // file.
- IncludeSorterByFile.insert(std::make_pair(
- FileID,
- llvm::make_unique<IncludeSorter>(
- &SourceMgr, &LangOpts, FileID,
- SourceMgr.getFilename(SourceMgr.getLocForStartOfFile(FileID)),
- Style)));
- }
- return IncludeSorterByFile[FileID]->CreateIncludeInsertion(Header, IsAngled);
-}
-
-void IncludeInserter::AddInclude(StringRef file_name, bool IsAngled,
- SourceLocation HashLocation,
- SourceLocation end_location) {
- FileID FileID = SourceMgr.getFileID(HashLocation);
- if (IncludeSorterByFile.find(FileID) == IncludeSorterByFile.end()) {
- IncludeSorterByFile.insert(std::make_pair(
- FileID, llvm::make_unique<IncludeSorter>(
- &SourceMgr, &LangOpts, FileID,
- SourceMgr.getFilename(HashLocation), Style)));
- }
- IncludeSorterByFile[FileID]->AddInclude(file_name, IsAngled, HashLocation,
- end_location);
-}
-
-} // namespace tidy
-} // namespace clang
Removed: clang-tools-extra/trunk/clang-tidy/IncludeInserter.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/IncludeInserter.h?rev=245051&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/IncludeInserter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/IncludeInserter.h (removed)
@@ -1,75 +0,0 @@
-//===---------- IncludeInserter.h - clang-tidy ----------------------------===//
-//
-// 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_INCLUDEINSERTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
-
-#include "IncludeSorter.h"
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Lex/PPCallbacks.h"
-#include <memory>
-#include <string>
-
-namespace clang {
-namespace tidy {
-
-// IncludeInserter can be used by ClangTidyChecks in the following fashion:
-// class MyCheck : public ClangTidyCheck {
-// public:
-// void registerPPCallbacks(CompilerInstance& Compiler) override {
-// Inserter.reset(new IncludeInserter(&Compiler.getSourceManager(),
-// &Compiler.getLangOpts()));
-// Compiler.getPreprocessor().addPPCallbacks(
-// Inserter->CreatePPCallback());
-// }
-//
-// void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
-//
-// void check(const ast_matchers::MatchFinder::MatchResult& Result) override {
-// ...
-// Inserter->CreateIncludeInsertion(
-// Result.SourceManager->getMainFileID(), "path/to/Header.h",
-// /*IsAngled=*/false);
-// ...
-// }
-//
-// private:
-// std::unique_ptr<IncludeInserter> Inserter;
-// };
-class IncludeInserter {
-public:
- IncludeInserter(const SourceManager &SourceMgr, const LangOptions &LangOpts,
- IncludeSorter::IncludeStyle Style);
- ~IncludeInserter();
-
- // Create PPCallbacks for registration with the compiler's preprocessor.
- std::unique_ptr<PPCallbacks> CreatePPCallbacks();
-
- // Creates a Header inclusion directive fixit. Returns None on error or
- // if inclusion directive already exists.
- llvm::Optional<FixItHint>
- CreateIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
-
-private:
- void AddInclude(StringRef file_name, bool IsAngled,
- SourceLocation hash_location, SourceLocation end_location);
-
- llvm::DenseMap<FileID, std::unique_ptr<IncludeSorter>> IncludeSorterByFile;
- llvm::DenseMap<FileID, std::set<std::string>> InsertedHeaders;
- const SourceManager &SourceMgr;
- const LangOptions &LangOpts;
- const IncludeSorter::IncludeStyle Style;
- friend class IncludeInserterCallback;
-};
-
-} // namespace tidy
-} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
Removed: clang-tools-extra/trunk/clang-tidy/IncludeSorter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/IncludeSorter.cpp?rev=245051&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/IncludeSorter.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/IncludeSorter.cpp (removed)
@@ -1,289 +0,0 @@
-//===---------- IncludeSorter.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 "IncludeSorter.h"
-#include "clang/Lex/Lexer.h"
-
-namespace clang {
-namespace tidy {
-
-namespace {
-
-StringRef RemoveFirstSuffix(StringRef Str, ArrayRef<const char *> Suffixes) {
- for (StringRef Suffix : Suffixes) {
- if (Str.endswith(Suffix)) {
- return Str.substr(0, Str.size() - Suffix.size());
- }
- }
- return Str;
-}
-
-StringRef MakeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) {
- // The list of suffixes to remove from source file names to get the
- // "canonical" file names.
- // E.g. tools/sort_includes.cc and tools/sort_includes_test.cc
- // would both canonicalize to tools/sort_includes and tools/sort_includes.h
- // (once canonicalized) will match as being the main include file associated
- // with the source files.
- if (Style == IncludeSorter::IS_LLVM) {
- return RemoveFirstSuffix(
- RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"Test"});
- }
- return RemoveFirstSuffix(
- RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),
- {"_unittest", "_regtest", "_test"});
-}
-
-// Scan to the end of the line and return the offset of the next line.
-size_t FindNextLine(const char *Text) {
- size_t EOLIndex = std::strcspn(Text, "\n");
- return Text[EOLIndex] == '\0' ? EOLIndex : EOLIndex + 1;
-}
-
-IncludeSorter::IncludeKinds
-DetermineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile,
- bool IsAngled, IncludeSorter::IncludeStyle Style) {
- // Compute the two "canonical" forms of the include's filename sans extension.
- // The first form is the include's filename without ".h" or "-inl.h" at the
- // end. The second form is the first form with "/public/" in the file path
- // replaced by "/internal/".
- if (IsAngled) {
- // If the system include (<foo>) ends with ".h", then it is a normal C-style
- // include. Otherwise assume it is a C++-style extensionless include.
- return IncludeFile.endswith(".h") ? IncludeSorter::IK_CSystemInclude
- : IncludeSorter::IK_CXXSystemInclude;
- }
- StringRef CanonicalInclude = MakeCanonicalName(IncludeFile, Style);
- if (CanonicalFile.equals(CanonicalInclude)) {
- return IncludeSorter::IK_MainTUInclude;
- }
- if (Style == IncludeSorter::IS_Google) {
- std::pair<StringRef, StringRef> Parts = CanonicalInclude.split("/public/");
- std::string AltCanonicalInclude =
- Parts.first.str() + "/internal/" + Parts.second.str();
- std::string ProtoCanonicalInclude =
- Parts.first.str() + "/proto/" + Parts.second.str();
-
- // Determine the kind of this inclusion.
- if (CanonicalFile.equals(AltCanonicalInclude) ||
- CanonicalFile.equals(ProtoCanonicalInclude)) {
- return IncludeSorter::IK_MainTUInclude;
- }
- }
- return IncludeSorter::IK_NonSystemInclude;
-}
-
-} // namespace
-
-IncludeSorter::IncludeSorter(const SourceManager *SourceMgr,
- const LangOptions *LangOpts, const FileID FileID,
- StringRef FileName, IncludeStyle Style)
- : SourceMgr(SourceMgr), LangOpts(LangOpts), Style(Style),
- CurrentFileID(FileID), CanonicalFile(MakeCanonicalName(FileName, Style)) {
-}
-
-void IncludeSorter::AddInclude(StringRef FileName, bool IsAngled,
- SourceLocation HashLocation,
- SourceLocation EndLocation) {
- int Offset = FindNextLine(SourceMgr->getCharacterData(EndLocation));
-
- // Record the relevant location information for this inclusion directive.
- IncludeLocations[FileName].push_back(
- SourceRange(HashLocation, EndLocation.getLocWithOffset(Offset)));
- SourceLocations.push_back(IncludeLocations[FileName].back());
-
- // Stop if this inclusion is a duplicate.
- if (IncludeLocations[FileName].size() > 1)
- return;
-
- // Add the included file's name to the appropriate bucket.
- IncludeKinds Kind =
- DetermineIncludeKind(CanonicalFile, FileName, IsAngled, Style);
- if (Kind != IK_InvalidInclude)
- IncludeBucket[Kind].push_back(FileName.str());
-}
-
-Optional<FixItHint> IncludeSorter::CreateIncludeInsertion(StringRef FileName,
- bool IsAngled) {
- std::string IncludeStmt =
- IsAngled ? llvm::Twine("#include <" + FileName + ">\n").str()
- : llvm::Twine("#include \"" + FileName + "\"\n").str();
- if (SourceLocations.empty()) {
- // If there are no includes in this file, add it in the first line.
- // FIXME: insert after the file comment or the header guard, if present.
- IncludeStmt.append("\n");
- return FixItHint::CreateInsertion(
- SourceMgr->getLocForStartOfFile(CurrentFileID), IncludeStmt);
- }
-
- auto IncludeKind =
- DetermineIncludeKind(CanonicalFile, FileName, IsAngled, Style);
-
- if (!IncludeBucket[IncludeKind].empty()) {
- for (const std::string &IncludeEntry : IncludeBucket[IncludeKind]) {
- if (FileName < IncludeEntry) {
- const auto &Location = IncludeLocations[IncludeEntry][0];
- return FixItHint::CreateInsertion(Location.getBegin(), IncludeStmt);
- } else if (FileName == IncludeEntry) {
- return llvm::None;
- }
- }
- // FileName comes after all include entries in bucket, insert it after
- // last.
- const std::string &LastInclude = IncludeBucket[IncludeKind].back();
- SourceRange LastIncludeLocation = IncludeLocations[LastInclude].back();
- return FixItHint::CreateInsertion(LastIncludeLocation.getEnd(),
- IncludeStmt);
- }
- // Find the non-empty include bucket to be sorted directly above
- // 'IncludeKind'. If such a bucket exists, we'll want to sort the include
- // after that bucket. If no such bucket exists, find the first non-empty
- // include bucket in the file. In that case, we'll want to sort the include
- // before that bucket.
- IncludeKinds NonEmptyKind = IK_InvalidInclude;
- for (int i = IK_InvalidInclude - 1; i >= 0; --i) {
- if (!IncludeBucket[i].empty()) {
- NonEmptyKind = static_cast<IncludeKinds>(i);
- if (NonEmptyKind < IncludeKind)
- break;
- }
- }
- if (NonEmptyKind == IK_InvalidInclude) {
- return llvm::None;
- }
-
- if (NonEmptyKind < IncludeKind) {
- // Create a block after.
- const std::string &LastInclude = IncludeBucket[NonEmptyKind].back();
- SourceRange LastIncludeLocation = IncludeLocations[LastInclude].back();
- IncludeStmt = '\n' + IncludeStmt;
- return FixItHint::CreateInsertion(LastIncludeLocation.getEnd(),
- IncludeStmt);
- }
- // Create a block before.
- const std::string &FirstInclude = IncludeBucket[NonEmptyKind][0];
- SourceRange FirstIncludeLocation = IncludeLocations[FirstInclude].back();
- IncludeStmt.append("\n");
- return FixItHint::CreateInsertion(FirstIncludeLocation.getBegin(),
- IncludeStmt);
-}
-
-std::vector<FixItHint> IncludeSorter::GetEdits() {
- if (SourceLocations.empty())
- return {};
-
- typedef std::map<int, std::pair<SourceRange, std::string>>
- FileLineToSourceEditMap;
- FileLineToSourceEditMap Edits;
- auto SourceLocationIterator = SourceLocations.begin();
- auto SourceLocationIteratorEnd = SourceLocations.end();
-
- // Compute the Edits that need to be done to each line to add, replace, or
- // delete inclusions.
- for (int IncludeKind = 0; IncludeKind < IK_InvalidInclude; ++IncludeKind) {
- std::sort(IncludeBucket[IncludeKind].begin(),
- IncludeBucket[IncludeKind].end(),
- [](const std::string &Left, const std::string &Right) {
- return llvm::StringRef(Left).compare_lower(Right) < 0;
- });
- for (const auto &IncludeEntry : IncludeBucket[IncludeKind]) {
- auto &Location = IncludeLocations[IncludeEntry];
- SourceRangeVector::iterator LocationIterator = Location.begin();
- SourceRangeVector::iterator LocationIteratorEnd = Location.end();
- SourceRange FirstLocation = *LocationIterator;
-
- // If the first occurrence of a particular include is on the current
- // source line we are examining, leave it alone.
- if (FirstLocation == *SourceLocationIterator)
- ++LocationIterator;
-
- // Add the deletion Edits for any (remaining) instances of this inclusion,
- // and remove their Locations from the source Locations to be processed.
- for (; LocationIterator != LocationIteratorEnd; ++LocationIterator) {
- int LineNumber =
- SourceMgr->getSpellingLineNumber(LocationIterator->getBegin());
- Edits[LineNumber] = std::make_pair(*LocationIterator, "");
- SourceLocationIteratorEnd =
- std::remove(SourceLocationIterator, SourceLocationIteratorEnd,
- *LocationIterator);
- }
-
- if (FirstLocation == *SourceLocationIterator) {
- // Do nothing except move to the next source Location (Location of an
- // inclusion in the original, unchanged source file).
- ++SourceLocationIterator;
- continue;
- }
-
- // Add (or append to) the replacement text for this line in source file.
- int LineNumber =
- SourceMgr->getSpellingLineNumber(SourceLocationIterator->getBegin());
- if (Edits.find(LineNumber) == Edits.end()) {
- Edits[LineNumber].first =
- SourceRange(SourceLocationIterator->getBegin());
- }
- StringRef SourceText = Lexer::getSourceText(
- CharSourceRange::getCharRange(FirstLocation), *SourceMgr, *LangOpts);
- Edits[LineNumber].second.append(SourceText.data(), SourceText.size());
- }
-
- // Clear the bucket.
- IncludeBucket[IncludeKind].clear();
- }
-
- // Go through the single-line Edits and combine them into blocks of Edits.
- int CurrentEndLine = 0;
- SourceRange CurrentRange;
- std::string CurrentText;
- std::vector<FixItHint> Fixes;
- for (const auto &LineEdit : Edits) {
- const SourceRange &EditRange = LineEdit.second.first;
- // If the current edit is on the next line after the previous edit, add it
- // to the current block edit.
- if (LineEdit.first == CurrentEndLine + 1 &&
- CurrentRange.getBegin() != CurrentRange.getEnd()) {
- if (EditRange.getBegin() != EditRange.getEnd()) {
- ++CurrentEndLine;
- CurrentRange.setEnd(EditRange.getEnd());
- }
- CurrentText += LineEdit.second.second;
- // Otherwise report the current block edit and start a new block.
- } else {
- if (CurrentEndLine) {
- Fixes.push_back(CreateFixIt(CurrentRange, CurrentText));
- }
-
- CurrentEndLine = LineEdit.first;
- CurrentRange = EditRange;
- CurrentText = LineEdit.second.second;
- }
- }
- // Finally, report the current block edit if there is one.
- if (CurrentEndLine) {
- Fixes.push_back(CreateFixIt(CurrentRange, CurrentText));
- }
-
- // Reset the remaining internal state.
- SourceLocations.clear();
- IncludeLocations.clear();
- return Fixes;
-}
-
-// Creates a fix-it for the given replacements.
-// Takes the the source location that will be replaced, and the new text.
-FixItHint IncludeSorter::CreateFixIt(SourceRange EditRange,
- const std::string &NewText) {
- FixItHint Fix;
- Fix.RemoveRange = CharSourceRange::getCharRange(EditRange);
- Fix.CodeToInsert = NewText;
- return Fix;
-}
-
-} // namespace tidy
-} // namespace clang
Removed: clang-tools-extra/trunk/clang-tidy/IncludeSorter.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/IncludeSorter.h?rev=245051&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/IncludeSorter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/IncludeSorter.h (removed)
@@ -1,82 +0,0 @@
-//===------------ IncludeSorter.h - clang-tidy ----------------------------===//
-//
-// 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_INCLUDESORTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
-
-#include "ClangTidy.h"
-#include <string>
-
-namespace clang {
-namespace tidy {
-
-// Class used by IncludeSorterCallback and IncludeInserterCallback to record the
-// names of the inclusions in a given source file being processed and generate
-// the necessary commands to sort the inclusions according to the precedence
-// enocded in IncludeKinds.
-class IncludeSorter {
-public:
- // Supported include styles.
- enum IncludeStyle { IS_LLVM = 0, IS_Google = 1 };
-
- // The classifications of inclusions, in the order they should be sorted.
- enum IncludeKinds {
- IK_MainTUInclude = 0, // e.g. #include "foo.h" when editing foo.cc
- IK_CSystemInclude = 1, // e.g. #include <stdio.h>
- IK_CXXSystemInclude = 2, // e.g. #include <vector>
- IK_NonSystemInclude = 3, // e.g. #include "bar.h"
- IK_InvalidInclude = 4 // total number of valid IncludeKinds
- };
-
- // IncludeSorter constructor; takes the FileID and name of the file to be
- // processed by the sorter.
- IncludeSorter(const SourceManager *SourceMgr, const LangOptions *LangOpts,
- const FileID FileID, StringRef FileName, IncludeStyle Style);
-
- // Returns the SourceManager-specific file ID for the file being handled by
- // the sorter.
- const FileID current_FileID() const { return CurrentFileID; }
-
- // Adds the given #include to the sorter.
- void AddInclude(StringRef FileName, bool IsAngled,
- SourceLocation HashLocation, SourceLocation EndLocation);
-
- // Returns the edits needed to sort the current set of includes and reset the
- // internal state (so that different blocks of includes are sorted separately
- // within the same file).
- std::vector<FixItHint> GetEdits();
-
- // Creates a quoted inclusion directive in the right sort order. Returns None
- // on error or if header inclusion directive for header already exists.
- Optional<FixItHint> CreateIncludeInsertion(StringRef FileName, bool IsAngled);
-
-private:
- typedef SmallVector<SourceRange, 1> SourceRangeVector;
-
- // Creates a fix-it for the given replacements.
- // Takes the the source location that will be replaced, and the new text.
- FixItHint CreateFixIt(SourceRange EditRange, const std::string &NewText);
-
- const SourceManager *SourceMgr;
- const LangOptions *LangOpts;
- const IncludeStyle Style;
- FileID CurrentFileID;
- // The file name stripped of common suffixes.
- StringRef CanonicalFile;
- // Locations of visited include directives.
- SourceRangeVector SourceLocations;
- // Mapping from file name to #include locations.
- llvm::StringMap<SourceRangeVector> IncludeLocations;
- // Includes sorted into buckets.
- SmallVector<std::string, 1> IncludeBucket[IK_InvalidInclude];
-};
-
-} // namespace tidy
-} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
Modified: clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h?rev=245052&r1=245051&r2=245052&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h Fri Aug 14 09:31:31 2015
@@ -11,7 +11,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASS_BY_VALUE_H
#include "../ClangTidy.h"
-#include "../IncludeInserter.h"
+#include "../utils/IncludeInserter.h"
#include <memory>
Modified: clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt?rev=245052&r1=245051&r2=245052&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt Fri Aug 14 09:31:31 2015
@@ -2,6 +2,8 @@ set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangTidyUtils
HeaderGuard.cpp
+ IncludeInserter.cpp
+ IncludeSorter.cpp
LINK_LIBS
clangAST
Copied: clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.h (from r245042, clang-tools-extra/trunk/clang-tidy/IncludeSorter.h)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.h?p2=clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.h&p1=clang-tools-extra/trunk/clang-tidy/IncludeSorter.h&r1=245042&r2=245052&rev=245052&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/IncludeSorter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.h Fri Aug 14 09:31:31 2015
@@ -10,7 +10,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
-#include "ClangTidy.h"
+#include "../ClangTidy.h"
#include <string>
namespace clang {
Modified: clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp?rev=245052&r1=245051&r2=245052&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp Fri Aug 14 09:31:31 2015
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "../clang-tidy/IncludeInserter.h"
+#include "../clang-tidy/utils/IncludeInserter.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "ClangTidyTest.h"
More information about the cfe-commits
mailing list