aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Lex/Preprocessor.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-08-27 06:37:51 +0000
committerDouglas Gregor <dgregor@apple.com>2011-08-27 06:37:51 +0000
commit6be16fe900bdd1e5f677d23ae34fffead5bcfc77 (patch)
tree7f294f558d6190ba441ff9fe78931781e5fefa57 /include/clang/Lex/Preprocessor.h
parent72e4d0c0bffd48eb76dabffbc044ee6f19dad6f8 (diff)
Take an entirely different approach to handling the "parsing" of
__import__ within the preprocessor, since the prior one foolishly assumed that Preprocessor::Lex() was re-entrant. We now handle __import__ at the top level (only), after macro expansion. This should fix the buildbot failures. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex/Preprocessor.h')
-rw-r--r--include/clang/Lex/Preprocessor.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 1ab6411e98..b14c7e8382 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -118,6 +118,9 @@ class Preprocessor : public llvm::RefCountedBase<Preprocessor> {
/// \brief Whether we have already loaded macros from the external source.
mutable bool ReadMacrosFromExternalSource : 1;
+ /// \brief Tracks the depth of Lex() Calls.
+ unsigned LexDepth;
+
/// Identifiers - This is mapping/lookup information for all identifiers in
/// the program, including program keywords.
mutable IdentifierTable Identifiers;
@@ -531,6 +534,7 @@ public:
/// Lex - To lex a token from the preprocessor, just pull a token from the
/// current lexer or macro object.
void Lex(Token &Result) {
+ ++LexDepth;
if (CurLexer)
CurLexer->Lex(Result);
else if (CurPTHLexer)
@@ -539,6 +543,11 @@ public:
CurTokenLexer->Lex(Result);
else
CachingLex(Result);
+ --LexDepth;
+
+ // If we have the __import__ keyword, handle the module import now.
+ if (Result.getKind() == tok::kw___import__ && LexDepth == 0)
+ HandleModuleImport(Result);
}
/// LexNonComment - Lex a token. If it's a comment, keep lexing until we get