[cfe-dev] Extracting struct name for typedef struct { ... } <name>

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Mon Aug 22 12:54:24 PDT 2016


On Mon, Aug 22, 2016 at 9:44 AM, Himanshu via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> I tried both RecordDecl  as well as TypedefNameDecl to extract names of
> such struct declarations, but I always get an empty string. Could you
> please let me know how to extract the struct name?
>

If you have the RecordDecl, you can use getTypedefNameForAnonDecl() to get
the corresponding TypedefNameDecl, which will have the name 'tstr'. That
only works in cases like the one below where the typedef provides a name
for linkage purposes to the struct (in particular, only in C++ and only if
the typedef is for exactly the struct type and not, say, a pointer to it).

If you want a more general solution, you'd need to walk the enclosing
DeclContext looking for the matching typedef.

For example:
>
> typedef struct {
> ...
> } tstr;
>
> I want to extract 'tstr' name for this struct typedef.
>
> Thanks!
> --
> Himanshu
>
> _______________________________________________
> 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/20160822/4c0df7f2/attachment.html>


More information about the cfe-dev mailing list