假设我分析了这样的代码:
struct Foo
{
void(*setParam)(const char* name, int value);
};
我使用clang LibTooling并在setParam上获取FieldDecl。
我想我可以得到这样的争论类型:
auto ft = fieldDecl->getFunctionType()->getAs<FunctionProtoType>();
for (size_t i = 0; i < fpt->getNumParams(); i++)
{
QualType paramType =
是否有可能编写一个宏,不管它嵌套了多少次,它都会精确地应用一次?
// how to implement this properly?
#define FOO(x) hello(x) // incorrect, works only for 1 level of nesting
// desired use below
void hello(int x);
FOO(x); // expanded to "hello(x)"
FOO(FOO(x)); // also expanded to "hello(x)", not "hello(hello(x))
我正在写一个工具来解析C家族的源代码项目,基本上遵循ubuntu12.04上的这两个教程 on clang3.4(主干192426)。
基于,它说我可以通过-p传递compile_commands.json,但是,如果我只输入$ ./main -p [path of compile_commands.json],它会抱怨缺少位置参数。似乎我仍然需要将所有文件名作为参数传递,如果项目真的很大,这是不切实际的。我更喜欢它可以简单地解析compile_commands.json中指定的所有文件,而不需要询问,但无法找到如何打开它。
因为我找不到的教程来做任何定制的事情,所以我改用类。有一个虚拟访问
我的项目使用clang-libtooling,由于来自头文件的错误而无法编译。错误是:C:\llvm\llvm\include\llvm\Support\MathExtras.h(372,31): error C4146: unary minus operator applied to unsigned type, result still unsigned,库头中的相关代码是: /// Gets the minimum value for a N-bit signed integer.
inline int64_t minIntN(int64_t N) {
assert(N >
相关链路
我使用CommonOptionsParser来解析clang工具的参数:
// parse the command-line args passed to your code
CommonOptionsParser op(argc, argv);
// create a new Clang Tool instance (a LibTooling environment)
ClangTool Tool(op.getCompilations(), op.getSourcePathList());
// run the Clang Tool, creating a new Fronten
类似于这个问题:Print the type of a parameter (ParmVarDecl) with clang API,我想以字符串的形式获取参数/字段类型,但重要的是,我希望类型是完全限定的,例如 namespace n {
class A {};
class B {
void f(std::vector<A> a) {}
std::vector<A> m_a;
};
} // n 我想要std::vector<n::A>,而不是std::vector<A>。 我尝试过这个解决方案:http://clang-de