CLang 3.5 LibTooling:获取clang :: VarDecl中变量的文件名 [英] CLang 3.5 LibTooling: getting file name of a variable in clang::VarDecl

查看:835
本文介绍了CLang 3.5 LibTooling:获取clang :: VarDecl中变量的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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:-

如何获取变量名在clang :: VarDecl中的位置

但我想这不是关于文件名哪些变量被声明。
我还提到了

But I guess it is not about file name in which variables are declared. I also referred to

http://clang.llvm.org/doxygen/classclang_1_1SourceLocation.html

没有可能返回文件名的任何函数。

There isn't any function which may return file name. Can anybody tell me how to get it?

推荐答案

你应该使用 SourceManager 获取 SourceLocation 中的具体数据。具体来说,请查看 SourceManager :: getFilename(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中变量的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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