[cfe-dev] Anonymous structs and unions in libclang

Konstantin Olkhovskiy lupus at oxnull.net
Wed Sep 18 10:04:34 PDT 2013


Hi List,

I'm trying to write a header file preprocessor with dependency tracking for
LuaJIT.
Unfortunately LuaJIT does not have C preprocessor, but it's able to parse C
sturcture and function declarations (as lua strings) using FFI interface.

All i need to do is given a `root' header file, track down all of it's
dependencies
(includes), and generate wrapper lua module with preprocessed declarations
for each
header file (and make sure it's not `included' twice in lua since LuaJIT
prohibits multiple
declarations of the same entity the same way C compilers do).

I'm trying to traverse AST nodes that are interesting to me, printing out
pretty much the
same as input, but without macros, with typedefs resolved, etc. libclang
does a great job
of building include tree, checking if header is guarded, finding all
interesting declarations!
But looks like it's missing support for anonymous structs and unions. For a
simple header
file like this:

struct mystruct {
union {
int a;
 float c;
};
struct {
const char *str1;
 char *str2;
} anon_struct;
int d;
char e;
};

I get an Unexposed type kind with the following spelling:
struct <anonymous struct at test.h:8:2> anon_struct;

Does Clang itself provides all necessary information about those
constructs? Is this
information simply not exposed via libclang? Or I'm missing something?

Thanks!

-- 
Regards,
Konstantin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130918/dab138bd/attachment.html>


More information about the cfe-dev mailing list