[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:58:55 PDT 2014


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

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

I don't think you need to call getTypeName here. It sounds like you want to
look up a declaration; getTypeName does that and then does some other stuff
that you don't want. Without knowing exactly what you're trying to do, I'd
think you probably want to invoke name lookup yourself from CorrectTypo.

*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> 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/bfb4a873/attachment.html>


More information about the cfe-dev mailing list