With an AST field visitor of the following form:<br><br><div> bool VisitFieldDecl( FieldDecl * f )</div><div> {</div><div> RecordDecl * r = f->getParent() ;</div><div><br></div><div> TypeSourceInfo * t = f->getTypeSourceInfo() ;</div>
<div><br></div><div> TypeLoc TL = t->getTypeLoc() ;</div><div><br></div><div> if ( const ArrayTypeLoc *Arr = dyn_cast<ArrayTypeLoc>(&TL) )<br></div>
<div> {</div><div> TL = Arr->getElementLoc() ;</div><div> }</div><div><br></div><div> const QualType & q = TL.getType() ;</div><div><br></div><div> cout</div><div> << r->getName().str()</div>
<div> << " : " << q.getAsString() << endl ;</div><div><br></div><div> return true ;</div><div> }</div><div><br></div><div>I get a printout of <br><br><classname> : type-dependence. Example:</div>
<div><br></div><div><div>struct Test</div><div>{</div><div> int a, b ;</div><div>} ;</div></div><div><br></div><div>gives:</div><div><br></div><div><div>Test : int</div><div>Test : int</div></div><div><br></div><div>For anonymous structs like:</div>
<div><br></div><div><div>struct TestA</div><div>{</div><div> struct {</div><div> int a, b ;</div><div> } m ;</div><div>} ;</div></div><div><br></div><div>I do get a "name" for the dependent type m:</div>
<div><br></div><div>TestA : struct <anonymous struct at asample2.cpp:8:4><br></div><div><br></div><div>However, when the AST visitor is called for the a, b fields in this anonymous struct, my r->getName().str() call returns an empty string.</div>
<div><br></div><div>I'm guessing I could get the "name" above, if I could get the QualType from the 'RecordDecl * r' variable, but am unsure how to do so, because getTypeSourceInfo() doesn't appear to be available to a RecordDecl object. How can I get the RecordDecl's QualType?</div>
<div><br></div>-- <br>
Peeter<br>