diff --git a/lldb/include/lldb/Symbol/LineTable.h b/lldb/include/lldb/Symbol/LineTable.h index 0323bf5e8039a..72c9d67fb2041 100644 --- a/lldb/include/lldb/Symbol/LineTable.h +++ b/lldb/include/lldb/Symbol/LineTable.h @@ -9,6 +9,7 @@ #ifndef liblldb_LineTable_h_ #define liblldb_LineTable_h_ +#include "lldb/Core/Address.h" #include "lldb/Core/ModuleChild.h" #include "lldb/Core/Section.h" #include "lldb/Symbol/LineEntry.h" diff --git a/lldb/include/lldb/Target/SwiftLanguageRuntime.h b/lldb/include/lldb/Target/SwiftLanguageRuntime.h index c3e609359b7d9..95f088bbc4f50 100644 --- a/lldb/include/lldb/Target/SwiftLanguageRuntime.h +++ b/lldb/include/lldb/Target/SwiftLanguageRuntime.h @@ -13,17 +13,10 @@ #ifndef liblldb_SwiftLanguageRuntime_h_ #define liblldb_SwiftLanguageRuntime_h_ -// C Includes -// C++ Includes -#include -#include -#include -// Other libraries and framework includes -// Project includes #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Breakpoint/BreakpointPrecondition.h" #include "lldb/Core/PluginInterface.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/LanguageRuntime.h" #include "lldb/lldb-private.h" @@ -31,6 +24,10 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Support/Casting.h" +#include +#include +#include + namespace swift { namespace remote { class MemoryReader; diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index abd443880bf2a..2673baa811eb3 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -125,7 +125,7 @@ #include "Plugins/ExpressionParser/Swift/SwiftREPL.h" #include "Plugins/InstrumentationRuntime/SwiftRuntimeReporting/SwiftRuntimeReporting.h" #include "Plugins/Language/Swift/SwiftLanguage.h" -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Target/SwiftLanguageRuntime.h" // END SWIFT diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 0100e34a31c00..fb9017a5221db 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -54,7 +54,7 @@ #include "Plugins/Language/ObjC/ObjCLanguage.h" // BEGIN SWIFT -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Target/SwiftLanguageRuntime.h" // END SWIFT diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 44b9a30ae5b14..a8fab13a3d787 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -54,7 +54,7 @@ #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h" // BEGIN SWIFT -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" // END SWIFT #include "llvm/Support/Compiler.h" diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp index a59a5adfbd523..3c4a177748796 100644 --- a/lldb/source/Core/ValueObjectDynamicValue.cpp +++ b/lldb/source/Core/ValueObjectDynamicValue.cpp @@ -10,7 +10,6 @@ #include "lldb/Core/Value.h" #include "lldb/Core/ValueObject.h" #include "lldb/Symbol/CompilerType.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/Type.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/LanguageRuntime.h" @@ -23,6 +22,8 @@ #include "lldb/Utility/Status.h" #include "lldb/lldb-types.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" + #include namespace lldb_private { class Declaration; diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp index 3db3a3bc9ca22..d90b13cc65a81 100644 --- a/lldb/source/Core/ValueObjectVariable.cpp +++ b/lldb/source/Core/ValueObjectVariable.cpp @@ -16,7 +16,6 @@ #include "lldb/Symbol/Declaration.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/SymbolContextScope.h" #include "lldb/Symbol/Type.h" @@ -33,6 +32,8 @@ #include "lldb/lldb-private-enumerations.h" #include "lldb/lldb-types.h" +#include "Plugins/TypeSystem/Swift/TypeSystemSwift.h" + #include "llvm/ADT/StringRef.h" #include diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp index ce6c6a8f4417b..207ab37320414 100644 --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -12,7 +12,6 @@ #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Symbol/Symbol.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/Variable.h" #include "lldb/Target/ExecutionContext.h" @@ -24,6 +23,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/RegisterValue.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" + #include using namespace lldb_private; diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp index 2b327ee867aac..7af629b36251c 100644 --- a/lldb/source/Expression/UserExpression.cpp +++ b/lldb/source/Expression/UserExpression.cpp @@ -30,7 +30,6 @@ #include "lldb/Symbol/Block.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/TypeSystem.h" @@ -45,6 +44,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" + using namespace lldb_private; char UserExpression::ID; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp index e2e31ca0e6ad1..b34dd6ae56bb3 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -16,7 +16,7 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" -#include "lldb/Symbol/SwiftASTContext.h" // Needed for llvm::isa(...) +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" // Needed for llvm::isa(...) #include "lldb/Symbol/TypeSystem.h" #include "swift/AST/Decl.h" diff --git a/lldb/source/Plugins/ExpressionParser/Swift/CMakeLists.txt b/lldb/source/Plugins/ExpressionParser/Swift/CMakeLists.txt index c3333faf6a7b8..6c2828f502385 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/CMakeLists.txt +++ b/lldb/source/Plugins/ExpressionParser/Swift/CMakeLists.txt @@ -26,6 +26,7 @@ add_lldb_library(lldbPluginExpressionParserSwift PLUGIN lldbSymbol lldbTarget lldbUtility + lldbPluginTypeSystemSwift swiftAST swiftBasic swiftClangImporter diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp index 4ac6bc40a2b90..84397dd8069c1 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp @@ -12,9 +12,9 @@ #include "SwiftASTManipulator.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Expression/ExpressionParser.h" #include "lldb/Expression/ExpressionSourceCode.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/Target.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp index 7aa65aaf88da0..4cdd6fc796b0b 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp @@ -9,7 +9,7 @@ #include "SwiftExpressionSourceCode.h" #include "Plugins/ExpressionParser/Swift/SwiftASTManipulator.h" -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Target/Language.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Target.h" diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.cpp index c5635e582199f..0a2b34306b53a 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.cpp @@ -12,13 +12,10 @@ #include "SwiftPersistentExpressionState.h" #include "SwiftExpressionVariable.h" -#include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Core/Value.h" - -#include "lldb/Symbol/SwiftASTContext.h" // Needed for llvm::isa(...) +#include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Symbol/TypeSystem.h" - #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp index c93a196f3d0d3..93db68c4c5ca4 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp @@ -14,6 +14,7 @@ #include "SwiftExpressionVariable.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -25,7 +26,6 @@ #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.h b/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.h index 840b6e22ed045..0eb99fda52550 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.h +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.h @@ -13,9 +13,8 @@ #ifndef liblldb_SwiftREPL_h_ #define liblldb_SwiftREPL_h_ -#include "lldb/Symbol/SwiftASTContext.h" -#include "lldb/Utility/Status.h" #include "lldb/Expression/REPL.h" +#include "lldb/Utility/Status.h" #include "lldb/lldb-public.h" #include @@ -24,6 +23,7 @@ namespace lldb_private { class IRExecutionUnit; +class SwiftASTContextForExpressions; //---------------------------------------------------------------------- /// @class SwiftREPL SwiftREPL.h "lldb/Expression/SwiftREPL.h" diff --git a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp index 9abf0ff3b9877..5211d6bffcc02 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.cpp @@ -11,7 +11,6 @@ #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/Variable.h" @@ -24,6 +23,8 @@ #include "lldb/Target/Thread.h" #include "lldb/Utility/RegularExpression.h" #include "Plugins/Process/Utility/HistoryThread.h" + +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "swift/AST/ASTContext.h" #include "swift/AST/NameLookup.h" #include "swift/ClangImporter/ClangImporter.h" diff --git a/lldb/source/Plugins/Language/Swift/CMakeLists.txt b/lldb/source/Plugins/Language/Swift/CMakeLists.txt index 194250e8dc2b0..d8cd8f2bbe410 100644 --- a/lldb/source/Plugins/Language/Swift/CMakeLists.txt +++ b/lldb/source/Plugins/Language/Swift/CMakeLists.txt @@ -23,6 +23,7 @@ add_lldb_library(lldbPluginSwiftLanguage PLUGIN lldbTarget lldbUtility lldbPluginObjCLanguage + lldbPluginTypeSystemSwift swiftAST swiftClangImporter clangAST diff --git a/lldb/source/Plugins/Language/Swift/SwiftArray.cpp b/lldb/source/Plugins/Language/Swift/SwiftArray.cpp index f1932ef207fac..ffd49b4bcd40e 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftArray.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftArray.cpp @@ -13,9 +13,9 @@ #include "SwiftArray.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/SwiftLanguageRuntime.h" #include "lldb/Target/Target.h" diff --git a/lldb/source/Plugins/Language/Swift/SwiftDictionary.cpp b/lldb/source/Plugins/Language/Swift/SwiftDictionary.cpp index 4ba3e8f4713a9..355fd15d46f26 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftDictionary.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftDictionary.cpp @@ -12,9 +12,9 @@ #include "SwiftDictionary.h" -#include "lldb/DataFormatters/FormattersHelpers.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" +#include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Target/Process.h" #include "lldb/Target/SwiftLanguageRuntime.h" diff --git a/lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp b/lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp index c8db652cc0dfe..9d8a1baa7e3b3 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp @@ -14,9 +14,9 @@ #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/SwiftLanguageRuntime.h" #include "lldb/Utility/DataBufferHeap.h" diff --git a/lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp b/lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp index bcae741e700ae..fef90f1c2595c 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp @@ -13,9 +13,9 @@ #include "SwiftOptionSet.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Core/ValueObject.h" #include "lldb/Symbol/CompilerType.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Utility/StreamString.h" #include "swift/AST/Decl.h" diff --git a/lldb/source/Plugins/Language/Swift/SwiftOptional.cpp b/lldb/source/Plugins/Language/Swift/SwiftOptional.cpp index 171e7191c09aa..17793d8504692 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftOptional.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftOptional.cpp @@ -11,10 +11,10 @@ //===----------------------------------------------------------------------===// #include "SwiftOptional.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/ValueObjectPrinter.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/SwiftLanguageRuntime.h" #include "lldb/Utility/DataBufferHeap.h" diff --git a/lldb/source/Plugins/Language/Swift/SwiftSet.cpp b/lldb/source/Plugins/Language/Swift/SwiftSet.cpp index fdc4625808ec4..6a844525c97f4 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftSet.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftSet.cpp @@ -12,9 +12,9 @@ #include "SwiftSet.h" -#include "lldb/DataFormatters/FormattersHelpers.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" +#include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Target/Process.h" #include "lldb/Target/SwiftLanguageRuntime.h" diff --git a/lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp b/lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp index 60127f691a0d1..169ab16548371 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp @@ -1,7 +1,7 @@ #include "SwiftUnsafeTypes.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/DataFormatters/TypeSynthetic.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/SwiftLanguageRuntime.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Logging.h" diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp index 5265fe0c0c57d..dfe5398e8dfc7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp @@ -26,11 +26,11 @@ #include "clang/AST/DeclObjC.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/TypeMap.h" diff --git a/lldb/source/Plugins/TypeSystem/CMakeLists.txt b/lldb/source/Plugins/TypeSystem/CMakeLists.txt index 17c40aee44cc2..1350cbd599a8d 100644 --- a/lldb/source/Plugins/TypeSystem/CMakeLists.txt +++ b/lldb/source/Plugins/TypeSystem/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(Clang) +add_subdirectory(Swift) diff --git a/lldb/source/Plugins/TypeSystem/Swift/CMakeLists.txt b/lldb/source/Plugins/TypeSystem/Swift/CMakeLists.txt new file mode 100644 index 0000000000000..75bbfefe2f9f7 --- /dev/null +++ b/lldb/source/Plugins/TypeSystem/Swift/CMakeLists.txt @@ -0,0 +1,14 @@ +add_lldb_library(lldbPluginTypeSystemSwift PLUGIN + TypeSystemSwift.cpp + TypeSystemSwiftTypeRef.cpp + SwiftASTContext.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + lldbUtility + + LINK_COMPONENTS + Support +) diff --git a/lldb/source/Symbol/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp similarity index 99% rename from lldb/source/Symbol/SwiftASTContext.cpp rename to lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 06876809d5e3f..b1fc8b6250990 100644 --- a/lldb/source/Symbol/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 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 @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" // C++ Includes #include // std::once @@ -2238,7 +2238,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, logError("couldn't load the Swift stdlib"); return {}; } - + return swift_ast_sp; } @@ -8308,8 +8308,8 @@ bool SwiftASTContext::GetImplicitImports( for (ConstString name : persistent_expression_state->GetHandLoadedModules()) { SourceModule module_info; module_info.path.push_back(name); - auto *module = LoadOneModule(module_info, swift_ast_context, stack_frame_wp, - error); + auto *module = + LoadOneModule(module_info, swift_ast_context, stack_frame_wp, error); if (!module) return false; diff --git a/lldb/include/lldb/Symbol/SwiftASTContext.h b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h similarity index 64% rename from lldb/include/lldb/Symbol/SwiftASTContext.h rename to lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h index 40a8cf8427e04..c4b2778a766d4 100644 --- a/lldb/include/lldb/Symbol/SwiftASTContext.h +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 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 @@ -14,30 +14,16 @@ #define liblldb_SwiftASTContext_h_ #include "Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.h" +#include "Plugins/TypeSystem/Swift/TypeSystemSwift.h" +#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h" #include "lldb/Core/ClangForward.h" #include "lldb/Core/SwiftForward.h" #include "lldb/Core/ThreadSafeDenseMap.h" #include "lldb/Core/ThreadSafeDenseSet.h" -#include "lldb/Symbol/CompilerType.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/TypeSystem.h" -#include "lldb/Utility/ConstString.h" -#include "lldb/lldb-private.h" - #include "lldb/Utility/Either.h" -#include "lldb/Utility/Status.h" - -#include "llvm/ADT/Optional.h" -#include "llvm/Support/Threading.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Target/TargetOptions.h" -// FIXME: needed only for the DenseMap. -#include "clang/Basic/Module.h" -#include "clang/APINotes/APINotesManager.h" - -#include -#include - namespace swift { enum class IRGenDebugInfoLevel : unsigned; class CanType; @@ -89,437 +75,6 @@ class ClangExternalASTSourceCallbacks; CompilerType ToCompilerType(swift::Type qual_type); -/// The implementation of lldb::Type's m_payload field for TypeSystemSwift. -class TypePayloadSwift { - /// Layout: bit 1 ... IsFixedValueBuffer. - Type::Payload m_payload = 0; - - static constexpr unsigned FixedValueBufferBit = 1; - -public: - TypePayloadSwift() = default; - explicit TypePayloadSwift(bool is_fixed_value_buffer); - explicit TypePayloadSwift(Type::Payload opaque_payload) - : m_payload(opaque_payload) {} - operator Type::Payload() { return m_payload; } - - /// \return whether this is a Swift fixed-size buffer. Resilient variables in - /// fixed-size buffers may be indirect depending on the runtime size of the - /// type. This is more a property of the value than of its type. - bool IsFixedValueBuffer() { - return Flags(m_payload).Test(FixedValueBufferBit); - } - void SetIsFixedValueBuffer(bool is_fixed_value_buffer) { - m_payload = is_fixed_value_buffer - ? Flags(m_payload).Set(FixedValueBufferBit) - : Flags(m_payload).Clear(FixedValueBufferBit); - } -}; - -/// Abstract base class for all Swift TypeSystems. -/// -/// Swift CompilerTypes are either a mangled name or a Swift AST -/// type. If the typesystem is a TypeSystemSwiftTypeRef, they are -/// mangled names. -/// -/// \verbatim -/// TypeSystem (abstract) -/// │ -/// ↓ -/// TypeSystemSwift (abstract) -/// │ │ -/// ↓ ↓ -/// TypeSystemSwiftTypeRef ⟷ SwiftASTContext (deprecated) -/// │ -/// ↓ -/// SwiftASTContextForExpressions -/// -/// \endverbatim -class TypeSystemSwift : public TypeSystem { - /// LLVM RTTI support. - static char ID; - -public: - /// LLVM RTTI support. - /// \{ - bool isA(const void *ClassID) const override { return ClassID == &ID; } - static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } - /// \} - - TypeSystemSwift(); - - virtual lldb::TypeSP GetCachedType(ConstString mangled) = 0; - virtual void SetCachedType(ConstString mangled, - const lldb::TypeSP &type_sp) = 0; - virtual bool IsImportedType(lldb::opaque_compiler_type_t type, - CompilerType *original_type) = 0; - virtual CompilerType GetErrorType() = 0; - virtual CompilerType GetReferentType(lldb::opaque_compiler_type_t type) = 0; - static CompilerType GetInstanceType(CompilerType ct); - virtual CompilerType GetInstanceType(lldb::opaque_compiler_type_t type) = 0; - enum class TypeAllocationStrategy { eInline, ePointer, eDynamic, eUnknown }; - virtual TypeAllocationStrategy - GetAllocationStrategy(lldb::opaque_compiler_type_t type) = 0; - struct TupleElement { - ConstString element_name; - CompilerType element_type; - }; - virtual CompilerType - CreateTupleType(const std::vector &elements) = 0; - virtual void DumpTypeDescription( - lldb::opaque_compiler_type_t type, bool print_help_if_available, - bool print_extensions_if_available, - lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0; - virtual void DumpTypeDescription( - lldb::opaque_compiler_type_t type, Stream *s, - bool print_help_if_available, bool print_extensions_if_available, - lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0; - virtual CompilerType - GetTypeFromMangledTypename(ConstString mangled_typename) = 0; - - /// Unavailable hardcoded functions that don't make sense for Swift. - /// \{ - ConstString DeclContextGetName(void *opaque_decl_ctx) override { return {}; } - ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override { - return {}; - } - bool - DeclContextIsClassMethod(void *opaque_decl_ctx, - lldb::LanguageType *language_ptr, - bool *is_instance_method_ptr, - ConstString *language_object_name_ptr) override { - return false; - } - bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override { - return false; - } - bool IsCharType(lldb::opaque_compiler_type_t type) override { return false; } - bool IsCompleteType(lldb::opaque_compiler_type_t type) override { - return true; - } - bool IsConst(lldb::opaque_compiler_type_t type) override { return false; } - bool IsCStringType(lldb::opaque_compiler_type_t type, - uint32_t &length) override { - return false; - } - bool IsVectorType(lldb::opaque_compiler_type_t type, - CompilerType *element_type, uint64_t *size) override { - return false; - } - uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, - CompilerType *base_type_ptr) override { - return 0; - } - bool IsBlockPointerType(lldb::opaque_compiler_type_t type, - CompilerType *function_pointer_type_ptr) override { - return false; - } - bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override { - return false; - } - bool IsBeingDefined(lldb::opaque_compiler_type_t type) override { - return false; - } - bool CanPassInRegisters(const CompilerType &type) override { - // FIXME: Implement this. There was an abort() here to figure out which - // tests where hitting this code. At least TestSwiftReturns and - // TestSwiftStepping were failing because of this Darwin. - return false; - } - unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override { - return 0; - } - CompilerType - GetTypeForDecl(lldb::opaque_compiler_type_t opaque_decl) override { - llvm_unreachable("GetTypeForDecl not implemented"); - } - CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override { - return {}; - } - const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override { - // See: https://reviews.llvm.org/D67239. At this time of writing this API - // is only used by DumpDataExtractor for the C type system. - llvm_unreachable("GetFloatTypeSemantics not implemented."); - } - lldb::BasicType - GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override { - return lldb::eBasicTypeInvalid; - } - uint32_t - GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t opaque_type) override { - return 0; - } - CompilerType - GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t opaque_type, - size_t idx, uint32_t *bit_offset_ptr) override { - return {}; - } - /// \} -protected: - /// Used in the logs. - std::string m_description; -}; - -/// A Swift TypeSystem that does not own a swift::ASTContext. -class TypeSystemSwiftTypeRef : public TypeSystemSwift { - /// LLVM RTTI support. - static char ID; - -public: - /// LLVM RTTI support. - /// \{ - bool isA(const void *ClassID) const override { - return ClassID == &ID || TypeSystemSwift::isA(ClassID); - } - static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } - /// \} - - TypeSystemSwiftTypeRef(SwiftASTContext *swift_ast_context); - - Module *GetModule() const; - swift::CanType GetCanonicalSwiftType(CompilerType compiler_type); - swift::Type GetSwiftType(CompilerType compiler_type); - CompilerType ReconstructType(CompilerType type); - CompilerType - GetTypeFromMangledTypename(ConstString mangled_typename) override; - - // PluginInterface functions - ConstString GetPluginName() override; - uint32_t GetPluginVersion() override; - - bool SupportsLanguage(lldb::LanguageType language) override; - Status IsCompatible() override; - - void DiagnoseWarnings(Process &process, Module &module) const override; - DWARFASTParser *GetDWARFParser() override; - // CompilerDecl functions - ConstString DeclGetName(void *opaque_decl) override { - return ConstString(""); - } - - // CompilerDeclContext functions - std::vector - DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name, - const bool ignore_imported_decls) override { - return {}; - } - - bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, - void *other_opaque_decl_ctx) override { - if (opaque_decl_ctx == other_opaque_decl_ctx) - return true; - return false; - } - - // Tests -#ifndef NDEBUG - bool Verify(lldb::opaque_compiler_type_t type) override; -#endif - bool IsArrayType(lldb::opaque_compiler_type_t type, - CompilerType *element_type, uint64_t *size, - bool *is_incomplete) override; - bool IsAggregateType(lldb::opaque_compiler_type_t type) override; - bool IsDefined(lldb::opaque_compiler_type_t type) override; - bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, - bool &is_complex) override; - bool IsFunctionType(lldb::opaque_compiler_type_t type, - bool *is_variadic_ptr) override; - size_t - GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override; - CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, - const size_t index) override; - bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override; - bool IsIntegerType(lldb::opaque_compiler_type_t type, - bool &is_signed) override; - bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, - CompilerType *target_type, // Can pass NULL - bool check_cplusplus, bool check_objc) override; - bool IsPointerType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type) override; - bool IsScalarType(lldb::opaque_compiler_type_t type) override; - bool IsVoidType(lldb::opaque_compiler_type_t type) override; - // Type Completion - bool GetCompleteType(lldb::opaque_compiler_type_t type) override; - // AST related queries - uint32_t GetPointerByteSize() override; - // Accessors - ConstString GetTypeName(lldb::opaque_compiler_type_t type) override; - ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type, - const SymbolContext *sc) override; - ConstString GetMangledTypeName(lldb::opaque_compiler_type_t type) override; - uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type, - CompilerType *pointee_or_element_clang_type) override; - lldb::LanguageType - GetMinimumLanguage(lldb::opaque_compiler_type_t type) override; - lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override; - - // Creating related types - CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, - uint64_t *stride) override; - CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override; - int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override; - CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, - size_t idx) override; - CompilerType - GetFunctionReturnType(lldb::opaque_compiler_type_t type) override; - size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override; - TypeMemberFunctionImpl - GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, - size_t idx) override; - CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override; - CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override; - - // Exploring the type - llvm::Optional - GetBitSize(lldb::opaque_compiler_type_t type, - ExecutionContextScope *exe_scope) override; - llvm::Optional - GetByteStride(lldb::opaque_compiler_type_t type, - ExecutionContextScope *exe_scope) override; - lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, - uint64_t &count) override; - lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override; - uint32_t GetNumChildren(lldb::opaque_compiler_type_t type, - bool omit_empty_base_classes, - const ExecutionContext *exe_ctx) override; - uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override; - CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, - std::string &name, uint64_t *bit_offset_ptr, - uint32_t *bitfield_bit_size_ptr, - bool *is_bitfield_ptr) override; - CompilerType GetChildCompilerTypeAtIndex( - lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, - bool transparent_pointers, bool omit_empty_base_classes, - bool ignore_array_bounds, std::string &child_name, - uint32_t &child_byte_size, int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class, bool &child_is_deref_of_parent, - ValueObject *valobj, uint64_t &language_flags) override; - uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, - const char *name, - bool omit_empty_base_classes) override; - size_t - GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, - const char *name, bool omit_empty_base_classes, - std::vector &child_indexes) override; - size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type) override; - CompilerType GetTypeForFormatters(lldb::opaque_compiler_type_t type) override; - LazyBool ShouldPrintAsOneLiner(lldb::opaque_compiler_type_t type, - ValueObject *valobj) override; - bool IsMeaninglessWithoutDynamicResolution( - lldb::opaque_compiler_type_t type) override; - - // Dumping types -#ifndef NDEBUG - /// Convenience LLVM-style dump method for use in the debugger only. - LLVM_DUMP_METHOD virtual void - dump(lldb::opaque_compiler_type_t type) const override; -#endif - - void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - Stream *s, lldb::Format format, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size, - uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - bool show_types, bool show_summary, bool verbose, - uint32_t depth) override; - - bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s, - lldb::Format format, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size, - uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - ExecutionContextScope *exe_scope, - bool is_base_class) override; - - void DumpTypeDescription( - lldb::opaque_compiler_type_t type, - lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; - void DumpTypeDescription( - lldb::opaque_compiler_type_t type, Stream *s, - lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; - void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - Stream *s, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size) override; - bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type) override; - llvm::Optional - GetTypeBitAlign(lldb::opaque_compiler_type_t type, - ExecutionContextScope *exe_scope) override; - CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, - size_t bit_size) override { - return CompilerType(); - } - bool IsTypedefType(lldb::opaque_compiler_type_t type) override; - CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override; - CompilerType - GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override; - CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override; - CompilerType - GetLValueReferenceType(lldb::opaque_compiler_type_t type) override; - CompilerType - GetRValueReferenceType(lldb::opaque_compiler_type_t type) override; - uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override; - CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, - size_t idx, - uint32_t *bit_offset_ptr) override; - bool IsReferenceType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type, bool *is_rvalue) override; - bool - ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) override; - - // Swift-specific methods. - lldb::TypeSP GetCachedType(ConstString mangled) override; - void SetCachedType(ConstString mangled, const lldb::TypeSP &type_sp) override; - bool IsImportedType(lldb::opaque_compiler_type_t type, - CompilerType *original_type) override; - CompilerType GetErrorType() override; - CompilerType GetReferentType(lldb::opaque_compiler_type_t type) override; - CompilerType GetInstanceType(lldb::opaque_compiler_type_t type) override; - TypeAllocationStrategy - GetAllocationStrategy(lldb::opaque_compiler_type_t type) override; - CompilerType - CreateTupleType(const std::vector &elements) override; - void DumpTypeDescription( - lldb::opaque_compiler_type_t type, bool print_help_if_available, - bool print_extensions_if_available, - lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; - void DumpTypeDescription( - lldb::opaque_compiler_type_t type, Stream *s, - bool print_help_if_available, bool print_extensions_if_available, - lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; - -private: - /// Helper that creates an AST type from \p type. - void *ReconstructType(lldb::opaque_compiler_type_t type); - /// Cast \p opaque_type as a mangled name. - const char *AsMangledName(lldb::opaque_compiler_type_t opaque_type); - - /// Wrap \p node as \p Global(TypeMangling(node)), remangle the type - /// and create a CompilerType from it. - CompilerType RemangleAsType(swift::Demangle::Demangler &Dem, - swift::Demangle::NodePointer node); - - /// Demangle the mangled name of the canonical type of \p type and - /// drill into the Global(TypeMangling(Type())). - /// - /// \return the child of Type or a nullptr. - swift::Demangle::NodePointer - DemangleCanonicalType(swift::Demangle::Demangler &Dem, - lldb::opaque_compiler_type_t type); - - /// Return an APINotes manager for the module with module id \id. - /// APINotes are used to get at the SDK swiftification annotations. - clang::api_notes::APINotesManager * - GetAPINotesManager(ClangExternalASTSourceCallbacks *source, unsigned id); - - /// The sibling SwiftASTContext. - SwiftASTContext *m_swift_ast_context = nullptr; - - /// The APINotesManager responsible for each Clang module. - llvm::DenseMap> - m_apinotes_manager; -}; - /// This "middle" class between TypeSystemSwiftTypeRef and /// SwiftASTContextForExpressions will eventually go away, as more and /// more functionality becomes available in TypeSystemSwiftTypeRef. @@ -1200,12 +755,10 @@ class SwiftASTContext : public TypeSystemSwift { /// Retrieves the modules that need to be implicitly imported in a given /// execution scope. This includes the modules imported by both the compile /// unit as well as any imports from previous expression evaluations. - static bool - GetImplicitImports(SwiftASTContext &swift_ast_context, SymbolContext &sc, - ExecutionContextScope &exe_scope, - lldb::StackFrameWP &stack_frame_wp, - llvm::SmallVectorImpl &modules, - Status &error); + static bool GetImplicitImports( + SwiftASTContext &swift_ast_context, SymbolContext &sc, + ExecutionContextScope &exe_scope, lldb::StackFrameWP &stack_frame_wp, + llvm::SmallVectorImpl &modules, Status &error); /// Cache the user's imports from a SourceFile in a given execution scope such /// that they are carried over into future expression evaluations. diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp new file mode 100644 index 0000000000000..e3bc85bf415fa --- /dev/null +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp @@ -0,0 +1,13 @@ +//===-- TypeSystemSwift.cpp ==---------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2020 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 "Plugins/TypeSystem/Swift/TypeSystemSwift.h" diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h new file mode 100644 index 0000000000000..f991c465939ac --- /dev/null +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h @@ -0,0 +1,198 @@ +//===-- TypeSystemSwift.h ---------------------------------------*- C++ -*-===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2020 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 +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_TypeSystemSwift_h_ +#define liblldb_TypeSystemSwift_h_ + +#include "lldb/Symbol/CompilerType.h" +#include "lldb/Symbol/SymbolFile.h" +#include "lldb/Symbol/Type.h" +#include "lldb/Symbol/TypeSystem.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Flags.h" +#include "lldb/lldb-private.h" + +namespace lldb_private { + +/// The implementation of lldb::Type's m_payload field for TypeSystemSwift. +class TypePayloadSwift { + /// Layout: bit 1 ... IsFixedValueBuffer. + Type::Payload m_payload = 0; + + static constexpr unsigned FixedValueBufferBit = 1; + +public: + TypePayloadSwift() = default; + explicit TypePayloadSwift(bool is_fixed_value_buffer); + explicit TypePayloadSwift(Type::Payload opaque_payload) + : m_payload(opaque_payload) {} + operator Type::Payload() { return m_payload; } + + /// \return whether this is a Swift fixed-size buffer. Resilient variables in + /// fixed-size buffers may be indirect depending on the runtime size of the + /// type. This is more a property of the value than of its type. + bool IsFixedValueBuffer() { + return Flags(m_payload).Test(FixedValueBufferBit); + } + void SetIsFixedValueBuffer(bool is_fixed_value_buffer) { + m_payload = is_fixed_value_buffer + ? Flags(m_payload).Set(FixedValueBufferBit) + : Flags(m_payload).Clear(FixedValueBufferBit); + } +}; + +/// Abstract base class for all Swift TypeSystems. +/// +/// Swift CompilerTypes are either a mangled name or a Swift AST +/// type. If the typesystem is a TypeSystemSwiftTypeRef, they are +/// mangled names. +/// +/// \verbatim +/// TypeSystem (abstract) +/// │ +/// ↓ +/// TypeSystemSwift (abstract) +/// │ │ +/// ↓ ↓ +/// TypeSystemSwiftTypeRef ⟷ SwiftASTContext (deprecated) +/// │ +/// ↓ +/// SwiftASTContextForExpressions +/// +/// \endverbatim +class TypeSystemSwift : public TypeSystem { + /// LLVM RTTI support. + static char ID; + +public: + /// LLVM RTTI support. + /// \{ + bool isA(const void *ClassID) const override { return ClassID == &ID; } + static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } + /// \} + + TypeSystemSwift(); + + virtual lldb::TypeSP GetCachedType(ConstString mangled) = 0; + virtual void SetCachedType(ConstString mangled, + const lldb::TypeSP &type_sp) = 0; + virtual bool IsImportedType(lldb::opaque_compiler_type_t type, + CompilerType *original_type) = 0; + virtual CompilerType GetErrorType() = 0; + virtual CompilerType GetReferentType(lldb::opaque_compiler_type_t type) = 0; + static CompilerType GetInstanceType(CompilerType ct); + virtual CompilerType GetInstanceType(lldb::opaque_compiler_type_t type) = 0; + enum class TypeAllocationStrategy { eInline, ePointer, eDynamic, eUnknown }; + virtual TypeAllocationStrategy + GetAllocationStrategy(lldb::opaque_compiler_type_t type) = 0; + struct TupleElement { + ConstString element_name; + CompilerType element_type; + }; + virtual CompilerType + CreateTupleType(const std::vector &elements) = 0; + virtual void DumpTypeDescription( + lldb::opaque_compiler_type_t type, bool print_help_if_available, + bool print_extensions_if_available, + lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0; + virtual void DumpTypeDescription( + lldb::opaque_compiler_type_t type, Stream *s, + bool print_help_if_available, bool print_extensions_if_available, + lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0; + virtual CompilerType + GetTypeFromMangledTypename(ConstString mangled_typename) = 0; + + /// Unavailable hardcoded functions that don't make sense for Swift. + /// \{ + ConstString DeclContextGetName(void *opaque_decl_ctx) override { return {}; } + ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override { + return {}; + } + bool + DeclContextIsClassMethod(void *opaque_decl_ctx, + lldb::LanguageType *language_ptr, + bool *is_instance_method_ptr, + ConstString *language_object_name_ptr) override { + return false; + } + bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override { + return false; + } + bool IsCharType(lldb::opaque_compiler_type_t type) override { return false; } + bool IsCompleteType(lldb::opaque_compiler_type_t type) override { + return true; + } + bool IsConst(lldb::opaque_compiler_type_t type) override { return false; } + bool IsCStringType(lldb::opaque_compiler_type_t type, + uint32_t &length) override { + return false; + } + bool IsVectorType(lldb::opaque_compiler_type_t type, + CompilerType *element_type, uint64_t *size) override { + return false; + } + uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, + CompilerType *base_type_ptr) override { + return 0; + } + bool IsBlockPointerType(lldb::opaque_compiler_type_t type, + CompilerType *function_pointer_type_ptr) override { + return false; + } + bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override { + return false; + } + bool IsBeingDefined(lldb::opaque_compiler_type_t type) override { + return false; + } + bool CanPassInRegisters(const CompilerType &type) override { + // FIXME: Implement this. There was an abort() here to figure out which + // tests where hitting this code. At least TestSwiftReturns and + // TestSwiftStepping were failing because of this Darwin. + return false; + } + unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override { + return 0; + } + CompilerType + GetTypeForDecl(lldb::opaque_compiler_type_t opaque_decl) override { + llvm_unreachable("GetTypeForDecl not implemented"); + } + CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override { + return {}; + } + const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override { + // See: https://reviews.llvm.org/D67239. At this time of writing this API + // is only used by DumpDataExtractor for the C type system. + llvm_unreachable("GetFloatTypeSemantics not implemented."); + } + lldb::BasicType + GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override { + return lldb::eBasicTypeInvalid; + } + uint32_t + GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t opaque_type) override { + return 0; + } + CompilerType + GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t opaque_type, + size_t idx, uint32_t *bit_offset_ptr) override { + return {}; + } + /// \} +protected: + /// Used in the logs. + std::string m_description; +}; + +} // namespace lldb_private +#endif diff --git a/lldb/source/Symbol/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp similarity index 97% rename from lldb/source/Symbol/TypeSystemSwiftTypeRef.cpp rename to lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index d591ba9b4a2f5..42c6a67dd2d89 100644 --- a/lldb/source/Symbol/TypeSystemSwiftTypeRef.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/TypeList.h" @@ -28,10 +28,10 @@ #include "swift/Demangling/Demangler.h" #include "swift/Strings.h" -#include "clang/AST/Decl.h" -#include "clang/AST/DeclObjC.h" #include "clang/APINotes/APINotesManager.h" #include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" using namespace lldb; using namespace lldb_private; @@ -270,7 +270,8 @@ GetCanonicalNode(lldb_private::Module *M, swift::Demangle::Demangler &Dem, case Node::Kind::TypeAlias: { auto node_clangtype = ResolveTypeAlias(M, Dem, node); if (CompilerType clang_type = node_clangtype.second) - return getCanonicalNode(GetClangTypeNode(clang_type.GetCanonicalType(), Dem)); + return getCanonicalNode( + GetClangTypeNode(clang_type.GetCanonicalType(), Dem)); if (node_clangtype.first) return getCanonicalNode(node_clangtype.first); return node; @@ -360,10 +361,9 @@ clang::api_notes::APINotesManager *TypeSystemSwiftTypeRef::GetAPINotesManager( } /// Desugar a sugared type. -static swift::Demangle::NodePointer Desugar(swift::Demangle::Demangler &Dem, - swift::Demangle::NodePointer node, - Node::Kind bound_kind, - Node::Kind kind, llvm::StringRef name) { +static swift::Demangle::NodePointer +Desugar(swift::Demangle::Demangler &Dem, swift::Demangle::NodePointer node, + Node::Kind bound_kind, Node::Kind kind, llvm::StringRef name) { using namespace swift::Demangle; NodePointer desugared = Dem.createNode(bound_kind); NodePointer type = Dem.createNode(Node::Kind::Type); @@ -398,8 +398,7 @@ GetNodeForPrinting(const std::string &m_description, lldb_private::Module &M, GetAPINotesManagerFn get_apinotes_manager, GetClangImporterFn get_clangimporter, swift::Demangle::Demangler &Dem, - swift::Demangle::NodePointer node, - bool resolve_objc_module, + swift::Demangle::NodePointer node, bool resolve_objc_module, bool desugar = true) { if (!node) return node; @@ -445,8 +444,7 @@ GetNodeForPrinting(const std::string &m_description, lldb_private::Module &M, // Create a new node with the Clang module instead of "__C". NodePointer renamed = Dem.createNode(kind); - NodePointer module = - Dem.createNode(Node::Kind::Module, toplevel_module); + NodePointer module = Dem.createNode(Node::Kind::Module, toplevel_module); renamed->addChild(module, Dem); // This is unfortunate performance-wise, but only ClangImporter @@ -525,12 +523,12 @@ GetNodeForPrinting(const std::string &m_description, lldb_private::Module &M, } } } - + auto clang_importer = get_clangimporter(); if (!clang_importer) break; - //swift::DeclName imported_name = clang_importer->importName(clang_decl, {}); - //imported_name.getBaseName().userFacingName() + // swift::DeclName imported_name = clang_importer->importName(clang_decl, + // {}); imported_name.getBaseName().userFacingName() NodePointer identifier = Dem.createNode(Node::Kind::Identifier, swift_name); renamed->addChild(identifier, Dem); return renamed; @@ -563,10 +561,10 @@ GetNodeForPrinting(const std::string &m_description, lldb_private::Module &M, if (type->getKind() == Node::Kind::Type && type->getNumChildren() == 1) rett->addChild(type->getChild(0), Dem); - else if (child->getKind() == Node::Kind::ImplResult) - for (NodePointer type : *node) - if (type->getKind() == Node::Kind::Type) - rett->addChild(type, Dem); + else if (child->getKind() == Node::Kind::ImplResult) + for (NodePointer type : *node) + if (type->getKind() == Node::Kind::Type) + rett->addChild(type, Dem); } args_ty->addChild(args_tuple, Dem); args->addChild(args_ty, Dem); @@ -606,7 +604,7 @@ GetNodeForPrinting(const std::string &m_description, lldb_private::Module &M, if (node->getNumChildren() == 2 && node->getChild(0)->getKind() == Node::Kind::Identifier) return node->getChild(0); - break; + break; default: break; } @@ -632,7 +630,7 @@ GetNodeForPrinting(const std::string &m_description, lldb_private::Module &M, module = node->getChild(0)->getChild(0); if (module->getKind() != Node::Kind::Module) break; - + canonical->addChild(module, Dem); canonical->addChild(identifier, Dem); return canonical; @@ -715,7 +713,8 @@ static uint32_t collectTypeInfo(Module *M, swift::Demangle::Demangler &Dem, break; case Node::Kind::SugaredArray: case Node::Kind::SugaredDictionary: - swift_flags |= eTypeIsGeneric | eTypeIsBound | eTypeHasChildren | eTypeIsStructUnion; + swift_flags |= + eTypeIsGeneric | eTypeIsBound | eTypeHasChildren | eTypeIsStructUnion; break; case Node::Kind::DependentGenericParamType: @@ -725,7 +724,7 @@ static uint32_t collectTypeInfo(Module *M, swift::Demangle::Demangler &Dem, case Node::Kind::DependentGenericType: case Node::Kind::DependentMemberType: swift_flags |= eTypeHasValue | eTypeIsPointer | eTypeIsScalar | - eTypeIsGenericTypeParam; + eTypeIsGenericTypeParam; break; case Node::Kind::DynamicSelf: @@ -773,7 +772,8 @@ static uint32_t collectTypeInfo(Module *M, swift::Demangle::Demangler &Dem, if (node->getNumChildren() != 2) break; // Bug-for-bug compatibility. - if (!(collectTypeInfo(M, Dem, node->getChild(1)) & eTypeIsGenericTypeParam)) + if (!(collectTypeInfo(M, Dem, node->getChild(1)) & + eTypeIsGenericTypeParam)) swift_flags |= eTypeHasValue | eTypeHasChildren; auto module = node->getChild(0); auto ident = node->getChild(1); @@ -865,7 +865,8 @@ static uint32_t collectTypeInfo(Module *M, swift::Demangle::Demangler &Dem, collect_clang_type(clang_type.GetCanonicalType()); return swift_flags; } - swift_flags |= collectTypeInfo(M, Dem, node_clangtype.first, generic_walk); + swift_flags |= + collectTypeInfo(M, Dem, node_clangtype.first, generic_walk); return swift_flags; } default: @@ -986,8 +987,9 @@ template <> bool Equivalent(uint32_t l, uint32_t r) { if (l != r) { // Failure. Dump it for easier debugging. llvm::dbgs() << "TypeSystemSwiftTypeRef diverges from SwiftASTContext:\n"; -#define HANDLE_ENUM_CASE(VAL, CASE) \ - if (VAL & CASE) llvm::dbgs() << " | " << #CASE +#define HANDLE_ENUM_CASE(VAL, CASE) \ + if (VAL & CASE) \ + llvm::dbgs() << " | " << #CASE llvm::dbgs() << "l = " << l; HANDLE_ENUM_CASE(l, eTypeHasChildren); @@ -1021,7 +1023,7 @@ template <> bool Equivalent(uint32_t l, uint32_t r) { HANDLE_ENUM_CASE(l, eTypeIsGeneric); HANDLE_ENUM_CASE(l, eTypeIsBound); llvm::dbgs() << "\nr = " << r; - + HANDLE_ENUM_CASE(r, eTypeHasChildren); HANDLE_ENUM_CASE(r, eTypeHasValue); HANDLE_ENUM_CASE(r, eTypeIsArray); @@ -1084,7 +1086,8 @@ template <> bool Equivalent(ConstString l, ConstString r) { // If the new variant supports something the old one didn't, accept it. if (r.IsEmpty() || r.GetStringRef().equals("") || - r.GetStringRef().contains("__ObjC.") || r.GetStringRef().contains(" -> ()")) + r.GetStringRef().contains("__ObjC.") || + r.GetStringRef().contains(" -> ()")) return true; std::string r_prime = @@ -1102,8 +1105,9 @@ template <> bool Equivalent(ConstString l, ConstString r) { // isn't worth the effort and we accept over-qualified types // instead. It would be best to just always qualify types not from // the current module. - l_prime = std::regex_replace( - l.GetStringRef().str(), std::regex("(CoreGraphics|Foundation|)\\."), ""); + l_prime = + std::regex_replace(l.GetStringRef().str(), + std::regex("(CoreGraphics|Foundation|)\\."), ""); if (llvm::StringRef(l_prime) == r.GetStringRef()) return true; @@ -1113,7 +1117,7 @@ template <> bool Equivalent(ConstString l, ConstString r) { } return l == r; } -} +} // namespace #endif // This can be removed once the transition is complete. @@ -1220,7 +1224,7 @@ bool TypeSystemSwiftTypeRef::IsAggregateType(opaque_compiler_type_t type) { using namespace swift::Demangle; Demangler Dem; NodePointer node = DemangleCanonicalType(Dem, type); - + if (!node) return false; switch (node->getKind()) { @@ -1247,9 +1251,7 @@ bool TypeSystemSwiftTypeRef::IsAggregateType(opaque_compiler_type_t type) { } bool TypeSystemSwiftTypeRef::IsDefined(opaque_compiler_type_t type) { - auto impl = [&]() -> bool { - return type; - }; + auto impl = [&]() -> bool { return type; }; VALIDATE_AND_RETURN(impl, IsDefined, type, (ReconstructType(type))); } bool TypeSystemSwiftTypeRef::IsFloatingPointType(opaque_compiler_type_t type, diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h new file mode 100644 index 0000000000000..14e6e21481a59 --- /dev/null +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h @@ -0,0 +1,292 @@ +//===-- TypeSystemSwiftTypeRef.h --------------------------------*- C++ -*-===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2020 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 +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_TypeSystemSwiftTypeRef_h_ +#define liblldb_TypeSystemSwiftTypeRef_h_ + +#include "Plugins/TypeSystem/Swift/TypeSystemSwift.h" +#include "lldb/Core/SwiftForward.h" + +#include "swift/AST/Type.h" +#include "swift/Demangling/Demangle.h" +#include "swift/Demangling/Demangler.h" + +// FIXME: needed only for the DenseMap. +#include "clang/APINotes/APINotesManager.h" +#include "clang/Basic/Module.h" + +namespace lldb_private { +class SwiftASTContext; +class ClangExternalASTSourceCallbacks; + +/// A Swift TypeSystem that does not own a swift::ASTContext. +class TypeSystemSwiftTypeRef : public TypeSystemSwift { + /// LLVM RTTI support. + static char ID; + +public: + /// LLVM RTTI support. + /// \{ + bool isA(const void *ClassID) const override { + return ClassID == &ID || TypeSystemSwift::isA(ClassID); + } + static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } + /// \} + + TypeSystemSwiftTypeRef(SwiftASTContext *swift_ast_context); + + Module *GetModule() const; + swift::CanType GetCanonicalSwiftType(CompilerType compiler_type); + swift::Type GetSwiftType(CompilerType compiler_type); + CompilerType ReconstructType(CompilerType type); + CompilerType + GetTypeFromMangledTypename(ConstString mangled_typename) override; + + // PluginInterface functions + ConstString GetPluginName() override; + uint32_t GetPluginVersion() override; + + bool SupportsLanguage(lldb::LanguageType language) override; + Status IsCompatible() override; + + void DiagnoseWarnings(Process &process, Module &module) const override; + DWARFASTParser *GetDWARFParser() override; + // CompilerDecl functions + ConstString DeclGetName(void *opaque_decl) override { + return ConstString(""); + } + + // CompilerDeclContext functions + std::vector + DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name, + const bool ignore_imported_decls) override { + return {}; + } + + bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, + void *other_opaque_decl_ctx) override { + if (opaque_decl_ctx == other_opaque_decl_ctx) + return true; + return false; + } + + // Tests +#ifndef NDEBUG + bool Verify(lldb::opaque_compiler_type_t type) override; +#endif + bool IsArrayType(lldb::opaque_compiler_type_t type, + CompilerType *element_type, uint64_t *size, + bool *is_incomplete) override; + bool IsAggregateType(lldb::opaque_compiler_type_t type) override; + bool IsDefined(lldb::opaque_compiler_type_t type) override; + bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, + bool &is_complex) override; + bool IsFunctionType(lldb::opaque_compiler_type_t type, + bool *is_variadic_ptr) override; + size_t + GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override; + CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, + const size_t index) override; + bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override; + bool IsIntegerType(lldb::opaque_compiler_type_t type, + bool &is_signed) override; + bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, + CompilerType *target_type, // Can pass NULL + bool check_cplusplus, bool check_objc) override; + bool IsPointerType(lldb::opaque_compiler_type_t type, + CompilerType *pointee_type) override; + bool IsScalarType(lldb::opaque_compiler_type_t type) override; + bool IsVoidType(lldb::opaque_compiler_type_t type) override; + // Type Completion + bool GetCompleteType(lldb::opaque_compiler_type_t type) override; + // AST related queries + uint32_t GetPointerByteSize() override; + // Accessors + ConstString GetTypeName(lldb::opaque_compiler_type_t type) override; + ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type, + const SymbolContext *sc) override; + ConstString GetMangledTypeName(lldb::opaque_compiler_type_t type) override; + uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type, + CompilerType *pointee_or_element_clang_type) override; + lldb::LanguageType + GetMinimumLanguage(lldb::opaque_compiler_type_t type) override; + lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override; + + // Creating related types + CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, + uint64_t *stride) override; + CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override; + int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override; + CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, + size_t idx) override; + CompilerType + GetFunctionReturnType(lldb::opaque_compiler_type_t type) override; + size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override; + TypeMemberFunctionImpl + GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, + size_t idx) override; + CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override; + CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override; + + // Exploring the type + llvm::Optional + GetBitSize(lldb::opaque_compiler_type_t type, + ExecutionContextScope *exe_scope) override; + llvm::Optional + GetByteStride(lldb::opaque_compiler_type_t type, + ExecutionContextScope *exe_scope) override; + lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, + uint64_t &count) override; + lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override; + uint32_t GetNumChildren(lldb::opaque_compiler_type_t type, + bool omit_empty_base_classes, + const ExecutionContext *exe_ctx) override; + uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override; + CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, + std::string &name, uint64_t *bit_offset_ptr, + uint32_t *bitfield_bit_size_ptr, + bool *is_bitfield_ptr) override; + CompilerType GetChildCompilerTypeAtIndex( + lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, + bool transparent_pointers, bool omit_empty_base_classes, + bool ignore_array_bounds, std::string &child_name, + uint32_t &child_byte_size, int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, + bool &child_is_base_class, bool &child_is_deref_of_parent, + ValueObject *valobj, uint64_t &language_flags) override; + uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, + const char *name, + bool omit_empty_base_classes) override; + size_t + GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, + const char *name, bool omit_empty_base_classes, + std::vector &child_indexes) override; + size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type) override; + CompilerType GetTypeForFormatters(lldb::opaque_compiler_type_t type) override; + LazyBool ShouldPrintAsOneLiner(lldb::opaque_compiler_type_t type, + ValueObject *valobj) override; + bool IsMeaninglessWithoutDynamicResolution( + lldb::opaque_compiler_type_t type) override; + + // Dumping types +#ifndef NDEBUG + /// Convenience LLVM-style dump method for use in the debugger only. + LLVM_DUMP_METHOD virtual void + dump(lldb::opaque_compiler_type_t type) const override; +#endif + + void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, + Stream *s, lldb::Format format, const DataExtractor &data, + lldb::offset_t data_offset, size_t data_byte_size, + uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, + bool show_types, bool show_summary, bool verbose, + uint32_t depth) override; + + bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s, + lldb::Format format, const DataExtractor &data, + lldb::offset_t data_offset, size_t data_byte_size, + uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, + ExecutionContextScope *exe_scope, + bool is_base_class) override; + + void DumpTypeDescription( + lldb::opaque_compiler_type_t type, + lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; + void DumpTypeDescription( + lldb::opaque_compiler_type_t type, Stream *s, + lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; + void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, + Stream *s, const DataExtractor &data, + lldb::offset_t data_offset, size_t data_byte_size) override; + bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, + CompilerType *pointee_type) override; + llvm::Optional + GetTypeBitAlign(lldb::opaque_compiler_type_t type, + ExecutionContextScope *exe_scope) override; + CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, + size_t bit_size) override { + return CompilerType(); + } + bool IsTypedefType(lldb::opaque_compiler_type_t type) override; + CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override; + CompilerType + GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override; + CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override; + CompilerType + GetLValueReferenceType(lldb::opaque_compiler_type_t type) override; + CompilerType + GetRValueReferenceType(lldb::opaque_compiler_type_t type) override; + uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override; + CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, + size_t idx, + uint32_t *bit_offset_ptr) override; + bool IsReferenceType(lldb::opaque_compiler_type_t type, + CompilerType *pointee_type, bool *is_rvalue) override; + bool + ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) override; + + // Swift-specific methods. + lldb::TypeSP GetCachedType(ConstString mangled) override; + void SetCachedType(ConstString mangled, const lldb::TypeSP &type_sp) override; + bool IsImportedType(lldb::opaque_compiler_type_t type, + CompilerType *original_type) override; + CompilerType GetErrorType() override; + CompilerType GetReferentType(lldb::opaque_compiler_type_t type) override; + CompilerType GetInstanceType(lldb::opaque_compiler_type_t type) override; + TypeAllocationStrategy + GetAllocationStrategy(lldb::opaque_compiler_type_t type) override; + CompilerType + CreateTupleType(const std::vector &elements) override; + void DumpTypeDescription( + lldb::opaque_compiler_type_t type, bool print_help_if_available, + bool print_extensions_if_available, + lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; + void DumpTypeDescription( + lldb::opaque_compiler_type_t type, Stream *s, + bool print_help_if_available, bool print_extensions_if_available, + lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; + +private: + /// Helper that creates an AST type from \p type. + void *ReconstructType(lldb::opaque_compiler_type_t type); + /// Cast \p opaque_type as a mangled name. + const char *AsMangledName(lldb::opaque_compiler_type_t opaque_type); + + /// Wrap \p node as \p Global(TypeMangling(node)), remangle the type + /// and create a CompilerType from it. + CompilerType RemangleAsType(swift::Demangle::Demangler &Dem, + swift::Demangle::NodePointer node); + + /// Demangle the mangled name of the canonical type of \p type and + /// drill into the Global(TypeMangling(Type())). + /// + /// \return the child of Type or a nullptr. + swift::Demangle::NodePointer + DemangleCanonicalType(swift::Demangle::Demangler &Dem, + lldb::opaque_compiler_type_t type); + + /// Return an APINotes manager for the module with module id \id. + /// APINotes are used to get at the SDK swiftification annotations. + clang::api_notes::APINotesManager * + GetAPINotesManager(ClangExternalASTSourceCallbacks *source, unsigned id); + + /// The sibling SwiftASTContext. + SwiftASTContext *m_swift_ast_context = nullptr; + + /// The APINotesManager responsible for each Clang module. + llvm::DenseMap> + m_apinotes_manager; +}; + +} // namespace lldb_private +#endif diff --git a/lldb/source/Symbol/CMakeLists.txt b/lldb/source/Symbol/CMakeLists.txt index e0101858b10b7..037f1f4128e46 100644 --- a/lldb/source/Symbol/CMakeLists.txt +++ b/lldb/source/Symbol/CMakeLists.txt @@ -23,7 +23,6 @@ add_lldb_library(lldbSymbol LocateSymbolFile.cpp ObjectFile.cpp PostfixExpression.cpp - SwiftASTContext.cpp Symbol.cpp SymbolContext.cpp SymbolFile.cpp @@ -33,7 +32,6 @@ add_lldb_library(lldbSymbol TypeList.cpp TypeMap.cpp TypeSystem.cpp - TypeSystemSwiftTypeRef.cpp UnwindPlan.cpp UnwindTable.cpp Variable.cpp diff --git a/lldb/source/Target/ABI.cpp b/lldb/source/Target/ABI.cpp index d7a1dfa67d215..e793502772926 100644 --- a/lldb/source/Target/ABI.cpp +++ b/lldb/source/Target/ABI.cpp @@ -13,12 +13,13 @@ #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Symbol/CompilerType.h" #include "lldb/Symbol/TypeSystem.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/Log.h" #include "llvm/Support/TargetRegistry.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" + using namespace lldb; using namespace lldb_private; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 81e7bb5edc16c..9b52b92ace72b 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -7,9 +7,11 @@ //===----------------------------------------------------------------------===// #include "lldb/Target/Target.h" -#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h" +#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h" #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h" #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" +#include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Breakpoint/BreakpointIDList.h" #include "lldb/Breakpoint/BreakpointPrecondition.h" #include "lldb/Breakpoint/BreakpointResolver.h" @@ -39,11 +41,8 @@ #include "lldb/Interpreter/OptionGroupWatchpoint.h" #include "lldb/Interpreter/OptionValues.h" #include "lldb/Interpreter/Property.h" -#include "Plugins/TypeSystem/Clang/TypeSystemClang.h" -#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/SymbolVendor.h" diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp index 49d4ed9ee9c70..b9a8c8dc4b42c 100644 --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -13,7 +13,6 @@ #include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Target/ABI.h" #include "lldb/Target/LanguageRuntime.h" #include "lldb/Target/Process.h" diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp b/lldb/source/Target/ThreadPlanStepOut.cpp index 9770715c32dbc..222bda9ccbafd 100644 --- a/lldb/source/Target/ThreadPlanStepOut.cpp +++ b/lldb/source/Target/ThreadPlanStepOut.cpp @@ -13,7 +13,6 @@ #include "lldb/Symbol/Block.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/VariableList.h" diff --git a/lldb/unittests/Symbol/CMakeLists.txt b/lldb/unittests/Symbol/CMakeLists.txt index 06489df0d3300..04338514c2a89 100644 --- a/lldb/unittests/Symbol/CMakeLists.txt +++ b/lldb/unittests/Symbol/CMakeLists.txt @@ -18,6 +18,7 @@ add_lldb_unittest(SymbolTests lldbPluginSymbolFileDWARF lldbPluginSymbolFileSymtab lldbPluginTypeSystemClang + lldbPluginTypeSystemSwift lldbPluginPlatformMacOSX LLVMTestingSupport ) diff --git a/lldb/unittests/Symbol/TestSwiftASTContext.cpp b/lldb/unittests/Symbol/TestSwiftASTContext.cpp index a8521ddf081f7..c78e5607591c8 100644 --- a/lldb/unittests/Symbol/TestSwiftASTContext.cpp +++ b/lldb/unittests/Symbol/TestSwiftASTContext.cpp @@ -12,9 +12,9 @@ #include "gtest/gtest.h" +#include "Plugins/TypeSystem/Swift/SwiftASTContext.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" -#include "lldb/Symbol/SwiftASTContext.h" using namespace lldb; using namespace lldb_private; diff --git a/lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp b/lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp index a4eb11bf6511d..2e4af7fc23c51 100644 --- a/lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp +++ b/lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp @@ -12,10 +12,11 @@ #include "gtest/gtest.h" -#include "lldb/Symbol/SwiftASTContext.h" +#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h" #include "swift/Demangling/Demangle.h" #include "swift/Demangling/Demangler.h" #include "swift/Strings.h" +#include "llvm/ADT/StringRef.h" using namespace lldb; using namespace lldb_private;