[cfe-dev] (no subject)

John McCall rjmccall at apple.com
Tue Dec 18 22:17:29 PST 2012


On Dec 18, 2012, at 10:01 PM, Peeter Joot <peeter.joot at gmail.com> wrote:
> On Tue, Dec 18, 2012 at 10:04 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> you can use something like
> T->castAs<RecordType>()->getDecl()->getName() to grab the name of a
> struct/class/union,
> 
> 
> With the following input:
> 
> typedef struct foo
> {
>    unsigned char m;
>    unsigned char n;
> } foo;
> 
> typedef struct Foo
> {
>    unsigned char m;
>    unsigned char n;
> } bar;
> 
> typedef Foo moo ;
> 
> 
> and this AST visitor fragment:
> 
>    bool VisitTypedefDecl( TypedefDecl * dtDecl )
>    {
>       const QualType &  qtUnderLying         = dtDecl->getUnderlyingType() ;
>       const Type *      tUnderlying          = qtUnderLying.getTypePtr() ;
>       string            theUnderlyingType    = qtUnderLying.getAsString( ) ;
>       string            typeDefinitionName   = dtDecl->getName().str() ;
>       string *          pName                = NULL ;
>       bool              ignore               = false ;
> 
>       if ( const RecordType * r = dyn_cast<RecordType>( tUnderlying ) )
>       {
> cout << "RecordType: " << typeDefinitionName << ","<< theUnderlyingType << ":" << r->getDecl()->getName().str() << endl ;
> 
> 
> That RecordType cast is only successful for the moo typedef, giving:
> 
> RecordType: moo,struct Foo:Foo
> 
> What sort of type would tUnderLying be for the bar and foo typedefs?

In C++, 'struct foo' is an ElaboratedType, and RecordType is only used
directly for types like 'foo'.

If you really want to look at the type as spelled, you should also look through
ParenTypes, which I believes you'll get in cases like this:
  typedef struct Foo (foo);

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121218/87a8e35f/attachment.html>


More information about the cfe-dev mailing list