-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLDB] Add more helper functions to CompilerType class (second try). #73472
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
Changes from all commits
a063ebd
29cd28d
6ea102e
11a1024
be41ee4
88efed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,6 +302,192 @@ bool CompilerType::IsBeingDefined() const { | |
return false; | ||
} | ||
|
||
bool CompilerType::IsInteger() const { | ||
bool is_signed = false; // May be reset by the call below. | ||
return IsIntegerType(is_signed); | ||
} | ||
|
||
bool CompilerType::IsFloat() const { | ||
uint32_t count = 0; | ||
bool is_complex = false; | ||
return IsFloatingPointType(count, is_complex); | ||
} | ||
|
||
bool CompilerType::IsEnumerationType() const { | ||
bool is_signed = false; // May be reset by the call below. | ||
return IsEnumerationType(is_signed); | ||
} | ||
|
||
bool CompilerType::IsUnscopedEnumerationType() const { | ||
return IsEnumerationType() && !IsScopedEnumerationType(); | ||
} | ||
|
||
bool CompilerType::IsIntegerOrUnscopedEnumerationType() const { | ||
return IsInteger() || IsUnscopedEnumerationType(); | ||
} | ||
|
||
bool CompilerType::IsSigned() const { | ||
return GetTypeInfo() & lldb::eTypeIsSigned; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function looks like it's working around a bug in GetTypeInfo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (i.e., could this be fixed by modifying TypeSystemClang::GetTypeInfo to return the sign bit on enums? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adrian-prantl Actually I think it already works properly without special-casing enums (I went back and looked and could not figure out why I had done this). I've cleaned it up now and removed the special casing. Are you OK with me committing this now? |
||
} | ||
|
||
bool CompilerType::IsNullPtrType() const { | ||
return GetCanonicalType().GetBasicTypeEnumeration() == | ||
lldb::eBasicTypeNullPtr; | ||
} | ||
|
||
bool CompilerType::IsBoolean() const { | ||
return GetCanonicalType().GetBasicTypeEnumeration() == lldb::eBasicTypeBool; | ||
} | ||
|
||
bool CompilerType::IsEnumerationIntegerTypeSigned() const { | ||
if (IsValid()) | ||
return GetEnumerationIntegerType().GetTypeInfo() & lldb::eTypeIsSigned; | ||
|
||
return false; | ||
} | ||
|
||
bool CompilerType::IsScalarOrUnscopedEnumerationType() const { | ||
return IsScalarType() || IsUnscopedEnumerationType(); | ||
} | ||
|
||
bool CompilerType::IsPromotableIntegerType() const { | ||
// Unscoped enums are always considered as promotable, even if their | ||
// underlying type does not need to be promoted (e.g. "int"). | ||
if (IsUnscopedEnumerationType()) | ||
return true; | ||
|
||
switch (GetCanonicalType().GetBasicTypeEnumeration()) { | ||
case lldb::eBasicTypeBool: | ||
case lldb::eBasicTypeChar: | ||
case lldb::eBasicTypeSignedChar: | ||
case lldb::eBasicTypeUnsignedChar: | ||
case lldb::eBasicTypeShort: | ||
case lldb::eBasicTypeUnsignedShort: | ||
case lldb::eBasicTypeWChar: | ||
case lldb::eBasicTypeSignedWChar: | ||
case lldb::eBasicTypeUnsignedWChar: | ||
case lldb::eBasicTypeChar16: | ||
case lldb::eBasicTypeChar32: | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This likely needs a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
llvm_unreachable("All cases handled above."); | ||
} | ||
|
||
bool CompilerType::IsPointerToVoid() const { | ||
if (!IsValid()) | ||
return false; | ||
|
||
return IsPointerType() && | ||
GetPointeeType().GetBasicTypeEnumeration() == lldb::eBasicTypeVoid; | ||
} | ||
|
||
bool CompilerType::IsRecordType() const { | ||
if (!IsValid()) | ||
return false; | ||
|
||
return GetCanonicalType().GetTypeClass() & | ||
(lldb::eTypeClassClass | lldb::eTypeClassStruct | | ||
lldb::eTypeClassUnion); | ||
} | ||
|
||
bool CompilerType::IsVirtualBase(CompilerType target_base, | ||
CompilerType *virtual_base, | ||
bool carry_virtual) const { | ||
if (CompareTypes(target_base)) | ||
return carry_virtual; | ||
|
||
if (!carry_virtual) { | ||
uint32_t num_virtual_bases = GetNumVirtualBaseClasses(); | ||
for (uint32_t i = 0; i < num_virtual_bases; ++i) { | ||
uint32_t bit_offset; | ||
auto base = GetVirtualBaseClassAtIndex(i, &bit_offset); | ||
if (base.IsVirtualBase(target_base, virtual_base, | ||
/*carry_virtual*/ true)) { | ||
if (virtual_base) | ||
*virtual_base = base; | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
||
uint32_t num_direct_bases = GetNumDirectBaseClasses(); | ||
for (uint32_t i = 0; i < num_direct_bases; ++i) { | ||
uint32_t bit_offset; | ||
auto base = GetDirectBaseClassAtIndex(i, &bit_offset); | ||
if (base.IsVirtualBase(target_base, virtual_base, carry_virtual)) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool CompilerType::IsContextuallyConvertibleToBool() const { | ||
return IsScalarType() || IsUnscopedEnumerationType() || IsPointerType() || | ||
IsNullPtrType() || IsArrayType(); | ||
} | ||
|
||
bool CompilerType::IsBasicType() const { | ||
return GetCanonicalType().GetBasicTypeEnumeration() != | ||
lldb::eBasicTypeInvalid; | ||
} | ||
|
||
std::string CompilerType::TypeDescription() { | ||
auto name = GetTypeName(); | ||
auto canonical_name = GetCanonicalType().GetTypeName(); | ||
if (name.IsEmpty() || canonical_name.IsEmpty()) | ||
return "''"; // Should not happen, unless the input is broken somehow. | ||
|
||
if (name == canonical_name) | ||
return llvm::formatv("'{0}'", name); | ||
|
||
return llvm::formatv("'{0}' (canonically referred to as '{1}')", name, | ||
canonical_name); | ||
} | ||
|
||
bool CompilerType::CompareTypes(CompilerType rhs) const { | ||
if (*this == rhs) | ||
return true; | ||
|
||
const ConstString name = GetFullyUnqualifiedType().GetTypeName(); | ||
const ConstString rhs_name = rhs.GetFullyUnqualifiedType().GetTypeName(); | ||
return name == rhs_name; | ||
} | ||
|
||
const char *CompilerType::GetTypeTag() { | ||
switch (GetTypeClass()) { | ||
case lldb::eTypeClassClass: | ||
return "class"; | ||
case lldb::eTypeClassEnumeration: | ||
return "enum"; | ||
case lldb::eTypeClassStruct: | ||
return "struct"; | ||
case lldb::eTypeClassUnion: | ||
return "union"; | ||
default: | ||
return "unknown"; | ||
} | ||
llvm_unreachable("All cases are covered by code above."); | ||
} | ||
|
||
uint32_t CompilerType::GetNumberOfNonEmptyBaseClasses() { | ||
uint32_t ret = 0; | ||
uint32_t num_direct_bases = GetNumDirectBaseClasses(); | ||
|
||
for (uint32_t i = 0; i < num_direct_bases; ++i) { | ||
uint32_t bit_offset; | ||
CompilerType base_type = GetDirectBaseClassAtIndex(i, &bit_offset); | ||
if (base_type.GetNumFields() > 0 || | ||
base_type.GetNumberOfNonEmptyBaseClasses() > 0) | ||
ret += 1; | ||
} | ||
return ret; | ||
} | ||
|
||
// Type Completion | ||
|
||
bool CompilerType::GetCompleteType() const { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems extremely specific to the C language family. I don't think that's a problem, but it would be nice to at least document that this may be only defined in TypeSystemClang?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done? I think?