Skip to content

Move DWARFImporterDelegate into ClangImporter and remove DWARFImporter. #26648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions include/swift/AST/ClangModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,6 @@ class ClangModuleLoader : public ModuleLoader {
virtual bool
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
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
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ namespace swift {
/// Only used by lldb-moduleimport-test.
bool EnableMemoryBufferImporter = false;

/// Enable the DWARFImporter. Only used by lldb-moduleimport-test.
bool EnableDWARFImporter = false;

/// Allows using identifiers with a leading dollar.
bool EnableDollarIdentifiers = false;

Expand Down
40 changes: 31 additions & 9 deletions include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,28 @@ class TypeDecl;
class VisibleDeclConsumer;
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
/// from Clang ASTs over to Swift ASTs.
class ClangImporter final : public ClangModuleLoader {
friend class ClangModuleUnit;
friend class DWARFImporter;

public:
class Implementation;
Expand All @@ -73,8 +90,11 @@ class ClangImporter final : public ClangModuleLoader {
Implementation &Impl;

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:
/// Create a new Clang importer that can import a suitable Clang
/// module into the given ASTContext.
Expand All @@ -89,13 +109,15 @@ class ClangImporter final : public ClangModuleLoader {
///
/// \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
/// an error occurred.
static std::unique_ptr<ClangImporter>
create(ASTContext &ctx,
const ClangImporterOptions &importerOpts,
std::string swiftPCHHash = "",
DependencyTracker *tracker = nullptr);
create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
std::string swiftPCHHash = "", DependencyTracker *tracker = nullptr,
std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate = {});

ClangImporter(const ClangImporter &) = delete;
ClangImporter(ClangImporter &&) = delete;
Expand Down Expand Up @@ -150,15 +172,15 @@ class ClangImporter final : public ClangModuleLoader {
/// Look for declarations associated with the given name.
///
/// \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.
///
/// 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.
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
/// a "related entity kind" to determine which type it should be. For example,
Expand All @@ -171,7 +193,7 @@ class ClangImporter final : public ClangModuleLoader {
void
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
StringRef relatedEntityKind,
llvm::function_ref<void(TypeDecl *)> receiver) override;
llvm::function_ref<void(TypeDecl *)> receiver);

/// Look for textually included declarations from the bridging header.
///
Expand Down
135 changes: 0 additions & 135 deletions include/swift/DWARFImporter/DWARFImporter.h

This file was deleted.

9 changes: 2 additions & 7 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include "swift/AST/ASTDemangler.h"

#include "swift/AST/ASTContext.h"
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/Decl.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/GenericSignatureBuilder.h"
#include "swift/AST/Module.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/Type.h"
#include "swift/AST/Types.h"
#include "swift/ClangImporter/ClangImporter.h"
#include "swift/Demangling/Demangler.h"
#include "swift/Demangling/ManglingMacros.h"

Expand Down Expand Up @@ -1045,7 +1045,7 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
ForeignModuleKind foreignKind,
Demangle::Node::Kind kind) {
// Check to see if we have an importer loaded.
auto importer = Ctx.getClangModuleLoader();
auto importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
if (!importer)
return nullptr;

Expand Down Expand Up @@ -1094,11 +1094,6 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
break;
case ForeignModuleKind::Imported:
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;
Expand Down
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ add_subdirectory(Basic)
add_subdirectory(ClangImporter)
add_subdirectory(Demangling)
add_subdirectory(Driver)
add_subdirectory(DWARFImporter)
add_subdirectory(Frontend)
add_subdirectory(FrontendTool)
add_subdirectory(Index)
Expand Down
1 change: 1 addition & 0 deletions lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_swift_host_library(swiftClangImporter STATIC
ClangAdapter.cpp
ClangDiagnosticConsumer.cpp
ClangImporter.cpp
DWARFImporter.cpp
IAMInference.cpp
ImportDecl.cpp
ImportEnumInfo.cpp
Expand Down
Loading