mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal Swift syntax for module imports, e.g., import Cocoa However, to enable importing Clang modules, one needs to point Swift at a particular SDK with the -sdk= argument, e.g., swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk and, of course, that SDK needs to provide support for modules. There are a number of moving parts here. The major pieces are: CMake support for linking Clang into Swift: CMake users will now need to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD to the locations of the Clang source tree (which defaults to tools/clang under your LLVM source tree) and the Clang build tree. Makefile support for linking Clang into Swift: Makefile users will need to have Clang located in tools/clang and Swift located in tools/swift, and builds should just work. Module loader abstraction: similar to Clang's module loader, a module loader is responsible for resolving a module name to an actual module, loading that module in the process. It will also be responsible for performing name lookup into that module. Clang importer: the only implementation of the module loader abstraction, the importer creates a Clang compiler instance capable of building and loading Clang modules. The approach we take here is to parse a dummy .m file in Objective-C ARC mode with modules enabled, but never tear down that compilation unit. Then, when we get a request to import a Clang module, we turn that into a module-load request to Clang's module loader, which will build an appropriate module on-the-fly or used a cached module file. Note that name lookup into Clang modules is not yet implemented. That's the next major step. Swift SVN r3199
This commit is contained in:
@@ -22,6 +22,10 @@
|
||||
#include "swift/Basic/SourceLoc.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
|
||||
namespace clang {
|
||||
class Module;
|
||||
}
|
||||
|
||||
namespace swift {
|
||||
class ASTContext;
|
||||
class BraceStmt;
|
||||
@@ -227,7 +231,23 @@ public:
|
||||
return DC->getContextKind() == DeclContextKind::BuiltinModule;
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief Represents a Clang module that has been imported into Swift.
|
||||
class ClangModule : public Module {
|
||||
clang::Module *clangModule;
|
||||
|
||||
public:
|
||||
ClangModule(ASTContext &ctx, Component *comp, clang::Module *clangModule);
|
||||
|
||||
/// \brief Retrieve the underlying Clang module.
|
||||
clang::Module *getClangModule() const { return clangModule; }
|
||||
|
||||
static bool classof(const DeclContext *DC) {
|
||||
return DC->getContextKind() == DeclContextKind::ClangModule;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user