[cfe-commits] r138704 - in /cfe/trunk: include/clang/Basic/IdentifierTable.h include/clang/Lex/Preprocessor.h lib/Lex/Preprocessor.cpp test/Modules/lookup.cpp
Douglas Gregor
dgregor at apple.com
Fri Aug 26 23:37:51 PDT 2011
Author: dgregor
Date: Sat Aug 27 01:37:51 2011
New Revision: 138704
URL: http://llvm.org/viewvc/llvm-project?rev=138704&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/test/Modules/lookup.cpp
Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=138704&r1=138703&r2=138704&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Sat Aug 27 01:37:51 2011
@@ -252,7 +252,7 @@
void RecomputeNeedsHandleIdentifier() {
NeedsHandleIdentifier =
(isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
- isExtensionToken() | (getTokenID() == tok::kw___import__));
+ isExtensionToken());
}
};
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=138704&r1=138703&r2=138704&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Aug 27 01:37:51 2011
@@ -118,6 +118,9 @@
/// \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 @@
/// 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 @@
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
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=138704&r1=138703&r2=138704&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sat Aug 27 01:37:51 2011
@@ -88,6 +88,8 @@
// We haven't read anything from the external source.
ReadMacrosFromExternalSource = false;
+ LexDepth = 0;
+
// "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.
// This gets unpoisoned where it is allowed.
(Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
@@ -484,7 +486,7 @@
if (!DisableMacroExpansion && !Identifier.isExpandDisabled()) {
if (MI->isEnabled()) {
if (!HandleMacroExpandedIdentifier(Identifier, MI))
- goto finish;
+ return;
} else {
// C99 6.10.3.4p2 says that a disabled macro may never again be
// expanded, even if it's in a context where it could be expanded in the
@@ -506,12 +508,6 @@
// like "#define TY typeof", "TY(1) x".
if (II.isExtensionToken() && !DisableMacroExpansion)
Diag(Identifier, diag::ext_token_used);
-
-finish:
- // If we have the start of a module import, handle it now.
- if (Identifier.is(tok::kw___import__) &&
- !InMacroArgs && !DisableMacroExpansion)
- HandleModuleImport(Identifier);
}
void Preprocessor::HandleModuleImport(Token &Import) {
Modified: cfe/trunk/test/Modules/lookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/lookup.cpp?rev=138704&r1=138703&r2=138704&view=diff
==============================================================================
--- cfe/trunk/test/Modules/lookup.cpp (original)
+++ cfe/trunk/test/Modules/lookup.cpp Sat Aug 27 01:37:51 2011
@@ -18,7 +18,6 @@
// RUN: %clang_cc1 -emit-module -x c++ -o %T/lookup_right_cxx.pcm %S/Inputs/lookup_right.hpp
// RUN: %clang_cc1 -x c++ -I %T %s -verify
// RUN: %clang_cc1 -ast-print -x c++ -I %T %s | FileCheck -check-prefix=CHECK-PRINT %s
-// XFAIL: win32
// CHECK-PRINT: int *f0(int *);
// CHECK-PRINT: float *f0(float *);
More information about the cfe-commits
mailing list