Skip to content

Commit

Permalink
[lldb][NFCI] TypeSystemClang::GetTypeForIdentifier should take a Stri…
Browse files Browse the repository at this point in the history
…ngRef

This method just takes its ConstString parameter and gets a StringRef
out of it. Let's just pass in a StringRef directly.

This also cleans up some logic in the callers to be a little easier to
read and to avoid unnecessary ConstString creation.

Differential Revision: https://reviews.llvm.org/D153054
  • Loading branch information
bulbazord committed Jun 16, 2023
1 parent 00264ea commit 4c8b6fa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 deletions.
44 changes: 21 additions & 23 deletions lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,30 @@ NSDictionary_Additionals::GetAdditionalSynthetics() {

static CompilerType GetLLDBNSPairType(TargetSP target_sp) {
CompilerType compiler_type;

TypeSystemClangSP scratch_ts_sp =
ScratchTypeSystemClang::GetForTarget(*target_sp);

if (scratch_ts_sp) {
ConstString g_lldb_autogen_nspair("__lldb_autogen_nspair");

compiler_type = scratch_ts_sp->GetTypeForIdentifier<clang::CXXRecordDecl>(
g_lldb_autogen_nspair);

if (!compiler_type) {
compiler_type = scratch_ts_sp->CreateRecordType(
nullptr, OptionalClangModuleID(), lldb::eAccessPublic,
g_lldb_autogen_nspair.GetCString(), clang::TTK_Struct,
lldb::eLanguageTypeC);

if (compiler_type) {
TypeSystemClang::StartTagDeclarationDefinition(compiler_type);
CompilerType id_compiler_type =
scratch_ts_sp->GetBasicType(eBasicTypeObjCID);
TypeSystemClang::AddFieldToRecordType(
compiler_type, "key", id_compiler_type, lldb::eAccessPublic, 0);
TypeSystemClang::AddFieldToRecordType(
compiler_type, "value", id_compiler_type, lldb::eAccessPublic, 0);
TypeSystemClang::CompleteTagDeclarationDefinition(compiler_type);
}
if (!scratch_ts_sp)
return compiler_type;

static constexpr llvm::StringLiteral g_lldb_autogen_nspair("__lldb_autogen_nspair");

compiler_type = scratch_ts_sp->GetTypeForIdentifier<clang::CXXRecordDecl>(g_lldb_autogen_nspair);

if (!compiler_type) {
compiler_type = scratch_ts_sp->CreateRecordType(
nullptr, OptionalClangModuleID(), lldb::eAccessPublic,
g_lldb_autogen_nspair, clang::TTK_Struct, lldb::eLanguageTypeC);

if (compiler_type) {
TypeSystemClang::StartTagDeclarationDefinition(compiler_type);
CompilerType id_compiler_type =
scratch_ts_sp->GetBasicType(eBasicTypeObjCID);
TypeSystemClang::AddFieldToRecordType(
compiler_type, "key", id_compiler_type, lldb::eAccessPublic, 0);
TypeSystemClang::AddFieldToRecordType(
compiler_type, "value", id_compiler_type, lldb::eAccessPublic, 0);
TypeSystemClang::CompleteTagDeclarationDefinition(compiler_type);
}
}
return compiler_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CompilerType RegisterTypeBuilderClang::GetRegisterType(
// See if we have made this type before and can reuse it.
CompilerType fields_type =
type_system->GetTypeForIdentifier<clang::CXXRecordDecl>(
ConstString(register_type_name.c_str()));
register_type_name);

if (!fields_type) {
// In most ABI, a change of field type means a change in storage unit.
Expand Down
11 changes: 5 additions & 6 deletions lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
// symbols in PDB for types with const or volatile modifiers, but we need
// to create only one declaration for them all.
Type::ResolveState type_resolve_state;
CompilerType clang_type = m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>(
ConstString(name), decl_context);
CompilerType clang_type =
m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>(name, decl_context);
if (!clang_type.IsValid()) {
auto access = GetAccessibilityForUdt(*udt);

Expand Down Expand Up @@ -479,8 +479,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
uint64_t bytes = enum_type->getLength();

// Check if such an enum already exists in the current context
CompilerType ast_enum = m_ast.GetTypeForIdentifier<clang::EnumDecl>(
ConstString(name), decl_context);
CompilerType ast_enum =
m_ast.GetTypeForIdentifier<clang::EnumDecl>(name, decl_context);
if (!ast_enum.IsValid()) {
auto underlying_type_up = enum_type->getUnderlyingType();
if (!underlying_type_up)
Expand Down Expand Up @@ -557,8 +557,7 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {

// Check if such a typedef already exists in the current context
CompilerType ast_typedef =
m_ast.GetTypeForIdentifier<clang::TypedefNameDecl>(ConstString(name),
decl_ctx);
m_ast.GetTypeForIdentifier<clang::TypedefNameDecl>(name, decl_ctx);
if (!ast_typedef.IsValid()) {
CompilerType target_ast_type = target_type->GetFullCompilerType();

Expand Down
44 changes: 21 additions & 23 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,31 +252,29 @@ class TypeSystemClang : public TypeSystem {

template <typename RecordDeclType>
CompilerType
GetTypeForIdentifier(ConstString type_name,
GetTypeForIdentifier(llvm::StringRef type_name,
clang::DeclContext *decl_context = nullptr) {
CompilerType compiler_type;

if (type_name.GetLength()) {
clang::ASTContext &ast = getASTContext();
if (!decl_context)
decl_context = ast.getTranslationUnitDecl();

clang::IdentifierInfo &myIdent = ast.Idents.get(type_name.GetCString());
clang::DeclarationName myName =
ast.DeclarationNames.getIdentifier(&myIdent);

clang::DeclContext::lookup_result result = decl_context->lookup(myName);

if (!result.empty()) {
clang::NamedDecl *named_decl = *result.begin();
if (const RecordDeclType *record_decl =
llvm::dyn_cast<RecordDeclType>(named_decl))
compiler_type =
CompilerType(weak_from_this(),
clang::QualType(record_decl->getTypeForDecl(), 0)
.getAsOpaquePtr());
}
}
if (type_name.empty())
return compiler_type;

clang::ASTContext &ast = getASTContext();
if (!decl_context)
decl_context = ast.getTranslationUnitDecl();

clang::IdentifierInfo &myIdent = ast.Idents.get(type_name);
clang::DeclarationName myName =
ast.DeclarationNames.getIdentifier(&myIdent);
clang::DeclContext::lookup_result result = decl_context->lookup(myName);
if (result.empty())
return compiler_type;

clang::NamedDecl *named_decl = *result.begin();
if (const RecordDeclType *record_decl =
llvm::dyn_cast<RecordDeclType>(named_decl))
compiler_type = CompilerType(
weak_from_this(),
clang::QualType(record_decl->getTypeForDecl(), 0).getAsOpaquePtr());

return compiler_type;
}
Expand Down

0 comments on commit 4c8b6fa

Please sign in to comment.