[cfe-commits] r38603 - in /cfe/cfe/trunk: Lex/Lexer.cpp include/clang/Lex/Lexer.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:07 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:07 2007
New Revision: 38603

URL: http://llvm.org/viewvc/llvm-project?rev=38603&view=rev
Log:
Allow the buffer start/end positions to be optionally specified.  Make sure
to use them instead of the current buffer start/end when computing diagnostics.

Modified:
    cfe/cfe/trunk/Lex/Lexer.cpp
    cfe/cfe/trunk/include/clang/Lex/Lexer.h

Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38603&r1=38602&r2=38603&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:23:07 2007
@@ -37,10 +37,12 @@
 
 static void InitCharacterInfo();
 
-Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp)
-  : BufferPtr(File->getBufferStart()), BufferStart(BufferPtr),
-    BufferEnd(File->getBufferEnd()), InputFile(File), CurFileID(fileid), PP(pp),
-    Features(PP.getLangOptions()) {
+Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp,
+             const char *BufStart, const char *BufEnd)
+  : BufferPtr(BufStart ? BufStart : File->getBufferStart()),
+    BufferStart(BufferPtr),
+    BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
+    InputFile(File), CurFileID(fileid), PP(pp), Features(PP.getLangOptions()) {
   InitCharacterInfo();
       
   assert(BufferEnd[0] == 0 &&
@@ -127,9 +129,9 @@
 /// getSourceLocation - Return a source location identifier for the specified
 /// offset in the current file.
 SourceLocation Lexer::getSourceLocation(const char *Loc) const {
-  assert(Loc >= InputFile->getBufferStart() && Loc <= InputFile->getBufferEnd()
-         && "Location out of range for this buffer!");
-  return SourceLocation(CurFileID, Loc-InputFile->getBufferStart());
+  assert(Loc >= BufferStart && Loc <= BufferEnd &&
+         "Location out of range for this buffer!");
+  return SourceLocation(CurFileID, Loc-BufferStart);
 }
 
 

Modified: cfe/cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Lexer.h?rev=38603&r1=38602&r2=38603&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Lexer.h Wed Jul 11 11:23:07 2007
@@ -78,7 +78,8 @@
   /// with the specified preprocessor managing the lexing process.  This lexer
   /// assumes that the specified SourceBuffer and Preprocessor objects will
   /// outlive it, but doesn't take ownership of either pointer.
-  Lexer(const SourceBuffer *InBuffer, unsigned CurFileID, Preprocessor &PP);
+  Lexer(const SourceBuffer *InBuffer, unsigned CurFileID, Preprocessor &PP,
+        const char *BufStart = 0, const char *BufEnd = 0);
   
   /// getFeatures - Return the language features currently enabled.  NOTE: this
   /// lexer modifies features as a file is parsed!





More information about the cfe-commits mailing list