wrong printing of typedefs?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

wrong printing of typedefs?

Maximilian Odendahl-2
Hi,

I have such a typedef in my source file:


typedef struct { int var1; int var2; } type1;


Using this code:

DeclContext *DC = TranslationUnitDecl::castToDeclContext(D);
DeclContext::decl_iterator it = DC->decls_begin(), end = DC->decls_end();
   while (it != end) {
     switch (it->getKind()) {
       case Decl::Typedef:
         if (it->getLocation().isValid() &&
s.getSourceManager().isFromMainFile(it->getLocation())) {
           it->print (OutFile);

I would have expected to get the same thing back, but I actually get

struct {
     int var1;
     int var2;
};
typedef type1 type1;

which does not compile of course. Using dump returns the same issue.

Is this a bug in clang somewhere?

Thanks for any help,
Max


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: wrong printing of typedefs?

Daniel Dunbar
Hi Max,

Currently, the print() method on Decl's isn't a reliable way to get
back something which is semantically equivalent and will compile.

It would be great if clang -cc1 -ast-print could be used on any input
file, and the output could be expected to compile & have the same
semantics, but right now there are a lot of substantial problems
preventing this from working.

We would like this to work however, so if want to work on this we
would gladly accept patches to improve things.

 - Daniel

On Wed, Jun 9, 2010 at 1:00 PM, Maximilian Odendahl
<[hidden email]> wrote:

> Hi,
>
> I have such a typedef in my source file:
>
>
> typedef struct { int var1; int var2; } type1;
>
>
> Using this code:
>
> DeclContext *DC = TranslationUnitDecl::castToDeclContext(D);
> DeclContext::decl_iterator it = DC->decls_begin(), end = DC->decls_end();
>   while (it != end) {
>     switch (it->getKind()) {
>       case Decl::Typedef:
>         if (it->getLocation().isValid() &&
> s.getSourceManager().isFromMainFile(it->getLocation())) {
>           it->print (OutFile);
>
> I would have expected to get the same thing back, but I actually get
>
> struct {
>     int var1;
>     int var2;
> };
> typedef type1 type1;
>
> which does not compile of course. Using dump returns the same issue.
>
> Is this a bug in clang somewhere?
>
> Thanks for any help,
> Max
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev