问题描述
我有一个 clang :: VarDecl 对象。我想获取变量的文件名/位置(至少如果它们是全局的)。我也通过一个问题: -
I am having a clang::VarDecl object. I want to fetch the file name/location of the variable (at least if they are global). I also skimmed through a question:-
但我想这不是关于文件名哪些变量被声明。
我还提到了
But I guess it is not about file name in which variables are declared.I also referred to
没有可能返回文件名的任何函数。
There isn't any function which may return file name. Can anybody tell me how to get it?
推荐答案
你应该使用 SourceManager 获取 SourceLocation 中的具体数据。具体来说,请查看。
You're supposed to use SourceManager to get concrete data out of a SourceLocation. In particular, take a look at the SourceManager::getFilename(SourceLocation) method.
您可以通过以下方式获取 SourceManager 使用 CompilerInstance :: getSourceManager 。
You can get an instance of a SourceManager by using CompilerInstance::getSourceManager.
这篇关于CLang 3.5 LibTooling:获取clang :: VarDecl中变量的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!