summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-12-10 23:20:59 +0000
committerTed Kremenek <kremenek@apple.com>2008-12-10 23:20:59 +0000
commit8e1f05fc2625d48722ddd596ca1dcc1e2ba12971 (patch)
treef3ca0f2d5b41636566772d200fa47615d1f564b0
parent6c2522a1cf7161af65af145b65a89b57cd840653 (diff)
downloadbcm5719-llvm-8e1f05fc2625d48722ddd596ca1dcc1e2ba12971.tar.gz
bcm5719-llvm-8e1f05fc2625d48722ddd596ca1dcc1e2ba12971.zip
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. llvm-svn: 60860
-rw-r--r--clang/include/clang/Lex/Lexer.h4
-rw-r--r--clang/include/clang/Lex/PTHLexer.h4
-rw-r--r--clang/include/clang/Lex/PreprocessorLexer.h4
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp12
4 files changed, 14 insertions, 10 deletions
diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index 77399e6d56a..4ca11145fcd 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -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.
diff --git a/clang/include/clang/Lex/PTHLexer.h b/clang/include/clang/Lex/PTHLexer.h
index 7f6ae53d7ab..a1d41b54b6b 100644
--- a/clang/include/clang/Lex/PTHLexer.h
+++ b/clang/include/clang/Lex/PTHLexer.h
@@ -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.
diff --git a/clang/include/clang/Lex/PreprocessorLexer.h b/clang/include/clang/Lex/PreprocessorLexer.h
index e178d27374c..a889a55b526 100644
--- a/clang/include/clang/Lex/PreprocessorLexer.h
+++ b/clang/include/clang/Lex/PreprocessorLexer.h
@@ -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.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index bb2536d1e60..cd50f0e38f7 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -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.
OpenPOWER on IntegriCloud