HOWTO: use a CXCursor referring a Typedef

I'm trying to access the newly defined type (CXType), as well as the aliased type, starting from a CXCursor of kind CXCursor_TypedefDecl.

Calling clang_getCursorType() on that cursor yields a type of kind "Invalid". Is that a bug or am I using the wrong function ?

Thanks,
    Stefan

I'm trying to access the newly defined type (CXType), as well as the
aliased type, starting from a CXCursor of kind CXCursor_TypedefDecl.

There isn't an API to access just the aliased type as it was written. You can use clang_getCanonicalType() to get down to the canonical form of the type. I'd be fine with adding some kind of clang_getDesugaredType() operation to desugar a given type by one step.

Calling clang_getCursorType() on that cursor yields a type of kind
"Invalid". Is that a bug or am I using the wrong function ?

That's a bug I just fixed in r124133. Thanks!

  - Doug

That might be useful indeed.

Given

   typedef int const * const &RPInt;

How can I access the details of the aliased type ? Right now I'm seeing an LValueReference, which I can "unwrap" using clang_getPointeeType multiple times. Is there a way to learn about any involved cv-qualifiers ?

On a somewhat related note: I can't see any type representing arrays, and no way to retrieve the array size(s).
(Array parameters seem to decay to pointer types, which also looks wrong.)

Thanks,
         Stefan

CXType doesn’t fully expose the Clang type system, although it could. I’d support the addition of APIs to extract more information from CXTypes.

  • Doug

The attached patch adds two new functions clang_isConstQualifiedType and clang_isVolatileQualifiedType. It works fine in the context I tried it in.
How does that look ?

Thanks,
         Stefan

patch (1.84 KB)

Index: tools/libclang/CXType.cpp

Sure. This revised patch addresses the above points.

     Stefan

patch (3.22 KB)

Hi Stefan,

It would also be great to exercise these APIs in c-index-test, so we can regression test them with tests that use c-index-test + FileCheck.

Committed (with a test) in r124377. Thanks!

  - Doug