[cfe-commits] r60860 - in /cfe/trunk: include/clang/Lex/Lexer.h include/clang/Lex/PTHLexer.h include/clang/Lex/PreprocessorLexer.h lib/Lex/PPLexerChange.cpp
Ted Kremenek
kremenek at apple.com
Wed Dec 10 15:21:02 PST 2008
Author: kremenek
Date: Wed Dec 10 17:20:59 2008
New Revision: 60860
URL: http://llvm.org/viewvc/llvm-project?rev=60860&view=rev
Log:
PreprocessorLexer (and subclasses):
- 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.
Modified:
cfe/trunk/include/clang/Lex/Lexer.h
cfe/trunk/include/clang/Lex/PTHLexer.h
cfe/trunk/include/clang/Lex/PreprocessorLexer.h
cfe/trunk/lib/Lex/PPLexerChange.cpp
Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=60860&r1=60859&r2=60860&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Wed Dec 10 17:20:59 2008
@@ -177,6 +177,10 @@
/// 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.
Modified: cfe/trunk/include/clang/Lex/PTHLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHLexer.h?rev=60860&r1=60859&r2=60860&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Wed Dec 10 17:20:59 2008
@@ -69,6 +69,10 @@
/// 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.
Modified: cfe/trunk/include/clang/Lex/PreprocessorLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorLexer.h?rev=60860&r1=60859&r2=60860&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessorLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorLexer.h Wed Dec 10 17:20:59 2008
@@ -79,6 +79,10 @@
virtual void IndirectLex(Token& Result) = 0;
+ /// getSourceLocation - Return the source location for the next observable
+ /// location.
+ virtual SourceLocation getSourceLocation() = 0;
+
//===--------------------------------------------------------------------===//
// #if directive handling.
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=60860&r1=60859&r2=60860&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Wed Dec 10 17:20:59 2008
@@ -275,16 +275,8 @@
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.
More information about the cfe-commits
mailing list