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

Thompson, John John_Thompson at playstation.sony.com
Tue Mar 25 15:51:14 PDT 2014


Hi Richard,

Thanks for the response.

>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?

In Sema::CorrectTypo, I've looked up a type name in the GlobalModuleIndex, and found the corresponding type via getTypeName in the form of a ParsedType that seems to contain an ExtQualsTypeCommonBase.  I want to create a TypoCorrection, and I think I need to give it a NamedDecl for the type via TypoCorrection::setCorrectionDecl, but I couldn't figure out how to find it.  I'm I on the right track?  This is regarding moving the code for looking for a mission module import into CorrectTypo, per your suggestion.

Thanks.

-John

From: metafoo at gmail.com [mailto:metafoo at gmail.com] On Behalf Of Richard Smith
Sent: Tuesday, March 25, 2014 3:34 PM
To: Thompson, John
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] queston for clang developers: Given a ParsedType in a Sema function, how can I get the corresponding NamedDecl?

On Tue, Mar 25, 2014 at 3:05 PM, Thompson, John <John_Thompson at playstation.sony.com<mailto: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/b21896db/attachment.html>


More information about the cfe-dev mailing list