@@ -29,39 +29,41 @@ using namespace lldb_private::formatters;
29
29
using namespace lldb_private ::formatters::swift;
30
30
31
31
// / If this is a Clang enum wrapped in a Swift type, return the clang::EnumDecl.
32
- static clang::EnumDecl *GetAsEnumDecl (CompilerType swift_type) {
32
+ static std::pair<clang::EnumDecl *, TypeSystemClang *>
33
+ GetAsEnumDecl (CompilerType swift_type) {
33
34
if (!swift_type)
34
- return nullptr ;
35
+ return { nullptr , nullptr } ;
35
36
36
37
TypeSystemSwift *swift_ast_ctx =
37
38
llvm::dyn_cast_or_null<TypeSystemSwift>(swift_type.GetTypeSystem ());
38
39
if (!swift_ast_ctx)
39
- return nullptr ;
40
+ return { nullptr , nullptr } ;
40
41
41
42
CompilerType clang_type;
42
43
if (!swift_ast_ctx->IsImportedType (swift_type.GetOpaqueQualType (),
43
44
&clang_type))
44
- return nullptr ;
45
+ return { nullptr , nullptr } ;
45
46
46
47
if (!clang_type.IsValid ())
47
- return nullptr ;
48
+ return { nullptr , nullptr } ;
48
49
49
- if (!llvm::isa<TypeSystemClang>(clang_type.GetTypeSystem ()))
50
- return nullptr ;
50
+ auto *clang_ts = llvm::dyn_cast<TypeSystemClang>(clang_type.GetTypeSystem ());
51
+ if (!clang_ts)
52
+ return {nullptr , nullptr };
51
53
52
54
auto qual_type =
53
55
clang::QualType::getFromOpaquePtr (clang_type.GetOpaqueQualType ());
54
56
if (qual_type->getTypeClass () != clang::Type::TypeClass::Enum)
55
- return nullptr ;
57
+ return { nullptr , nullptr } ;
56
58
57
59
if (const clang::EnumType *enum_type = qual_type->getAs <clang::EnumType>())
58
- return enum_type->getDecl ();
59
- return nullptr ;
60
+ return { enum_type->getDecl (), clang_ts} ;
61
+ return { nullptr , nullptr } ;
60
62
}
61
63
62
64
bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
63
65
WouldEvenConsiderFormatting (CompilerType swift_type) {
64
- return GetAsEnumDecl (swift_type);
66
+ return GetAsEnumDecl (swift_type). first ;
65
67
}
66
68
67
69
lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
@@ -70,33 +72,33 @@ lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
70
72
TypeSummaryImpl::Flags ()),
71
73
m_type(clang_type), m_cases() {}
72
74
73
- static ConstString GetDisplayCaseName (::swift::ClangImporter *clang_importer,
74
- clang::EnumConstantDecl *case_decl) {
75
- if (clang_importer) {
76
- ::swift::Identifier imported_identifier =
77
- clang_importer->getEnumConstantName (case_decl);
78
- if (false == imported_identifier.empty ())
79
- return ConstString (imported_identifier.str ());
80
- }
81
- return ConstString (case_decl->getName ());
82
- }
83
-
84
75
void lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
85
76
FillCasesIfNeeded () {
86
77
if (m_cases.hasValue ())
87
78
return ;
88
79
89
80
m_cases = CasesVector ();
90
- clang::EnumDecl *enum_decl = GetAsEnumDecl (m_type);
81
+ auto decl_ts = GetAsEnumDecl (m_type);
82
+ clang::EnumDecl *enum_decl = decl_ts.first ;
91
83
if (!enum_decl)
92
84
return ;
93
85
94
- if (auto *ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(
95
- m_type.GetTypeSystem ()))
96
- m_type = ts->ReconstructType (m_type);
86
+ // FIXME: Delete this type reconstruction block. For GetSwiftName() to
87
+ // fully work, ClangImporter's ImportName class needs to be made
88
+ // standalone and provided with a callback to read the APINote
89
+ // information.
90
+ auto *ts = llvm::cast<TypeSystemSwift>(m_type.GetTypeSystem ());
91
+ if (auto *trts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(ts)) {
92
+ m_type = trts->ReconstructType (m_type);
93
+ ts = llvm::cast<SwiftASTContext>(m_type.GetTypeSystem ());
94
+ decl_ts = GetAsEnumDecl (m_type);
95
+ enum_decl = decl_ts.first ;
96
+ if (!enum_decl)
97
+ return ;
98
+ }
99
+
97
100
SwiftASTContext *swift_ast_ctx =
98
101
llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem ());
99
- ::swift::ClangImporter *clang_importer = swift_ast_ctx->GetClangImporter ();
100
102
auto iter = enum_decl->enumerator_begin (), end = enum_decl->enumerator_end ();
101
103
for (; iter != end; ++iter) {
102
104
clang::EnumConstantDecl *case_decl = *iter;
@@ -109,7 +111,7 @@ void lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
109
111
case_init_val = case_init_val.zext (64 );
110
112
if (case_init_val.getBitWidth () > 64 )
111
113
continue ;
112
- ConstString case_name (GetDisplayCaseName (clang_importer, case_decl ));
114
+ ConstString case_name (ts-> GetSwiftName (case_decl, *decl_ts. second ));
113
115
m_cases->push_back ({case_init_val, case_name});
114
116
}
115
117
}
0 commit comments