]> granicus.if.org Git - clang/commitdiff
Don't treat 'import' as a contextual keyword when we're in a caching lexer, or when...
authorDouglas Gregor <dgregor@apple.com>
Wed, 4 Jan 2012 06:20:15 +0000 (06:20 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 4 Jan 2012 06:20:15 +0000 (06:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147524 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Preprocessor.h
lib/Lex/PPCaching.cpp
lib/Lex/Preprocessor.cpp
test/Modules/lookup.cpp

index 8c7b0bce3fe2e3170a2b5500b3c110f59fb701e4..fcaf9c6a2c648ebdbdb1ecb889dad227de35fdb3 100644 (file)
@@ -683,6 +683,10 @@ public:
       CachedTokens[CachedLexPos-1] = Tok;
   }
 
+  /// \brief Recompute the current lexer kind based on the CurLexer/CurPTHLexer/
+  /// CurTokenLexer pointers.
+  void recomputeCurLexerKind();
+  
   /// \brief Specify the point at which code-completion will be performed.
   ///
   /// \param File the file in which code completion should occur. If
index 986341b98668dfc2058d1fe7d6e00c4aa380fb92..0d5e34f0bfecb56159b21e5995514bff86d3f383 100644 (file)
@@ -42,6 +42,7 @@ void Preprocessor::Backtrack() {
          && "EnableBacktrackAtThisPos was not called!");
   CachedLexPos = BacktrackPositions.back();
   BacktrackPositions.pop_back();
+  recomputeCurLexerKind();
 }
 
 void Preprocessor::CachingLex(Token &Result) {
@@ -74,8 +75,7 @@ void Preprocessor::EnterCachingLexMode() {
     return;
 
   PushIncludeMacroStack();
-  if (CurLexerKind != CLK_LexAfterModuleImport)
-    CurLexerKind = CLK_CachingLexer;
+  CurLexerKind = CLK_CachingLexer;
 }
 
 
index 046b0dfb01ab818e4017bc889dc4c09e4e6d0bb6..cfa9e23e60f85b7429e5fa15d6aeb3da11eb8490 100644 (file)
@@ -266,6 +266,17 @@ Preprocessor::macro_end(bool IncludeExternalMacros) const {
   return Macros.end();
 }
 
+void Preprocessor::recomputeCurLexerKind() {
+  if (CurLexer)
+    CurLexerKind = CLK_Lexer;
+  else if (CurPTHLexer)
+    CurLexerKind = CLK_PTHLexer;
+  else if (CurTokenLexer)
+    CurLexerKind = CLK_TokenLexer;
+  else 
+    CurLexerKind = CLK_CachingLexer;
+}
+
 bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
                                           unsigned CompleteLine,
                                           unsigned CompleteColumn) {
@@ -550,7 +561,12 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
   
   // If this is the 'import' contextual keyword, note that the next token 
   // indicates a module name.
-  if (II.isImport() && !InMacroArgs && !DisableMacroExpansion) {
+  //
+  // 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.isImport() && !InMacroArgs && !DisableMacroExpansion &&
+      getLangOptions().Modules && CurLexerKind != CLK_CachingLexer) {
     ModuleImportLoc = Identifier.getLocation();
     ModuleImportPath.clear();
     ModuleImportExpectsIdentifier = true;
@@ -562,14 +578,7 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
 ///
 void Preprocessor::LexAfterModuleImport(Token &Result) {
   // Figure out what kind of lexer we actually have.
-  if (CurLexer)
-    CurLexerKind = CLK_Lexer;
-  else if (CurPTHLexer)
-    CurLexerKind = CLK_PTHLexer;
-  else if (CurTokenLexer)
-    CurLexerKind = CLK_TokenLexer;
-  else 
-    CurLexerKind = CLK_CachingLexer;
+  recomputeCurLexerKind();
   
   // Lex the next token.
   Lex(Result);
index 5e84532e60ff5652d264a7759ca954c80fda1518..fdbdfd7a5cf9b03c77ec3f1c6da649cc0b1a40f7 100644 (file)
@@ -15,6 +15,12 @@ void test(int i, float f) {
   ::f0(&f);
 }
 
+int import;
+
+void f() {
+ int import;
+}
+
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c++ -emit-module -fmodule-cache-path %t -fmodule-name=lookup_left_cxx %S/Inputs/module.map -verify
 // RUN: %clang_cc1 -fmodules -x objective-c++ -emit-module -fmodule-cache-path %t -fmodule-name=lookup_right_cxx %S/Inputs/module.map -verify