]> granicus.if.org Git - clang/commitdiff
simplify the lexer ctor to take a SLoc instead of a sloc and a redundant buffer*.
authorChris Lattner <sabre@nondot.org>
Fri, 20 Jul 2007 16:52:03 +0000 (16:52 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Jul 2007 16:52:03 +0000 (16:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40104 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/TextDiagnosticPrinter.cpp
Lex/Lexer.cpp
Lex/MacroExpander.cpp
Lex/Pragma.cpp
Lex/Preprocessor.cpp
include/clang/Lex/Lexer.h

index f37732c24165ab4d07030a61bb39d32056cd5405..87f33741b0856dfddabd002c2df2b8b2c68c74df 100644 (file)
@@ -108,15 +108,11 @@ unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
   // TODO: this could be special cased for common tokens like identifiers, ')',
   // etc to make this faster, if it mattered.  This could use 
   // Lexer::isObviouslySimpleCharacter for example.
-  unsigned FileID = Loc.getFileID();
   
   // Create a lexer starting at the beginning of this token.
-  Lexer TheLexer(SourceMgr.getBuffer(FileID), Loc,
-                 *ThePreprocessor, StrData);
-  
+  Lexer TheLexer(Loc, *ThePreprocessor, StrData);
   LexerToken TheTok;
   TheLexer.LexRawToken(TheTok);
-
   return TheTok.getLength();
 }
 
index a1db060c3e6886b8e14e7e4cad33387c7041495a..4efd62113d4f75dbf0d832e89a2408a9e6549fd3 100644 (file)
@@ -34,20 +34,24 @@ using namespace clang;
 
 static void InitCharacterInfo();
 
-Lexer::Lexer(const llvm::MemoryBuffer *File, SourceLocation fileloc,
-             Preprocessor &pp, const char *BufStart, const char *BufEnd)
-  : BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
-    InputFile(File), FileLoc(fileloc), PP(pp), Features(PP.getLangOptions()) {
+Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp,
+             const char *BufStart, const char *BufEnd)
+  : FileLoc(fileloc), PP(pp), Features(PP.getLangOptions()) {
+      
+  SourceManager &SourceMgr = PP.getSourceManager();
+  InputFile =SourceMgr.getBuffer(SourceMgr.getPhysicalLoc(FileLoc).getFileID());
+      
   Is_PragmaLexer = false;
   IsMainFile = false;
   InitCharacterInfo();
       
+  BufferPtr = BufStart ? BufStart : InputFile->getBufferStart();
+  BufferEnd = BufEnd ? BufEnd : InputFile->getBufferEnd();
+
   assert(BufferEnd[0] == 0 &&
          "We assume that the input buffer has a null character at the end"
          " to simplify lexing!");
-    
-  BufferPtr = BufStart ? BufStart : File->getBufferStart();
-
+  
   // Start of the file is a start of line.
   IsAtStartOfLine = true;
 
index 9a80ac3c3fbf3f0a8de7b699b79c44c0d357277a..53ff3f14ca0d2932f974ce8b8678e61c9d49c3cc 100644 (file)
@@ -578,13 +578,8 @@ void MacroExpander::PasteTokens(LexerToken &Tok) {
       SourceManager &SourceMgr = PP.getSourceManager();
       const char *ResultStrData = SourceMgr.getCharacterData(ResultTokLoc);
       
-      unsigned FileID = ResultTokLoc.getFileID();
-      assert(FileID && "Could not get FileID for paste?");
-      
       // Make a lexer object so that we lex and expand the paste result.
-      Lexer *TL = new Lexer(SourceMgr.getBuffer(FileID),
-                            SourceLocation::getFileLoc(FileID, 0), PP,
-                            ResultStrData, 
+      Lexer *TL = new Lexer(ResultTokLoc, PP, ResultStrData, 
                             ResultStrData+LHSLen+RHSLen /*don't include null*/);
       
       // Lex a token in raw mode.  This way it won't look up identifiers
index 596b7e76e46b60fbdb36a4504a227a292295d6c4..d717d040a5ea9990e758cafe131c0684940a0e98 100644 (file)
@@ -140,12 +140,9 @@ void Preprocessor::Handle_Pragma(LexerToken &Tok) {
   SourceLocation TokLoc = CreateString(&StrVal[0], StrVal.size(), StrLoc);
   const char *StrData = SourceMgr.getCharacterData(TokLoc);
 
-  unsigned FileID = SourceMgr.getPhysicalLoc(TokLoc).getFileID();
-  assert(FileID && "Could not get FileID for _Pragma?");
-
   // Make and enter a lexer object so that we lex and expand the tokens just
   // like any others.
-  Lexer *TL = new Lexer(SourceMgr.getBuffer(FileID), TokLoc, *this,
+  Lexer *TL = new Lexer(TokLoc, *this,
                         StrData, StrData+StrVal.size()-1 /* no null */);
   
   // Ensure that the lexer thinks it is inside a directive, so that end \n will
index c3fd55426469e1adda9f984375c548332a07cc83..59ade23f5ce944f4b370245156f6c6fef038b9d7 100644 (file)
@@ -281,8 +281,7 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart,
   // lexer to parse it correctly.
   if (CharNo != 0) {
     // Create a lexer starting at this token position.
-    const llvm::MemoryBuffer *SrcBuf =SourceMgr.getBuffer(TokStart.getFileID());
-    Lexer TheLexer(SrcBuf, TokStart, *this, TokPtr);
+    Lexer TheLexer(TokStart, *this, TokPtr);
     LexerToken Tok;
     // Skip over characters the remaining characters.
     const char *TokStartPtr = TokPtr;
@@ -390,9 +389,7 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
   if (MaxIncludeStackDepth < IncludeMacroStack.size())
     MaxIncludeStackDepth = IncludeMacroStack.size();
 
-  const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(FileID);
-  Lexer *TheLexer = new Lexer(Buffer, SourceLocation::getFileLoc(FileID, 0),
-                              *this);
+  Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this);
   if (isMainFile) TheLexer->setIsMainFile();
   EnterSourceFileWithLexer(TheLexer, CurDir);
 }  
index 268231c0ea7db7ab5dfbbcc39af11d236f61f9e5..5b797bb7df7cd1cd185f585bf42975ecd7de2515 100644 (file)
@@ -36,7 +36,7 @@ class Preprocessor;
 class Lexer {
   //===--------------------------------------------------------------------===//
   // Constant configuration values for this lexer.
-  const char * const BufferEnd;  // End of the buffer.
+  const char *BufferEnd;         // End of the buffer.
   const llvm::MemoryBuffer *InputFile; // The file we are reading from.
   SourceLocation FileLoc;        // Location for start of file.
   Preprocessor &PP;              // Preprocessor object controlling lexing.
@@ -93,15 +93,17 @@ class Lexer {
   /// we are currently in.
   std::vector<PPConditionalInfo> ConditionalStack;
   
+  Lexer(const Lexer&);          // DO NOT IMPLEMENT
+  void operator=(const Lexer&); // DO NOT IMPLEMENT
   friend class Preprocessor;
 public:
     
   /// Lexer constructor - Create a new lexer object for the specified buffer
   /// with the specified preprocessor managing the lexing process.  This lexer
-  /// assumes that the specified MemoryBuffer and Preprocessor objects will
-  /// outlive it, but doesn't take ownership of either pointer.
-  Lexer(const llvm::MemoryBuffer *InBuffer, SourceLocation FileLoc, 
-        Preprocessor &PP, const char *BufStart = 0, const char *BufEnd = 0);
+  /// assumes that the associated MemoryBuffer and Preprocessor objects will
+  /// outlive it, so it doesn't take ownership of either of them.
+  Lexer(SourceLocation FileLoc, 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!