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 | 4b391087f9c5582d448ab66ccbc7028f7673f380 (patch) | |
tree | 79542f1e647e808232a917bb055520dda0a80009 /lib/Lex/PPLexerChange.cpp | |
parent | 29a1cfbec38d255dd24ba660333a2430849a2f1c (diff) |
- 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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59486 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PPLexerChange.cpp')
-rw-r--r-- | lib/Lex/PPLexerChange.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 3b63c9bb09..87330983d6 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/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; } |