如何使用Clang的C ++ API从文件名/行/列三元组中获取SourceLocation [英] How can I get a SourceLocation from a filename/line/column triplet using Clang's C++ API

查看:71
本文介绍了如何使用Clang的C ++ API从文件名/行/列三元组中获取SourceLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

libclang C API为此目的具有以下功能:

The libclang C API has the following function for this purpose:

CXSourceLocation clang_getLocation(CXTranslationUnit tu,CXFile文件,无符号的行,无符号列)

我找不到C ++ API的等效项.有许多 getLocation 函数,但没有一个采用这组参数.

I can't find an equivalent for the C++ API. There are many getLocation functions but none that take this set of arguments.

如果存在,我最终将尝试在给定的源位置获取 DeclRef .

I am ultimately trying to get the DeclRef at a given source location, if it exists.

推荐答案

通过 SourceManager 有点笨拙地找到文件 column三元组的文件如下:

Finding a SourceLocation for a file:line:column triplet can be done somewhat awkwardly through the SourceManager as follows:

SourceManager& srcmgr = astctx.getSourceManager();
FileManager& filemgr = srcmgr.getFileManager();
const FileEntry* file_entry_ptr = filemgr.getFile(filename);
SourceLocation loc = srcmgr.translateFileLineCol(file_entry_ptr, line, column);

尽管如此,我仍然不知道如何找到 Stmt .

I still do not know how to find the Stmt at that point though.

这篇关于如何使用Clang的C ++ API从文件名/行/列三元组中获取SourceLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆