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