Quellcode durchsuchen

[modules] Before checking whether the controlling macro of a header is defined,
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

Richard Smith vor 10 Jahren
Ursprung
Commit
dc8f320f3b

+ 0 - 13
include/clang/Basic/IdentifierTable.h

@@ -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

+ 6 - 1
include/clang/Lex/ExternalPreprocessorSource.h

@@ -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;
 };

+ 10 - 8
include/clang/Lex/HeaderSearch.h

@@ -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;
   }
   

+ 0 - 1
include/clang/Serialization/ASTReader.h

@@ -304,7 +304,6 @@ class ASTReader
     public ExternalHeaderFileInfoSource,
     public ExternalSemaSource,
     public IdentifierInfoLookup,
-    public ExternalIdentifierLookup,
     public ExternalSLocEntrySource
 {
 public:

+ 0 - 2
lib/Basic/IdentifierTable.cpp

@@ -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.

+ 7 - 2
lib/Lex/HeaderSearch.cpp

@@ -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"
@@ -33,9 +34,13 @@
 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;

+ 2 - 0
test/Modules/Inputs/submodule-visibility/a.h

@@ -5,3 +5,5 @@ int n;
 #endif
 
 #define A
+
+#include "c.h"

+ 3 - 0
test/Modules/Inputs/submodule-visibility/b.h

@@ -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

+ 6 - 0
test/Modules/Inputs/submodule-visibility/c.h

@@ -0,0 +1,6 @@
+#ifndef C_H_INCLUDED
+#define C_H_INCLUDED
+
+struct C {};
+
+#endif

+ 1 - 0
test/Modules/Inputs/submodule-visibility/module.modulemap

@@ -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" }

+ 1 - 0
test/Modules/Inputs/submodule-visibility/other.h

@@ -0,0 +1 @@
+#include "c.h"