]> granicus.if.org Git - clang/commitdiff
[modules] Before checking whether the controlling macro of a header is defined,
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Jul 2015 02:29:35 +0000 (02:29 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Jul 2015 02:29:35 +0000 (02:29 +0000)
update the identifier in case we've imported a definition of the macro (and
thus the contents of the header) from a module.

Also fold ExternalIdentifierLookup into ExternalPreprocessorSource; it no longer
makes sense to keep these separate now that the only user of the former also
needs the latter.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241137 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/IdentifierTable.h
include/clang/Lex/ExternalPreprocessorSource.h
include/clang/Lex/HeaderSearch.h
include/clang/Serialization/ASTReader.h
lib/Basic/IdentifierTable.cpp
lib/Lex/HeaderSearch.cpp
test/Modules/Inputs/submodule-visibility/a.h
test/Modules/Inputs/submodule-visibility/b.h
test/Modules/Inputs/submodule-visibility/c.h [new file with mode: 0644]
test/Modules/Inputs/submodule-visibility/module.modulemap
test/Modules/Inputs/submodule-visibility/other.h [new file with mode: 0644]

index bc586e41f85494bd41324d4bbf2abbb95716a077..33a8b747c62d7e97ef4cf39c7a8d8b5ef93bd66f 100644 (file)
@@ -406,19 +406,6 @@ public:
   virtual IdentifierIterator *getIdentifiers();
 };
 
-/// \brief An abstract class used to resolve numerical identifier
-/// references (meaningful only to some external source) into
-/// IdentifierInfo pointers.
-class ExternalIdentifierLookup {
-public:
-  virtual ~ExternalIdentifierLookup();
-
-  /// \brief Return the identifier associated with the given ID number.
-  ///
-  /// The ID 0 is associated with the NULL identifier.
-  virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
-};
-
 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
 ///
 /// This has no other purpose, but this is an extremely performance-critical
index 33e7a2d84b88f7e41d516fcc872d6c516283323b..adf8e713e99e6876e2e6f27a243a274d5c52f77d 100644 (file)
@@ -23,7 +23,7 @@ class Module;
 /// information.
 ///
 /// This abstract class allows an external sources (such as the \c ASTReader) 
-/// to provide additional macro definitions.
+/// to provide additional preprocessing information.
 class ExternalPreprocessorSource {
 public:
   virtual ~ExternalPreprocessorSource();
@@ -34,6 +34,11 @@ public:
   /// \brief Update an out-of-date identifier.
   virtual void updateOutOfDateIdentifier(IdentifierInfo &II) = 0;
 
+  /// \brief Return the identifier associated with the given ID number.
+  ///
+  /// The ID 0 is associated with the NULL identifier.
+  virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
+
   /// \brief Map a module ID to a module.
   virtual Module *getModule(unsigned ModuleID) = 0;
 };
index da640e232549131cf8076cf2a4df853848f59e5d..4c1338010078f43975b931611e5fef61553bb336 100644 (file)
@@ -27,7 +27,7 @@
 namespace clang {
   
 class DiagnosticsEngine;  
-class ExternalIdentifierLookup;
+class ExternalPreprocessorSource;
 class FileEntry;
 class FileManager;
 class HeaderSearchOptions;
@@ -111,8 +111,9 @@ struct HeaderFileInfo {
 
   /// \brief Retrieve the controlling macro for this header file, if
   /// any.
-  const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External);
-  
+  const IdentifierInfo *
+  getControllingMacro(ExternalPreprocessorSource *External);
+
   /// \brief Determine whether this is a non-default header file info, e.g.,
   /// it corresponds to an actual header we've included or tried to include.
   bool isNonDefault() const {
@@ -242,8 +243,9 @@ class HeaderSearch {
   llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
   
   /// \brief Entity used to resolve the identifier IDs of controlling
-  /// macros into IdentifierInfo pointers, as needed.
-  ExternalIdentifierLookup *ExternalLookup;
+  /// macros into IdentifierInfo pointers, and keep the identifire up to date,
+  /// as needed.
+  ExternalPreprocessorSource *ExternalLookup;
 
   /// \brief Entity used to look up stored header file information.
   ExternalHeaderFileInfoSource *ExternalSource;
@@ -345,11 +347,11 @@ public:
     FileInfo.clear();
   }
 
-  void SetExternalLookup(ExternalIdentifierLookup *EIL) {
-    ExternalLookup = EIL;
+  void SetExternalLookup(ExternalPreprocessorSource *EPS) {
+    ExternalLookup = EPS;
   }
 
-  ExternalIdentifierLookup *getExternalLookup() const {
+  ExternalPreprocessorSource *getExternalLookup() const {
     return ExternalLookup;
   }
   
index 670124082cfe3eabede1b9073c276cca343c08be..ef5b107a2fdaefd5f1c13ad2c3473a54c2c380c3 100644 (file)
@@ -304,7 +304,6 @@ class ASTReader
     public ExternalHeaderFileInfoSource,
     public ExternalSemaSource,
     public IdentifierInfoLookup,
-    public ExternalIdentifierLookup,
     public ExternalSLocEntrySource
 {
 public:
index 40b28222b8bc23f7b89142fbccaa5d9864ca0d37..36fba994f1e767dd8aabffd4536ab6f7fafd5d9d 100644 (file)
@@ -71,8 +71,6 @@ IdentifierIterator *IdentifierInfoLookup::getIdentifiers() {
   return new EmptyLookupIterator();
 }
 
-ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
-
 IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
                                  IdentifierInfoLookup* externalLookup)
   : HashTable(8192), // Start with space for 8K identifiers.
index 67a00586a64c32c91be02de84f1690a5e0a9fd1e..89120ff84d91c72001b8a154fef493d354f501bd 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Lex/ExternalPreprocessorSource.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/LexDiagnostic.h"
 using namespace clang;
 
 const IdentifierInfo *
-HeaderFileInfo::getControllingMacro(ExternalIdentifierLookup *External) {
-  if (ControllingMacro)
+HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) {
+  if (ControllingMacro) {
+    if (ControllingMacro->isOutOfDate())
+      External->updateOutOfDateIdentifier(
+          *const_cast<IdentifierInfo *>(ControllingMacro));
     return ControllingMacro;
+  }
 
   if (!ControllingMacroID || !External)
     return nullptr;
index 34ac6b2b2eabdecf4060157377eac4ec2dc2147f..e4965d72218ba9610157dab9846980ae39b427b4 100644 (file)
@@ -5,3 +5,5 @@ int n;
 #endif
 
 #define A
+
+#include "c.h"
index dae75bf3315b57ea7a449a23745f59548c79c15f..67ef6529dbd819573abc17cb386d2b773bad1b95 100644 (file)
@@ -1,5 +1,8 @@
 int m = n;
 
+#include "other.h"
+#include "c.h"
+
 #if defined(A) && !defined(ALLOW_NAME_LEAKAGE)
 #error A is defined
 #endif
diff --git a/test/Modules/Inputs/submodule-visibility/c.h b/test/Modules/Inputs/submodule-visibility/c.h
new file mode 100644 (file)
index 0000000..259b8c7
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef C_H_INCLUDED
+#define C_H_INCLUDED
+
+struct C {};
+
+#endif
index 2e13344dc635c63df9314752e239dae647fd7ff6..d2f0c7783ffa2b39ae8bc3be613820cf39aa4ce4 100644 (file)
@@ -1,4 +1,5 @@
 module x { module a { header "a.h" } module b { header "b.h" } }
+module other { header "other.h" }
 
 module cycles {
   module cycle1 { header "cycle1.h" }
diff --git a/test/Modules/Inputs/submodule-visibility/other.h b/test/Modules/Inputs/submodule-visibility/other.h
new file mode 100644 (file)
index 0000000..f40c757
--- /dev/null
@@ -0,0 +1 @@
+#include "c.h"