@@ -9944,3 +9944,33 @@ void TypeSystemClang::LogCreation() const {
99449944 LLDB_LOG (log, " Created new TypeSystem for (ASTContext*){0:x} '{1}'" ,
99459945 &getASTContext (), getDisplayName ());
99469946}
9947+
9948+ clang::SourceLocation TypeSystemClang::GetLocForDecl (const Declaration &decl) {
9949+ // If the Declaration is invalid there is nothing to do.
9950+ if (!decl.IsValid ())
9951+ return {};
9952+
9953+ clang::SourceManager &sm = getASTContext ().getSourceManager ();
9954+ clang::FileManager &fm = sm.getFileManager ();
9955+
9956+ auto fe = fm.getFileRef (decl.GetFile ().GetPath ());
9957+ if (!fe)
9958+ return {};
9959+
9960+ clang::FileID fid = sm.translateFile (*fe);
9961+ if (fid.isInvalid ()) {
9962+ // We see the file for the first time, so create a dummy file for it now.
9963+
9964+ // Connect the new dummy file to the main file via some fake include
9965+ // location. This is necessary as all file's in the SourceManager need to be
9966+ // reachable via an include chain from the main file.
9967+ SourceLocation ToIncludeLocOrFakeLoc;
9968+ assert (sm.getMainFileID ().isValid ());
9969+ ToIncludeLocOrFakeLoc = sm.getLocForStartOfFile (sm.getMainFileID ());
9970+ fid = sm.createFileID (*fe, ToIncludeLocOrFakeLoc, clang::SrcMgr::C_User);
9971+ }
9972+
9973+ // Clang requires column numbers to be >= 1..
9974+ return sm.translateLineCol (fid, decl.GetLine (),
9975+ std::max<uint16_t >(decl.GetColumn (), 1 ));
9976+ }
0 commit comments