|
28 | 28 | #include "swift/ClangImporter/ClangModule.h"
|
29 | 29 | #include "swift/Parse/Parser.h"
|
30 | 30 | #include "swift/Subsystems.h"
|
| 31 | +#include "swift/Strings.h" |
31 | 32 | #include "clang/Basic/Module.h"
|
32 | 33 | #include "llvm/ADT/DenseMap.h"
|
33 | 34 | #include "llvm/ADT/TinyPtrVector.h"
|
@@ -317,6 +318,23 @@ void ImportResolver::bindImport(UnboundImport &&I) {
|
317 | 318 | ID.get()->setModule(nullptr);
|
318 | 319 | return;
|
319 | 320 | }
|
| 321 | + // If the imported module is a clang module, add an implicit import statement |
| 322 | + // to request the SPIs from the module. |
| 323 | + if (M->isNonSwiftModule() && ID && |
| 324 | + !ID.get()->getAttrs().hasAttribute<SPIAccessControlAttr>()) { |
| 325 | + ImportDecl *id = ID.get(); |
| 326 | + auto *newId = ImportDecl::create(id->getASTContext(), id->getDeclContext(), |
| 327 | + SourceLoc(), id->getImportKind(), SourceLoc(), id->getImportPath()); |
| 328 | + // Copy all the existing attribute from the actual import statement. |
| 329 | + llvm::for_each(id->getAttrs(), |
| 330 | + [&](DeclAttribute *attr) {newId->getAttrs().add(attr);}); |
| 331 | + // Add SPI attribute with the default group name. |
| 332 | + newId->getAttrs().add(SPIAccessControlAttr::create(id->getASTContext(), |
| 333 | + SourceLoc(), SourceRange(), |
| 334 | + { ctx.getIdentifier(CLANG_MODULE_DEFUALT_SPI_GROUP_NAME) })); |
| 335 | + // So we'll resolve the new import. |
| 336 | + unboundImports.push_back(UnboundImport(newId)); |
| 337 | + } |
320 | 338 |
|
321 | 339 | auto topLevelModule = I.getTopLevelModule(M, SF);
|
322 | 340 |
|
|
0 commit comments