]> granicus.if.org Git - clang/commitdiff
More simplifications to the lexer ctors.
authorChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 07:56:59 +0000 (07:56 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 07:56:59 +0000 (07:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62419 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Lexer.h
lib/Lex/Lexer.cpp

index bed77b667d828d344b89525c2f0f23e144959d29..ff89e8197d9e341c3e6bb26d08d140c8764fd533 100644 (file)
@@ -77,8 +77,9 @@ public:
   /// with the specified preprocessor managing the lexing process.  This lexer
   /// assumes that the associated file buffer and Preprocessor objects will
   /// outlive it, so it doesn't take ownership of either of them.
+  Lexer(SourceLocation FileLoc, Preprocessor &PP);
   Lexer(SourceLocation FileLoc, Preprocessor &PP,
-        const char *BufStart = 0, const char *BufEnd = 0);
+        const char *BufStart, const char *BufEnd);
   
   /// Lexer constructor - Create a new raw lexer object.  This object is only
   /// suitable for calls to 'LexRawToken'.  This lexer assumes that the text
@@ -310,6 +311,7 @@ private:
   /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize
   /// method.
   char getCharAndSizeSlow(const char *Ptr, unsigned &Size, Token *Tok = 0);
+public:
   
   /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever
   /// emit a warning.
@@ -325,6 +327,7 @@ private:
     Size = 0;
     return getCharAndSizeSlowNoWarn(Ptr, Size, Features);
   }
+private:
   
   /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a
   /// diagnostic.
index c5b36fce613a760481d43d4f9691d7fc34785c83..c379f58b0c6c8c5b5812deb2ddcfc9d2a349416d 100644 (file)
@@ -90,6 +90,28 @@ void Lexer::InitLexer(const char *BufStart, const char *BufPtr,
   ExtendedTokenMode = 0;
 }
 
+/// Lexer constructor - Create a new lexer object for the specified buffer
+/// with the specified preprocessor managing the lexing process.  This lexer
+/// assumes that the associated file buffer and Preprocessor objects will
+/// outlive it, so it doesn't take ownership of either of them.
+Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP)
+// FIXME: This is really horrible and only needed for _Pragma lexers, split this
+// out of the main lexer path!
+: PreprocessorLexer(&PP, 
+                    PP.getSourceManager().getCanonicalFileID(
+                               PP.getSourceManager().getSpellingLoc(fileloc))),
+  FileLoc(fileloc),
+  Features(PP.getLangOptions()) {
+  
+  SourceManager &SourceMgr = PP.getSourceManager();
+  const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(getFileID());
+  
+  InitLexer(InputFile->getBufferStart(), InputFile->getBufferStart(),
+            InputFile->getBufferEnd());
+  
+  // Default to keeping comments if the preprocessor wants them.
+  SetCommentRetentionState(PP.getCommentRetentionState());
+}
 
 /// Lexer constructor - Create a new lexer object for the specified buffer
 /// with the specified preprocessor managing the lexing process.  This lexer
@@ -105,16 +127,8 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP,
                       FileLoc(fileloc),
     Features(PP.getLangOptions()) {
       
-  SourceManager &SourceMgr = PP.getSourceManager();
-  const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(getFileID());
-      
-  // BufferPtr and BufferEnd can start out somewhere inside the current buffer.
-  // If unspecified, they starts at the start/end of the buffer.
-  const char *BufStart = InputFile->getBufferStart();
-  if (BufPtr == 0) BufPtr = BufStart;
-  if (BufEnd == 0) BufEnd = InputFile->getBufferEnd();
-      
-  InitLexer(BufStart, BufPtr, BufEnd);
+  InitLexer(PP.getSourceManager().getBuffer(getFileID())->getBufferStart(),
+            BufPtr, BufEnd);
   
   // Default to keeping comments if the preprocessor wants them.
   SetCommentRetentionState(PP.getCommentRetentionState());