etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

Cleanup some code by using appropriate APIs.
Some coding style cleanups.

There is no behavior changes.

http://reviews.llvm.org/D20279

Files:
  clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tidy/utils/HeaderFileExtensionsUtils.cpp
  clang-tidy/utils/HeaderFileExtensionsUtils.h
  clang-tidy/utils/HeaderGuard.cpp
  clang-tidy/utils/IncludeInserter.cpp
  clang-tidy/utils/IncludeInserter.h
  clang-tidy/utils/IncludeSorter.cpp
  clang-tidy/utils/IncludeSorter.h
  clang-tidy/utils/TypeTraits.cpp

Index: clang-tidy/utils/TypeTraits.cpp
===================================================================
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -77,7 +77,8 @@
 }
 
 // Based on QualType::isTrivial.
-bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
+bool isTriviallyDefaultConstructible(QualType Type,
+                                     const ASTContext &Context) {
   if (Type.isNull())
     return false;
 
Index: clang-tidy/utils/IncludeSorter.h
===================================================================
--- clang-tidy/utils/IncludeSorter.h
+++ clang-tidy/utils/IncludeSorter.h
@@ -15,7 +15,7 @@
 
 namespace clang {
 namespace tidy {
-namespace utils {  
+namespace utils {
 
 // Class used by IncludeSorterCallback and IncludeInserterCallback to record the
 // names of the inclusions in a given source file being processed and generate
@@ -66,10 +66,6 @@
 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;
Index: clang-tidy/utils/IncludeSorter.cpp
===================================================================
--- clang-tidy/utils/IncludeSorter.cpp
+++ clang-tidy/utils/IncludeSorter.cpp
@@ -12,7 +12,7 @@
 
 namespace clang {
 namespace tidy {
-namespace utils {  
+namespace utils {
 
 namespace {
 
@@ -254,7 +254,8 @@
       // Otherwise report the current block edit and start a new block.
     } else {
       if (CurrentEndLine) {
-        Fixes.push_back(CreateFixIt(CurrentRange, CurrentText));
+        Fixes.push_back(
+            FixItHint::CreateReplacement(CurrentRange, CurrentText));
       }
 
       CurrentEndLine = LineEdit.first;
@@ -264,25 +265,15 @@
   }
   // Finally, report the current block edit if there is one.
   if (CurrentEndLine) {
-    Fixes.push_back(CreateFixIt(CurrentRange, CurrentText));
+    Fixes.push_back(FixItHint::CreateReplacement(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;
-}
-
 IncludeSorter::IncludeStyle
 IncludeSorter::parseIncludeStyle(const std::string &Value) {
   return Value == "llvm" ? IS_LLVM : IS_Google;
Index: clang-tidy/utils/IncludeInserter.h
===================================================================
--- clang-tidy/utils/IncludeInserter.h
+++ clang-tidy/utils/IncludeInserter.h
@@ -60,8 +60,8 @@
   CreateIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
 
 private:
-  void AddInclude(StringRef file_name, bool IsAngled,
-                  SourceLocation hash_location, SourceLocation end_location);
+  void AddInclude(StringRef FileName, bool IsAngled,
+                  SourceLocation HashLocation, SourceLocation EndLocation);
 
   llvm::DenseMap<FileID, std::unique_ptr<IncludeSorter>> IncludeSorterByFile;
   llvm::DenseMap<FileID, std::set<std::string>> InsertedHeaders;
Index: clang-tidy/utils/IncludeInserter.cpp
===================================================================
--- clang-tidy/utils/IncludeInserter.cpp
+++ clang-tidy/utils/IncludeInserter.cpp
@@ -67,18 +67,18 @@
   return IncludeSorterByFile[FileID]->CreateIncludeInsertion(Header, IsAngled);
 }
 
-void IncludeInserter::AddInclude(StringRef file_name, bool IsAngled,
+void IncludeInserter::AddInclude(StringRef FileName, bool IsAngled,
                                  SourceLocation HashLocation,
-                                 SourceLocation end_location) {
+                                 SourceLocation EndLocation) {
   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);
+  IncludeSorterByFile[FileID]->AddInclude(FileName, IsAngled, HashLocation,
+                                          EndLocation);
 }
 
 } // namespace utils
Index: clang-tidy/utils/HeaderGuard.cpp
===================================================================
--- clang-tidy/utils/HeaderGuard.cpp
+++ clang-tidy/utils/HeaderGuard.cpp
@@ -19,29 +19,16 @@
 namespace utils {
 
 /// \brief canonicalize a path by removing ./ and ../ components.
-// FIXME: Consider moving this to llvm::sys::path.
 static std::string cleanPath(StringRef Path) {
-  SmallString<256> NewPath;
-  for (auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
-       I != E; ++I) {
-    if (*I == ".")
-      continue;
-    if (*I == "..") {
-      // Drop the last component.
-      NewPath.resize(llvm::sys::path::parent_path(NewPath).size());
-    } else {
-      if (!NewPath.empty() && !NewPath.endswith("/"))
-        NewPath += '/';
-      NewPath += *I;
-    }
-  }
-  return NewPath.str();
+  SmallString<256> Result =  Path;
+  llvm::sys::path::remove_dots(Result, true);
+  return Result.str();
 }
 
 namespace {
 class HeaderGuardPPCallbacks : public PPCallbacks {
 public:
-  explicit HeaderGuardPPCallbacks(Preprocessor *PP, HeaderGuardCheck *Check)
+  HeaderGuardPPCallbacks(Preprocessor *PP, HeaderGuardCheck *Check)
       : PP(PP), Check(Check) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
Index: clang-tidy/utils/HeaderFileExtensionsUtils.h
===================================================================
--- clang-tidy/utils/HeaderFileExtensionsUtils.h
+++ clang-tidy/utils/HeaderFileExtensionsUtils.h
@@ -10,13 +10,10 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADER_FILE_EXTENSIONS_UTILS_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADER_FILE_EXTENSIONS_UTILS_H
 
-#include <string>
-
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/SmallSet.h"
-#include "llvm/Support/Path.h"
 
 namespace clang {
 namespace tidy {
Index: clang-tidy/utils/HeaderFileExtensionsUtils.cpp
===================================================================
--- clang-tidy/utils/HeaderFileExtensionsUtils.cpp
+++ clang-tidy/utils/HeaderFileExtensionsUtils.cpp
@@ -9,6 +9,7 @@
 
 #include "HeaderFileExtensionsUtils.h"
 #include "clang/Basic/CharInfo.h"
+#include "llvm/Support/Path.h"
 
 namespace clang {
 namespace tidy {
Index: clang-tidy/utils/DeclRefExprUtils.cpp
===================================================================
--- clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tidy/utils/DeclRefExprUtils.cpp
@@ -15,7 +15,7 @@
 
 namespace clang {
 namespace tidy {
-namespace utils {  
+namespace utils {
 namespace decl_ref_expr {
 
 using namespace ::clang::ast_matchers;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to