Search code examples
ctypedeflibclang

Get typedef type and name with libclang?


I can get the name and the type of typedefs if they're anonymous structures and the like, but normal typedefs(eg typedef int size_t) I can only get size_t. How can I get the type "int"?


Solution

  • Almost a year late, but this is the first result that came up when I was searching for this exact question, so here's a hopefully better answer:

    In clang-c/Index.h, the function clang_getTypedefDeclUnderlyingType will get the type the typedef was typedef'd from, and clang_getCursorType gets the type it was typedef'd to. To clarify, for the line:

    typedef a b;

    clang_getTypedefDeclUnderlyingType returns a, and clang_getCursorType returns b (both as a CXType).