使用clang获取预处理器常量值
我使用叮当引擎来解析C代码。我知道如何检查光标下的文本是否为预处理器指令。但如何获得游标下的预处理器常量值呢使用clang获取预处理器常量值,c,clang,C,Clang,我使用叮当引擎来解析C代码。我知道如何检查光标下的文本是否为预处理器指令。但如何获得游标下的预处理器常量值呢 #include <stdio.h> #include <clang-c/Index.h> #define TEST "test" int main() { char *source_filename = "/home/user1/projects/prep/prep.c"; CXIndex index; CXTranslationUn
#include <stdio.h>
#include <clang-c/Index.h>
#define TEST "test"
int main()
{
char *source_filename = "/home/user1/projects/prep/prep.c";
CXIndex index;
CXTranslationUnit tu;
CXFile file;
CXSourceLocation loc;
CXCursor cursor;
index = clang_createIndex(0, 0);
tu = clang_createTranslationUnitFromSourceFile(index, source_filename,
0, NULL, 0, NULL);
file = clang_getFile(tu, source_filename);
loc = clang_getLocation(tu, file, 4, 9);
cursor = clang_getCursor(tu, loc);
if (clang_isPreprocessing(cursor.kind)) {
/* How to get TEST constant value? */
}
clang_disposeTranslationUnit(tu);
clang_disposeIndex(index);
}
#包括
#包括
#定义测试“TEST”
int main()
{
char*source_filename=“/home/user1/projects/prep/prep.c”;
cx指数;
cxtranslationunittu;
CXFile文件;
cxsourceloc;
cx光标;
index=clang_createIndex(0,0);
tu=clang_CreateTransationUnitFromSourceFile(索引、源文件名、,
0,空,0,空);
file=clang_getFile(tu,源文件名);
loc=clang_getLocation(图,文件,4,9);
cursor=clang_getCursor(tu,loc);
if(clang_isPreprocessing(cursor.kind)){
/*如何获得测试常量值*/
}
clang_disposeTranslationUnit(图);
clang_disposeIndex(索引);
}
还有一个问题。我应该在工作后释放CXFile、CXSourceLocation和CXCursor类型的变量吗。我找不到适合它们的
clangu\u dispose
函数。谢谢您的评论。我为Vim插件编写了一个小程序,它将在状态行中的光标下显示变量类型(以及预处理器常量值,如果我理解的话)。我从来没有听说过clangd,老实说,直到今天我才开始阅读ClangDocs。因此,我将尝试更多地了解clangd。