[lldb][NFC] Use StringRef in ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize

This commit is contained in:
Raphael Isemann 2019-12-25 18:23:09 +01:00
parent 2498d88259
commit caf460d979
3 changed files with 43 additions and 49 deletions

View File

@ -155,9 +155,9 @@ public:
static lldb::BasicType GetBasicTypeEnumeration(ConstString name); static lldb::BasicType GetBasicTypeEnumeration(ConstString name);
CompilerType GetBuiltinTypeForDWARFEncodingAndBitSize(const char *type_name, CompilerType
uint32_t dw_ate, GetBuiltinTypeForDWARFEncodingAndBitSize(llvm::StringRef type_name,
uint32_t bit_size); uint32_t dw_ate, uint32_t bit_size);
CompilerType GetCStringType(bool is_const); CompilerType GetCStringType(bool is_const);

View File

@ -598,7 +598,7 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
case DW_TAG_base_type: case DW_TAG_base_type:
resolve_state = Type::ResolveState::Full; resolve_state = Type::ResolveState::Full;
clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize( clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(
attrs.name.GetCString(), attrs.encoding, attrs.name.GetStringRef(), attrs.encoding,
attrs.byte_size.getValueOr(0) * 8); attrs.byte_size.getValueOr(0) * 8);
break; break;
@ -809,7 +809,7 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
if (!enumerator_clang_type) { if (!enumerator_clang_type) {
if (attrs.byte_size) { if (attrs.byte_size) {
enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize( enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(
NULL, DW_ATE_signed, *attrs.byte_size * 8); "", DW_ATE_signed, *attrs.byte_size * 8);
} else { } else {
enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt); enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt);
} }

View File

@ -907,11 +907,9 @@ CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) {
} }
CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize( CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
const char *type_name, uint32_t dw_ate, uint32_t bit_size) { llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
ASTContext &ast = getASTContext(); ASTContext &ast = getASTContext();
#define streq(a, b) strcmp(a, b) == 0
switch (dw_ate) { switch (dw_ate) {
default: default:
break; break;
@ -934,17 +932,14 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
case DW_ATE_lo_user: case DW_ATE_lo_user:
// This has been seen to mean DW_AT_complex_integer // This has been seen to mean DW_AT_complex_integer
if (type_name) { if (type_name.contains("complex")) {
if (::strstr(type_name, "complex")) {
CompilerType complex_int_clang_type = CompilerType complex_int_clang_type =
GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed, GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed,
bit_size / 2); bit_size / 2);
return CompilerType( return CompilerType(this, ast.getComplexType(ClangUtil::GetQualType(
this, complex_int_clang_type))
ast.getComplexType(ClangUtil::GetQualType(complex_int_clang_type))
.getAsOpaquePtr()); .getAsOpaquePtr());
} }
}
break; break;
case DW_ATE_complex_float: case DW_ATE_complex_float:
@ -966,13 +961,13 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
break; break;
case DW_ATE_float: case DW_ATE_float:
if (streq(type_name, "float") && if (type_name == "float" &&
QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy)) QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
return CompilerType(this, ast.FloatTy.getAsOpaquePtr()); return CompilerType(this, ast.FloatTy.getAsOpaquePtr());
if (streq(type_name, "double") && if (type_name == "double" &&
QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy)) QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
return CompilerType(this, ast.DoubleTy.getAsOpaquePtr()); return CompilerType(this, ast.DoubleTy.getAsOpaquePtr());
if (streq(type_name, "long double") && if (type_name == "long double" &&
QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy)) QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
return CompilerType(this, ast.LongDoubleTy.getAsOpaquePtr()); return CompilerType(this, ast.LongDoubleTy.getAsOpaquePtr());
// Fall back to not requiring a name match // Fall back to not requiring a name match
@ -987,31 +982,31 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
break; break;
case DW_ATE_signed: case DW_ATE_signed:
if (type_name) { if (!type_name.empty()) {
if (streq(type_name, "wchar_t") && if (type_name == "wchar_t" &&
QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy) && QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy) &&
(getTargetInfo() && (getTargetInfo() &&
TargetInfo::isTypeSigned(getTargetInfo()->getWCharType()))) TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
return CompilerType(this, ast.WCharTy.getAsOpaquePtr()); return CompilerType(this, ast.WCharTy.getAsOpaquePtr());
if (streq(type_name, "void") && if (type_name == "void" &&
QualTypeMatchesBitSize(bit_size, ast, ast.VoidTy)) QualTypeMatchesBitSize(bit_size, ast, ast.VoidTy))
return CompilerType(this, ast.VoidTy.getAsOpaquePtr()); return CompilerType(this, ast.VoidTy.getAsOpaquePtr());
if (strstr(type_name, "long long") && if (type_name.contains("long long") &&
QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy)) QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
return CompilerType(this, ast.LongLongTy.getAsOpaquePtr()); return CompilerType(this, ast.LongLongTy.getAsOpaquePtr());
if (strstr(type_name, "long") && if (type_name.contains("long") &&
QualTypeMatchesBitSize(bit_size, ast, ast.LongTy)) QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
return CompilerType(this, ast.LongTy.getAsOpaquePtr()); return CompilerType(this, ast.LongTy.getAsOpaquePtr());
if (strstr(type_name, "short") && if (type_name.contains("short") &&
QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy)) QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
return CompilerType(this, ast.ShortTy.getAsOpaquePtr()); return CompilerType(this, ast.ShortTy.getAsOpaquePtr());
if (strstr(type_name, "char")) { if (type_name.contains("char")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
return CompilerType(this, ast.CharTy.getAsOpaquePtr()); return CompilerType(this, ast.CharTy.getAsOpaquePtr());
if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
return CompilerType(this, ast.SignedCharTy.getAsOpaquePtr()); return CompilerType(this, ast.SignedCharTy.getAsOpaquePtr());
} }
if (strstr(type_name, "int")) { if (type_name.contains("int")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
return CompilerType(this, ast.IntTy.getAsOpaquePtr()); return CompilerType(this, ast.IntTy.getAsOpaquePtr());
if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty)) if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
@ -1034,8 +1029,7 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
break; break;
case DW_ATE_signed_char: case DW_ATE_signed_char:
if (ast.getLangOpts().CharIsSigned && type_name && if (ast.getLangOpts().CharIsSigned && type_name == "char") {
streq(type_name, "char")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
return CompilerType(this, ast.CharTy.getAsOpaquePtr()); return CompilerType(this, ast.CharTy.getAsOpaquePtr());
} }
@ -1044,27 +1038,27 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
break; break;
case DW_ATE_unsigned: case DW_ATE_unsigned:
if (type_name) { if (!type_name.empty()) {
if (streq(type_name, "wchar_t")) { if (type_name == "wchar_t") {
if (QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)) { if (QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)) {
if (!(getTargetInfo() && if (!(getTargetInfo() &&
TargetInfo::isTypeSigned(getTargetInfo()->getWCharType()))) TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
return CompilerType(this, ast.WCharTy.getAsOpaquePtr()); return CompilerType(this, ast.WCharTy.getAsOpaquePtr());
} }
} }
if (strstr(type_name, "long long")) { if (type_name.contains("long long")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
return CompilerType(this, ast.UnsignedLongLongTy.getAsOpaquePtr()); return CompilerType(this, ast.UnsignedLongLongTy.getAsOpaquePtr());
} else if (strstr(type_name, "long")) { } else if (type_name.contains("long")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
return CompilerType(this, ast.UnsignedLongTy.getAsOpaquePtr()); return CompilerType(this, ast.UnsignedLongTy.getAsOpaquePtr());
} else if (strstr(type_name, "short")) { } else if (type_name.contains("short")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr()); return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
} else if (strstr(type_name, "char")) { } else if (type_name.contains("char")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr()); return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
} else if (strstr(type_name, "int")) { } else if (type_name.contains("int")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
return CompilerType(this, ast.UnsignedIntTy.getAsOpaquePtr()); return CompilerType(this, ast.UnsignedIntTy.getAsOpaquePtr());
if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty)) if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
@ -1087,8 +1081,7 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
break; break;
case DW_ATE_unsigned_char: case DW_ATE_unsigned_char:
if (!ast.getLangOpts().CharIsSigned && type_name && if (!ast.getLangOpts().CharIsSigned && type_name == "char") {
streq(type_name, "char")) {
if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy)) if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
return CompilerType(this, ast.CharTy.getAsOpaquePtr()); return CompilerType(this, ast.CharTy.getAsOpaquePtr());
} }
@ -1102,23 +1095,24 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
break; break;
case DW_ATE_UTF: case DW_ATE_UTF:
if (type_name) { if (!type_name.empty()) {
if (streq(type_name, "char16_t")) if (type_name == "char16_t")
return CompilerType(this, ast.Char16Ty.getAsOpaquePtr()); return CompilerType(this, ast.Char16Ty.getAsOpaquePtr());
if (streq(type_name, "char32_t")) if (type_name == "char32_t")
return CompilerType(this, ast.Char32Ty.getAsOpaquePtr()); return CompilerType(this, ast.Char32Ty.getAsOpaquePtr());
if (streq(type_name, "char8_t")) if (type_name == "char8_t")
return CompilerType(this, ast.Char8Ty.getAsOpaquePtr()); return CompilerType(this, ast.Char8Ty.getAsOpaquePtr());
} }
break; break;
} }
// This assert should fire for anything that we don't catch above so we know // This assert should fire for anything that we don't catch above so we know
// to fix any issues we run into. // to fix any issues we run into.
if (type_name) { if (!type_name.empty()) {
Host::SystemLog(Host::eSystemLogError, "error: need to add support for " std::string type_name_str = type_name.str();
"DW_TAG_base_type '%s' encoded with " Host::SystemLog(Host::eSystemLogError,
"DW_ATE = 0x%x, bit_size = %u\n", "error: need to add support for DW_TAG_base_type '%s' "
type_name, dw_ate, bit_size); "encoded with DW_ATE = 0x%x, bit_size = %u\n",
type_name_str.c_str(), dw_ate, bit_size);
} else { } else {
Host::SystemLog(Host::eSystemLogError, "error: need to add support for " Host::SystemLog(Host::eSystemLogError, "error: need to add support for "
"DW_TAG_base_type encoded with " "DW_TAG_base_type encoded with "