mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -71,32 +71,6 @@ public:
|
|||||||
virtual bool
|
virtual bool
|
||||||
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
|
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
|
||||||
const DeclContext *importedDC) = 0;
|
const DeclContext *importedDC) = 0;
|
||||||
|
|
||||||
/// Look for declarations associated with the given name.
|
|
||||||
///
|
|
||||||
/// \param name The name we're searching for.
|
|
||||||
virtual void lookupValue(DeclName name, VisibleDeclConsumer &consumer) {}
|
|
||||||
|
|
||||||
/// Look up a type declaration by its Clang name.
|
|
||||||
///
|
|
||||||
/// Note that this method does no filtering. If it finds the type in a loaded
|
|
||||||
/// module, it returns it. This is intended for use in reflection / debugging
|
|
||||||
/// contexts where access is not a problem.
|
|
||||||
virtual void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
|
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) {}
|
|
||||||
|
|
||||||
/// Look up type a declaration synthesized by the Clang importer itself, using
|
|
||||||
/// a "related entity kind" to determine which type it should be. For example,
|
|
||||||
/// this can be used to find the synthesized error struct for an
|
|
||||||
/// NS_ERROR_ENUM.
|
|
||||||
///
|
|
||||||
/// Note that this method does no filtering. If it finds the type in a loaded
|
|
||||||
/// module, it returns it. This is intended for use in reflection / debugging
|
|
||||||
/// contexts where access is not a problem.
|
|
||||||
virtual void
|
|
||||||
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
|
|
||||||
StringRef relatedEntityKind,
|
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace swift
|
} // namespace swift
|
||||||
|
|||||||
@@ -115,9 +115,6 @@ namespace swift {
|
|||||||
/// Only used by lldb-moduleimport-test.
|
/// Only used by lldb-moduleimport-test.
|
||||||
bool EnableMemoryBufferImporter = false;
|
bool EnableMemoryBufferImporter = false;
|
||||||
|
|
||||||
/// Enable the DWARFImporter. Only used by lldb-moduleimport-test.
|
|
||||||
bool EnableDWARFImporter = false;
|
|
||||||
|
|
||||||
/// Allows using identifiers with a leading dollar.
|
/// Allows using identifiers with a leading dollar.
|
||||||
bool EnableDollarIdentifiers = false;
|
bool EnableDollarIdentifiers = false;
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,28 @@ class TypeDecl;
|
|||||||
class VisibleDeclConsumer;
|
class VisibleDeclConsumer;
|
||||||
enum class SelectorSplitKind;
|
enum class SelectorSplitKind;
|
||||||
|
|
||||||
|
/// This interface is implemented by LLDB to serve as a fallback when Clang
|
||||||
|
/// modules can't be imported from source in the debugger.
|
||||||
|
///
|
||||||
|
/// During compile time, ClangImporter-imported Clang modules are compiled with
|
||||||
|
/// -gmodules, which emits a DWARF rendition of all types defined in the module
|
||||||
|
/// into the .pcm file. On Darwin, these types can be collected by
|
||||||
|
/// dsymutil. This delegate allows DWARFImporter to ask LLDB to look up a Clang
|
||||||
|
/// type by name, synthesize a Clang AST from it. DWARFImporter then hands this
|
||||||
|
/// Clang AST to ClangImporter to import the type into Swift.
|
||||||
|
class DWARFImporterDelegate {
|
||||||
|
public:
|
||||||
|
virtual ~DWARFImporterDelegate() {}
|
||||||
|
/// Perform a qualified lookup of a Clang type with this name.
|
||||||
|
/// \param kind Only return results with this type kind.
|
||||||
|
virtual void lookupValue(StringRef name, llvm::Optional<ClangTypeKind> kind,
|
||||||
|
SmallVectorImpl<clang::Decl *> &results) {}
|
||||||
|
};
|
||||||
|
|
||||||
/// Class that imports Clang modules into Swift, mapping directly
|
/// Class that imports Clang modules into Swift, mapping directly
|
||||||
/// from Clang ASTs over to Swift ASTs.
|
/// from Clang ASTs over to Swift ASTs.
|
||||||
class ClangImporter final : public ClangModuleLoader {
|
class ClangImporter final : public ClangModuleLoader {
|
||||||
friend class ClangModuleUnit;
|
friend class ClangModuleUnit;
|
||||||
friend class DWARFImporter;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class Implementation;
|
class Implementation;
|
||||||
@@ -74,8 +91,11 @@ private:
|
|||||||
Implementation &Impl;
|
Implementation &Impl;
|
||||||
|
|
||||||
ClangImporter(ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
|
ClangImporter(ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
|
||||||
DependencyTracker *tracker);
|
DependencyTracker *tracker,
|
||||||
|
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate);
|
||||||
|
|
||||||
|
ModuleDecl *loadModuleClang(SourceLoc importLoc,
|
||||||
|
ArrayRef<std::pair<Identifier, SourceLoc>> path);
|
||||||
public:
|
public:
|
||||||
/// Create a new Clang importer that can import a suitable Clang
|
/// Create a new Clang importer that can import a suitable Clang
|
||||||
/// module into the given ASTContext.
|
/// module into the given ASTContext.
|
||||||
@@ -90,13 +110,15 @@ public:
|
|||||||
///
|
///
|
||||||
/// \param tracker The object tracking files this compilation depends on.
|
/// \param tracker The object tracking files this compilation depends on.
|
||||||
///
|
///
|
||||||
|
/// \param dwarfImporterDelegate A helper object that can synthesize
|
||||||
|
/// Clang Decls from debug info. Used by LLDB.
|
||||||
|
///
|
||||||
/// \returns a new Clang module importer, or null (with a diagnostic) if
|
/// \returns a new Clang module importer, or null (with a diagnostic) if
|
||||||
/// an error occurred.
|
/// an error occurred.
|
||||||
static std::unique_ptr<ClangImporter>
|
static std::unique_ptr<ClangImporter>
|
||||||
create(ASTContext &ctx,
|
create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
|
||||||
const ClangImporterOptions &importerOpts,
|
std::string swiftPCHHash = "", DependencyTracker *tracker = nullptr,
|
||||||
std::string swiftPCHHash = "",
|
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate = {});
|
||||||
DependencyTracker *tracker = nullptr);
|
|
||||||
|
|
||||||
ClangImporter(const ClangImporter &) = delete;
|
ClangImporter(const ClangImporter &) = delete;
|
||||||
ClangImporter(ClangImporter &&) = delete;
|
ClangImporter(ClangImporter &&) = delete;
|
||||||
@@ -152,7 +174,7 @@ public:
|
|||||||
/// Look for declarations associated with the given name.
|
/// Look for declarations associated with the given name.
|
||||||
///
|
///
|
||||||
/// \param name The name we're searching for.
|
/// \param name The name we're searching for.
|
||||||
void lookupValue(DeclName name, VisibleDeclConsumer &consumer) override;
|
void lookupValue(DeclName name, VisibleDeclConsumer &consumer);
|
||||||
|
|
||||||
/// Look up a type declaration by its Clang name.
|
/// Look up a type declaration by its Clang name.
|
||||||
///
|
///
|
||||||
@@ -160,7 +182,7 @@ public:
|
|||||||
/// module, it returns it. This is intended for use in reflection / debugging
|
/// module, it returns it. This is intended for use in reflection / debugging
|
||||||
/// contexts where access is not a problem.
|
/// contexts where access is not a problem.
|
||||||
void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
|
void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) override;
|
llvm::function_ref<void(TypeDecl *)> receiver);
|
||||||
|
|
||||||
/// Look up type a declaration synthesized by the Clang importer itself, using
|
/// Look up type a declaration synthesized by the Clang importer itself, using
|
||||||
/// a "related entity kind" to determine which type it should be. For example,
|
/// a "related entity kind" to determine which type it should be. For example,
|
||||||
@@ -173,7 +195,7 @@ public:
|
|||||||
void
|
void
|
||||||
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
|
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
|
||||||
StringRef relatedEntityKind,
|
StringRef relatedEntityKind,
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) override;
|
llvm::function_ref<void(TypeDecl *)> receiver);
|
||||||
|
|
||||||
/// Look for textually included declarations from the bridging header.
|
/// Look for textually included declarations from the bridging header.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
//===--- DWARFImporter.h - Import Clang Modules -----------------*- C++ -*-===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
|
||||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
//
|
|
||||||
// See https://swift.org/LICENSE.txt for license information
|
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// \file This file implements support for loading Clang modules that were
|
|
||||||
// reconstructed from DWARF into Swift.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
#ifndef SWIFT_DWARF_IMPORTER_H
|
|
||||||
#define SWIFT_DWARF_IMPORTER_H
|
|
||||||
|
|
||||||
#include "swift/AST/ClangModuleLoader.h"
|
|
||||||
#include "swift/AST/Module.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace clang {
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace swift {
|
|
||||||
|
|
||||||
/// This interface is implemented by LLDB to serve as a fallback when Clang
|
|
||||||
/// modules can't be imported from source in the debugger.
|
|
||||||
///
|
|
||||||
/// During compile time, ClangImporter-imported Clang modules are compiled with
|
|
||||||
/// -gmodules, which emits a DWARF rendition of all types defined in the module
|
|
||||||
/// into the .pcm file. On Darwin, these types can be collected by
|
|
||||||
/// dsymutil. This delegate allows DWARFImporter to ask LLDB to look up a Clang
|
|
||||||
/// type by name, synthesize a Clang AST from it. DWARFImporter then hands this
|
|
||||||
/// Clang AST to ClangImporter to import the type into Swift.
|
|
||||||
class DWARFImporterDelegate {
|
|
||||||
public:
|
|
||||||
virtual ~DWARFImporterDelegate() = default;
|
|
||||||
/// Perform a qualified lookup of a Clang type with this name.
|
|
||||||
/// \param kind Only return results with this type kind.
|
|
||||||
virtual void lookupValue(StringRef name, llvm::Optional<ClangTypeKind> kind,
|
|
||||||
SmallVectorImpl<clang::Decl *> &results) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Class that imports Clang modules into Swift, mapping directly
|
|
||||||
/// from Clang ASTs over to Swift ASTs.
|
|
||||||
class DWARFImporter final : public ClangModuleLoader {
|
|
||||||
friend class ClangModuleUnit;
|
|
||||||
|
|
||||||
public:
|
|
||||||
class Implementation;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Implementation &Impl;
|
|
||||||
|
|
||||||
DWARFImporter(ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
|
|
||||||
std::unique_ptr<DWARFImporterDelegate> delegate,
|
|
||||||
DependencyTracker *tracker);
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Create a new DWARF importer that can import a Clang Modules from DWARF
|
|
||||||
/// into the given ASTContext.
|
|
||||||
///
|
|
||||||
/// \param ctx The ASTContext into which the module will be imported.
|
|
||||||
/// The ASTContext's SearchPathOptions will be used for the DWARF importer.
|
|
||||||
///
|
|
||||||
/// \param importerOpts The options to use for the DWARF importer.
|
|
||||||
///
|
|
||||||
/// \param tracker The object tracking files this compilation depends on.
|
|
||||||
///
|
|
||||||
/// \returns a new DWARF module importer, or null (with a diagnostic) if
|
|
||||||
/// an error occurred.
|
|
||||||
static std::unique_ptr<DWARFImporter>
|
|
||||||
create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
|
|
||||||
std::unique_ptr<DWARFImporterDelegate> delegate = {},
|
|
||||||
DependencyTracker *tracker = nullptr);
|
|
||||||
|
|
||||||
DWARFImporter(const DWARFImporter &) = delete;
|
|
||||||
DWARFImporter(DWARFImporter &&) = delete;
|
|
||||||
DWARFImporter &operator=(const DWARFImporter &) = delete;
|
|
||||||
DWARFImporter &operator=(DWARFImporter &&) = delete;
|
|
||||||
|
|
||||||
~DWARFImporter();
|
|
||||||
|
|
||||||
void collectVisibleTopLevelModuleNames(
|
|
||||||
SmallVectorImpl<Identifier> &names) const override;
|
|
||||||
|
|
||||||
/// Check whether the module with a given name can be imported without
|
|
||||||
/// importing it.
|
|
||||||
///
|
|
||||||
/// Note that even if this check succeeds, errors may still occur if the
|
|
||||||
/// module is loaded in full.
|
|
||||||
bool canImportModule(std::pair<Identifier, SourceLoc> named) override;
|
|
||||||
bool addSearchPath(StringRef newSearchPath, bool isFramework,
|
|
||||||
bool isSystem) override;
|
|
||||||
ModuleDecl *
|
|
||||||
loadModule(SourceLoc importLoc,
|
|
||||||
ArrayRef<std::pair<Identifier, SourceLoc>> path) override;
|
|
||||||
|
|
||||||
ValueDecl *importDecl(clang::Decl *clangDecl);
|
|
||||||
|
|
||||||
void lookupValue(DeclName name, VisibleDeclConsumer &consumer) override {}
|
|
||||||
/// Behaves like \p ClangImporter::lookupValue.
|
|
||||||
void lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
|
||||||
NLKind lookupKind, SmallVectorImpl<ValueDecl *> &results);
|
|
||||||
/// Perform a qualified lookup of a Clang type with this name and only return
|
|
||||||
/// results with the specified type kind.
|
|
||||||
void lookupTypeDecl(StringRef rawName, ClangTypeKind kind,
|
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) override;
|
|
||||||
bool
|
|
||||||
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
|
|
||||||
const DeclContext *importedDC) override;
|
|
||||||
void loadExtensions(NominalTypeDecl *nominal,
|
|
||||||
unsigned previousGeneration) override;
|
|
||||||
void loadObjCMethods(
|
|
||||||
ClassDecl *classDecl, ObjCSelector selector, bool isInstanceMethod,
|
|
||||||
unsigned previousGeneration,
|
|
||||||
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods) override;
|
|
||||||
ModuleDecl *getImportedHeaderModule() const override;
|
|
||||||
void verifyAllModules() override;
|
|
||||||
clang::ASTContext &getClangASTContext() const override;
|
|
||||||
clang::Preprocessor &getClangPreprocessor() const override;
|
|
||||||
clang::Sema &getClangSema() const override;
|
|
||||||
const clang::CompilerInstance &getClangInstance() const override;
|
|
||||||
|
|
||||||
void printStatistics() const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace swift
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#include "swift/AST/ASTDemangler.h"
|
#include "swift/AST/ASTDemangler.h"
|
||||||
|
|
||||||
#include "swift/AST/ASTContext.h"
|
#include "swift/AST/ASTContext.h"
|
||||||
#include "swift/AST/ClangModuleLoader.h"
|
|
||||||
#include "swift/AST/Decl.h"
|
#include "swift/AST/Decl.h"
|
||||||
#include "swift/AST/GenericSignature.h"
|
#include "swift/AST/GenericSignature.h"
|
||||||
#include "swift/AST/GenericSignatureBuilder.h"
|
#include "swift/AST/GenericSignatureBuilder.h"
|
||||||
@@ -30,6 +29,7 @@
|
|||||||
#include "swift/AST/NameLookup.h"
|
#include "swift/AST/NameLookup.h"
|
||||||
#include "swift/AST/Type.h"
|
#include "swift/AST/Type.h"
|
||||||
#include "swift/AST/Types.h"
|
#include "swift/AST/Types.h"
|
||||||
|
#include "swift/ClangImporter/ClangImporter.h"
|
||||||
#include "swift/Demangling/Demangler.h"
|
#include "swift/Demangling/Demangler.h"
|
||||||
#include "swift/Demangling/ManglingMacros.h"
|
#include "swift/Demangling/ManglingMacros.h"
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
#include "llvm/ADT/StringSwitch.h"
|
||||||
@@ -1069,7 +1069,7 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
|
|||||||
ForeignModuleKind foreignKind,
|
ForeignModuleKind foreignKind,
|
||||||
Demangle::Node::Kind kind) {
|
Demangle::Node::Kind kind) {
|
||||||
// Check to see if we have an importer loaded.
|
// Check to see if we have an importer loaded.
|
||||||
auto importer = Ctx.getClangModuleLoader();
|
auto importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
|
||||||
if (!importer)
|
if (!importer)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
@@ -1118,11 +1118,6 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
|
|||||||
break;
|
break;
|
||||||
case ForeignModuleKind::Imported:
|
case ForeignModuleKind::Imported:
|
||||||
importer->lookupTypeDecl(name, *lookupKind, found);
|
importer->lookupTypeDecl(name, *lookupKind, found);
|
||||||
|
|
||||||
// Try the DWARFImporter if it exists.
|
|
||||||
if (!consumer.Result)
|
|
||||||
if (auto *dwarf_importer = Ctx.getDWARFModuleLoader())
|
|
||||||
dwarf_importer->lookupTypeDecl(name, *lookupKind, found);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return consumer.Result;
|
return consumer.Result;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ add_subdirectory(Basic)
|
|||||||
add_subdirectory(ClangImporter)
|
add_subdirectory(ClangImporter)
|
||||||
add_subdirectory(Demangling)
|
add_subdirectory(Demangling)
|
||||||
add_subdirectory(Driver)
|
add_subdirectory(Driver)
|
||||||
add_subdirectory(DWARFImporter)
|
|
||||||
add_subdirectory(Frontend)
|
add_subdirectory(Frontend)
|
||||||
add_subdirectory(FrontendTool)
|
add_subdirectory(FrontendTool)
|
||||||
add_subdirectory(Index)
|
add_subdirectory(Index)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ add_swift_host_library(swiftClangImporter STATIC
|
|||||||
ClangAdapter.cpp
|
ClangAdapter.cpp
|
||||||
ClangDiagnosticConsumer.cpp
|
ClangDiagnosticConsumer.cpp
|
||||||
ClangImporter.cpp
|
ClangImporter.cpp
|
||||||
|
DWARFImporter.cpp
|
||||||
IAMInference.cpp
|
IAMInference.cpp
|
||||||
ImportDecl.cpp
|
ImportDecl.cpp
|
||||||
ImportEnumInfo.cpp
|
ImportEnumInfo.cpp
|
||||||
|
|||||||
@@ -400,13 +400,13 @@ bool ClangImporter::Implementation::shouldIgnoreBridgeHeaderTopLevelDecl(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangImporter::ClangImporter(ASTContext &ctx,
|
ClangImporter::ClangImporter(
|
||||||
const ClangImporterOptions &clangImporterOpts,
|
ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
|
||||||
DependencyTracker *tracker)
|
DependencyTracker *tracker,
|
||||||
: ClangModuleLoader(tracker),
|
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate)
|
||||||
Impl(*new Implementation(ctx, clangImporterOpts))
|
: ClangModuleLoader(tracker),
|
||||||
{
|
Impl(*new Implementation(ctx, clangImporterOpts,
|
||||||
}
|
std::move(dwarfImporterDelegate))) {}
|
||||||
|
|
||||||
ClangImporter::~ClangImporter() {
|
ClangImporter::~ClangImporter() {
|
||||||
delete &Impl;
|
delete &Impl;
|
||||||
@@ -923,14 +923,12 @@ ClangImporter::getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
|
|||||||
return PCHFilename.getValue();
|
return PCHFilename.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ClangImporter>
|
std::unique_ptr<ClangImporter> ClangImporter::create(
|
||||||
ClangImporter::create(ASTContext &ctx,
|
ASTContext &ctx, const ClangImporterOptions &importerOpts,
|
||||||
const ClangImporterOptions &importerOpts,
|
std::string swiftPCHHash, DependencyTracker *tracker,
|
||||||
std::string swiftPCHHash,
|
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate) {
|
||||||
DependencyTracker *tracker) {
|
std::unique_ptr<ClangImporter> importer{new ClangImporter(
|
||||||
std::unique_ptr<ClangImporter> importer{
|
ctx, importerOpts, tracker, std::move(dwarfImporterDelegate))};
|
||||||
new ClangImporter(ctx, importerOpts, tracker)
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<std::string> invocationArgStrs;
|
std::vector<std::string> invocationArgStrs;
|
||||||
|
|
||||||
@@ -1581,7 +1579,7 @@ bool ClangImporter::canImportModule(std::pair<Identifier, SourceLoc> moduleID) {
|
|||||||
return clangModule->isAvailable(ctx.getLangOpts(), getTargetInfo(), r, mh, m);
|
return clangModule->isAvailable(ctx.getLangOpts(), getTargetInfo(), r, mh, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleDecl *ClangImporter::loadModule(
|
ModuleDecl *ClangImporter::loadModuleClang(
|
||||||
SourceLoc importLoc,
|
SourceLoc importLoc,
|
||||||
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
|
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
|
||||||
auto &clangContext = Impl.getClangASTContext();
|
auto &clangContext = Impl.getClangASTContext();
|
||||||
@@ -1674,6 +1672,15 @@ ModuleDecl *ClangImporter::loadModule(
|
|||||||
return Impl.finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
|
return Impl.finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModuleDecl *ClangImporter::loadModule(
|
||||||
|
SourceLoc importLoc,
|
||||||
|
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
|
||||||
|
ModuleDecl *MD = loadModuleClang(importLoc, path);
|
||||||
|
if (!MD)
|
||||||
|
MD = Impl.loadModuleDWARF(importLoc, path);
|
||||||
|
return MD;
|
||||||
|
}
|
||||||
|
|
||||||
ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
|
ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
|
||||||
const clang::Module *clangModule,
|
const clang::Module *clangModule,
|
||||||
bool findOverlay) {
|
bool findOverlay) {
|
||||||
@@ -1840,8 +1847,9 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
|
|||||||
llvm_unreachable("Unexpected platform");
|
llvm_unreachable("Unexpected platform");
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangImporter::Implementation::Implementation(ASTContext &ctx,
|
ClangImporter::Implementation::Implementation(
|
||||||
const ClangImporterOptions &opts)
|
ASTContext &ctx, const ClangImporterOptions &opts,
|
||||||
|
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate)
|
||||||
: SwiftContext(ctx),
|
: SwiftContext(ctx),
|
||||||
ImportForwardDeclarations(opts.ImportForwardDeclarations),
|
ImportForwardDeclarations(opts.ImportForwardDeclarations),
|
||||||
InferImportAsMember(opts.InferImportAsMember),
|
InferImportAsMember(opts.InferImportAsMember),
|
||||||
@@ -1851,8 +1859,8 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
|
|||||||
IsReadingBridgingPCH(false),
|
IsReadingBridgingPCH(false),
|
||||||
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
|
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
|
||||||
BridgingHeaderLookupTable(new SwiftLookupTable(nullptr)),
|
BridgingHeaderLookupTable(new SwiftLookupTable(nullptr)),
|
||||||
platformAvailability(ctx.LangOpts),
|
platformAvailability(ctx.LangOpts), nameImporter(),
|
||||||
nameImporter() {}
|
DWARFImporter(std::move(dwarfImporterDelegate)) {}
|
||||||
|
|
||||||
ClangImporter::Implementation::~Implementation() {
|
ClangImporter::Implementation::~Implementation() {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@@ -2493,11 +2501,11 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
|
|||||||
return true; // no info found about that header.
|
return true; // no info found about that header.
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangImporter::lookupValue(DeclName name, VisibleDeclConsumer &consumer){
|
void ClangImporter::lookupValue(DeclName name, VisibleDeclConsumer &consumer) {
|
||||||
Impl.forEachLookupTable([&](SwiftLookupTable &table) -> bool {
|
Impl.forEachLookupTable([&](SwiftLookupTable &table) -> bool {
|
||||||
Impl.lookupValue(table, name, consumer);
|
Impl.lookupValue(table, name, consumer);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangImporter::lookupTypeDecl(
|
void ClangImporter::lookupTypeDecl(
|
||||||
@@ -2523,6 +2531,7 @@ void ClangImporter::lookupTypeDecl(
|
|||||||
auto &sema = Impl.Instance->getSema();
|
auto &sema = Impl.Instance->getSema();
|
||||||
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
|
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
|
||||||
lookupKind);
|
lookupKind);
|
||||||
|
bool foundViaClang = false;
|
||||||
if (sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
|
if (sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
|
||||||
for (auto clangDecl : lookupResult) {
|
for (auto clangDecl : lookupResult) {
|
||||||
if (!isa<clang::TypeDecl>(clangDecl) &&
|
if (!isa<clang::TypeDecl>(clangDecl) &&
|
||||||
@@ -2531,10 +2540,16 @@ void ClangImporter::lookupTypeDecl(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto *imported = Impl.importDecl(clangDecl, Impl.CurrentVersion);
|
auto *imported = Impl.importDecl(clangDecl, Impl.CurrentVersion);
|
||||||
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported))
|
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported)) {
|
||||||
|
foundViaClang = true;
|
||||||
receiver(importedType);
|
receiver(importedType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If Clang couldn't find the type, query the DWARFImporterDelegate.
|
||||||
|
if (!foundViaClang)
|
||||||
|
Impl.lookupTypeDeclDWARF(rawName, kind, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangImporter::lookupRelatedEntity(
|
void ClangImporter::lookupRelatedEntity(
|
||||||
|
|||||||
178
lib/ClangImporter/DWARFImporter.cpp
Normal file
178
lib/ClangImporter/DWARFImporter.cpp
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
//===--- DWARFImporter.cpp - Import Clang modules from DWARF --------------===//
|
||||||
|
//
|
||||||
|
// This source file is part of the Swift.org open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
||||||
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
//
|
||||||
|
// See https://swift.org/LICENSE.txt for license information
|
||||||
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "ImporterImpl.h"
|
||||||
|
#include "swift/AST/Module.h"
|
||||||
|
|
||||||
|
using namespace swift;
|
||||||
|
|
||||||
|
/// Represents a Clang module that was "imported" from debug info. Since all the
|
||||||
|
/// loading of types is done on demand, this class is effectively empty.
|
||||||
|
class DWARFModuleUnit final : public LoadedFile {
|
||||||
|
~DWARFModuleUnit() = default;
|
||||||
|
ClangImporter::Implementation &owner;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DWARFModuleUnit(ModuleDecl &M, ClangImporter::Implementation &owner)
|
||||||
|
: LoadedFile(FileUnitKind::DWARFModule, M), owner(owner) {}
|
||||||
|
|
||||||
|
virtual bool isSystemModule() const override { return false; }
|
||||||
|
|
||||||
|
/// Forwards the request to the ClangImporter, which forwards it to the
|
||||||
|
/// DWARFimporterDelegate.
|
||||||
|
virtual void
|
||||||
|
lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
||||||
|
NLKind lookupKind,
|
||||||
|
SmallVectorImpl<ValueDecl *> &results) const override {
|
||||||
|
owner.lookupValueDWARF(accessPath, name, lookupKind, results);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual TypeDecl *
|
||||||
|
lookupNestedType(Identifier name,
|
||||||
|
const NominalTypeDecl *baseType) const override {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
|
||||||
|
VisibleDeclConsumer &consumer,
|
||||||
|
NLKind lookupKind) const override {}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
|
||||||
|
VisibleDeclConsumer &consumer) const override {}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
lookupClassMember(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
||||||
|
SmallVectorImpl<ValueDecl *> &decls) const override {}
|
||||||
|
|
||||||
|
void lookupObjCMethods(
|
||||||
|
ObjCSelector selector,
|
||||||
|
SmallVectorImpl<AbstractFunctionDecl *> &results) const override {}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
getTopLevelDecls(SmallVectorImpl<Decl *> &results) const override {}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
getDisplayDecls(SmallVectorImpl<Decl *> &results) const override {}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
getImportedModules(SmallVectorImpl<ModuleDecl::ImportedModule> &imports,
|
||||||
|
ModuleDecl::ImportFilter filter) const override {}
|
||||||
|
|
||||||
|
virtual void getImportedModulesForLookup(
|
||||||
|
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const override {};
|
||||||
|
|
||||||
|
virtual void collectLinkLibraries(
|
||||||
|
ModuleDecl::LinkLibraryCallback callback) const override {};
|
||||||
|
|
||||||
|
Identifier
|
||||||
|
getDiscriminatorForPrivateValue(const ValueDecl *D) const override {
|
||||||
|
llvm_unreachable("no private decls in Clang modules");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual StringRef getFilename() const override { return ""; }
|
||||||
|
|
||||||
|
virtual const clang::Module *getUnderlyingClangModule() const override {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool classof(const FileUnit *file) {
|
||||||
|
return file->getKind() == FileUnitKind::DWARFModule;
|
||||||
|
}
|
||||||
|
static bool classof(const DeclContext *DC) {
|
||||||
|
return isa<FileUnit>(DC) && classof(cast<FileUnit>(DC));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ModuleDecl *ClangImporter::Implementation::loadModuleDWARF(
|
||||||
|
SourceLoc importLoc, ArrayRef<std::pair<Identifier, SourceLoc>> path) {
|
||||||
|
// There's no importing from debug info if no importer is installed.
|
||||||
|
if (!DWARFImporter)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// FIXME: Implement submodule support!
|
||||||
|
Identifier name = path[0].first;
|
||||||
|
auto it = DWARFModuleUnits.find(name);
|
||||||
|
if (it != DWARFModuleUnits.end())
|
||||||
|
return it->second->getParentModule();
|
||||||
|
|
||||||
|
auto *decl = ModuleDecl::create(name, SwiftContext);
|
||||||
|
decl->setIsNonSwiftModule();
|
||||||
|
decl->setHasResolvedImports();
|
||||||
|
auto wrapperUnit = new (SwiftContext) DWARFModuleUnit(*decl, *this);
|
||||||
|
DWARFModuleUnits.insert({name, wrapperUnit});
|
||||||
|
decl->addFile(*wrapperUnit);
|
||||||
|
|
||||||
|
// Force load overlay modules for all imported modules.
|
||||||
|
decl->forAllVisibleModules({}, [](ModuleDecl::ImportedModule import) {});
|
||||||
|
|
||||||
|
// Register the module with the ASTContext so it is available for lookups.
|
||||||
|
ModuleDecl *&loaded = SwiftContext.LoadedModules[name];
|
||||||
|
if (!loaded)
|
||||||
|
loaded = decl;
|
||||||
|
|
||||||
|
return decl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangImporter::Implementation::lookupValueDWARF(
|
||||||
|
ModuleDecl::AccessPathTy accessPath, DeclName name, NLKind lookupKind,
|
||||||
|
SmallVectorImpl<ValueDecl *> &results) {
|
||||||
|
if (!swift::ModuleDecl::matchesAccessPath(accessPath, name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (lookupKind != NLKind::QualifiedLookup)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!DWARFImporter)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SmallVector<clang::Decl *, 4> decls;
|
||||||
|
DWARFImporter->lookupValue(name.getBaseIdentifier().str(), llvm::None, decls);
|
||||||
|
for (auto *clangDecl : decls) {
|
||||||
|
auto *namedDecl = dyn_cast_or_null<clang::NamedDecl>(clangDecl);
|
||||||
|
if (!namedDecl)
|
||||||
|
continue;
|
||||||
|
auto *swiftDecl = cast_or_null<ValueDecl>(
|
||||||
|
importDeclReal(namedDecl->getMostRecentDecl(), CurrentVersion));
|
||||||
|
if (!swiftDecl)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (swiftDecl->getFullName().matchesRef(name) &&
|
||||||
|
swiftDecl->getDeclContext()->isModuleScopeContext())
|
||||||
|
results.push_back(swiftDecl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangImporter::Implementation::lookupTypeDeclDWARF(
|
||||||
|
StringRef rawName, ClangTypeKind kind,
|
||||||
|
llvm::function_ref<void(TypeDecl *)> receiver) {
|
||||||
|
if (!DWARFImporter)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SmallVector<clang::Decl *, 1> decls;
|
||||||
|
DWARFImporter->lookupValue(rawName, kind, decls);
|
||||||
|
for (auto *clangDecl : decls) {
|
||||||
|
if (!isa<clang::TypeDecl>(clangDecl) &&
|
||||||
|
!isa<clang::ObjCContainerDecl>(clangDecl) &&
|
||||||
|
!isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto *namedDecl = dyn_cast_or_null<clang::NamedDecl>(clangDecl);
|
||||||
|
if (!namedDecl)
|
||||||
|
continue;
|
||||||
|
Decl *importedDecl = cast_or_null<ValueDecl>(
|
||||||
|
importDeclReal(namedDecl->getMostRecentDecl(), CurrentVersion));
|
||||||
|
|
||||||
|
if (auto *importedType = dyn_cast_or_null<TypeDecl>(importedDecl))
|
||||||
|
receiver(importedType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -318,11 +318,11 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
|
|||||||
public LazyConformanceLoader
|
public LazyConformanceLoader
|
||||||
{
|
{
|
||||||
friend class ClangImporter;
|
friend class ClangImporter;
|
||||||
friend class DWARFImporter;
|
|
||||||
using Version = importer::ImportNameVersion;
|
using Version = importer::ImportNameVersion;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Implementation(ASTContext &ctx, const ClangImporterOptions &opts);
|
Implementation(ASTContext &ctx, const ClangImporterOptions &opts,
|
||||||
|
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate);
|
||||||
~Implementation();
|
~Implementation();
|
||||||
|
|
||||||
/// Swift AST context.
|
/// Swift AST context.
|
||||||
@@ -603,7 +603,18 @@ public:
|
|||||||
void addBridgeHeaderTopLevelDecls(clang::Decl *D);
|
void addBridgeHeaderTopLevelDecls(clang::Decl *D);
|
||||||
bool shouldIgnoreBridgeHeaderTopLevelDecl(clang::Decl *D);
|
bool shouldIgnoreBridgeHeaderTopLevelDecl(clang::Decl *D);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// The DWARF importer delegate, if installed.
|
||||||
|
std::unique_ptr<DWARFImporterDelegate> DWARFImporter;
|
||||||
|
/// The list of Clang modules found in the debug info.
|
||||||
|
llvm::DenseMap<Identifier, LoadedFile *> DWARFModuleUnits;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// "Import" a module from debug info. Because debug info types are read on
|
||||||
|
/// demand, this doesn't really do any work.
|
||||||
|
ModuleDecl *loadModuleDWARF(SourceLoc importLoc,
|
||||||
|
ArrayRef<std::pair<Identifier, SourceLoc>> path);
|
||||||
|
|
||||||
void recordImplicitUnwrapForDecl(Decl *decl, bool isIUO) {
|
void recordImplicitUnwrapForDecl(Decl *decl, bool isIUO) {
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
Type ty;
|
Type ty;
|
||||||
@@ -1308,6 +1319,17 @@ public:
|
|||||||
void lookupValue(SwiftLookupTable &table, DeclName name,
|
void lookupValue(SwiftLookupTable &table, DeclName name,
|
||||||
VisibleDeclConsumer &consumer);
|
VisibleDeclConsumer &consumer);
|
||||||
|
|
||||||
|
/// Look for namespace-scope values with the given name using the
|
||||||
|
/// DWARFImporterDelegate.
|
||||||
|
void lookupValueDWARF(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
||||||
|
NLKind lookupKind,
|
||||||
|
SmallVectorImpl<ValueDecl *> &results);
|
||||||
|
|
||||||
|
/// Look for top-level scope types with a name and kind using the
|
||||||
|
/// DWARFImporterDelegate.
|
||||||
|
void lookupTypeDeclDWARF(StringRef rawName, ClangTypeKind kind,
|
||||||
|
llvm::function_ref<void(TypeDecl *)> receiver);
|
||||||
|
|
||||||
/// Look for namespace-scope values in the given Swift lookup table.
|
/// Look for namespace-scope values in the given Swift lookup table.
|
||||||
void lookupVisibleDecls(SwiftLookupTable &table,
|
void lookupVisibleDecls(SwiftLookupTable &table,
|
||||||
VisibleDeclConsumer &consumer);
|
VisibleDeclConsumer &consumer);
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
add_swift_host_library(swiftDWARFImporter STATIC
|
|
||||||
DWARFImporter.cpp)
|
|
||||||
target_link_libraries(swiftDWARFImporter PRIVATE
|
|
||||||
swiftAST
|
|
||||||
swiftParse
|
|
||||||
)
|
|
||||||
@@ -1,286 +0,0 @@
|
|||||||
//===--- DWARFImporter.cpp - Import Clang modules from DWARF --------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
|
||||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
//
|
|
||||||
// See https://swift.org/LICENSE.txt for license information
|
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "swift/DWARFImporter/DWARFImporter.h"
|
|
||||||
#include "swift/AST/ASTContext.h"
|
|
||||||
#include "swift/AST/Module.h"
|
|
||||||
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
|
||||||
#include "clang/Frontend/FrontendActions.h"
|
|
||||||
#include "../ClangImporter/ImporterImpl.h"
|
|
||||||
|
|
||||||
using namespace swift;
|
|
||||||
|
|
||||||
std::unique_ptr<DWARFImporter>
|
|
||||||
DWARFImporter::create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
|
|
||||||
std::unique_ptr<DWARFImporterDelegate> delegate,
|
|
||||||
DependencyTracker *tracker) {
|
|
||||||
std::unique_ptr<DWARFImporter> importer{
|
|
||||||
new DWARFImporter(ctx, importerOpts, std::move(delegate), tracker)
|
|
||||||
};
|
|
||||||
return importer;
|
|
||||||
}
|
|
||||||
|
|
||||||
class DWARFModuleUnit final : public LoadedFile {
|
|
||||||
|
|
||||||
~DWARFModuleUnit() = default;
|
|
||||||
DWARFImporter::Implementation &owner;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DWARFModuleUnit(ModuleDecl &M, DWARFImporter::Implementation &owner)
|
|
||||||
: LoadedFile(FileUnitKind::DWARFModule, M), owner(owner) {}
|
|
||||||
|
|
||||||
virtual bool isSystemModule() const override { return false; }
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
|
||||||
NLKind lookupKind,
|
|
||||||
SmallVectorImpl<ValueDecl *> &results) const override;
|
|
||||||
|
|
||||||
virtual TypeDecl *
|
|
||||||
lookupNestedType(Identifier name,
|
|
||||||
const NominalTypeDecl *baseType) const override {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
|
|
||||||
VisibleDeclConsumer &consumer,
|
|
||||||
NLKind lookupKind) const override {}
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
|
|
||||||
VisibleDeclConsumer &consumer) const override {}
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
lookupClassMember(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
|
||||||
SmallVectorImpl<ValueDecl *> &decls) const override {}
|
|
||||||
|
|
||||||
void lookupObjCMethods(
|
|
||||||
ObjCSelector selector,
|
|
||||||
SmallVectorImpl<AbstractFunctionDecl *> &results) const override {}
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
getTopLevelDecls(SmallVectorImpl<Decl *> &results) const override {}
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
getDisplayDecls(SmallVectorImpl<Decl *> &results) const override {}
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
getImportedModules(SmallVectorImpl<ModuleDecl::ImportedModule> &imports,
|
|
||||||
ModuleDecl::ImportFilter filter) const override {}
|
|
||||||
|
|
||||||
virtual void getImportedModulesForLookup(
|
|
||||||
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const override {};
|
|
||||||
|
|
||||||
virtual void collectLinkLibraries(
|
|
||||||
ModuleDecl::LinkLibraryCallback callback) const override {};
|
|
||||||
|
|
||||||
Identifier
|
|
||||||
getDiscriminatorForPrivateValue(const ValueDecl *D) const override {
|
|
||||||
llvm_unreachable("no private decls in Clang modules");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual StringRef getFilename() const override { return ""; }
|
|
||||||
|
|
||||||
virtual const clang::Module *getUnderlyingClangModule() const override {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool classof(const FileUnit *file) {
|
|
||||||
return file->getKind() == FileUnitKind::DWARFModule;
|
|
||||||
}
|
|
||||||
static bool classof(const DeclContext *DC) {
|
|
||||||
return isa<FileUnit>(DC) && classof(cast<FileUnit>(DC));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class DWARFImporter::Implementation {
|
|
||||||
public:
|
|
||||||
ASTContext &SwiftContext;
|
|
||||||
|
|
||||||
std::unique_ptr<DWARFImporterDelegate> delegate;
|
|
||||||
ClangImporter &clangImporter;
|
|
||||||
|
|
||||||
llvm::DenseMap<Identifier, DWARFModuleUnit *> ModuleWrappers;
|
|
||||||
Implementation(ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
|
|
||||||
std::unique_ptr<DWARFImporterDelegate> delegate,
|
|
||||||
DependencyTracker *tracker)
|
|
||||||
: SwiftContext(ctx), delegate(std::move(delegate)),
|
|
||||||
clangImporter(
|
|
||||||
*static_cast<ClangImporter *>(ctx.getClangModuleLoader())) {}
|
|
||||||
|
|
||||||
ModuleDecl *loadModule(SourceLoc importLoc,
|
|
||||||
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
|
|
||||||
// FIXME: Implement submodule support!
|
|
||||||
Identifier name = path[0].first;
|
|
||||||
|
|
||||||
auto it = ModuleWrappers.find(name);
|
|
||||||
if (it != ModuleWrappers.end())
|
|
||||||
return it->second->getParentModule();
|
|
||||||
|
|
||||||
auto *decl = ModuleDecl::create(name, SwiftContext);
|
|
||||||
decl->setIsNonSwiftModule();
|
|
||||||
decl->setHasResolvedImports();
|
|
||||||
auto wrapperUnit = new (SwiftContext) DWARFModuleUnit(*decl, *this);
|
|
||||||
ModuleWrappers.insert({name, wrapperUnit});
|
|
||||||
decl->addFile(*wrapperUnit);
|
|
||||||
|
|
||||||
// Force load overlay modules for all imported modules.
|
|
||||||
decl->forAllVisibleModules({}, [](ModuleDecl::ImportedModule import) {});
|
|
||||||
|
|
||||||
// Register the module with the ASTContext so it is available for lookups.
|
|
||||||
ModuleDecl *&loaded = SwiftContext.LoadedModules[name];
|
|
||||||
if (!loaded)
|
|
||||||
loaded = decl;
|
|
||||||
|
|
||||||
return decl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
ValueDecl *importDecl(clang::Decl *clangDecl) {
|
|
||||||
auto *namedDecl = dyn_cast_or_null<clang::NamedDecl>(clangDecl);
|
|
||||||
if (!namedDecl)
|
|
||||||
return nullptr;
|
|
||||||
return cast_or_null<ValueDecl>(clangImporter.Impl.importDeclReal(
|
|
||||||
namedDecl->getMostRecentDecl(), clangImporter.Impl.CurrentVersion));
|
|
||||||
}
|
|
||||||
|
|
||||||
void lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
|
||||||
NLKind lookupKind, SmallVectorImpl<ValueDecl *> &results) {
|
|
||||||
if (!swift::ModuleDecl::matchesAccessPath(accessPath, name))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (lookupKind != NLKind::QualifiedLookup)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!delegate)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SmallVector<clang::Decl *, 4> decls;
|
|
||||||
delegate->lookupValue(name.getBaseIdentifier().str(), llvm::None, decls);
|
|
||||||
for (auto *clangDecl : decls) {
|
|
||||||
auto *decl = importDecl(clangDecl);
|
|
||||||
if (!decl)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (decl->getFullName().matchesRef(name) &&
|
|
||||||
decl->getDeclContext()->isModuleScopeContext())
|
|
||||||
results.push_back(decl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void lookupTypeDecl(StringRef rawName, ClangTypeKind kind,
|
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) {
|
|
||||||
SmallVector<clang::Decl *, 1> decls;
|
|
||||||
delegate->lookupValue(rawName, kind, decls);
|
|
||||||
for (auto *clangDecl : decls) {
|
|
||||||
if (!isa<clang::TypeDecl>(clangDecl) &&
|
|
||||||
!isa<clang::ObjCContainerDecl>(clangDecl) &&
|
|
||||||
!isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto *imported = importDecl(clangDecl);
|
|
||||||
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported))
|
|
||||||
receiver(importedType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clang::ASTContext &getClangASTContext() const {
|
|
||||||
return clangImporter.getClangASTContext();
|
|
||||||
}
|
|
||||||
clang::Preprocessor &getClangPreprocessor() const {
|
|
||||||
return clangImporter.getClangPreprocessor();
|
|
||||||
}
|
|
||||||
clang::Sema &getClangSema() const { return clangImporter.getClangSema(); }
|
|
||||||
const clang::CompilerInstance &getClangInstance() const {
|
|
||||||
return clangImporter.getClangInstance();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void DWARFModuleUnit::lookupValue(ModuleDecl::AccessPathTy accessPath,
|
|
||||||
DeclName name, NLKind lookupKind,
|
|
||||||
SmallVectorImpl<ValueDecl *> &results) const {
|
|
||||||
owner.lookupValue(accessPath, name, lookupKind, results);
|
|
||||||
}
|
|
||||||
|
|
||||||
DWARFImporter::DWARFImporter(ASTContext &ctx,
|
|
||||||
const ClangImporterOptions &clangImporterOpts,
|
|
||||||
std::unique_ptr<DWARFImporterDelegate> delegate,
|
|
||||||
DependencyTracker *tracker)
|
|
||||||
: ClangModuleLoader(tracker),
|
|
||||||
Impl(*new Implementation(ctx, clangImporterOpts, std::move(delegate),
|
|
||||||
tracker)) {}
|
|
||||||
|
|
||||||
DWARFImporter::~DWARFImporter() { delete &Impl; }
|
|
||||||
|
|
||||||
void DWARFImporter::collectVisibleTopLevelModuleNames(
|
|
||||||
SmallVectorImpl<Identifier> &names) const {}
|
|
||||||
|
|
||||||
bool DWARFImporter::canImportModule(std::pair<Identifier, SourceLoc> named) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DWARFImporter::addSearchPath(StringRef newSearchPath, bool isFramework,
|
|
||||||
bool isSystem) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ModuleDecl *
|
|
||||||
DWARFImporter::loadModule(SourceLoc importLoc,
|
|
||||||
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
|
|
||||||
return Impl.loadModule(importLoc, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueDecl *DWARFImporter::importDecl(clang::Decl *clangDecl) {
|
|
||||||
return Impl.importDecl(clangDecl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DWARFImporter::lookupValue(ModuleDecl::AccessPathTy accessPath,
|
|
||||||
DeclName name, NLKind lookupKind,
|
|
||||||
SmallVectorImpl<ValueDecl *> &results) {
|
|
||||||
Impl.lookupValue(accessPath, name, lookupKind, results);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DWARFImporter::lookupTypeDecl(
|
|
||||||
StringRef rawName, ClangTypeKind kind,
|
|
||||||
llvm::function_ref<void(TypeDecl *)> receiver) {
|
|
||||||
Impl.lookupTypeDecl(rawName, kind, receiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DWARFImporter::isInOverlayModuleForImportedModule(
|
|
||||||
const DeclContext *overlayDC, const DeclContext *importedDC) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DWARFImporter::loadExtensions(NominalTypeDecl *nominal,
|
|
||||||
unsigned previousGeneration) {}
|
|
||||||
|
|
||||||
void DWARFImporter::loadObjCMethods(
|
|
||||||
ClassDecl *classDecl, ObjCSelector selector, bool isInstanceMethod,
|
|
||||||
unsigned previousGeneration,
|
|
||||||
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods) {}
|
|
||||||
|
|
||||||
ModuleDecl *DWARFImporter::getImportedHeaderModule() const { return nullptr; }
|
|
||||||
|
|
||||||
void DWARFImporter::verifyAllModules() {};
|
|
||||||
|
|
||||||
clang::ASTContext &DWARFImporter::getClangASTContext() const {
|
|
||||||
return Impl.getClangASTContext();
|
|
||||||
}
|
|
||||||
clang::Preprocessor &DWARFImporter::getClangPreprocessor() const {
|
|
||||||
return Impl.getClangPreprocessor();
|
|
||||||
}
|
|
||||||
clang::Sema &DWARFImporter::getClangSema() const { return Impl.getClangSema(); }
|
|
||||||
const clang::CompilerInstance &DWARFImporter::getClangInstance() const {
|
|
||||||
return Impl.getClangInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DWARFImporter::printStatistics() const {}
|
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
#include "swift/Basic/FileTypes.h"
|
#include "swift/Basic/FileTypes.h"
|
||||||
#include "swift/Basic/SourceManager.h"
|
#include "swift/Basic/SourceManager.h"
|
||||||
#include "swift/Basic/Statistic.h"
|
#include "swift/Basic/Statistic.h"
|
||||||
#include "swift/DWARFImporter/DWARFImporter.h"
|
|
||||||
#include "swift/Frontend/ParseableInterfaceModuleLoader.h"
|
#include "swift/Frontend/ParseableInterfaceModuleLoader.h"
|
||||||
#include "swift/Parse/DelayedParsingCallbacks.h"
|
#include "swift/Parse/DelayedParsingCallbacks.h"
|
||||||
#include "swift/Parse/Lexer.h"
|
#include "swift/Parse/Lexer.h"
|
||||||
@@ -377,17 +376,6 @@ bool CompilerInstance::setUpModuleLoaders() {
|
|||||||
Context->addModuleLoader(std::move(SML));
|
Context->addModuleLoader(std::move(SML));
|
||||||
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
|
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
|
||||||
|
|
||||||
if (Invocation.getLangOptions().EnableDWARFImporter) {
|
|
||||||
auto dwarfImporter =
|
|
||||||
DWARFImporter::create(*Context, Invocation.getClangImporterOptions(),
|
|
||||||
nullptr, getDependencyTracker());
|
|
||||||
if (!dwarfImporter) {
|
|
||||||
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Context->addModuleLoader(std::move(dwarfImporter));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ target_link_libraries(swiftFrontendTool INTERFACE
|
|||||||
target_link_libraries(swiftFrontendTool PRIVATE
|
target_link_libraries(swiftFrontendTool PRIVATE
|
||||||
swiftClangImporter
|
swiftClangImporter
|
||||||
swiftDemangling
|
swiftDemangling
|
||||||
swiftDWARFImporter
|
|
||||||
swiftFrontend
|
swiftFrontend
|
||||||
swiftIDE
|
swiftIDE
|
||||||
swiftImmediate
|
swiftImmediate
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ add_swift_host_library(swiftIDE STATIC
|
|||||||
target_link_libraries(swiftIDE PRIVATE
|
target_link_libraries(swiftIDE PRIVATE
|
||||||
swiftAST
|
swiftAST
|
||||||
swiftClangImporter
|
swiftClangImporter
|
||||||
swiftDWARFImporter
|
|
||||||
swiftFrontend
|
swiftFrontend
|
||||||
swiftIndex
|
swiftIndex
|
||||||
swiftParse
|
swiftParse
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
module ObjCModule {
|
|
||||||
header "objc-header.h"
|
|
||||||
export *
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
struct Point {
|
|
||||||
int x, y;
|
|
||||||
};
|
|
||||||
|
|
||||||
@interface ObjCClass
|
|
||||||
- (instancetype)init;
|
|
||||||
@end
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
// REQUIRES: executable_test
|
|
||||||
// REQUIRES: objc_interop
|
|
||||||
|
|
||||||
// RUN: %empty-directory(%t)
|
|
||||||
|
|
||||||
// RUN: cp %S/Inputs/objc-header.h %S/Inputs/module.modulemap %t
|
|
||||||
// RUN: %target-build-swift -emit-executable %s -g -o %t/a.out \
|
|
||||||
// RUN: -module-name basic -emit-module -I%t
|
|
||||||
// -DOBJC -module-name basic
|
|
||||||
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out | %FileCheck %s
|
|
||||||
|
|
||||||
// RUN: rm %t/objc-header.h
|
|
||||||
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out \
|
|
||||||
// RUN: | %FileCheck %s --check-prefix=FAIL
|
|
||||||
|
|
||||||
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out \
|
|
||||||
// RUN: -enable-dwarf-importer | %FileCheck %s --check-prefix=SWIFTONLY
|
|
||||||
|
|
||||||
// CHECK: Importing basic... ok!
|
|
||||||
// FAIL: Importing basic... ok!
|
|
||||||
// SWIFTONLY: Importing basic... ok!
|
|
||||||
import ObjCModule
|
|
||||||
|
|
||||||
let pureSwift = Int32(42)
|
|
||||||
// FAIL-NOT: var_decl
|
|
||||||
// CHECK: var_decl "pureSwift" {{.*}} type='Int32'
|
|
||||||
// SWIFTONLY: var_decl "pureSwift" {{.*}} type='Int32'
|
|
||||||
|
|
||||||
let point = Point(x: 1, y: 2)
|
|
||||||
// CHECK: var_decl "point" {{.*}} type='Point'
|
|
||||||
// SWIFTONLY-NOT: var_decl "point"
|
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ add_sourcekit_library(SourceKitSwiftLang
|
|||||||
SwiftTypeContextInfo.cpp
|
SwiftTypeContextInfo.cpp
|
||||||
LINK_LIBS
|
LINK_LIBS
|
||||||
SourceKitCore swiftDriver swiftFrontend
|
SourceKitCore swiftDriver swiftFrontend
|
||||||
swiftDWARFImporter swiftClangImporter swiftIDE
|
swiftClangImporter swiftIDE
|
||||||
swiftAST swiftMarkup swiftParse swiftParseSIL swiftSIL swiftSILGen
|
swiftAST swiftMarkup swiftParse swiftParseSIL swiftSIL swiftSILGen
|
||||||
swiftSILOptimizer swiftIRGen swiftSema swiftBasic swiftSerialization
|
swiftSILOptimizer swiftIRGen swiftSema swiftBasic swiftSerialization
|
||||||
swiftSyntax swiftOption libcmark_static
|
swiftSyntax swiftOption libcmark_static
|
||||||
|
|||||||
@@ -6,6 +6,5 @@ target_link_libraries(lldb-moduleimport-test
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
swiftASTSectionImporter
|
swiftASTSectionImporter
|
||||||
swiftClangImporter
|
swiftClangImporter
|
||||||
swiftDWARFImporter
|
|
||||||
swiftFrontend)
|
swiftFrontend)
|
||||||
|
|
||||||
|
|||||||
@@ -225,10 +225,6 @@ int main(int argc, char **argv) {
|
|||||||
desc("The directory that holds the compiler resource files"),
|
desc("The directory that holds the compiler resource files"),
|
||||||
cat(Visible));
|
cat(Visible));
|
||||||
|
|
||||||
opt<bool> EnableDWARFImporter(
|
|
||||||
"enable-dwarf-importer",
|
|
||||||
desc("Import with LangOptions.EnableDWARFImporter = true"), cat(Visible));
|
|
||||||
|
|
||||||
ParseCommandLineOptions(argc, argv);
|
ParseCommandLineOptions(argc, argv);
|
||||||
|
|
||||||
// Unregister our options so they don't interfere with the command line
|
// Unregister our options so they don't interfere with the command line
|
||||||
@@ -295,7 +291,6 @@ int main(int argc, char **argv) {
|
|||||||
Invocation.setModuleName("lldbtest");
|
Invocation.setModuleName("lldbtest");
|
||||||
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
|
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
|
||||||
Invocation.getLangOptions().EnableMemoryBufferImporter = true;
|
Invocation.getLangOptions().EnableMemoryBufferImporter = true;
|
||||||
Invocation.getLangOptions().EnableDWARFImporter = EnableDWARFImporter;
|
|
||||||
|
|
||||||
if (!ResourceDir.empty()) {
|
if (!ResourceDir.empty()) {
|
||||||
Invocation.setRuntimeResourcePath(ResourceDir);
|
Invocation.setRuntimeResourcePath(ResourceDir);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ add_swift_host_tool(sil-func-extractor
|
|||||||
target_link_libraries(sil-func-extractor
|
target_link_libraries(sil-func-extractor
|
||||||
PRIVATE
|
PRIVATE
|
||||||
swiftClangImporter
|
swiftClangImporter
|
||||||
swiftDWARFImporter
|
|
||||||
swiftFrontend
|
swiftFrontend
|
||||||
swiftSerialization
|
swiftSerialization
|
||||||
swiftSILGen
|
swiftSILGen
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ add_swift_host_tool(sil-nm
|
|||||||
target_link_libraries(sil-nm
|
target_link_libraries(sil-nm
|
||||||
PRIVATE
|
PRIVATE
|
||||||
swiftClangImporter
|
swiftClangImporter
|
||||||
swiftDWARFImporter
|
|
||||||
swiftFrontend
|
swiftFrontend
|
||||||
swiftSerialization
|
swiftSerialization
|
||||||
swiftSILGen
|
swiftSILGen
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ target_link_libraries(SwiftParseTests
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
swiftSIL
|
swiftSIL
|
||||||
swiftClangImporter
|
swiftClangImporter
|
||||||
swiftDWARFImporter
|
|
||||||
swiftParse
|
swiftParse
|
||||||
swiftAST
|
swiftAST
|
||||||
# FIXME: Sema must go last because of circular dependencies with AST.
|
# FIXME: Sema must go last because of circular dependencies with AST.
|
||||||
swiftSema
|
swiftSema
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,6 @@
|
|||||||
// REQUIRES: OS=macosx
|
// REQUIRES: OS=macosx
|
||||||
// REQUIRES: asserts
|
// REQUIRES: asserts
|
||||||
// REQUIRES: CMAKE_GENERATOR=Ninja
|
// REQUIRES: CMAKE_GENERATOR=Ninja
|
||||||
|
//
|
||||||
|
// TODO: Re-enable this.
|
||||||
|
// REQUIRES: disabled
|
||||||
|
|||||||
Reference in New Issue
Block a user