[cfe-commits] r59486 - in /cfe/trunk: include/clang/Lex/Lexer.h lib/Lex/PPLexerChange.cpp
Ted Kremenek
kremenek at apple.com
Mon Nov 17 17:33:13 PST 2008
Author: kremenek
Date: Mon Nov 17 19:33:13 2008
New Revision: 59486
URL: http://llvm.org/viewvc/llvm-project?rev=59486&view=rev
Log:
- 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.
Modified:
cfe/trunk/include/clang/Lex/Lexer.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=59486&r1=59485&r2=59486&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Mon Nov 17 19:33:13 2008
@@ -113,6 +113,9 @@
// 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.
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=59486&r1=59485&r2=59486&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Mon Nov 17 19:33:13 2008
@@ -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;
}
More information about the cfe-commits
mailing list