]> granicus.if.org Git - clang/commitdiff
PreprocessorLexer (and subclasses):
authorTed Kremenek <kremenek@apple.com>
Wed, 10 Dec 2008 23:20:59 +0000 (23:20 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 10 Dec 2008 23:20:59 +0000 (23:20 +0000)
- Added virtual method 'getSourceLocation()' (no arguments) that gets the location of the next "observable" location (e.g., next character, next token).
PPLexerChange.cpp:
- Implemented FIXME by using PreprocessorLexer::getSourceLocation() to get the location in the file we are returning to after lexing a #included file.  This appears to be slightly faster than having the branch (i.e., 'if(CurLexer)').  It's also not a really hot part of the Preprocessor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60860 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Lexer.h
include/clang/Lex/PTHLexer.h
include/clang/Lex/PreprocessorLexer.h
lib/Lex/PPLexerChange.cpp

index 77399e6d56abeed392f29510db726755d46a6692..4ca11145fcdaff923f5bdadec572bc0a5f4d2849 100644 (file)
@@ -177,6 +177,10 @@ public:
   /// getSourceLocation - Return a source location identifier for the specified
   /// offset in the current file.
   SourceLocation getSourceLocation(const char *Loc) const;
+    
+  /// getSourceLocation - Return a source location for the next character in
+  /// the current file.
+  SourceLocation getSourceLocation() { return getSourceLocation(BufferPtr); }
   
   /// Stringify - Convert the specified string into a C string by escaping '\'
   /// and " characters.  This does not add surrounding ""'s to the string.
index 7f6ae53d7aba683c31004f450abeef6dc853a5a8..a1d41b54b6b6bc029f11fd84502f4783a417a2aa 100644 (file)
@@ -69,6 +69,10 @@ public:
   ///  the PreprocessorLexer interface.
   void IndirectLex(Token &Result) { Lex(Result); }
   
+  /// getSourceLocation - Return a source location for the token in
+  /// the current file.
+  SourceLocation getSourceLocation() { return GetToken().getLocation(); }
+
 private:
   
   /// AtLastToken - Returns true if the PTHLexer is at the last token.
index e178d27374c501f8790480af8786e180a9a3bb67..a889a55b526f9760fa2650f6e725d2e9d4501d7a 100644 (file)
@@ -79,6 +79,10 @@ protected:
   
   virtual void IndirectLex(Token& Result) = 0;
   
+  /// getSourceLocation - Return the source location for the next observable
+  ///  location.
+  virtual SourceLocation getSourceLocation() = 0;
+  
   //===--------------------------------------------------------------------===//
   // #if directive handling.
   
index bb2536d1e6098b3802006c6d5dcaff06b612bc89..cd50f0e38f74b983e3184d33a61e6b0ca03da0d9 100644 (file)
@@ -275,16 +275,8 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
     if (Callbacks && !isEndOfMacro && CurPPLexer) {
       SrcMgr::CharacteristicKind FileType =
         SourceMgr.getFileCharacteristic(CurPPLexer->getFileID());
-
-      if (CurLexer) {
-        Callbacks->FileChanged(CurLexer->getSourceLocation(CurLexer->BufferPtr),
-                               PPCallbacks::ExitFile, FileType);
-      }
-      else {
-        // FIXME: Is this okay to use the location of 'Result'?
-        Callbacks->FileChanged(Result.getLocation(), PPCallbacks::ExitFile,
-                               FileType);  
-      }
+        Callbacks->FileChanged(CurPPLexer->getSourceLocation(),
+                               PPCallbacks::ExitFile, FileType); 
     }
 
     // Client should lex another token.