<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Dec 18, 2012, at 10:01 PM, Peeter Joot <<a href="mailto:peeter.joot@gmail.com">peeter.joot@gmail.com</a>> wrote:</div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 18, 2012 at 10:04 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div id=":5g"> you can use something like<br>
T->castAs<RecordType>()->getDecl()->getName() to grab the name of a<br>
struct/class/union,</div></blockquote></div><br><div class="gmail_extra"><br>With the following input:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">typedef struct foo</div><div class="gmail_extra">
{</div><div class="gmail_extra">   unsigned char m;</div><div class="gmail_extra">   unsigned char n;</div><div class="gmail_extra">} foo;</div><div class="gmail_extra"><br></div><div class="gmail_extra">typedef struct Foo</div>
<div class="gmail_extra">{</div><div class="gmail_extra">   unsigned char m;</div><div class="gmail_extra">   unsigned char n;</div><div class="gmail_extra">} bar;</div><div class="gmail_extra"><br></div><div class="gmail_extra">
typedef Foo moo ;</div><div><br></div><div><br></div><div>and this AST visitor fragment:</div><div><br></div><div><div>   bool VisitTypedefDecl( TypedefDecl * dtDecl )</div><div>   {</div><div>      const QualType &  qtUnderLying         = dtDecl->getUnderlyingType() ;</div>
<div>      const Type *      tUnderlying          = qtUnderLying.getTypePtr() ;</div><div>      string            theUnderlyingType    = qtUnderLying.getAsString( ) ;</div><div>      string            typeDefinitionName   = dtDecl->getName().str() ;</div>
<div>      string *          pName                = NULL ;</div><div>      bool              ignore               = false ;</div><div><br></div><div>      if ( const RecordType * r = dyn_cast<RecordType>( tUnderlying ) )</div>
<div>      {</div><div>cout << "RecordType: " << typeDefinitionName << ","<< theUnderlyingType << ":" << r->getDecl()->getName().str() << endl ;</div>
<div><br></div><div><br></div><div>That RecordType cast is only successful for the moo typedef, giving:</div><div><br></div><div>RecordType: moo,struct Foo:Foo<br></div></div><div><br></div><div>What sort of type would tUnderLying be for the bar and foo typedefs?</div></div></div></div></blockquote><div><br></div><div>In C++, 'struct foo' is an ElaboratedType, and RecordType is only used</div><div>directly for types like 'foo'.</div><div><br></div><div>If you really want to look at the type as spelled, you should also look through</div><div>ParenTypes, which I believes you'll get in cases like this:</div><div>  typedef struct Foo (foo);</div><div><br></div><div>John.</div></div></body></html>