[cfe-dev] Patch adding a Boolean flag to TagDecl nodes.

Enea Zaffanella zaffanella at cs.unipr.it
Thu Feb 11 02:01:14 PST 2010


Douglas Gregor wrote:
> On Feb 3, 2010, at 2:01 PM, Abramo Bagnara wrote:

[...]

>> Our aim is exactly that and it works perfectly using the proposed patch:
>> the RecordDecl inserted in DeclContext parsing
>>
>> typedef struct s { int a; } x;
>>
>> is marked with IsDefinedInDeclarator bit and then can be excluded from
>> pretty printer output.
> 
> Ah, I understand the issue now. It's less about the problem of "does
> this typedef contain the definition of struct s?" and more about the
> problem of "was struct s defined by itself or as part of some other
> declaration?". My proposed solution didn't cover the latter at all.

Well, the solution we proposed worked _almost_ perfectly.

It turns out that tracking tag type *definitions* is not enough, since 
the declarator could also introduce a brand new tag type declaration 
which is not a definition.

The following example shows this:
===================================
struct Unknown* p;
===================================

This is pretty printed by clang as follows:
===================================
# clang -cc1 -ast-print test.c
[...snip...]
struct Unknown;
struct Unknown *p;
===================================

The fix is in the attached patch.

For clarity, we changed the same of the Boolean flag 
IsDefinedInDeclarator to IsEmbeddedInDeclarator:
its value is now computed as follows, exploiting
clang notion of "canonical" declaration:

   Owned->setEmbeddedInDeclarator(Owned->isDefinition() ||
                                  Owned->isCanonicalDecl());


Cheers,
Enea Zaffanella.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TagDecl.patch
Type: text/x-patch
Size: 3617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100211/09ca3d09/attachment.bin>


More information about the cfe-dev mailing list