libclang getting original struct parameter types

This appears to be a duplicate question (I found someone asking the same thing yesterday but I can't find it now), except that the other copy of this question provided an alternative answer that doesn't really address the problem.

I'm working on a small tool using libclang to summarize the struct and function declarations in a given header file, as part of a tool to build automatic Ruby bindings for unit testing.

I'm currently running my fledgling program on its own source file for testing purposes, and as I traverse this function declaration (for instance):

enum CXChildVisitResult statementVisitor(CXCursor cursor, CXCursor parent, CXClientData client_data);

the return type node (which is an enum) contains basically what I'd expect, but all three of the parameters (which are all struct types) have CXType "int". According to what I've been able to find, it is pretty standard for compilers to treat structs as integer types and just replace member accesses with suitable offsets.

This seems bizarre to me, since knowing the actual struct type would be totally necessary for a tool to, for instance, determine whether a member access is being used in a valid way elsewhere in the AST. I tried to get a hold of the original source using clang_getCursorExtent, but this gives offsets into the post-preprocessed file, so I can't simply re-open the file for reading in order to get the text. More to the point, if I'm going to use libclang to find the parameter declarations, I'd like to use libclang to understand them as well. It feels a little silly to use a static code analysis library to help me identify which strings of C code I'll need to parse by hand.

Is there a cmd-line flag that I can pass along to clang to convince it to retain struct types, or some other way to get the parameter types as declared in the code?

链接地址: http://www.djcxy.com/p/94586.html

上一篇: Javascript Node.js和Socket.IO广播服务器

下一篇: libclang获取原始结构参数类型