[cfe-dev] queston for clang developers: Given a ParsedType in a Sema function, how can I get the corresponding NamedDecl?

Richard Smith richard at metafoo.co.uk
Tue Mar 25 15:33:44 PDT 2014


On Tue, Mar 25, 2014 at 3:05 PM, Thompson, John <
John_Thompson at playstation.sony.com> wrote:

>  Hi,
>
>
>
> I have a ParsedType returned from a getTypeName call in a Sema function.
> How can I find the corresponding NamedDecl?
>

To confirm: you're looking for the NamedDecl that declares the type found
by name lookup in getTypeName?

First convert the ParsedType to a QualType by calling GetTypeFromParser.
Then switch over the type class of the Type* in the QualType, and pick the
declaration out of it. You'd need to handle at least UnresolvedUsingType,
TypedefType, TagType, ElaboratedType, TemplateTypeParmType,
TemplateSpecializationType, InjectedClassNameType, DependentNameType, and
DependentTemplateSpecializationType. Maybe some of the ObjC types too.

But this is a bit of an unusual thing to want to do, and doing the above
will be fragile. Maybe there's a better way; what's the larger context?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140325/6e8b9d53/attachment.html>


More information about the cfe-dev mailing list