@@ -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(
14541458clang::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 *
16931699TypeSystemClang::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,
21882197FunctionDecl *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(
22582273ParmVarDecl *TypeSystemClang::CreateParameterDeclaration (
22592274 clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
22602275 const char *name, const CompilerType ¶m_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,11 @@ 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+ // FIXME: we should pass the location of the parameter not the function
7816+ auto *param = CreateParameterDeclaration (
7817+ func, /* owning_module=*/ {}, name.data (),
7818+ GetType (prototype.getParamType (param_index)), clang::SC_None,
7819+ func->getLocation (), /* add_decl=*/ false );
78017820 assert (param);
78027821
78037822 params.push_back (param);
@@ -7810,7 +7829,8 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
78107829 lldb::opaque_compiler_type_t type, llvm::StringRef name,
78117830 const char *mangled_name, const CompilerType &method_clang_type,
78127831 lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
7813- bool is_explicit, bool is_attr_used, bool is_artificial) {
7832+ bool is_explicit, bool is_attr_used, bool is_artificial,
7833+ const Declaration &declaration) {
78147834 if (!type || !method_clang_type.IsValid () || name.empty ())
78157835 return nullptr ;
78167836
@@ -7951,6 +7971,10 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
79517971 cxx_method_decl->setParams (CreateParameterDeclarations (
79527972 cxx_method_decl, *method_function_prototype, /* parameter_names=*/ {}));
79537973
7974+ const clang::SourceLocation location = GetLocForDecl (declaration);
7975+ cxx_method_decl->setLocation (location);
7976+ cxx_method_decl->setRangeEnd (location);
7977+
79547978 AddAccessSpecifierDecl (cxx_record_decl, getASTContext (),
79557979 GetCXXRecordDeclAccess (cxx_record_decl),
79567980 access_specifier);
0 commit comments