r220460 - Refactor implementation of 'exclude header'.
Richard Smith
richard-llvm at metafoo.co.uk
Wed Oct 22 19:01:20 PDT 2014
Author: rsmith
Date: Wed Oct 22 21:01:19 2014
New Revision: 220460
URL: http://llvm.org/viewvc/llvm-project?rev=220460&view=rev
Log:
Refactor implementation of 'exclude header'.
This was not a real header role, and was never exposed to clients of ModuleMap.
Remove the enumeration value for it and track it as marking the header as
'known' rather than creating an extra KnownHeader entry that *every single*
client ignores.
Added:
cfe/trunk/test/Modules/Inputs/declare-use/m.h
cfe/trunk/test/Modules/Inputs/declare-use/m2.h
Modified:
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/test/Modules/Inputs/declare-use/module.map
cfe/trunk/test/Modules/textual-headers.cpp
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=220460&r1=220459&r2=220460&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Wed Oct 22 21:01:19 2014
@@ -74,8 +74,6 @@ public:
/// \brief This header is part of the module (for layering purposes) but
/// should be textually included.
TextualHeader,
- /// \brief This header is explicitly excluded from the module.
- ExcludedHeader
// Caution: Adding an enumerator needs other changes.
// Adjust the number of bits for KnownHeader::Storage.
// Adjust the bitfield HeaderFileInfo::HeaderRole size.
@@ -99,8 +97,8 @@ public:
ModuleHeaderRole getRole() const { return Storage.getInt(); }
/// \brief Whether this header is available in the module.
- bool isAvailable() const {
- return getRole() != ExcludedHeader && getModule()->isAvailable();
+ bool isAvailable() const {
+ return getModule()->isAvailable();
}
// \brief Whether this known header is valid (i.e., it has an
@@ -444,6 +442,9 @@ public:
void addHeader(Module *Mod, const FileEntry *Header,
ModuleHeaderRole Role);
+ /// \brief Marks this header as being excluded from the given module.
+ void excludeHeader(Module *Mod, const FileEntry *Header);
+
/// \brief Parse the given module map file, and record any modules we
/// encounter.
///
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=220460&r1=220459&r2=220460&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Wed Oct 22 21:01:19 2014
@@ -253,12 +253,6 @@ void ModuleMap::diagnoseHeaderInclusion(
HeadersMap::iterator Known = findKnownHeader(File);
if (Known != Headers.end()) {
for (const KnownHeader &Header : Known->second) {
- // Excluded headers don't really belong to a module.
- if (Header.getRole() == ModuleMap::ExcludedHeader) {
- Excluded = true;
- continue;
- }
-
// If 'File' is part of 'RequestingModule' we can definitely include it.
if (Header.getModule() == RequestingModule)
return;
@@ -281,6 +275,8 @@ void ModuleMap::diagnoseHeaderInclusion(
// We have found a module that we can happily use.
return;
}
+
+ Excluded = true;
}
// We have found a header, but it is private.
@@ -332,10 +328,6 @@ ModuleMap::findModuleForHeader(const Fil
for (SmallVectorImpl<KnownHeader>::iterator I = Known->second.begin(),
E = Known->second.end();
I != E; ++I) {
- // Cannot use a module if the header is excluded in it.
- if (I->getRole() == ModuleMap::ExcludedHeader)
- continue;
-
// Cannot use a module if it is unavailable.
if (!I->getModule()->isAvailable())
continue;
@@ -791,9 +783,7 @@ void ModuleMap::setUmbrellaDir(Module *M
void ModuleMap::addHeader(Module *Mod, const FileEntry *Header,
ModuleHeaderRole Role) {
- if (Role == ExcludedHeader) {
- Mod->ExcludedHeaders.push_back(Header);
- } else if (Role == TextualHeader) {
+ if (Role == TextualHeader) {
Mod->TextualHeaders.push_back(Header);
} else {
if (Role == PrivateHeader)
@@ -806,6 +796,16 @@ void ModuleMap::addHeader(Module *Mod, c
Headers[Header].push_back(KnownHeader(Mod, Role));
}
+void ModuleMap::excludeHeader(Module *Mod, const FileEntry *Header) {
+ Mod->ExcludedHeaders.push_back(Header);
+
+ // Add this as a known header so we won't implicitly add it to any
+ // umbrella directory module.
+ // FIXME: Should we only exclude it from umbrella modules within the
+ // specified module?
+ (void) Headers[Header];
+}
+
const FileEntry *
ModuleMap::getContainingModuleMapFile(const Module *Module) const {
if (Module->DefinitionLoc.isInvalid())
@@ -1767,12 +1767,12 @@ void ModuleMapParser::parseHeaderDecl(MM
// Record this umbrella header.
Map.setUmbrellaHeader(ActiveModule, File);
}
+ } else if (LeadingToken == MMToken::ExcludeKeyword) {
+ Map.excludeHeader(ActiveModule, File);
} else {
// Record this header.
ModuleMap::ModuleHeaderRole Role = ModuleMap::NormalHeader;
- if (LeadingToken == MMToken::ExcludeKeyword)
- Role = ModuleMap::ExcludedHeader;
- else if (LeadingToken == MMToken::PrivateKeyword)
+ if (LeadingToken == MMToken::PrivateKeyword)
Role = ModuleMap::PrivateHeader;
else if (LeadingToken == MMToken::TextualKeyword)
Role = ModuleMap::TextualHeader;
Added: cfe/trunk/test/Modules/Inputs/declare-use/m.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/declare-use/m.h?rev=220460&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/declare-use/m.h (added)
+++ cfe/trunk/test/Modules/Inputs/declare-use/m.h Wed Oct 22 21:01:19 2014
@@ -0,0 +1,8 @@
+#ifdef GIMME_AN_M
+
+#ifndef M_H
+#define M_H
+const int m = 42;
+#endif
+
+#endif
Added: cfe/trunk/test/Modules/Inputs/declare-use/m2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/declare-use/m2.h?rev=220460&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/declare-use/m2.h (added)
+++ cfe/trunk/test/Modules/Inputs/declare-use/m2.h Wed Oct 22 21:01:19 2014
@@ -0,0 +1 @@
+#include "m.h"
Modified: cfe/trunk/test/Modules/Inputs/declare-use/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/declare-use/module.map?rev=220460&r1=220459&r2=220460&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/declare-use/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/declare-use/module.map Wed Oct 22 21:01:19 2014
@@ -61,5 +61,10 @@ module XL {
textual header "l.h"
}
+module XM {
+ private textual header "m.h"
+ textual header "m2.h"
+}
+
module XS {
}
Modified: cfe/trunk/test/Modules/textual-headers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/textual-headers.cpp?rev=220460&r1=220459&r2=220460&view=diff
==============================================================================
--- cfe/trunk/test/Modules/textual-headers.cpp (original)
+++ cfe/trunk/test/Modules/textual-headers.cpp Wed Oct 22 21:01:19 2014
@@ -1,6 +1,6 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-strict-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodules-strict-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodules-strict-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify -fmodules-no-error-recovery
#define GIMME_A_K
#include "k.h"
@@ -8,4 +8,11 @@
#define GIMME_AN_L
#include "l.h" // expected-error {{module XG does not depend on a module exporting 'l.h'}}
+#include "m2.h" // expected-error {{module XG does not depend on a module exporting 'm2.h'}}
+const int use_m = m;
+
+#define GIMME_AN_M
+#include "m.h"
+const int use_m_2 = m;
+
const int g = k + l;
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=220460&r1=220459&r2=220460&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Oct 22 21:01:19 2014
@@ -6650,11 +6650,7 @@ CXModule clang_getModuleForFile(CXTransl
HeaderSearch &HS = Unit.getPreprocessor().getHeaderSearchInfo();
ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE);
- if (Module *Mod = Header.getModule()) {
- if (Header.getRole() != ModuleMap::ExcludedHeader)
- return Mod;
- }
- return nullptr;
+ return Header.getModule();
}
CXFile clang_Module_getASTFile(CXModule CXMod) {
More information about the cfe-commits
mailing list