Skip to content

Commit fd387c5

Browse files
author
David Ungar
authored
Merge pull request #26094 from davidungar/explicitMemberCount
[NameLookup, ASTScope] Add localizableMemberCount to IterableDeclContext.
2 parents da38e25 + dee833a commit fd387c5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/swift/AST/DeclContext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,13 @@ class IterableDeclContext {
692692
/// member loading, as a key when doing lookup in this IDC.
693693
serialization::DeclID SerialID;
694694

695+
/// Because \c parseDelayedDecl and lazy member adding can add members *after*
696+
/// an \c ASTScope tree is created, there must be some way for the tree to
697+
/// detect when a member has been added. A bit would suffice,
698+
/// but would be more fragile, The scope code could count the members each
699+
/// time, but I think it's a better trade to just keep a count here.
700+
unsigned memberCount = 0;
701+
695702
template<class A, class B, class C>
696703
friend struct ::llvm::cast_convert_val;
697704

@@ -721,6 +728,9 @@ class IterableDeclContext {
721728
/// is inserted immediately after the hint.
722729
void addMember(Decl *member, Decl *hint = nullptr);
723730

731+
/// See \c memberCount
732+
unsigned getMemberCount() const { return memberCount; }
733+
724734
/// Check whether there are lazily-loaded members.
725735
bool hasLazyMembers() const {
726736
return FirstDeclAndLazyMembers.getInt() & LazyMembers::Present;

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ DeclRange IterableDeclContext::getMembers() const {
716716
void IterableDeclContext::addMember(Decl *member, Decl *Hint) {
717717
// Add the member to the list of declarations without notification.
718718
addMemberSilently(member, Hint);
719+
++memberCount;
719720

720721
// Notify our parent declaration that we have added the member, which can
721722
// be used to update the lookup tables.

0 commit comments

Comments
 (0)