r194225 - Modules: Teach the preprocessor to recognize 'import' only after an '@'.
Douglas Gregor
dgregor at apple.com
Thu Nov 7 14:55:02 PST 2013
Author: dgregor
Date: Thu Nov 7 16:55:02 2013
New Revision: 194225
URL: http://llvm.org/viewvc/llvm-project?rev=194225&view=rev
Log:
Modules: Teach the preprocessor to recognize 'import' only after an '@'.
The preprocessor currently recognizes module declarations to load a
module based on seeing the 'import' keyword followed by an
identifier. This sequence is fairly unlikely in C (one would need a
type named 'import'), but is more common in Objective-C (where a
variable named 'import' can cause problems). Since import declarations
currently require a leading '@', recognize that in the preprocessor as
well. Fixes <rdar://problem/15084587>.
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/test/Modules/import-decl.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=194225&r1=194224&r2=194225&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Nov 7 16:55:02 2013
@@ -222,7 +222,10 @@ class Preprocessor : public RefCountedBa
/// \brief The module import path that we're currently processing.
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> ModuleImportPath;
-
+
+ /// \brief Whether the last token we lexed was an '@'.
+ bool LastTokenWasAt;
+
/// \brief Whether the module import expectes an identifier next. Otherwise,
/// it expects a '.' or ';'.
bool ModuleImportExpectsIdentifier;
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=194225&r1=194224&r2=194225&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Nov 7 16:55:02 2013
@@ -65,6 +65,7 @@ Preprocessor::Preprocessor(IntrusiveRefC
TheModuleLoader(TheModuleLoader), ExternalSource(0),
Identifiers(opts, IILookup), IncrementalProcessing(IncrProcessing),
CodeComplete(0), CodeCompletionFile(0), CodeCompletionOffset(0),
+ LastTokenWasAt(false), ModuleImportExpectsIdentifier(false),
CodeCompletionReached(0), SkipMainFilePreamble(0, true), CurPPLexer(0),
CurDirLookup(0), CurLexerKind(CLK_Lexer), Callbacks(0),
MacroArgCache(0), Record(0), MIChainHead(0), MICache(0),
@@ -687,14 +688,15 @@ bool Preprocessor::HandleIdentifier(Toke
if (II.isExtensionToken() && !DisableMacroExpansion)
Diag(Identifier, diag::ext_token_used);
- // If this is the 'import' contextual keyword, note
+ // If this is the 'import' contextual keyword following an '@', note
// that the next token indicates a module name.
//
// Note that we do not treat 'import' as a contextual
// keyword when we're in a caching lexer, because caching lexers only get
// used in contexts where import declarations are disallowed.
- if (II.isModulesImport() && !InMacroArgs && !DisableMacroExpansion &&
- getLangOpts().Modules && CurLexerKind != CLK_CachingLexer) {
+ if (LastTokenWasAt && II.isModulesImport() && !InMacroArgs &&
+ !DisableMacroExpansion && getLangOpts().Modules &&
+ CurLexerKind != CLK_CachingLexer) {
ModuleImportLoc = Identifier.getLocation();
ModuleImportPath.clear();
ModuleImportExpectsIdentifier = true;
@@ -727,6 +729,8 @@ void Preprocessor::Lex(Token &Result) {
break;
}
} while (!ReturnedToken);
+
+ LastTokenWasAt = Result.is(tok::at);
}
Modified: cfe/trunk/test/Modules/import-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/import-decl.cpp?rev=194225&r1=194224&r2=194225&view=diff
==============================================================================
--- cfe/trunk/test/Modules/import-decl.cpp (original)
+++ cfe/trunk/test/Modules/import-decl.cpp Thu Nov 7 16:55:02 2013
@@ -8,3 +8,12 @@
int main() {
return 0;
}
+
+// <rdar://problem/15084587>
+ at interface A
+-method;
+ at end
+
+void testImport(A *import) {
+ [import method];
+}
More information about the cfe-commits
mailing list