如何获取我当前使用 Clang 访问的文件的名称?
How can I get the name of the file I'm currently visiting with Clang?
当我访问,让我们说,一个声明(Clang库中的Decl
),我怎么能得到这个Decl
被写入的文件的名称?
有一个FileData类,但我找不到任何其他类允许我得到这个FileData
可以向SourceManager查询当前文件的FileEntry。
例如在匹配器回调:
void MyMatcher::run(const MatchFinder::MatchResult& Result) {
ASTContext* Context = Result.Context;
if (const Decl* D = Result.Nodes.getNodeAs<Decl>("MyDecl")) {
SourceManager& SrcMgr = Context->getSourceManager();
const FileEntry* Entry = SrcMgr.getFileEntryForID(SrcMgr.getFileID(D.getCaretLocation()));
const char* FileName = Entry->getName();
}
}
相关文章:
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 用于访问容器<T>数据成员的正确 API
- 访问者访问变体并返回不同类型时出错
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法访问嵌套类.类的使用无效
- 类无法访问自己的私有静态 constexpr 方法 - Clang bug?
- Clang vs GCC:挥发性访问的不同代码
- 为什么 clang 不允许通过实例访问嵌套枚举类?
- 我相信这是 clang++ 中的一个错误,与访问类的公共成员函数有关
- 如何访问序列化的 clang 抽象语法树 (AST)
- clang或gcc关于这个内部类成员访问是否正确
- 是否有对 Clang 递归 ASTVisitor 的最终访问方法
- 如何在使用clang-format访问修饰符后缩进
- 在 Clang 中确定访问的 CXXRecordDecl 是类、结构还是联合
- 当使用RecursiveASTVisitor访问Clang AST时,确定Stmt的父函数节点
- 如何获取我当前使用 Clang 访问的文件的名称?
- 在 B 类中声明为好友的 A 类成员模板函数无法访问 A 类的私有成员(仅限 Clang)
- Clang访问修饰符顺序和decltype