This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatcher] Add isStaticDataMember matcher for varDecl.
AbandonedPublic

Authored by hokein on Oct 14 2016, 2:56 AM.

Details

Event Timeline

hokein updated this revision to Diff 74640.Oct 14 2016, 2:56 AM
hokein retitled this revision from to [ASTMatcher] Add isStaticDataMember matcher for varDecl..
hokein updated this object.
hokein added a reviewer: klimek.
hokein added a subscriber: cfe-commits.
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman added inline comments.
include/clang/ASTMatchers/ASTMatchers.h
3005

How does this differ from the existing matcher hasStaticStorageDuration() over a fieldDecl()?

hokein added inline comments.Oct 14 2016, 7:29 AM
include/clang/ASTMatchers/ASTMatchers.h
3005

fieldDecl document says that fieldDecl is "an instance of this class is created by Sema::ActOnField to
represent a member of a struct/union/class.". So for static class members, they should not belong to fieldDecl as they are not bound to class instances.

Technically, we can't apply hasStaticStorageDuration() and isStaticStorageClass over a fieldDecl.

aaron.ballman added inline comments.Oct 14 2016, 7:39 AM
include/clang/ASTMatchers/ASTMatchers.h
3005

That's a really good point, but the question still remains: since we have hasStaticStorageDuration() already, can we find a way to use that same matcher rather than introduce a new matcher under a new name that does the same thing?

This time I tested a matcher, and found that you get the correct behavior from varDecl(hasStaticStorageDuration(), hasParent(recordDecl())).

I think this is especially important to try to do because we have hasStaticStorageDuration() and isStaticStorageClass(), so adding isStaticDataMember() adds a third option to possibly confuse users.

hokein abandoned this revision.Oct 17 2016, 2:34 AM
hokein added inline comments.
include/clang/ASTMatchers/ASTMatchers.h
3005

Thanks for the explanations, I think it makes sense.

Previously I thought isStaticDataMember is an more obvious ast matcher.
varDecl(hasStaticStorageDuration(), hasParent(cxxRecordDecl())) and varDecl(hasStaticStorageDuration(), hasDeclContext(cxxRecordDecl()), isDefinition()) can do the same thing.