如何使用 Clang 的 C++ API 从文件名/行/列三元组中获取源位置
How can I get a SourceLocation from a filename/line/column triplet using Clang's C++ API
libclang
C API具有以下功能:
CXSourceLocation clang_getLocation(
CXTranslationUnit tu,
CXFile file,
unsigned line,
unsigned column
)
我找不到一个等价的c++ API。有许多getLocation
函数,但没有一个接受这组参数。
我最终试图在给定的源位置获得DeclRef
,如果它存在。
通过SourceManager
查找file:line:column三元组的SourceLocation
可能有些笨拙,具体如下:
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
在这一点上,虽然
相关文章:
- 如何有效地找到数组中三元组和的最小差异?
- 黑客兰克中的错误比较三元组代码
- 在C++中生成字母的三元组
- 从 numpy 数组获取指针以将图像发送到C++
- 指针数组.获取指针元素的值
- 特征用三元组填充稀疏行主矩阵
- 循环以使用 cstring 数组 c++ 获取用户输入
- 求数组中三元组 (i, j, k) 的数量,使得 A[i] + A[j] = 2 * A[k]
- 一种从元组/数组获取参数包的方法
- 为什么在 Gnu gcc/g++ 中解析三元组序列的字符串文字?
- 如何使用数组获取输入,并将其存储在record.h类的主类中的变量中
- 如何使用数组获取命令行参数
- 使用欧几里得公式求全毕达哥拉斯三元组
- 所有毕达哥拉斯的三元组都小于500
- 从 JSON 数组获取天气
- 来自三元组的稀疏矩阵
- 如何在C++中对三元组进行排序
- 在最小执行时间内找到给定数组中和为零的所有唯一三元组
- 在c++中查找数组中和等于零的所有唯一三元组
- 如何使用 Clang 的 C++ API 从文件名/行/列三元组中获取源位置