[cfe-dev] retrieving anonymous struct decl name (original) (raw)
David Rector via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 21 11:22:19 PST 2020
- Previous message: [cfe-dev] retrieving anonymous struct decl name
- Next message: [cfe-dev] retrieving anonymous struct decl name
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
You cannot get the VarDecl name from the TagDecl; the anonymous struct is placed as its own node and the VarDecls placed subsequently (which is a bit unfortunate, it would be nice if the syntax were more directly represented, but that might present its own problems); but you might benefit from looking at how DeclPrinter handles this tricky case:
https://github.com/llvm-mirror/clang/blob/master/lib/AST/DeclPrinter.cpp#L394
Basically, while iterating over decls(), you would look for TagDecls for which isFreeStanding()
returns false, then accumulate the subsequent VarDecls whose “base” type (after removing pointers etc.) is the TagDecl, and when those are exhausted you handle the Tag + VarDecls together as a whole.
Not 100% sure what you ultimately want to do but hope that helps.
On Dec 20, 2020, at 10:11 PM, John Leidel via cfe-dev <cfe-dev at lists.llvm.org> wrote:
I'm still working on the same issue associated with translating anonymous struct decl's to non-anonymous structs. With the same original example, I have the TagDecl for the nested struct definition. Is there a way to retrieve the declaration name "first" from the TagDecl? typedef struct testcaset { struct { int value; } first[1]; int second; int third[1]; } testcaset; As an example below, I grab the RecordDecl for the top-level struct, then traverse each member using the decliterator. I have other code to examine each FieldDecl, but I'm specifically interested in the following. If I can dyncast to a TagDecl, then I'm looking at the struct declaration. I'm trying to retrieve the anonymous DeclarationName and use it to reset the declaration of the nested struct and its variable definition. Thoughts? for(RecordDecl::decliterator iter = RD->declsbegin(), end = RD->declsend(); iter != end; ++iter) { if(TagDecl *TD = dyncast(*iter)){ if(TD->isThisDeclarationADefinition()){ // This sets the struct definition and instance name to testcaset // how do I retrieve "first"? // this should induce struct first { }; struct first first[1]; TD->setDeclName( ??? ); } } }
cfe-dev mailing list cfe-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
- Previous message: [cfe-dev] retrieving anonymous struct decl name
- Next message: [cfe-dev] retrieving anonymous struct decl name
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]