问题描述
我无法检测 Clang 的 IndexingAction clang::ConceptDecls。 我有一个初始化的最小工作示例 一个 IndexingAction 并在一些包含两个的测试代码上运行它 概念声明。我已经验证前端“看到”了这些声明 转储 AST。
然而,IndexingAction 被设置为打印一条简单的消息 当它遇到任何类型的decl,并且没有这样的消息时 在运行上述代码时打印。因此,它 似乎 ConceptDecls 对 IndexingAction 不可见, 而其他声明被正确检测(clang::CXXRecordDecl, clang::FunctionDecl 等)。
我在 LLVM/Clang 11 和 12 中重现了这个问题。
示例代码如下:
#include "clang/Tooling/Tooling.h"
#include "clang/Index/IndexDataConsumer.h"
#include "clang/Index/IndexingAction.h"
#include "clang/Index/IndexingOptions.h"
#include <cstdio>
class IndexDataConsumer : public clang::index::IndexDataConsumer {
public:
// Print a message to stdout if any kind of declaration is found
bool handleDeclOccurrence(const clang::Decl*,clang::index::SymbolRoleSet,llvm::ArrayRef<clang::index::SymbolRelation>,clang::SourceLocation,clang::index::IndexDataConsumer::ASTNodeInfo) override {
printf("Found a decl occurrence\n");
return true;
}
};
class IndexActionFactory : public clang::tooling::FrontendActionFactory {
public:
std::unique_ptr<clang::FrontendAction> create() override {
// The most permissive set of indexing options possible
clang::index::IndexingOptions opts;
opts.IndexFunctionLocals = true;
opts.IndexImplicitInstantiation = true;
opts.IndexMacrosInPreprocessor = true;
opts.IndexParametersInDeclarations = true;
opts.IndexTemplateParameters = true;
opts.SystemSymbolFilter = clang::index::IndexingOptions::SystemSymbolFilterKind::None;
IndexDataConsumer idx;
return createIndexingAction(std::make_shared<IndexDataConsumer>(idx),opts);
}
};
int main() {
const std::string code = R"(
// Basic example of a concept
template <typename T,typename U = T> concept Sumable = requires(T a,U b) {
{a + b};
{b + a};
};
// Another basic example of a concept
template<typename T>
concept has_type_member = requires { typename T::type; };
)";
// Run the indexing action over the code above.
// If any decl is found in the AST,the printf should fire.
IndexActionFactory IndexFactory;
clang::tooling::runToolOnCodeWithArgs(IndexFactory.create(),code,{"-std=c++20"});
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)