如何比较clang中的两个源位置?
How can I compare two source locations in clang?
这似乎更像是一个c++问题,而不是Clang问题…
我必须使用c++来编写OCLint(静态代码分析器)规则。
我希望比较Clang库中具有"SourceLocation"类型的两个对象。
这个类型提供了关于位置的信息(基本上是一行&代码中对象(语句、声明等)的列。
基本上,我想知道语句A是在语句b之前开始和结束,还是在语句b之后。
在伪代码中,这意味着我想从 中获得一个布尔值:(stmt_A->getLocBegin() <例如,stmt_B->getLocBegin())。当然,这不能编译,因为"<"操作符没有在两个类型为"SourceLocation"的对象之间定义。
我在Clang文档中找到了一个方法,但是,由于我不经常使用c++,我没有找到使用它的方法,下面是这个方法:
http://clang.llvm.org/doxygen/classclang_1_1BeforeThanCompare_3_01SourceLocation_01_4.htmlclang::BeforeThanCompare<SourceLocation>::BeforeThanCompare (SourceManager &SM)
bool clang::BeforeThanCompare< SourceLocation >::operator()(SourceLocation LHS, SourceLocation RHS) const [inline]
我不知道如何使用SourceManager,或者简单地如何获得上面的这个布尔值
最后的代码展示了如何在Clang库中使用SourceManager,以及如何比较两个SourceLocation:
// Declaration of a SourceManager
SourceManager & loc_SM = _carrier->getSourceManager();
// Declaration of an object BeforeThanCompare<SourceLocation>
BeforeThanCompare<SourceLocation> isBefore(loc_SM); SourceLocation stmt_A, stmt_B;
// Get whether stmt_A is before or after Stmt_B
bool A_before_B = isBefore(stmt_A,stmt_B);
相关文章:
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 如何在单个链表中交换两个节点的位置,只修改指针
- 为什么动态分配的两个变量的内存位置不是连续的?
- 在两个不同的位置渲染 OpenGL 场景
- 如何在这两个分类的链接列表之间获得开关的位置
- 如何在C或C 的小数点后两个位置后四舍五入
- 如何在TIC TAC TOE中检查获胜者,以及如何不让两个玩家进入同一位置
- 原子功能无锁可以更改两个独立的存储位置
- git:将同一文件的两个位置保持同步
- C 中的内存模型:为什么在同一内存位置分配了结构中的两个整数
- 相同地址位置如何给出两个不同的值
- 可视C 编译器将相同的存储位置提供给两个变量
- 如何通过两个值在向量中的位置进行条件比较
- 更改指针指向指针的位置,同时保持其他两个指针的值
- 由 8 个或更多位置分隔的数组中两个元素的最大乘积
- 如何从字符串中一次选择两个字符?到达字符串的第 i 个位置
- c++,指向同一位置的两个指针如何保存不同的值
- 在不使用第三个变量作为中间位置的情况下交换两个变量
- 是否可以让两个c++程序访问同一个内存位置