[cfe-commits] r98630 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/AST/ASTContext.cpp lib/Basic/SourceManager.cpp lib/Frontend/RewriteObjC.cpp lib/Frontend/TextDiagnosticPrinter.cpp lib/Lex/Lexer.cpp lib/Lex/TokenLexer.cpp lib/Rewrite/HTMLRewrite.cpp lib/Rewrite/Rewriter.cpp lib/Sema/SemaChecking.cpp tools/CIndex/CIndex.cpp

Benjamin Kramer benny.kra at googlemail.com
Tue Mar 16 07:14:32 PDT 2010


Author: d0k
Date: Tue Mar 16 09:14:31 2010
New Revision: 98630

URL: http://llvm.org/viewvc/llvm-project?rev=98630&view=rev
Log:
Let SourceManager::getBufferData return StringRef instead of a pair of two const char*.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Frontend/RewriteObjC.cpp
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Lex/TokenLexer.cpp
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
    cfe/trunk/lib/Rewrite/Rewriter.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/tools/CIndex/CIndex.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Mar 16 09:14:31 2010
@@ -457,9 +457,8 @@
   /// 
   /// \param FID The file ID whose contents will be returned.
   /// \param Invalid If non-NULL, will be set true if an error occurred.
-  std::pair<const char*, const char*> getBufferData(FileID FID,
-                                                    bool *Invalid = 0) const;
-  
+  llvm::StringRef getBufferData(FileID FID, bool *Invalid = 0) const;
+
 
   //===--------------------------------------------------------------------===//
   // SourceLocation manipulation methods.

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Mar 16 09:14:31 2010
@@ -428,7 +428,7 @@
   bool Invalid = false;
   const char *BufferStart
     = SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin()), 
-                              &Invalid).first;
+                              &Invalid).data();
   if (Invalid)
     return false;
   
@@ -495,7 +495,7 @@
     = SourceMgr.getDecomposedLoc(DeclStartLoc);
   bool Invalid = false;
   const char *FileBufferStart
-    = SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).first;
+    = SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).data();
   if (Invalid)
     return 0;
   

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Mar 16 09:14:31 2010
@@ -474,8 +474,7 @@
   return false;
 }
 
-std::pair<const char*, const char*>
-SourceManager::getBufferData(FileID FID, bool *Invalid) const {
+llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
   if (Invalid)
     *Invalid = false;
   
@@ -483,10 +482,9 @@
   if (!Buf) {
     if (*Invalid)
       *Invalid = true;
-    const char *FakeText = "";
-    return std::make_pair(FakeText, FakeText + strlen(FakeText));
+    return "";
   }
-  return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
+  return Buf->getBuffer();
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Tue Mar 16 09:14:31 2010
@@ -706,9 +706,9 @@
 
 void RewriteObjC::RewriteInclude() {
   SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID);
-  std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID); 
-  const char *MainBufStart = MainBuf.first;
-  const char *MainBufEnd = MainBuf.second;
+  llvm::StringRef MainBuf = SM->getBufferData(MainFileID);
+  const char *MainBufStart = MainBuf.begin();
+  const char *MainBufEnd = MainBuf.end();
   size_t ImportLen = strlen("import");
 
   // Loop over the whole file, looking for includes.
@@ -731,9 +731,9 @@
 }
 
 void RewriteObjC::RewriteTabs() {
-  std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
-  const char *MainBufStart = MainBuf.first;
-  const char *MainBufEnd = MainBuf.second;
+  llvm::StringRef MainBuf = SM->getBufferData(MainFileID);
+  const char *MainBufStart = MainBuf.begin();
+  const char *MainBufEnd = MainBuf.end();
 
   // Loop over the whole file, looking for tabs.
   for (const char *BufPtr = MainBufStart; BufPtr != MainBufEnd; ++BufPtr) {
@@ -973,7 +973,6 @@
 }
 
 void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
-  std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
   SourceLocation LocStart = PDecl->getLocStart();
 
   // FIXME: handle protocol headers that are declared across multiple lines.

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Tue Mar 16 09:14:31 2010
@@ -331,13 +331,10 @@
 
   // Get information about the buffer it points into.
   bool Invalid = false;
-  std::pair<const char*, const char*> BufferInfo = SM.getBufferData(FID, 
-                                                                    &Invalid);
+  const char *BufStart = SM.getBufferData(FID, &Invalid).data();
   if (Invalid)
     return;
-  
-  const char *BufStart = BufferInfo.first;
-  
+
   unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
   unsigned CaretEndColNo
     = ColNo + Lexer::MeasureTokenLength(Loc, SM, *LangOpts);

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Mar 16 09:14:31 2010
@@ -230,18 +230,17 @@
   Loc = SM.getInstantiationLoc(Loc);
   std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
   bool Invalid = false;
-  std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first,
-                                                                 &Invalid);
+  llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
   if (Invalid)
     return 0;
-  
-  const char *StrData = Buffer.first+LocInfo.second;
+
+  const char *StrData = Buffer.data()+LocInfo.second;
 
   if (isWhitespace(StrData[0]))
     return 0;
 
   // Create a lexer starting at the beginning of this token.
-  Lexer TheLexer(Loc, LangOpts, Buffer.first, StrData, Buffer.second);
+  Lexer TheLexer(Loc, LangOpts, Buffer.begin(), StrData, Buffer.end());
   TheLexer.SetCommentRetentionState(true);
   Token TheTok;
   TheLexer.LexFromRawLexer(TheTok);

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Tue Mar 16 09:14:31 2010
@@ -441,7 +441,7 @@
 
       bool Invalid = false;
       const char *ScratchBufStart
-        = SourceMgr.getBufferData(LocFileID, &Invalid).first;
+        = SourceMgr.getBufferData(LocFileID, &Invalid).data();
       if (Invalid)
         return false;
 

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Mar 16 09:14:31 2010
@@ -44,7 +44,7 @@
   EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
 
   bool Invalid = false;
-  const char *BufferStart = SM.getBufferData(FID, &Invalid).first;
+  const char *BufferStart = SM.getBufferData(FID, &Invalid).data();
   if (Invalid)
     return;
   

Modified: cfe/trunk/lib/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Rewriter.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Tue Mar 16 09:14:31 2010
@@ -165,8 +165,8 @@
     return I->second;
   I = RewriteBuffers.insert(I, std::make_pair(FID, RewriteBuffer()));
 
-  std::pair<const char*, const char*> MB = SourceMgr->getBufferData(FID);
-  I->second.Initialize(MB.first, MB.second);
+  llvm::StringRef MB = SourceMgr->getBufferData(FID);
+  I->second.Initialize(MB.begin(), MB.end());
 
   return I->second;
 }

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 16 09:14:31 2010
@@ -60,12 +60,11 @@
     std::pair<FileID, unsigned> LocInfo =
       SourceMgr.getDecomposedLoc(StrTokSpellingLoc);
     bool Invalid = false;
-    std::pair<const char *,const char *> Buffer =
-      SourceMgr.getBufferData(LocInfo.first, &Invalid);
+    llvm::StringRef Buffer = SourceMgr.getBufferData(LocInfo.first, &Invalid);
     if (Invalid)
       return StrTokSpellingLoc;
       
-    const char *StrData = Buffer.first+LocInfo.second;
+    const char *StrData = Buffer.data()+LocInfo.second;
 
     // Create a langops struct and enable trigraphs.  This is sufficient for
     // relexing tokens.
@@ -73,8 +72,8 @@
     LangOpts.Trigraphs = true;
 
     // Create a lexer starting at the beginning of this token.
-    Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.first, StrData,
-                   Buffer.second);
+    Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.begin(), StrData,
+                   Buffer.end());
     Token TheTok;
     TheLexer.LexFromRawLexer(TheTok);
 

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=98630&r1=98629&r2=98630&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Tue Mar 16 09:14:31 2010
@@ -2044,13 +2044,12 @@
   std::pair<FileID, unsigned> LocInfo
     = CXXUnit->getSourceManager().getDecomposedLoc(Loc);
   bool Invalid = false;
-  std::pair<const char *,const char *> Buffer
+  llvm::StringRef Buffer
     = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
   if (Invalid)
     return createCXString("");
 
-  return createCXString(llvm::StringRef(Buffer.first+LocInfo.second,
-                                        CXTok.int_data[2]));
+  return createCXString(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
 }
 
 CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
@@ -2100,16 +2099,16 @@
 
   // Create a lexer
   bool Invalid = false;
-  std::pair<const char *,const char *> Buffer
+  llvm::StringRef Buffer
     = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
   
   Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
             CXXUnit->getASTContext().getLangOptions(),
-            Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second);
+            Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end());
   Lex.SetCommentRetentionState(true);
 
   // Lex tokens until we hit the end of the range.
-  const char *EffectiveBufferEnd = Buffer.first + EndLocInfo.second;
+  const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second;
   llvm::SmallVector<CXToken, 32> CXTokens;
   Token Tok;
   do {
@@ -2135,12 +2134,12 @@
       std::pair<FileID, unsigned> LocInfo
         = SourceMgr.getDecomposedLoc(Tok.getLocation());
       bool Invalid = false;
-      std::pair<const char *, const char *> Buf
+      llvm::StringRef Buf
         = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
       if (Invalid)
         return;
       
-      const char *StartPos= Buf.first + LocInfo.second;
+      const char *StartPos = Buf.data() + LocInfo.second;
       IdentifierInfo *II
         = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);
       CXTok.int_data[0] = II->getTokenID() == tok::identifier?





More information about the cfe-commits mailing list