<div dir="ltr"><div style>I'd like to record all typedef references, but weed out the old style C tag typedefs like these:</div><div><br></div><div>typedef struct foo</div><div>{</div><div> unsigned char m;</div><div>
unsigned char n;</div><div>} foo;</div><div><br></div><div style>I'd done that with the following ugly code using string compares:</div><div style><br></div><div style><div><div><div> // Find typedefs:</div><div>
bool VisitTypedefDecl( TypedefDecl * t )</div><div> {</div><div> const QualType & q = t->getUnderlyingType() ;</div><div><br></div><div> const Type * tt = q.getTypePtr() ;</div><div> string theUnderlyingType = q.getAsString( ) ;</div>
<div> string typeDefinitionName = t->getName().str() ;</div><div> string * pName = NULL ;</div><div><br></div><div> if ( tt->isStructureType() && (("struct " + typeDefinitionName) == theUnderlyingType ) )</div>
<div> {</div><div> pName = &typeDefinitionName ;</div><div> }</div><div> else if ( tt->isClassType() && (("class " + typeDefinitionName) == theUnderlyingType ) )</div><div> {</div>
<div> pName = &typeDefinitionName ;</div><div> }</div><div> else if ( tt->isUnionType() && (("union " + typeDefinitionName) == theUnderlyingType ) )</div><div> {</div><div> pName = &typeDefinitionName ;</div>
<div> }</div><div> else</div><div> {</div><div> insertIntoMap( typeDefinitionName, q, pName ) ;</div><div> }</div><div><br></div><div> return true ;</div><div> }</div></div></div><div><br>
</div><div style>This does two things:</div><div style>1) effectively strips off the 'struct', 'union', 'class' from theUnderlyingType.</div><div style>2) uses ugly string comparisions to see if we have 'typedef {struct|class|union} NNN NNN'.</div>
<div style><br></div><div style>Are there cleaner ways to do each of the above tasks?</div></div><div><br></div>-- <br>Peeter<br>
</div>