[clang-tools-extra] r178104 - Revised to use MemoryBuffer. Removed redundant llvm:: qualifiers. Removed unnecessary c_str() calls. Reformatted with clang-format.

Thompson, John John_Thompson at playstation.sony.com
Wed Mar 27 12:05:13 PDT 2013


Sean,

Sorry about that.

If it's not too late, here's a diff between the current Modularize.cpp with the original run through clang-format, which hopefully shows the more important differences:

--- d:\Clang\llvmmod\tools\clang\tools\extra\modularize\Modularize.cpp          2013-03-26 18:00:23 -0700
+++ OldModularize.cpp                2013-03-27 11:09:32 -0700
@@ -17,10 +17,9 @@
//
// Modularize takes as argument a file name for a file containing the
// newline-separated list of headers to check with respect to each other.
-// Lines beginning with '#' and empty lines are ignored.
// Modularize also accepts regular front-end arguments.
//
-// Usage:   modularize [-prefix (optional header path prefix)]
+// Usage:   modularize [-prefix (optional header path prefix)] \
//   (include-files_list) [(front-end-options) ...]
//
// Note that unless a "-prefex (header path)" option is specified,
@@ -69,9 +68,7 @@
#include "llvm/Config/config.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
-#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Preprocessor.h"
@@ -178,9 +175,9 @@
 typedef std::vector<HeaderEntry> HeaderContents;
-class EntityMap : public StringMap<SmallVector<Entry, 2> > {
+class EntityMap : public llvm::StringMap<llvm::SmallVector<Entry, 2> > {
public:
-  DenseMap<const FileEntry *, HeaderContents> HeaderContentMismatches;
+  llvm::DenseMap<const FileEntry *, HeaderContents> HeaderContentMismatches;
   void add(const std::string &Name, enum Entry::Kind Kind, Location Loc) {
     // Record this entity in its header.
@@ -188,7 +185,7 @@
     CurHeaderContents[Loc.File].push_back(HE);
     // Check whether we've seen this entry before.
-    SmallVector<Entry, 2> &Entries = (*this)[Name];
+    llvm::SmallVector<Entry, 2> &Entries = (*this)[Name];
     for (unsigned I = 0, N = Entries.size(); I != N; ++I) {
       if (Entries[I].Kind == Kind && Entries[I].Loc == Loc)
         return;
@@ -200,7 +197,7 @@
   }
   void mergeCurHeaderContents() {
-    for (DenseMap<const FileEntry *, HeaderContents>::iterator
+    for (llvm::DenseMap<const FileEntry *, HeaderContents>::iterator
              H = CurHeaderContents.begin(),
              HEnd = CurHeaderContents.end();
          H != HEnd; ++H) {
@@ -208,7 +205,7 @@
       std::sort(H->second.begin(), H->second.end());
       // Check whether we've seen this header before.
-      DenseMap<const FileEntry *, HeaderContents>::iterator KnownH =
+      llvm::DenseMap<const FileEntry *, HeaderContents>::iterator KnownH =
           AllHeaderContents.find(H->first);
       if (KnownH == AllHeaderContents.end()) {
         // We haven't seen this header before; record its contents.
@@ -230,8 +227,8 @@
     CurHeaderContents.clear();
   }
private:
-  DenseMap<const FileEntry *, HeaderContents> CurHeaderContents;
-  DenseMap<const FileEntry *, HeaderContents> AllHeaderContents;
+  llvm::DenseMap<const FileEntry *, HeaderContents> CurHeaderContents;
+  llvm::DenseMap<const FileEntry *, HeaderContents> AllHeaderContents;
};
 class CollectEntitiesVisitor :
@@ -376,7 +373,7 @@
   }
   // By default, use the path component of the list file name.
-  SmallString<256> HeaderDirectory(ListFileName);
+  SmallString<256> HeaderDirectory(ListFileName.c_str());
   sys::path::remove_filename(HeaderDirectory);
   // Get the prefix if we have one.
@@ -384,37 +381,33 @@
     HeaderDirectory = HeaderPrefix;
   // Load the list of headers.
-  SmallVector<std::string, 32> Headers;
+  llvm::SmallVector<std::string, 8> Headers;
   {
-    OwningPtr<MemoryBuffer> listBuffer;
-    if (error_code ec = MemoryBuffer::getFile(ListFileName, listBuffer)) {
-      errs() << argv[0] << ": error: Unable to get header list '" << ListFileName
-             << "': " << ec.message() << '\n';
-      return 1;
+    std::ifstream In(ListFileName.c_str());
+    if (!In) {
+      llvm::errs() << "Unable to open header list file \""
+                   << ListFileName.c_str() << "\"\n";
+      return 2;
     }
-    SmallVector<StringRef, 32> strings;
-    listBuffer->getBuffer().split(strings, "\n", -1, false);
-    for (SmallVectorImpl<StringRef>::iterator I = strings.begin(),
-                                              E = strings.end();
-         I != E; ++I) {
-      StringRef line = (*I).trim();
-      if (line.empty() || (line[0] == '#'))
+    std::string Line;
+    while (std::getline(In, Line)) {
+      if (Line.empty() || Line[0] == '#')
         continue;
       SmallString<256> headerFileName;
-      if (sys::path::is_absolute(line))
-        headerFileName = line;
+      if (sys::path::is_absolute(Line))
+        headerFileName = Line;
       else {
         headerFileName = HeaderDirectory;
-        sys::path::append(headerFileName, line);
+        sys::path::append(headerFileName, Line);
       }
-      Headers.push_back(headerFileName.str());
+      Headers.push_back(headerFileName.c_str());
     }
   }
   // Create the compilation database.
   SmallString<256> PathBuf;
-  sys::fs::current_path(PathBuf);
-  OwningPtr<CompilationDatabase> Compilations;
+  llvm::sys::fs::current_path(PathBuf);
+  llvm::OwningPtr<CompilationDatabase> Compilations;
   Compilations.reset(
       new FixedCompilationDatabase(Twine(PathBuf), CC1Arguments));
@@ -447,11 +440,11 @@
         continue;
       }
-      errs() << "error: '" << E->first() << "' defined at both "
-             << Which->File->getName() << ":" << Which->Line << ":"
-             << Which->Column << " and " << E->second[I].Loc.File->getName()
-             << ":" << E->second[I].Loc.Line << ":" << E->second[I].Loc.Column
-             << "\n";
+      llvm::errs()
+          << "error: '" << E->first().str().c_str() << "' defined at both "
+          << Which->File->getName() << ":" << Which->Line << ":"
+          << Which->Column << " and " << E->second[I].Loc.File->getName() << ":"
+          << E->second[I].Loc.Line << ":" << E->second[I].Loc.Column << "\n";
       HadErrors = 1;
     }
   }
@@ -460,22 +453,24 @@
   // they are included.
   // FIXME: Could we provide information about which preprocessor conditionals
   // are involved?
-  for (DenseMap<const FileEntry *, HeaderContents>::iterator
+  for (llvm::DenseMap<const FileEntry *, HeaderContents>::iterator
            H = Entities.HeaderContentMismatches.begin(),
            HEnd = Entities.HeaderContentMismatches.end();
        H != HEnd; ++H) {
     if (H->second.empty()) {
-      errs() << "internal error: phantom header content mismatch\n";
+      llvm::errs() << "internal error: phantom header content mismatch\n";
       continue;
     }
     HadErrors = 1;
-    errs() << "error: header '" << H->first->getName()
-           << "' has different contents dependening on how it was included\n";
+    llvm::errs()
+        << "error: header '" << H->first->getName()
+        << "' has different contents dependening on how it was included\n";
     for (unsigned I = 0, N = H->second.size(); I != N; ++I) {
-      errs() << "note: '" << H->second[I].Name << "' in " << H->second[I]
-          .Loc.File->getName() << " at " << H->second[I].Loc.Line << ":"
-             << H->second[I].Loc.Column << " not always provided\n";
+      llvm::errs() << "note: '" << H->second[I].Name.c_str() << "' in "
+                   << H->second[I].Loc.File->getName() << " at "
+                   << H->second[I].Loc.Line << ":" << H->second[I].Loc.Column
+                   << " not always provided\n";
     }
   }


From: cfe-commits-bounces at cs.uiuc.edu [mailto:cfe-commits-bounces at cs.uiuc.edu] On Behalf Of Sean Silva
Sent: Tuesday, March 26, 2013 6:17 PM
To: John Thompson
Cc: cfe-commits at cs.uiuc.edu
Subject: Re: [clang-tools-extra] r178104 - Revised to use MemoryBuffer. Removed redundant llvm:: qualifiers. Removed unnecessary c_str() calls. Reformatted with clang-format.

On Tue, Mar 26, 2013 at 9:02 PM, John Thompson <John.Thompson.JTSoftware at gmail.com<mailto:John.Thompson.JTSoftware at gmail.com>> wrote:
Author: jtsoftware
Date: Tue Mar 26 20:02:46 2013
New Revision: 178104

URL: http://llvm.org/viewvc/llvm-project?rev=178104&view=rev
Log:
Revised to use MemoryBuffer. Removed redundant llvm:: qualifiers.  Removed unnecessary c_str() calls.  Reformatted with clang-format.

It would be nice to keep these each in a separate commit, especially the reformatting.

-- Sean Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130327/10caefd8/attachment.html>


More information about the cfe-commits mailing list