[cfe-dev] (no subject)
Peeter Joot
peeter.joot at gmail.com
Tue Dec 18 18:48:23 PST 2012
I'd like to record all typedef references, but weed out the old style C tag
typedefs like these:
typedef struct foo
{
unsigned char m;
unsigned char n;
} foo;
I'd done that with the following ugly code using string compares:
// Find typedefs:
bool VisitTypedefDecl( TypedefDecl * t )
{
const QualType & q = t->getUnderlyingType() ;
const Type * tt = q.getTypePtr() ;
string theUnderlyingType = q.getAsString( ) ;
string typeDefinitionName = t->getName().str() ;
string * pName = NULL ;
if ( tt->isStructureType() && (("struct " + typeDefinitionName) ==
theUnderlyingType ) )
{
pName = &typeDefinitionName ;
}
else if ( tt->isClassType() && (("class " + typeDefinitionName) ==
theUnderlyingType ) )
{
pName = &typeDefinitionName ;
}
else if ( tt->isUnionType() && (("union " + typeDefinitionName) ==
theUnderlyingType ) )
{
pName = &typeDefinitionName ;
}
else
{
insertIntoMap( typeDefinitionName, q, pName ) ;
}
return true ;
}
This does two things:
1) effectively strips off the 'struct', 'union', 'class' from
theUnderlyingType.
2) uses ugly string comparisions to see if we have 'typedef
{struct|class|union} NNN NNN'.
Are there cleaner ways to do each of the above tasks?
--
Peeter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121218/ba7446e2/attachment.html>
More information about the cfe-dev
mailing list