]> granicus.if.org Git - clang/commitdiff
StringRefify some PCH interfaces.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 00:52:11 +0000 (00:52 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 00:52:11 +0000 (00:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86775 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHReader.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/PCHReader.cpp

index cc8b3a03e3e8b42432137c7185a9cc5faf6ac4a5..f9a31c1e45f9d730cb45f8ae16419f5fae90ccbf 100644 (file)
@@ -29,6 +29,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Bitcode/BitstreamReader.h"
 #include "llvm/System/DataTypes.h"
 #include <deque>
@@ -78,7 +79,7 @@ public:
   /// \brief Receives the target triple.
   ///
   /// \returns true to indicate the target triple is invalid or false otherwise.
-  virtual bool ReadTargetTriple(const std::string &Triple) {
+  virtual bool ReadTargetTriple(llvm::StringRef Triple) {
     return false;
   }
 
@@ -96,8 +97,7 @@ public:
   /// here.
   ///
   /// \returns true to indicate the predefines are invalid or false otherwise.
-  virtual bool ReadPredefinesBuffer(const char *PCHPredef,
-                                    unsigned PCHPredefLen,
+  virtual bool ReadPredefinesBuffer(llvm::StringRef PCHPredef,
                                     FileID PCHBufferID,
                                     std::string &SuggestedPredefines) {
     return false;
@@ -123,9 +123,8 @@ public:
     : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
 
   virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
-  virtual bool ReadTargetTriple(const std::string &Triple);
-  virtual bool ReadPredefinesBuffer(const char *PCHPredef,
-                                    unsigned PCHPredefLen,
+  virtual bool ReadTargetTriple(llvm::StringRef Triple);
+  virtual bool ReadPredefinesBuffer(llvm::StringRef PCHPredef,
                                     FileID PCHBufferID,
                                     std::string &SuggestedPredefines);
   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI);
@@ -444,9 +443,7 @@ private:
   void MaybeAddSystemRootToFilename(std::string &Filename);
 
   PCHReadResult ReadPCHBlock();
-  bool CheckPredefinesBuffer(const char *PCHPredef,
-                             unsigned PCHPredefLen,
-                             FileID PCHBufferID);
+  bool CheckPredefinesBuffer(llvm::StringRef PCHPredef, FileID PCHBufferID);
   bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record);
   PCHReadResult ReadSourceManagerBlock();
   PCHReadResult ReadSLocEntryRecord(unsigned ID);
index c0415bf550f886b0809ffca500c6223071233a35..b5e65589e32334d6fa5d4e15c7c06c3de60a9d75 100644 (file)
@@ -61,13 +61,12 @@ public:
     return false;
   }
 
-  virtual bool ReadTargetTriple(const std::string &Triple) {
+  virtual bool ReadTargetTriple(llvm::StringRef Triple) {
     TargetTriple = Triple;
     return false;
   }
 
-  virtual bool ReadPredefinesBuffer(const char *PCHPredef,
-                                    unsigned PCHPredefLen,
+  virtual bool ReadPredefinesBuffer(llvm::StringRef PCHPredef,
                                     FileID PCHBufferID,
                                     std::string &SuggestedPredefines) {
     Predefines = PCHPredef;
index ce7092753b28989228e0f3a1c208949f11deabe9..5cee9884ceb625aa9214a43b133421d9e54f70f2 100644 (file)
@@ -122,13 +122,13 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
   return false;
 }
 
-bool PCHValidator::ReadTargetTriple(const std::string &Triple) {
-  if (Triple != PP.getTargetInfo().getTriple().getTriple()) {
-    Reader.Diag(diag::warn_pch_target_triple)
-      << Triple << PP.getTargetInfo().getTriple().getTriple();
-    return true;
-  }
-  return false;
+bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) {
+  if (Triple == PP.getTargetInfo().getTriple().str())
+    return false;
+
+  Reader.Diag(diag::warn_pch_target_triple)
+    << Triple << PP.getTargetInfo().getTriple().str();
+  return true;
 }
 
 /// \brief Split the given string into a vector of lines, eliminating
@@ -138,30 +138,25 @@ bool PCHValidator::ReadTargetTriple(const std::string &Triple) {
 /// \param Len the length of Str.
 /// \param KeepEmptyLines true if empty lines should be included
 /// \returns a vector of lines, with the line endings removed
-static std::vector<std::string> splitLines(const char *Str, unsigned Len,
+static std::vector<std::string> splitLines(llvm::StringRef Str,
                                            bool KeepEmptyLines = false) {
   std::vector<std::string> Lines;
-  for (unsigned LineStart = 0; LineStart < Len; ++LineStart) {
+  for (unsigned LineStart = 0; LineStart < Str.size(); ++LineStart) {
     unsigned LineEnd = LineStart;
-    while (LineEnd < Len && Str[LineEnd] != '\n')
+    while (LineEnd < Str.size() && Str[LineEnd] != '\n')
       ++LineEnd;
     if (LineStart != LineEnd || KeepEmptyLines)
-      Lines.push_back(std::string(&Str[LineStart], &Str[LineEnd]));
+      Lines.push_back(Str.slice(LineStart, LineEnd));
     LineStart = LineEnd;
   }
   return Lines;
 }
 
-bool PCHValidator::ReadPredefinesBuffer(const char *PCHPredef,
-                                        unsigned PCHPredefLen,
+bool PCHValidator::ReadPredefinesBuffer(llvm::StringRef PCHPredef,
                                         FileID PCHBufferID,
                                         std::string &SuggestedPredefines) {
-  const char *Predef = PP.getPredefines().c_str();
-  unsigned PredefLen = PP.getPredefines().size();
-
   // If the two predefines buffers compare equal, we're done!
-  if (PredefLen == PCHPredefLen &&
-      strncmp(Predef, PCHPredef, PCHPredefLen) == 0)
+  if (PP.getPredefines() == PCHPredef)
     return false;
 
   SourceManager &SourceMgr = PP.getSourceManager();
@@ -169,8 +164,8 @@ bool PCHValidator::ReadPredefinesBuffer(const char *PCHPredef,
   // The predefines buffers are different. Determine what the
   // differences are, and whether they require us to reject the PCH
   // file.
-  std::vector<std::string> CmdLineLines = splitLines(Predef, PredefLen);
-  std::vector<std::string> PCHLines = splitLines(PCHPredef, PCHPredefLen);
+  std::vector<std::string> CmdLineLines = splitLines(PP.getPredefines());
+  std::vector<std::string> PCHLines = splitLines(PCHPredef);
 
   // Sort both sets of predefined buffer lines, since
   std::sort(CmdLineLines.begin(), CmdLineLines.end());
@@ -231,8 +226,8 @@ bool PCHValidator::ReadPredefinesBuffer(const char *PCHPredef,
           << MacroName;
 
       // Show the definition of this macro within the PCH file.
-      const char *MissingDef = strstr(PCHPredef, Missing.c_str());
-      unsigned Offset = MissingDef - PCHPredef;
+      const char *MissingDef = strstr(PCHPredef.data(), Missing.c_str());
+      unsigned Offset = MissingDef - PCHPredef.data();
       SourceLocation PCHMissingLoc
         = SourceMgr.getLocForStartOfFile(PCHBufferID)
             .getFileLocWithOffset(Offset);
@@ -255,8 +250,8 @@ bool PCHValidator::ReadPredefinesBuffer(const char *PCHPredef,
     }
 
     // Show the definition of this macro within the PCH file.
-    const char *MissingDef = strstr(PCHPredef, Missing.c_str());
-    unsigned Offset = MissingDef - PCHPredef;
+    const char *MissingDef = strstr(PCHPredef.data(), Missing.c_str());
+    unsigned Offset = MissingDef - PCHPredef.data();
     SourceLocation PCHMissingLoc
       = SourceMgr.getLocForStartOfFile(PCHBufferID)
       .getFileLocWithOffset(Offset);
@@ -630,11 +625,10 @@ bool PCHReader::Error(const char *Msg) {
 ///
 /// \returns true if there was a mismatch (in which case the PCH file
 /// should be ignored), or false otherwise.
-bool PCHReader::CheckPredefinesBuffer(const char *PCHPredef,
-                                      unsigned PCHPredefLen,
+bool PCHReader::CheckPredefinesBuffer(llvm::StringRef PCHPredef,
                                       FileID PCHBufferID) {
   if (Listener)
-    return Listener->ReadPredefinesBuffer(PCHPredef, PCHPredefLen, PCHBufferID,
+    return Listener->ReadPredefinesBuffer(PCHPredef, PCHBufferID,
                                           SuggestedPredefines);
   return false;
 }
@@ -1455,7 +1449,7 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
   }
 
   // Check the predefines buffer.
-  if (CheckPredefinesBuffer(PCHPredefines, PCHPredefinesLen,
+  if (CheckPredefinesBuffer(llvm::StringRef(PCHPredefines, PCHPredefinesLen),
                             PCHPredefinesBufferID))
     return IgnorePCH;