[clang-tools-extra] r183917 - cpp11-migrate: Add headers to file override information

Edwin Vane edwin.vane at intel.com
Thu Jun 13 10:17:32 PDT 2013


Author: revane
Date: Thu Jun 13 12:17:32 2013
New Revision: 183917

URL: http://llvm.org/viewvc/llvm-project?rev=183917&view=rev
Log:
cpp11-migrate: Add headers to file override information

File override structures now contain per-source overrides for headers.

For now, modified headers are written to disk when the Migrator is done.
This is only temporary behaviour since we can expect headers to be
changed by migrating multiple source files. The changes need to be
merged after all migrations are complete.


Modified:
    clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp
    clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h
    clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp

Modified: clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp?rev=183917&r1=183916&r2=183917&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp Thu Jun 13 12:17:32 2013
@@ -7,4 +7,10 @@ void SourceOverrides::applyOverrides(cla
          "Main source file override should exist!");
   SM.overrideFileContents(FM.getFile(MainFileName),
                           llvm::MemoryBuffer::getMemBuffer(MainFileOverride));
+
+  for (HeaderOverrides::const_iterator I = Headers.begin(),
+       E = Headers.end(); I != E; ++I)
+    SM.overrideFileContents(
+        FM.getFile(I->second.FileName),
+        llvm::MemoryBuffer::getMemBuffer(I->second.FileOverride));
 }

Modified: clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h?rev=183917&r1=183916&r2=183917&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h Thu Jun 13 12:17:32 2013
@@ -24,6 +24,14 @@ class SourceManager;
 class FileManager;
 } // namespace clang
 
+/// \brief Container for storing override information for a single headers.
+struct HeaderOverride {
+  std::string FileName;
+  std::string FileOverride;
+};
+
+/// \brief Container mapping header file names to override information.
+typedef std::map<std::string, HeaderOverride> HeaderOverrides;
 
 /// \brief Container storing the file content overrides for a source file.
 struct SourceOverrides {
@@ -36,6 +44,7 @@ struct SourceOverrides {
 
   std::string MainFileName;
   std::string MainFileOverride;
+  HeaderOverrides Headers;
 };
 
 /// \brief Maps source file names to content override information.

Modified: clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp?rev=183917&r1=183916&r2=183917&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp Thu Jun 13 12:17:32 2013
@@ -179,6 +179,19 @@ int main(int argc, const char **argv) {
     llvm::raw_fd_ostream FileStream(I->first.c_str(), ErrorInfo,
                                     llvm::raw_fd_ostream::F_Binary);
     FileStream << I->second.MainFileOverride;
+
+    // FIXME: The Migrator shouldn't be responsible for writing headers
+    // to disk. Instead, it should write replacement info and another tool
+    // should take all replacement info for a header from possibly many other
+    // migration processes and merge it into a final form. For now, the 
+    // updated header is written to disk for testing purposes.
+    for (HeaderOverrides::const_iterator HeaderI = I->second.Headers.begin(),
+                                         HeaderE = I->second.Headers.end();
+         HeaderI != HeaderE; ++HeaderI) {
+      llvm::raw_fd_ostream HeaderStream(I->first.c_str(), ErrorInfo,
+                                        llvm::raw_fd_ostream::F_Binary);
+      HeaderStream << HeaderI->second.FileOverride;
+    }
   }
 
   // Report execution times.





More information about the cfe-commits mailing list