Skip to content

Commit f7a2ce3

Browse files
committed
[lldb][TypeSystemClang] Set location on functions, parameters, enums and structures
1 parent 1aabc8a commit f7a2ce3

File tree

5 files changed

+73
-35
lines changed

5 files changed

+73
-35
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
13721372
ignore_containing_context ? m_ast.GetTranslationUnitDecl()
13731373
: containing_decl_ctx,
13741374
GetOwningClangModule(die), name, clang_type, attrs.storage,
1375-
attrs.is_inline);
1375+
attrs.is_inline, attrs.decl);
13761376
std::free(name_buf);
13771377

13781378
if (has_template_params) {
@@ -1382,11 +1382,11 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
13821382
ignore_containing_context ? m_ast.GetTranslationUnitDecl()
13831383
: containing_decl_ctx,
13841384
GetOwningClangModule(die), attrs.name.GetStringRef(), clang_type,
1385-
attrs.storage, attrs.is_inline);
1385+
attrs.storage, attrs.is_inline, attrs.decl);
13861386
clang::FunctionTemplateDecl *func_template_decl =
13871387
m_ast.CreateFunctionTemplateDecl(
13881388
containing_decl_ctx, GetOwningClangModule(die),
1389-
template_function_decl, template_param_infos);
1389+
template_function_decl, template_param_infos, attrs.decl);
13901390
m_ast.CreateFunctionTemplateSpecializationInfo(
13911391
template_function_decl, func_template_decl, template_param_infos);
13921392
}
@@ -1858,7 +1858,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
18581858
clang::ClassTemplateSpecializationDecl *class_specialization_decl =
18591859
m_ast.CreateClassTemplateSpecializationDecl(
18601860
containing_decl_ctx, GetOwningClangModule(die), class_template_decl,
1861-
tag_decl_kind, template_param_infos);
1861+
tag_decl_kind, template_param_infos, attrs.decl);
18621862
clang_type =
18631863
m_ast.CreateClassTemplateSpecializationType(class_specialization_decl);
18641864

@@ -1870,7 +1870,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
18701870
clang_type = m_ast.CreateRecordType(
18711871
containing_decl_ctx, GetOwningClangModule(die), attrs.accessibility,
18721872
attrs.name.GetCString(), tag_decl_kind, attrs.class_language, metadata,
1873-
attrs.exports_symbols);
1873+
attrs.exports_symbols, attrs.decl);
18741874
}
18751875

18761876
TypeSP type_sp = dwarf->MakeType(

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ void PdbAstBuilder::CreateFunctionParameters(PdbCompilandSymId func_id,
11281128
CompilerType param_type_ct = m_clang.GetType(qt);
11291129
clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration(
11301130
&function_decl, OptionalClangModuleID(), param_name.str().c_str(),
1131-
param_type_ct, clang::SC_None, true);
1131+
param_type_ct, clang::SC_None, clang::SourceLocation(), true);
11321132
lldbassert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0);
11331133

11341134
m_uid_to_decl[toOpaqueUid(param_uid)] = param;

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,8 @@ PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) {
969969

970970
clang::ParmVarDecl *param = m_ast.CreateParameterDeclaration(
971971
decl, OptionalClangModuleID(), nullptr,
972-
arg_type->GetForwardCompilerType(), clang::SC_None, true);
972+
arg_type->GetForwardCompilerType(), clang::SC_None,
973+
clang::SourceLocation(), true);
973974
if (param)
974975
params.push_back(param);
975976
}

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ CompilerType TypeSystemClang::CreateRecordType(
12821282
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
12831283
AccessType access_type, llvm::StringRef name, int kind,
12841284
LanguageType language, std::optional<ClangASTMetadata> metadata,
1285-
bool exports_symbols) {
1285+
bool exports_symbols, const Declaration &declaration) {
12861286
ASTContext &ast = getASTContext();
12871287

12881288
if (decl_ctx == nullptr)
@@ -1337,6 +1337,10 @@ CompilerType TypeSystemClang::CreateRecordType(
13371337
decl->setAnonymousStructOrUnion(true);
13381338
}
13391339

1340+
auto location = GetLocForDecl(declaration);
1341+
decl->setLocStart(location);
1342+
decl->setLocation(location);
1343+
13401344
if (metadata)
13411345
SetMetadata(decl, *metadata);
13421346

@@ -1454,7 +1458,8 @@ static TemplateParameterList *CreateTemplateParameterList(
14541458
clang::FunctionTemplateDecl *TypeSystemClang::CreateFunctionTemplateDecl(
14551459
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
14561460
clang::FunctionDecl *func_decl,
1457-
const TemplateParameterInfos &template_param_infos) {
1461+
const TemplateParameterInfos &template_param_infos,
1462+
const Declaration &declaration) {
14581463
// /// Create a function template node.
14591464
ASTContext &ast = getASTContext();
14601465

@@ -1468,6 +1473,7 @@ clang::FunctionTemplateDecl *TypeSystemClang::CreateFunctionTemplateDecl(
14681473
func_tmpl_decl->setDeclName(func_decl->getDeclName());
14691474
func_tmpl_decl->setTemplateParameters(template_param_list);
14701475
func_tmpl_decl->init(func_decl);
1476+
func_tmpl_decl->setLocation(GetLocForDecl(declaration));
14711477
SetOwningModule(func_tmpl_decl, owning_module);
14721478

14731479
for (size_t i = 0, template_param_decl_count = template_param_decls.size();
@@ -1693,7 +1699,8 @@ ClassTemplateSpecializationDecl *
16931699
TypeSystemClang::CreateClassTemplateSpecializationDecl(
16941700
DeclContext *decl_ctx, OptionalClangModuleID owning_module,
16951701
ClassTemplateDecl *class_template_decl, int kind,
1696-
const TemplateParameterInfos &template_param_infos) {
1702+
const TemplateParameterInfos &template_param_infos,
1703+
const Declaration &declaration) {
16971704
ASTContext &ast = getASTContext();
16981705
llvm::SmallVector<clang::TemplateArgument, 2> args(
16991706
template_param_infos.Size() +
@@ -1728,6 +1735,8 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
17281735
class_template_specialization_decl->setSpecializationKind(
17291736
TSK_ExplicitSpecialization);
17301737

1738+
class_template_specialization_decl->setLocation(GetLocForDecl(declaration));
1739+
17311740
return class_template_specialization_decl;
17321741
}
17331742

@@ -2188,7 +2197,8 @@ std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl,
21882197
FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
21892198
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
21902199
llvm::StringRef name, const CompilerType &function_clang_type,
2191-
clang::StorageClass storage, bool is_inline) {
2200+
clang::StorageClass storage, bool is_inline,
2201+
const Declaration &declaration) {
21922202
FunctionDecl *func_decl = nullptr;
21932203
ASTContext &ast = getASTContext();
21942204
if (!decl_ctx)
@@ -2209,6 +2219,11 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
22092219
func_decl->setConstexprKind(isConstexprSpecified
22102220
? ConstexprSpecKind::Constexpr
22112221
: ConstexprSpecKind::Unspecified);
2222+
2223+
const clang::SourceLocation location = GetLocForDecl(declaration);
2224+
func_decl->setLocation(location);
2225+
func_decl->setRangeEnd(location);
2226+
22122227
SetOwningModule(func_decl, owning_module);
22132228
decl_ctx->addDecl(func_decl);
22142229

@@ -2258,14 +2273,15 @@ CompilerType TypeSystemClang::CreateFunctionType(
22582273
ParmVarDecl *TypeSystemClang::CreateParameterDeclaration(
22592274
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
22602275
const char *name, const CompilerType &param_type, int storage,
2261-
bool add_decl) {
2276+
clang::SourceLocation loc, bool add_decl) {
22622277
ASTContext &ast = getASTContext();
22632278
auto *decl = ParmVarDecl::CreateDeserialized(ast, GlobalDeclID());
22642279
decl->setDeclContext(decl_ctx);
22652280
if (name && name[0])
22662281
decl->setDeclName(&ast.Idents.get(name));
22672282
decl->setType(ClangUtil::GetQualType(param_type));
22682283
decl->setStorageClass(static_cast<clang::StorageClass>(storage));
2284+
decl->setLocation(loc);
22692285
SetOwningModule(decl, owning_module);
22702286
if (add_decl)
22712287
decl_ctx->addDecl(decl);
@@ -2355,10 +2371,10 @@ CompilerType TypeSystemClang::CreateEnumerationType(
23552371
OptionalClangModuleID owning_module, const Declaration &decl,
23562372
const CompilerType &integer_clang_type, bool is_scoped,
23572373
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind) {
2358-
// TODO: Do something intelligent with the Declaration object passed in
2359-
// like maybe filling in the SourceLocation with it...
23602374
ASTContext &ast = getASTContext();
23612375

2376+
auto location = GetLocForDecl(decl);
2377+
23622378
// TODO: ask about these...
23632379
// const bool IsFixed = false;
23642380
EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, GlobalDeclID());
@@ -2368,6 +2384,8 @@ CompilerType TypeSystemClang::CreateEnumerationType(
23682384
enum_decl->setScoped(is_scoped);
23692385
enum_decl->setScopedUsingClassTag(is_scoped);
23702386
enum_decl->setFixed(false);
2387+
enum_decl->setLocation(location);
2388+
enum_decl->setLocStart(location);
23712389
SetOwningModule(enum_decl, owning_module);
23722390
if (decl_ctx)
23732391
decl_ctx->addDecl(enum_decl);
@@ -7794,10 +7812,10 @@ TypeSystemClang::CreateParameterDeclarations(
77947812
llvm::StringRef name =
77957813
!parameter_names.empty() ? parameter_names[param_index] : "";
77967814

7797-
auto *param =
7798-
CreateParameterDeclaration(func, /*owning_module=*/{}, name.data(),
7799-
GetType(prototype.getParamType(param_index)),
7800-
clang::SC_None, /*add_decl=*/false);
7815+
auto *param = CreateParameterDeclaration(
7816+
func, /*owning_module=*/{}, name.data(),
7817+
GetType(prototype.getParamType(param_index)), clang::SC_None,
7818+
func->getLocation(), /*add_decl=*/false);
78017819
assert(param);
78027820

78037821
params.push_back(param);
@@ -7810,7 +7828,8 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
78107828
lldb::opaque_compiler_type_t type, llvm::StringRef name,
78117829
const char *mangled_name, const CompilerType &method_clang_type,
78127830
lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
7813-
bool is_explicit, bool is_attr_used, bool is_artificial) {
7831+
bool is_explicit, bool is_attr_used, bool is_artificial,
7832+
const Declaration &declaration) {
78147833
if (!type || !method_clang_type.IsValid() || name.empty())
78157834
return nullptr;
78167835

@@ -7951,6 +7970,10 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
79517970
cxx_method_decl->setParams(CreateParameterDeclarations(
79527971
cxx_method_decl, *method_function_prototype, /*parameter_names=*/{}));
79537972

7973+
const clang::SourceLocation location = GetLocForDecl(declaration);
7974+
cxx_method_decl->setLocation(location);
7975+
cxx_method_decl->setRangeEnd(location);
7976+
79547977
AddAccessSpecifierDecl(cxx_record_decl, getASTContext(),
79557978
GetCXXRecordDeclAccess(cxx_record_decl),
79567979
access_specifier);

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,12 @@ class TypeSystemClang : public TypeSystem {
326326
bool is_framework = false,
327327
bool is_explicit = false);
328328

329-
CompilerType
330-
CreateRecordType(clang::DeclContext *decl_ctx,
331-
OptionalClangModuleID owning_module,
332-
lldb::AccessType access_type, llvm::StringRef name, int kind,
333-
lldb::LanguageType language,
334-
std::optional<ClangASTMetadata> metadata = std::nullopt,
335-
bool exports_symbols = false);
329+
CompilerType CreateRecordType(
330+
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
331+
lldb::AccessType access_type, llvm::StringRef name, int kind,
332+
lldb::LanguageType language,
333+
std::optional<ClangASTMetadata> metadata = std::nullopt,
334+
bool exports_symbols = false, const Declaration &declaration = {});
336335

337336
class TemplateParameterInfos {
338337
public:
@@ -420,7 +419,8 @@ class TypeSystemClang : public TypeSystem {
420419

421420
clang::FunctionTemplateDecl *CreateFunctionTemplateDecl(
422421
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
423-
clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos);
422+
clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos,
423+
const Declaration &declaration);
424424

425425
void CreateFunctionTemplateSpecializationInfo(
426426
clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template,
@@ -437,7 +437,7 @@ class TypeSystemClang : public TypeSystem {
437437
clang::ClassTemplateSpecializationDecl *CreateClassTemplateSpecializationDecl(
438438
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
439439
clang::ClassTemplateDecl *class_template_decl, int kind,
440-
const TemplateParameterInfos &infos);
440+
const TemplateParameterInfos &infos, const Declaration &declaration);
441441

442442
CompilerType
443443
CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl *
@@ -476,19 +476,19 @@ class TypeSystemClang : public TypeSystem {
476476
clang::FunctionDecl *CreateFunctionDeclaration(
477477
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
478478
llvm::StringRef name, const CompilerType &function_Type,
479-
clang::StorageClass storage, bool is_inline);
479+
clang::StorageClass storage, bool is_inline,
480+
const Declaration &declaration = {});
480481

481482
CompilerType
482483
CreateFunctionType(const CompilerType &result_type, const CompilerType *args,
483484
unsigned num_args, bool is_variadic, unsigned type_quals,
484485
clang::CallingConv cc = clang::CC_C,
485486
clang::RefQualifierKind ref_qual = clang::RQ_None);
486487

487-
clang::ParmVarDecl *
488-
CreateParameterDeclaration(clang::DeclContext *decl_ctx,
489-
OptionalClangModuleID owning_module,
490-
const char *name, const CompilerType &param_type,
491-
int storage, bool add_decl = false);
488+
clang::ParmVarDecl *CreateParameterDeclaration(
489+
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
490+
const char *name, const CompilerType &param_type, int storage,
491+
clang::SourceLocation loc, bool add_decl = false);
492492

493493
CompilerType CreateBlockPointerType(const CompilerType &function_type);
494494

@@ -996,7 +996,8 @@ class TypeSystemClang : public TypeSystem {
996996
lldb::opaque_compiler_type_t type, llvm::StringRef name,
997997
const char *mangled_name, const CompilerType &method_type,
998998
lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
999-
bool is_explicit, bool is_attr_used, bool is_artificial);
999+
bool is_explicit, bool is_attr_used, bool is_artificial,
1000+
const Declaration &declaration = {});
10001001

10011002
void AddMethodOverridesForCXXRecordType(lldb::opaque_compiler_type_t type);
10021003

@@ -1188,6 +1189,19 @@ class TypeSystemClang : public TypeSystem {
11881189
std::optional<uint64_t> GetObjCBitSize(clang::QualType qual_type,
11891190
ExecutionContextScope *exe_scope);
11901191

1192+
/// Turns the given \c decl into a \c clang::SourceLocation.
1193+
///
1194+
/// Will create a \c FileID in this \c DWARFASTParserClang's \c ASTContext
1195+
/// if necessary.
1196+
///
1197+
/// If no \c FileID could be found/created, returns an empty \c
1198+
/// SourceLocation.
1199+
///
1200+
/// FIXME: currently a no-op.
1201+
clang::SourceLocation GetLocForDecl(const lldb_private::Declaration &decl) {
1202+
return {};
1203+
}
1204+
11911205
// Classes that inherit from TypeSystemClang can see and modify these
11921206
std::string m_target_triple;
11931207
std::unique_ptr<clang::ASTContext> m_ast_up;

0 commit comments

Comments
 (0)