@@ -28,15 +28,39 @@ using namespace lldb_private;
28
28
using namespace lldb_private ::formatters;
29
29
using namespace lldb_private ::formatters::swift;
30
30
31
- bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
32
- WouldEvenConsiderFormatting (CompilerType clang_type) {
31
+ // / If this is a Clang enum wrapped in a Swift type, return the clang::EnumDecl.
32
+ static clang::EnumDecl *GetAsEnumDecl (CompilerType swift_type) {
33
+ if (!swift_type)
34
+ return nullptr ;
35
+
33
36
SwiftASTContext *swift_ast_ctx =
34
- llvm::dyn_cast_or_null<SwiftASTContext>(clang_type .GetTypeSystem ());
37
+ llvm::dyn_cast_or_null<SwiftASTContext>(swift_type .GetTypeSystem ());
35
38
if (!swift_ast_ctx)
36
- return false ;
39
+ return nullptr ;
40
+
41
+ CompilerType clang_type;
42
+ if (!swift_ast_ctx->IsImportedType (swift_type, &clang_type))
43
+ return nullptr ;
44
+
45
+ if (!clang_type.IsValid ())
46
+ return nullptr ;
47
+
48
+ if (!llvm::isa<ClangASTContext>(clang_type.GetTypeSystem ()))
49
+ return nullptr ;
50
+
51
+ auto qual_type =
52
+ clang::QualType::getFromOpaquePtr (clang_type.GetOpaqueQualType ());
53
+ if (qual_type->getTypeClass () != clang::Type::TypeClass::Enum)
54
+ return nullptr ;
55
+
56
+ if (const clang::EnumType *enum_type = qual_type->getAs <clang::EnumType>())
57
+ return enum_type->getDecl ();
58
+ return nullptr ;
59
+ }
37
60
38
- return clang_type.IsValid () &&
39
- swift_ast_ctx->IsImportedType (clang_type, nullptr );
61
+ bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
62
+ WouldEvenConsiderFormatting (CompilerType swift_type) {
63
+ return GetAsEnumDecl (swift_type);
40
64
}
41
65
42
66
lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
@@ -56,55 +80,27 @@ static ConstString GetDisplayCaseName(::swift::ClangImporter *clang_importer,
56
80
return ConstString (case_decl->getName ());
57
81
}
58
82
59
- static clang::EnumDecl *GetAsEnumDecl (const CompilerType &compiler_type) {
60
- if (compiler_type.IsValid () &&
61
- llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem ())) {
62
- opaque_compiler_type_t clang_type = compiler_type.GetOpaqueQualType ();
63
- clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
64
- const clang::Type::TypeClass type_class = qual_type->getTypeClass ();
65
- switch (type_class) {
66
- case clang::Type::TypeClass::Enum: {
67
- if (const clang::EnumType *enum_type =
68
- qual_type->getAs <clang::EnumType>())
69
- return enum_type->getDecl ();
70
- break ;
71
- }
72
- default :
73
- break ;
74
- }
75
- }
76
-
77
- return nullptr ;
78
- }
79
-
80
83
void lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
81
84
FillCasesIfNeeded () {
82
85
if (m_cases.hasValue ())
83
86
return ;
84
87
85
88
m_cases = CasesVector ();
86
- SwiftASTContext *swift_ast_ctx =
87
- llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem ());
88
-
89
- if (!swift_ast_ctx)
90
- return ;
91
- CompilerType original_type;
92
- if (!swift_ast_ctx->IsImportedType (m_type, &original_type))
93
- return ;
94
- clang::EnumDecl *enum_decl = GetAsEnumDecl (original_type);
89
+ clang::EnumDecl *enum_decl = GetAsEnumDecl (m_type);
95
90
if (!enum_decl)
96
91
return ;
97
92
93
+ SwiftASTContext *swift_ast_ctx =
94
+ llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem ());
98
95
::swift::ClangImporter *clang_importer = swift_ast_ctx->GetClangImporter ();
99
96
auto iter = enum_decl->enumerator_begin (), end = enum_decl->enumerator_end ();
100
97
for (; iter != end; ++iter) {
101
98
clang::EnumConstantDecl *case_decl = *iter;
102
99
if (case_decl) {
103
100
llvm::APInt case_init_val (case_decl->getInitVal ());
104
- // extend all cases to 64 bits so that equality check is fast
101
+ // Extend all cases to 64 bits so that equality check is fast
105
102
// but if they are larger than 64, I am going to get out of that
106
- // case
107
- // and then pick it up again as unmatched data at the end
103
+ // case and then pick it up again as unmatched data at the end.
108
104
if (case_init_val.getBitWidth () < 64 )
109
105
case_init_val = case_init_val.zext (64 );
110
106
if (case_init_val.getBitWidth () > 64 )
0 commit comments