[cfe-dev] Tracing Typedef Chain
Daniel Dilts via cfe-dev
cfe-dev at lists.llvm.org
Mon Nov 30 10:51:59 PST 2015
I tried this with:
auto t = type.getTypePtr();
auto tt = dyn_cast<TypedefType>(t);
while(tt) {
tt->getDecl()->dumpColor();
auto x = tt->getDecl()->getNameAsString();
tt = dyn_cast<TypedefType>(tt->desugar().getTypePtr());
}
It appeared to work fine when the typedef was at global scope, but when I
put the typedef in a namespace the first dyn_cast returned nullptr.
On Wed, Nov 25, 2015 at 1:49 PM, Yaron Keren <yaron.keren at gmail.com> wrote:
> Maybe
>
> Type *T = QT.getTypePtr();
> TypedefType *TT = cast<TypedefType>(T);
> TT->getDecl()->dumpColor();
>
>
> 2015-11-25 23:42 GMT+02:00 Régis Portalez <cfe-dev at lists.llvm.org>:
>
>> At what level are you working? Once in llvm IR, you can cast your type to
>> derived type, and then get the element type
>> ------------------------------
>> De : Daniel Dilts via cfe-dev <cfe-dev at lists.llvm.org>
>> Envoyé : 25/11/2015 22:13
>> À : cfe-dev <cfe-dev at lists.llvm.org>
>> Objet : Re: [cfe-dev] Tracing Typedef Chain
>>
>> I'm struggling to make this work. Could you possibly give me a more
>> complete example?
>>
>> On Mon, Nov 23, 2015 at 9:05 AM, mats petersson <mats at planetcatfish.com>
>> wrote:
>>
>>> If you call `getTypePtr` it should give you the "next" type.
>>>
>>> --
>>> Mats
>>>
>>> On 23 November 2015 at 16:27, Daniel Dilts via cfe-dev <
>>> cfe-dev at lists.llvm.org> wrote:
>>>
>>>> If I have code like this:
>>>>
>>>> typedef int X;
>>>> typedef X Y;
>>>> typedef Y Z;
>>>>
>>>> Z i = 0;
>>>>
>>>> I have the QualType for i. getAsString() returns "Z".
>>>> getCanonicalType().getAsString() returns "int".
>>>>
>>>> Is there some way to trace the typedef chain such that I get "Z", "Y",
>>>> "X", and "int"? Order is not particularly important to me, but it would be
>>>> nice to get them in that order.
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151130/2369832e/attachment.html>
More information about the cfe-dev
mailing list