diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-11-18 01:33:13 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-11-18 01:33:13 +0000 |
commit | 3d9740da29741c98270f9482afc5b50077e38f34 (patch) | |
tree | 70b2ed200321add70c5b977d756da863c3ed9d0c /clang | |
parent | 326f757698323b5e5d23d2a0e2cdba683cd9e6d3 (diff) | |
download | bcm5719-llvm-3d9740da29741c98270f9482afc5b50077e38f34.tar.gz bcm5719-llvm-3d9740da29741c98270f9482afc5b50077e38f34.zip |
- Add Lexer::isPragma() accessor for clients of Lexer that aren't friends.
- Add static method to test if the current lexer is a non-macro/non-pragma
lexer.
- Refactor some code in PPLexerChange to use this static method.
- No performance change.
llvm-svn: 59486
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Lex/Lexer.h | 3 | ||||
-rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 22 |
2 files changed, 17 insertions, 8 deletions
diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h index 3542ff4bc72..47a73fbd23e 100644 --- a/clang/include/clang/Lex/Lexer.h +++ b/clang/include/clang/Lex/Lexer.h @@ -113,6 +113,9 @@ public: // file is reached. LexTokenInternal(Result); } + + /// isPragmaLexer - Returns true if this Lexer is being used to lex a pragma. + bool isPragmaLexer() const { return Is_PragmaLexer; } /// IndirectLex - An indirect call to 'Lex' that can be invoked via /// the PreprocessorLexer interface. diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 3b63c9bb094..87330983d65 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -19,27 +19,33 @@ #include "clang/Basic/SourceManager.h" using namespace clang; -PPCallbacks::~PPCallbacks() { -} - +PPCallbacks::~PPCallbacks() {} //===----------------------------------------------------------------------===// // Miscellaneous Methods. //===----------------------------------------------------------------------===// +static inline bool IsNonPragmaNonMacroLexer(const Lexer* L, + const PreprocessorLexer* P) { + if (L) + return !L->isPragmaLexer(); + else + return P != 0; +} + /// isInPrimaryFile - Return true if we're in the top-level file, not in a /// #include. This looks through macro expansions and active _Pragma lexers. bool Preprocessor::isInPrimaryFile() const { - if (CurLexer && !CurLexer->Is_PragmaLexer) + if (IsNonPragmaNonMacroLexer(CurLexer.get(), CurPPLexer)) return IncludeMacroStack.empty(); // If there are any stacked lexers, we're in a #include. - assert(IncludeMacroStack[0].TheLexer && - !IncludeMacroStack[0].TheLexer->Is_PragmaLexer && + assert(IsNonPragmaNonMacroLexer(IncludeMacroStack[0].TheLexer, + IncludeMacroStack[0].ThePPLexer) && "Top level include stack isn't our primary lexer?"); for (unsigned i = 1, e = IncludeMacroStack.size(); i != e; ++i) - if (IncludeMacroStack[i].TheLexer && - !IncludeMacroStack[i].TheLexer->Is_PragmaLexer) + if (IsNonPragmaNonMacroLexer(IncludeMacroStack[i].TheLexer, + IncludeMacroStack[i].ThePPLexer)) return false; return true; } |