[cfe-dev] [libclang] Getting unqualified version of Type

John McCall via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 21 21:00:17 PST 2018


> On Feb 12, 2018, at 8:05 AM, Łukasz Kucharski via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> Is there a way to get "base" type of, well, Type. I see that it's
> possible to test for const or volatile, but I don't see a way, to get
> the underlying type.

It would be reasonable to add a clang_getUnqualifiedType.  It looks like the existing
functions intentionally only consider "local" qualifiers, so you would need to decide
whether the function should remove only local qualifiers or whether it should strip
type sugar until it can return an unqualified type.

For example:
  typedef int int32_t;
  typedef volatile int32_t vint32_t;
  const vint32_t x;

Should clang_getUnqualifiedType on the type of 'x' return the typedef type 'vint32_t' or
the underlying unqualified type 'int32_t'?  Note that in the latter case it is not necessary
to strip all the way down to 'int'.

John.

> 
> What I am ultimately trying to do is to map member relationships
> between classes, and currently the solution is missing some due to
> type `A` being different from `const A`.
> 
> The only workaround I see is to check with
> `clang_isConstQualifiedType` and parse spelling, which does not seem
> like a good idea.
> 
> This is an example class layout that I have problem with:
> 
> ```
> class A {};
> 
> class B {
> A a;
> }
> 
> class C {
>  const A a;
>  B* b;
> }
> ```
> 
> It's hard to map C->A.
> 
> `B` is possitle to obtain through checking `CXType::kind` against
> `CXType_Pointer` and `clang_getPointeeType`, so it's not a problem
> that `B` and `B*` are different as there is a programatic way to get
> it.
> 
> Is there a way to do it in current version of libclang? Or, would I
> need to manually work with AST.
> 
> Regards,
> Łukasz.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list