Page MenuHomePhabricator

[libclang] Fix clang_Cursor_isAnonymous
ClosedPublic

Authored by yvvan on Nov 28 2018, 3:38 AM.

Details

Summary

Use the same logic as in TypePrinter::printTag to determine that the tag is anonymous and the separate check for namespaces.

Diff Detail

Event Timeline

yvvan created this revision.Nov 28 2018, 3:38 AM
nik requested changes to this revision.Jan 9 2019, 11:30 PM
nik added inline comments.
test/Index/print-type.cpp
202

Hard coded paths will probably only work on your machine ;)

This revision now requires changes to proceed.Jan 9 2019, 11:30 PM
yvvan added a comment.Jan 9 2019, 11:36 PM

Good point :)

yvvan updated this revision to Diff 181005.Jan 10 2019, 1:14 AM

Replace the absolute path with {{.*}} to be independent from the machine.

nik accepted this revision.Jan 10 2019, 1:18 AM
This revision is now accepted and ready to land.Jan 10 2019, 1:18 AM
This revision was automatically updated to reflect the committed changes.
JornVernee added a subscriber: JornVernee.EditedApr 27 2019, 6:36 AM

This seems to have changed the behaviour w.r.t inline struct or union decls in fields and global variables e.g.

struct foo {
    struct {
        int x;
    } bar;
};

For the StructDecl cursor of 'bar' isAnonymous now returns true, instead of false.

I guess this was intended? But we were relying on this behaviour to collect all nested elements that were accessible through the parent struct, e.g.

struct foo {
    struct {
        int x;
    } bar;
    union {
        int y;
        int z;
    };
};

'y' and 'z' are accessible directly through foo by doing foo.y and foo.z., but 'x' is not, we have to do foo.bar.x. Since isAnonymous now returns true for both 'bar' and the 'inlined' anonymous union, there is no easy way to differentiate between whether it appears as part of a FieldDecl or not. The only alternative I've found is to look up the semantic parent, create a set of all the FieldDecl cursors, and then filter by the field's type's declaration cursors, which is kind of 'meh' for usability/performance, and doesn't work for all cases either.

Any alternative to get the old behaviour?

Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2019, 6:36 AM