[cfe-commits] r135769 - in /cfe/trunk: include/clang/Serialization/ASTReader.h include/clang/Serialization/ASTWriter.h lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendActions.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp lib/Serialization/ChainedIncludesSource.cpp lib/Serialization/GeneratePCH.cpp

Douglas Gregor dgregor at apple.com
Fri Jul 22 09:35:34 PDT 2011


Author: dgregor
Date: Fri Jul 22 11:35:34 2011
New Revision: 135769

URL: http://llvm.org/viewvc/llvm-project?rev=135769&view=rev
Log:
Switch all of the "isysroot" const char*'s throughout the AST reader
and writer to StringRef or std::string, as appropriate.

Modified:
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/include/clang/Serialization/ASTWriter.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp
    cfe/trunk/lib/Serialization/GeneratePCH.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Jul 22 11:35:34 2011
@@ -765,7 +765,7 @@
 
   /// \brief The system include root to be used when loading the
   /// precompiled header.
-  const char *isysroot;
+  std::string isysroot;
 
   /// \brief Whether to disable the normal validation performed on precompiled
   /// headers when they are loaded.
@@ -977,7 +977,7 @@
   /// help when an AST file is being used in cases where the
   /// underlying files in the file system may have changed, but
   /// parsing should still continue.
-  ASTReader(Preprocessor &PP, ASTContext *Context, const char *isysroot = 0,
+  ASTReader(Preprocessor &PP, ASTContext *Context, StringRef isysroot = "",
             bool DisableValidation = false, bool DisableStatCache = false);
 
   /// \brief Load the AST file without using any pre-initialized Preprocessor.
@@ -1006,7 +1006,7 @@
   /// underlying files in the file system may have changed, but
   /// parsing should still continue.
   ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
-            Diagnostic &Diags, const char *isysroot = 0,
+            Diagnostic &Diags, StringRef isysroot = "",
             bool DisableValidation = false, bool DisableStatCache = false);
   ~ASTReader();
 

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Fri Jul 22 11:35:34 2011
@@ -312,15 +312,15 @@
   void WriteSubStmt(Stmt *S);
 
   void WriteBlockInfoBlock();
-  void WriteMetadata(ASTContext &Context, const char *isysroot,
+  void WriteMetadata(ASTContext &Context, StringRef isysroot,
                      const std::string &OutputFile);
   void WriteLanguageOptions(const LangOptions &LangOpts);
   void WriteStatCache(MemorizeStatCalls &StatCalls);
   void WriteSourceManagerBlock(SourceManager &SourceMgr,
                                const Preprocessor &PP,
-                               const char* isysroot);
+                               StringRef isysroot);
   void WritePreprocessor(const Preprocessor &PP);
-  void WriteHeaderSearch(HeaderSearch &HS, const char* isysroot);
+  void WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot);
   void WritePreprocessorDetail(PreprocessingRecord &PPRec);
   void WritePragmaDiagnosticMappings(const Diagnostic &Diag);
   void WriteCXXBaseSpecifiersOffsets();
@@ -356,9 +356,9 @@
   void WriteDecl(ASTContext &Context, Decl *D);
 
   void WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
-                    const char* isysroot, const std::string &OutputFile);
+                    StringRef isysroot, const std::string &OutputFile);
   void WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
-                     const char* isysroot);
+                     StringRef isysroot);
   
 public:
   /// \brief Create a new precompiled header writer that outputs to
@@ -379,14 +379,11 @@
   /// \param StatCalls the object that cached all of the stat() calls made while
   /// searching for source files and headers.
   ///
-  /// \param isysroot if non-NULL, write a relocatable PCH file whose headers
+  /// \param isysroot if non-empty, write a relocatable PCH file whose headers
   /// are relative to the given system root.
-  ///
-  /// \param PPRec Record of the preprocessing actions that occurred while
-  /// preprocessing this file, e.g., macro expansions
   void WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
                 const std::string &OutputFile,
-                const char* isysroot);
+                StringRef isysroot);
 
   /// \brief Emit a source location.
   void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record);
@@ -616,7 +613,7 @@
 class PCHGenerator : public SemaConsumer {
   const Preprocessor &PP;
   std::string OutputFile;
-  const char *isysroot;
+  std::string isysroot;
   raw_ostream *Out;
   Sema *SemaPtr;
   MemorizeStatCalls *StatCalls; // owned by the FileManager
@@ -630,8 +627,8 @@
   const ASTWriter &getWriter() const { return Writer; }
 
 public:
-  PCHGenerator(const Preprocessor &PP, const std::string &OutputFile, bool Chaining,
-               const char *isysroot, raw_ostream *Out);
+  PCHGenerator(const Preprocessor &PP, const std::string &OutputFile, 
+               bool Chaining, StringRef isysroot, raw_ostream *Out);
   ~PCHGenerator();
   virtual void InitializeSema(Sema &S) { SemaPtr = &S; }
   virtual void HandleTranslationUnit(ASTContext &Ctx);

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Jul 22 11:35:34 2011
@@ -778,7 +778,7 @@
 public:
   PrecompilePreambleConsumer(ASTUnit &Unit,
                              const Preprocessor &PP, bool Chaining,
-                             const char *isysroot, llvm::raw_ostream *Out)
+                             StringRef isysroot, llvm::raw_ostream *Out)
     : PCHGenerator(PP, "", Chaining, isysroot, Out), Unit(Unit),
       Hash(Unit.getCurrentTopLevelHashValue()) {
     Hash = 0;
@@ -838,12 +838,13 @@
                                                        OS, Chaining))
       return 0;
     
-    const char *isysroot = CI.getFrontendOpts().RelocatablePCH ?
-                             Sysroot.c_str() : 0;  
+    if (!CI.getFrontendOpts().RelocatablePCH)
+      Sysroot.clear();
+
     CI.getPreprocessor().addPPCallbacks(
      new MacroDefinitionTrackerPPCallbacks(Unit.getCurrentTopLevelHashValue()));
     return new PrecompilePreambleConsumer(Unit, CI.getPreprocessor(), Chaining,
-                                          isysroot, OS);
+                                          Sysroot, OS);
   }
 
   virtual bool hasCodeCompletionSupport() const { return false; }
@@ -2347,7 +2348,7 @@
   std::vector<unsigned char> Buffer;
   llvm::BitstreamWriter Stream(Buffer);
   ASTWriter Writer(Stream);
-  Writer.WriteAST(getSema(), 0, std::string(), 0);
+  Writer.WriteAST(getSema(), 0, std::string(), "");
   
   // Write the generated bitstream to "Out".
   if (!Buffer.empty())

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Jul 22 11:35:34 2011
@@ -290,7 +290,7 @@
                                              bool Preamble) {
   llvm::OwningPtr<ASTReader> Reader;
   Reader.reset(new ASTReader(PP, &Context,
-                             Sysroot.empty() ? 0 : Sysroot.c_str(),
+                             Sysroot.empty() ? "" : Sysroot.c_str(),
                              DisablePCHValidation, DisableStatCache));
 
   Reader->setDeserializationListener(

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Jul 22 11:35:34 2011
@@ -82,9 +82,10 @@
   if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS, Chaining))
     return 0;
 
-  const char *isysroot = CI.getFrontendOpts().RelocatablePCH ?
-                             Sysroot.c_str() : 0;  
-  return new PCHGenerator(CI.getPreprocessor(), OutputFile, Chaining, isysroot, OS);
+  if (!CI.getFrontendOpts().RelocatablePCH)
+    Sysroot.clear();
+  return new PCHGenerator(CI.getPreprocessor(), OutputFile, Chaining, Sysroot,
+                          OS);
 }
 
 bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI,

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Jul 22 11:35:34 2011
@@ -1858,17 +1858,17 @@
   if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
     return;
 
-  if (isysroot == 0) {
+  if (isysroot.empty()) {
     // If no system root was given, default to '/'
     Filename.insert(Filename.begin(), '/');
     return;
   }
 
-  unsigned Length = strlen(isysroot);
+  unsigned Length = isysroot.size();
   if (isysroot[Length - 1] != '/')
     Filename.insert(Filename.begin(), '/');
 
-  Filename.insert(Filename.begin(), isysroot, isysroot + Length);
+  Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end());
 }
 
 ASTReader::ASTReadResult
@@ -5265,7 +5265,7 @@
 }
 
 ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
-                     const char *isysroot, bool DisableValidation,
+                     StringRef isysroot, bool DisableValidation,
                      bool DisableStatCache)
   : Listener(new PCHValidator(PP, *this)), DeserializationListener(0),
     SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
@@ -5286,7 +5286,7 @@
 }
 
 ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
-                     Diagnostic &Diags, const char *isysroot,
+                     Diagnostic &Diags, StringRef isysroot,
                      bool DisableValidation, bool DisableStatCache)
   : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr),
     Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), FirstInSource(0),

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Jul 22 11:35:34 2011
@@ -917,15 +917,15 @@
 /// \returns either the original filename (if it needs no adjustment) or the
 /// adjusted filename (which points into the @p Filename parameter).
 static const char *
-adjustFilenameForRelocatablePCH(const char *Filename, const char *isysroot) {
+adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) {
   assert(Filename && "No file name to adjust?");
 
-  if (!isysroot)
+  if (isysroot.empty())
     return Filename;
 
   // Verify that the filename and the system root have the same prefix.
   unsigned Pos = 0;
-  for (; Filename[Pos] && isysroot[Pos]; ++Pos)
+  for (; Filename[Pos] && Pos < isysroot.size(); ++Pos)
     if (Filename[Pos] != isysroot[Pos])
       return Filename; // Prefixes don't match.
 
@@ -943,7 +943,7 @@
 }
 
 /// \brief Write the AST metadata (e.g., i686-apple-darwin9).
-void ASTWriter::WriteMetadata(ASTContext &Context, const char *isysroot,
+void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot,
                               const std::string &OutputFile) {
   using namespace llvm;
 
@@ -967,7 +967,7 @@
   Record.push_back(VERSION_MINOR);
   Record.push_back(CLANG_VERSION_MAJOR);
   Record.push_back(CLANG_VERSION_MINOR);
-  Record.push_back(isysroot != 0);
+  Record.push_back(!isysroot.empty());
   // FIXME: This writes the absolute path for chained headers.
   const std::string &BlobStr = Chain ? Chain->getFileName() : Target.getTriple().getTriple();
   Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, BlobStr);
@@ -1329,7 +1329,7 @@
 /// \param HS The header search structure to save.
 ///
 /// \param Chain Whether we're creating a chained AST file.
-void ASTWriter::WriteHeaderSearch(HeaderSearch &HS, const char* isysroot) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot) {
   llvm::SmallVector<const FileEntry *, 16> FilesByUID;
   HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
   
@@ -1405,7 +1405,7 @@
 /// the files in the AST.
 void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
                                         const Preprocessor &PP,
-                                        const char *isysroot) {
+                                        StringRef isysroot) {
   RecordData Record;
 
   // Enter the source manager block.
@@ -2767,7 +2767,7 @@
 
 void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
                          const std::string &OutputFile,
-                         const char *isysroot) {
+                         StringRef isysroot) {
   // Emit the file header.
   Stream.Emit((unsigned)'C', 8);
   Stream.Emit((unsigned)'P', 8);
@@ -2783,7 +2783,7 @@
 }
 
 void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
-                             const char *isysroot,
+                             StringRef isysroot,
                              const std::string &OutputFile) {
   using namespace llvm;
 
@@ -2908,7 +2908,7 @@
   Stream.EnterSubblock(AST_BLOCK_ID, 5);
   WriteMetadata(Context, isysroot, OutputFile);
   WriteLanguageOptions(Context.getLangOptions());
-  if (StatCalls && !isysroot)
+  if (StatCalls && isysroot.empty())
     WriteStatCache(*StatCalls);
   WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
   // Write the record of special types.
@@ -3027,7 +3027,7 @@
 }
 
 void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
-                              const char *isysroot) {
+                              StringRef isysroot) {
   using namespace llvm;
 
   ASTContext &Context = SemaRef.Context;
@@ -3036,7 +3036,7 @@
   RecordData Record;
   Stream.EnterSubblock(AST_BLOCK_ID, 5);
   WriteMetadata(Context, isysroot, "");
-  if (StatCalls && !isysroot)
+  if (StatCalls && isysroot.empty())
     WriteStatCache(*StatCalls);
   // FIXME: Source manager block should only write new stuff, which could be
   // done by tracking the largest ID in the chain

Modified: cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp (original)
+++ cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp Fri Jul 22 11:35:34 2011
@@ -32,7 +32,7 @@
                              ASTDeserializationListener *deserialListener = 0) {
   Preprocessor &PP = CI.getPreprocessor();
   llvm::OwningPtr<ASTReader> Reader;
-  Reader.reset(new ASTReader(PP, &CI.getASTContext(), /*isysroot=*/0,
+  Reader.reset(new ASTReader(PP, &CI.getASTContext(), /*isysroot=*/"",
                              /*DisableValidation=*/true));
   Reader->setASTMemoryBuffers(memBufs, numBufs);
   Reader->setDeserializationListener(deserialListener);
@@ -103,7 +103,7 @@
     llvm::OwningPtr<ASTConsumer> consumer;
     consumer.reset(new PCHGenerator(Clang->getPreprocessor(), "-",
                                     /*Chaining=*/!firstInclude,
-                                    /*isysroot=*/0, &OS));
+                                    /*isysroot=*/"", &OS));
     Clang->getASTContext().setASTMutationListener(
                                             consumer->GetASTMutationListener());
     Clang->setASTConsumer(consumer.take());

Modified: cfe/trunk/lib/Serialization/GeneratePCH.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GeneratePCH.cpp?rev=135769&r1=135768&r2=135769&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/GeneratePCH.cpp (original)
+++ cfe/trunk/lib/Serialization/GeneratePCH.cpp Fri Jul 22 11:35:34 2011
@@ -23,18 +23,16 @@
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include "llvm/Support/raw_ostream.h"
 #include <string>
-#include <string.h>
-#include <stdlib.h>
 
 using namespace clang;
 
 PCHGenerator::PCHGenerator(const Preprocessor &PP,
                            const std::string &OutputFile,
                            bool Chaining,
-                           const char *isysroot,
+                           StringRef isysroot,
                            llvm::raw_ostream *OS)
-  : PP(PP), OutputFile(OutputFile), isysroot(0), Out(OS), SemaPtr(0),
-    StatCalls(0), Stream(Buffer), Writer(Stream), Chaining(Chaining) {
+  : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()), Out(OS), 
+    SemaPtr(0), StatCalls(0), Stream(Buffer), Writer(Stream), Chaining(Chaining) {
   // Install a stat() listener to keep track of all of the stat()
   // calls.
   StatCalls = new MemorizeStatCalls();
@@ -42,13 +40,9 @@
   // *after* the already installed ASTReader's stat cache.
   PP.getFileManager().addStatCache(StatCalls,
     /*AtBeginning=*/!Chaining);
-      
-  if (isysroot)
-    this->isysroot = strdup(isysroot);
 }
 
 PCHGenerator::~PCHGenerator() {
-  free((void*)isysroot);
 }
 
 void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {





More information about the cfe-commits mailing list