[cfe-dev] Getting the relevant code of a TypeDecl

Ilya Mirsky ilya.mirsky at gmail.com
Sun Dec 5 04:35:29 PST 2010


Hi,

I'm having a problem getting the relevant code of a TypeDecl.
Given the following code:

typedef struct MyStruct {
        int x;
        int y;
} MyStruct;


I would like to get it all.
In my ASTConsumer I'm actually getting 2 TypeDecls for the above code:
Typedef and Record.
I assume it'ss because the above code is a syntactic sugar for:

struct MyStruct {
>         int x;
>         int y;
> };`
>
> typedef struct MyStruct MyStruct;
>


So far so good, but when I try to print the Decls using *Decl::print* or *
SourceManager::getCharacterData* sending the SourceRange of the Decl,
I get the following output:

Decl Kind: Record
> Character Data:
> struct MyStruct {
>         int x;
>         int y;
> }
>
> Pretty-print: struct
>


Decl Kind: Typedef
> Character Data:
> Pretty-print: typedef MyStruct MyStruct
>


There are some issues here that either I don't understand, or it's a bug.

   1. For the Record, why the pretty print does not print the whole
   expression?
   From the documentation I've understood that the output of pretty print
   should be close to the original source.
   2. For the Typedef, I don't understand why I'm getting an empty string
   from *SourceManager::getCharacterData.*
   3. Also I don't understand the pretty-print of the Typedef. Shouldn't it
   be:
   typedef *struct* MyStruct MyStruct  ?


Any help or suggestions will be much appreciated.

Thanks in advance,
Ilya


-- 
Best Regards,
Ilya Mirsky
www.cs.bgu.ac.il/~mirskyil <http://www.cs.bgu.ac.il/%7Emirskyil>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101205/6d39a78a/attachment.html>


More information about the cfe-dev mailing list