<div dir="ltr">Hello all,<div><br></div><div>Currently, I'm using libTooling to generate the program's AST, which later I translate to our own AST, but I'm having some trouble retrieving the name of this RecordDecl:</div><div><br></div><div><div>typedef struct</div><div>{</div><div> int __count;</div><div><br></div><div><b> union</b></div><div><b> {</b></div><div><b> int __wch;</b></div><div><b> char __wchb[4];</b></div><div><b> } __value;</b></div><div><br></div><div>} __mbstate_t;</div><div><br></div><div>To get the recordDecl name, I'm using two methods:</div><div><br></div><div><div>bool clang_c_convertert::get_tag_name(<br></div></div><div><div> const clang::RecordDecl& rd,</div><div> std::string &name)</div><div>{</div><div> name = get_decl_name(rd);</div><div><br></div><div> if(!name.empty())</div><div> return false;</div><div><br></div><div> // Try to get the name from typedef (if one exists)</div><div> if (const clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(&rd))</div><div> {</div><div> if (const clang::TypedefNameDecl *tnd = rd.getTypedefNameForAnonDecl())</div><div> {</div><div> name = get_decl_name(*tnd);</div><div> return false;</div><div> }</div><div> else if (tag->getIdentifier())</div><div> {</div><div> name = get_decl_name(*tag);</div><div> return false;</div><div> }</div><div> }</div><div><br></div><div> <b>assert(rd.isAnonymousStructOrUnion());</b><br></div><div><br></div><div> return get_anon_tag_name(rd, name); // This build's a name based on the tag type</div><div>}</div></div><div><br></div><div>Where the method get_decl_name is:</div><div><br></div><div><div><div>std::string clang_c_convertert::get_decl_name(</div><div> const clang::NamedDecl &decl)</div><div>{</div><div> if(const clang::IdentifierInfo *identifier = decl.getIdentifier())</div><div> return identifier->getName().str();</div><div><br></div><div> std::string name;</div><div> llvm::raw_string_ostream rso(name);</div><div> decl.printName(rso);</div><div> return rso.str();</div><div>}</div></div></div><div><br></div><div>The problem is the inner union, which is not anonymous but I can't get the name. The bold assertion always fails.</div><div><br></div><div>Is there a way to get the union name, in this case? </div><div><br></div><div>Btw, I get there when parsing a varDecl and calling varDecl.getType(). It returns a RecordType and I call .getDecl() to parse the union declaration.</div><div><br></div><div>Thank you,</div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div>
</div></div>