Hi revane,

While reading the Core code I saw a few headers missing and some other things,
here are the changes I made:

- some headers were missing in Core for the .cpp files
- some headers were included but not necessary
- the CMakeLists.txt linked support for no apparent reason since it's already
  linked in the two CMakeLists.txt below in the hierarchy
- introduce a variable when looping on the transform instead of using (*I) and
  run clang-format on some lines
- StringRefisation of FileOverrides.h constructors.

http://llvm-reviews.chandlerc.com/D1101

Files:
  cpp11-migrate/AddOverride/AddOverride.cpp
  cpp11-migrate/CMakeLists.txt
  cpp11-migrate/Core/FileOverrides.cpp
  cpp11-migrate/Core/FileOverrides.h
  cpp11-migrate/Core/IncludeExcludeInfo.cpp
  cpp11-migrate/Core/IncludeExcludeInfo.h
  cpp11-migrate/Core/PerfSupport.cpp
  cpp11-migrate/Core/PerfSupport.h
  cpp11-migrate/Core/SyntaxCheck.cpp
  cpp11-migrate/Core/SyntaxCheck.h
  cpp11-migrate/Core/Transform.cpp
  cpp11-migrate/Core/Transform.h
  cpp11-migrate/Core/Transforms.cpp
  cpp11-migrate/Core/Transforms.h
  cpp11-migrate/LoopConvert/LoopConvert.cpp
  cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
  cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.cpp
  cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.h
  cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp
  cpp11-migrate/UseNullptr/UseNullptr.cpp
  cpp11-migrate/tool/Cpp11Migrate.cpp
Index: cpp11-migrate/AddOverride/AddOverride.cpp
===================================================================
--- cpp11-migrate/AddOverride/AddOverride.cpp
+++ cpp11-migrate/AddOverride/AddOverride.cpp
@@ -16,11 +16,8 @@
 #include "AddOverride.h"
 #include "AddOverrideActions.h"
 #include "AddOverrideMatchers.h"
+
 #include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendActions.h"
-#include "clang/Rewrite/Core/Rewriter.h"
-#include "clang/Tooling/Refactoring.h"
-#include "clang/Tooling/Tooling.h"
 
 using clang::ast_matchers::MatchFinder;
 using namespace clang::tooling;
@@ -36,11 +33,8 @@
                                 const CompilationDatabase &Database,
                                 const std::vector<std::string> &SourcePaths) {
   ClangTool AddOverrideTool(Database, SourcePaths);
-
   unsigned AcceptedChanges = 0;
-
   MatchFinder Finder;
-
   AddOverrideFixer Fixer(getReplacements(), AcceptedChanges, DetectMacros,
                          /*Owner=*/ *this);
   Finder.addMatcher(makeCandidateForOverrideAttrMatcher(), &Fixer);
@@ -56,7 +50,6 @@
   }
 
   setAcceptedChanges(AcceptedChanges);
-
   return 0;
 }
 
Index: cpp11-migrate/CMakeLists.txt
===================================================================
--- cpp11-migrate/CMakeLists.txt
+++ cpp11-migrate/CMakeLists.txt
@@ -1,5 +1,3 @@
-set(LLVM_LINK_COMPONENTS support)
-
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 add_subdirectory(tool)
Index: cpp11-migrate/Core/FileOverrides.cpp
===================================================================
--- cpp11-migrate/Core/FileOverrides.cpp
+++ cpp11-migrate/Core/FileOverrides.cpp
@@ -1,4 +1,20 @@
+//===-- Core/FileOverrides.cpp --------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file provides types and functionality for dealing with source
+/// and header file content overrides.
+///
+//===----------------------------------------------------------------------===//
+
 #include "Core/FileOverrides.h"
+
 #include "clang/Basic/SourceManager.h"
 
 void SourceOverrides::applyOverrides(clang::SourceManager &SM) const {
Index: cpp11-migrate/Core/FileOverrides.h
===================================================================
--- cpp11-migrate/Core/FileOverrides.h
+++ cpp11-migrate/Core/FileOverrides.h
@@ -12,9 +12,12 @@
 /// and header file content overrides.
 ///
 //===----------------------------------------------------------------------===//
+
 #ifndef CPP11_MIGRATE_FILE_OVERRIDES_H
 #define CPP11_MIGRATE_FILE_OVERRIDES_H
 
+#include "llvm/ADT/StringRef.h"
+
 #include <map>
 #include <string>
 
@@ -26,7 +29,8 @@
 
 /// \brief Container for storing override information for a single headers.
 struct HeaderOverride {
-  HeaderOverride(const char *FileName) : FileName(FileName) {}
+  HeaderOverride() {}
+  HeaderOverride(llvm::StringRef FileName) : FileName(FileName) {}
 
   std::string FileName;
   std::string FileOverride;
@@ -37,7 +41,7 @@
 
 /// \brief Container storing the file content overrides for a source file.
 struct SourceOverrides {
-  SourceOverrides(const std::string &MainFileName)
+  SourceOverrides(llvm::StringRef MainFileName)
       : MainFileName(MainFileName) {}
 
   /// \brief Convenience function for applying this source's overrides to
Index: cpp11-migrate/Core/IncludeExcludeInfo.cpp
===================================================================
--- cpp11-migrate/Core/IncludeExcludeInfo.cpp
+++ cpp11-migrate/Core/IncludeExcludeInfo.cpp
@@ -1,4 +1,4 @@
-//===-- Core/IncludeExcludeInfo.cpp - IncludeExclude class impl -*- C++ -*-===//
+//===-- Core/IncludeExcludeInfo.cpp - IncludeExclude class impl -----------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief This file provides the implemention of the IncludeExcludeInfo class
+/// \brief This file provides the implementation of the IncludeExcludeInfo class
 /// to handle the include and exclude command line options.
 ///
 //===----------------------------------------------------------------------===//
Index: cpp11-migrate/Core/IncludeExcludeInfo.h
===================================================================
--- cpp11-migrate/Core/IncludeExcludeInfo.h
+++ cpp11-migrate/Core/IncludeExcludeInfo.h
@@ -12,8 +12,9 @@
 /// to handle the include and exclude command line options.
 ///
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
-#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
+
+#ifndef CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
+#define CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/system_error.h"
@@ -48,4 +49,4 @@
   std::vector<std::string> ExcludeList;
 };
 
-#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
+#endif // CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
Index: cpp11-migrate/Core/PerfSupport.cpp
===================================================================
--- cpp11-migrate/Core/PerfSupport.cpp
+++ cpp11-migrate/Core/PerfSupport.cpp
@@ -1,4 +1,4 @@
-//===-- cpp11-migrate/Cpp11Migrate.cpp - Main file C++11 migration tool ---===//
+//===-- Core/PerfSupport.cpp - Perf measurement helpers -------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
Index: cpp11-migrate/Core/PerfSupport.h
===================================================================
--- cpp11-migrate/Core/PerfSupport.h
+++ cpp11-migrate/Core/PerfSupport.h
@@ -1,4 +1,4 @@
-//===-- cpp11-migrate/PerfSupport.h - Perf measurement helpers --*- C++ -*-===//
+//===-- Core/PerfSupport.h - Perf measurement helpers -----------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -16,11 +16,12 @@
 #ifndef CPP11_MIGRATE_PERFSUPPORT_H
 #define CPP11_MIGRATE_PERFSUPPORT_H
 
-#include <map>
-#include <vector>
 #include "Transform.h"
 #include "llvm/ADT/StringRef.h"
 
+#include <map>
+#include <vector>
+
 /// \brief A single piece of performance data: a duration in milliseconds and a
 /// label for that duration.
 struct PerfItem {
Index: cpp11-migrate/Core/SyntaxCheck.cpp
===================================================================
--- cpp11-migrate/Core/SyntaxCheck.cpp
+++ cpp11-migrate/Core/SyntaxCheck.cpp
@@ -1,3 +1,18 @@
+//===-- Core/SyntaxCheck.cpp ----------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file exposes functionaliy for doing a syntax-only check on
+/// files with overridden contents.
+///
+//===----------------------------------------------------------------------===//
+
 #include "SyntaxCheck.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
Index: cpp11-migrate/Core/SyntaxCheck.h
===================================================================
--- cpp11-migrate/Core/SyntaxCheck.h
+++ cpp11-migrate/Core/SyntaxCheck.h
@@ -12,12 +12,14 @@
 /// files with overridden contents.
 ///
 //===----------------------------------------------------------------------===//
+
 #ifndef CPP11_MIGRATE_SYNTAX_CHECK_H
 #define CPP11_MIGRATE_SYNTAX_CHECK_H
 
-#include <vector>
 #include "Core/FileOverrides.h"
 
+#include <vector>
+
 // Forward Declarations
 namespace clang {
 namespace tooling {
Index: cpp11-migrate/Core/Transform.cpp
===================================================================
--- cpp11-migrate/Core/Transform.cpp
+++ cpp11-migrate/Core/Transform.cpp
@@ -1,3 +1,18 @@
+//===-- Core/Transform.cpp - Transform Base Class Def'n -------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file provides the definition for the base Transform class from
+/// which all transforms must subclass.
+///
+//===----------------------------------------------------------------------===//
+
 #include "Core/Transform.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/LangOptions.h"
@@ -69,7 +84,7 @@
 /// FileManager and a DiagnosticsEngine. Transform uses this class to create a
 /// new Rewriter and SourceManager for every translation unit it transforms. A
 /// DiagnosticsEngine doesn't need to be re-created so it's constructed once. A
-/// SourceManager and Rewriter and (re)created as required.
+/// SourceManager and Rewriter are (re)created as required.
 ///
 /// FIXME: The DiagnosticsEngine should really come from somewhere more global.
 /// It shouldn't be re-created once for every transform.
@@ -140,13 +155,12 @@
     // in memory will always be necessary as the source goes down the transform
     // pipeline.
 
-    HeaderOverrides &Headers = Overrides.Headers;
-    HeaderOverrides::iterator HeaderI = Headers.find(Entry->getName());
-    if (HeaderI == Headers.end())
-      HeaderI = Headers.insert(HeaderOverrides::value_type(
-          Entry->getName(), Entry->getName())).first;
+    // Create HeaderOverride if not already existing
+    HeaderOverride &Header = Overrides.Headers[Entry->getName()];
+    if (Header.FileName.empty())
+      Header.FileName = Entry->getName();
 
-    HeaderI->second.FileOverride = ResultBuf;
+    Header.FileOverride = ResultBuf;
   }
 }
 
@@ -169,7 +183,7 @@
   const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc));
   if (!FE)
     return false;
-  
+
   return GlobalOptions.ModifiableHeaders.isFileIncluded(FE->getName());
 }
 
@@ -202,8 +216,7 @@
 
     FileOverrides::iterator I = Overrides->find(CurrentSource);
     if (I == Overrides->end())
-      I = Overrides
-        ->insert(FileOverrides::value_type(CurrentSource, CurrentSource)).first;
+      I = Overrides->insert(std::make_pair(CurrentSource, CurrentSource)).first;
 
     collectResults(RewriterOwner->getRewriter(), I->second);
   }
Index: cpp11-migrate/Core/Transform.h
===================================================================
--- cpp11-migrate/Core/Transform.h
+++ cpp11-migrate/Core/Transform.h
@@ -1,4 +1,4 @@
-//===-- cpp11-migrate/Transform.h - Transform Base Class Def'n --*- C++ -*-===//
+//===-- Core/Transform.h - Transform Base Class Def'n -----------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -8,22 +8,23 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief This file provides the definition for the base Transform class from
+/// \brief This file provides the declaration for the base Transform class from
 /// which all transforms must subclass.
 ///
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
-#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
 
-#include <string>
-#include <vector>
+#ifndef CPP11_MIGRATE_TRANSFORM_H
+#define CPP11_MIGRATE_TRANSFORM_H
+
 #include "Core/IncludeExcludeInfo.h"
 #include "Core/FileOverrides.h"
 #include "clang/Tooling/Refactoring.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Timer.h"
 
+#include <string>
+#include <vector>
 
 /// \brief Description of the riskiness of actions that can be taken by
 /// transforms.
@@ -223,4 +224,4 @@
   unsigned DeferredChanges;
 };
 
-#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
+#endif // CPP11_MIGRATE_TRANSFORM_H
Index: cpp11-migrate/Core/Transforms.cpp
===================================================================
--- cpp11-migrate/Core/Transforms.cpp
+++ cpp11-migrate/Core/Transforms.cpp
@@ -1,4 +1,4 @@
-//===-- cpp11-migrate/Transforms.cpp - class Transforms Impl ----*- C++ -*-===//
+//===-- Core/Transforms.cpp - class Transforms Impl -----------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
Index: cpp11-migrate/Core/Transforms.h
===================================================================
--- cpp11-migrate/Core/Transforms.h
+++ cpp11-migrate/Core/Transforms.h
@@ -1,4 +1,4 @@
-//===-- cpp11-migrate/Transforms.h - class Transforms Def'n -----*- C++ -*-===//
+//===-- Core/Transforms.h - class Transforms Def'n --------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -13,11 +13,13 @@
 /// transformations to the user and applying requested transforms.
 ///
 //===----------------------------------------------------------------------===//
+
 #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
 
 #include "llvm/Support/CommandLine.h"
 #include "llvm/ADT/StringRef.h"
+
 #include <vector>
 
 // Forward declarations
Index: cpp11-migrate/LoopConvert/LoopConvert.cpp
===================================================================
--- cpp11-migrate/LoopConvert/LoopConvert.cpp
+++ cpp11-migrate/LoopConvert/LoopConvert.cpp
@@ -17,7 +17,6 @@
 #include "LoopActions.h"
 #include "LoopMatchers.h"
 #include "clang/Frontend/FrontendActions.h"
-#include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
 
Index: cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
===================================================================
--- cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
+++ cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
@@ -1,4 +1,4 @@
-//===-- ReplaceAutoPtr.cpp ---------- std::auto_ptr replacement -*- C++ -*-===//
+//===-- ReplaceAutoPtr.cpp ---------- std::auto_ptr replacement -----------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -17,9 +17,6 @@
 #include "ReplaceAutoPtrActions.h"
 #include "ReplaceAutoPtrMatchers.h"
 
-#include "clang/Tooling/Refactoring.h"
-#include "clang/Tooling/Tooling.h"
-
 using namespace clang;
 using namespace clang::tooling;
 using namespace clang::ast_matchers;
@@ -29,9 +26,7 @@
                                const CompilationDatabase &Database,
                                const std::vector<std::string> &SourcePaths) {
   ClangTool Tool(Database, SourcePaths);
-
   unsigned AcceptedChanges = 0;
-
   MatchFinder Finder;
   AutoPtrReplacer Replacer(getReplacements(), AcceptedChanges,
                            /*Owner=*/*this);
Index: cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.cpp
===================================================================
--- cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.cpp
+++ cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.cpp
@@ -1,4 +1,4 @@
-//===-- ReplaceAutoPtrActions.cpp --- std::auto_ptr replacement -*- C++ -*-===//
+//===-- ReplaceAutoPtrActions.cpp --- std::auto_ptr replacement -----------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
Index: cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.h
===================================================================
--- cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.h
+++ cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrActions.h
@@ -12,6 +12,7 @@
 /// for the ReplaceAutoPtr transform.
 ///
 //===----------------------------------------------------------------------===//
+
 #ifndef CPP11_MIGRATE_REPLACE_AUTO_PTR_ACTIONS_H
 #define CPP11_MIGRATE_REPLACE_AUTO_PTR_ACTIONS_H
 
Index: cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp
===================================================================
--- cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp
+++ cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp
@@ -1,4 +1,4 @@
-//===-- ReplaceAutoPtrMatchers.cpp - std::auto_ptr replacement -*- C++ -*--===//
+//===-- ReplaceAutoPtrMatchers.cpp - std::auto_ptr replacement ------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
Index: cpp11-migrate/UseNullptr/UseNullptr.cpp
===================================================================
--- cpp11-migrate/UseNullptr/UseNullptr.cpp
+++ cpp11-migrate/UseNullptr/UseNullptr.cpp
@@ -17,7 +17,6 @@
 #include "NullptrActions.h"
 #include "NullptrMatchers.h"
 #include "clang/Frontend/FrontendActions.h"
-#include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
 
Index: cpp11-migrate/tool/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/tool/Cpp11Migrate.cpp
+++ cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -158,25 +158,24 @@
   for (Transforms::const_iterator I = TransformManager.begin(),
                                   E = TransformManager.end();
        I != E; ++I) {
-    if ((*I)->apply(FileStates, OptionsParser.getCompilations(),
-                    OptionsParser.getSourcePathList()) !=
+    Transform *T = *I;
+
+    if (T->apply(FileStates, OptionsParser.getCompilations(),
+                 OptionsParser.getSourcePathList()) !=
         0) {
       // FIXME: Improve ClangTool to not abort if just one file fails.
       return 1;
     }
 
     if (GlobalOptions.EnableTiming)
-      collectSourcePerfData(**I, PerfData);
+      collectSourcePerfData(*T, PerfData);
 
     if (SummaryMode) {
-      llvm::outs() << "Transform: " << (*I)->getName()
-                   << " - Accepted: "
-                   << (*I)->getAcceptedChanges();
-      if ((*I)->getChangesNotMade()) {
-         llvm::outs() << " - Rejected: "
-                      << (*I)->getRejectedChanges()
-                      << " - Deferred: "
-                      << (*I)->getDeferredChanges();
+      llvm::outs() << "Transform: " << T->getName()
+                   << " - Accepted: " << T->getAcceptedChanges();
+      if (T->getChangesNotMade()) {
+        llvm::outs() << " - Rejected: " << T->getRejectedChanges()
+                     << " - Deferred: " << T->getDeferredChanges();
       }
       llvm::outs() << "\n";
     }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to