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

Douglas Gregor dgregor at apple.com
Fri Feb 12 09:43:40 PST 2010


On Feb 11, 2010, at 2:01 AM, Enea Zaffanella wrote:

> 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;
> ===================================

Right.

> The fix is in the attached patch.

Looks good! Committed as r95991.

> 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());


I like IsEmbeddedInDeclarator much better! It describes what is happening very clearly.

	- Doug



More information about the cfe-dev mailing list