@@ -136,18 +136,16 @@ class ASTScopeImpl {
136136 // / storage declaration or is directly descended from it.
137137
138138private:
139- // / Always set by the constructor, so that when creating a child
140- // / the parent chain is available.
141- ASTScopeImpl *parent = nullptr ; // null at the root
139+ // / The pointer:
140+ // / - Always set by the constructor, so that when creating a child
141+ // / the parent chain is available. Null at the root.
142+ // / The int:
143+ // / - A flag indicating if the scope has been expanded yet or not.
144+ llvm::PointerIntPair<ASTScopeImpl *, 1 > parentAndWasExpanded;
142145
143146 // / Child scopes, sorted by source range.
144147 Children storedChildren;
145148
146- bool wasExpanded = false ;
147-
148- // / Can clear storedChildren, so must remember this
149- bool haveAddedCleanup = false ;
150-
151149 mutable Optional<CharSourceRange> cachedCharSourceRange;
152150
153151#pragma mark - constructor / destructor
@@ -177,8 +175,12 @@ class ASTScopeImpl {
177175
178176#pragma mark - tree declarations
179177protected:
180- NullablePtr<ASTScopeImpl> getParent () { return parent; }
181- NullablePtr<const ASTScopeImpl> getParent () const { return parent; }
178+ NullablePtr<ASTScopeImpl> getParent () {
179+ return parentAndWasExpanded.getPointer ();
180+ }
181+ NullablePtr<const ASTScopeImpl> getParent () const {
182+ return parentAndWasExpanded.getPointer ();
183+ }
182184
183185 const Children &getChildren () const { return storedChildren; }
184186
@@ -247,13 +249,13 @@ class ASTScopeImpl {
247249
248250#pragma mark - Scope tree creation
249251public:
250- // / Expand the scope. Asserts if it was already expanded .
252+ // / Expand the scope if unexpanded .
251253 ASTScopeImpl *expandAndBeCurrent (ScopeCreator &);
252254
253- bool getWasExpanded () const { return wasExpanded ; }
255+ bool getWasExpanded () const { return parentAndWasExpanded. getInt () ; }
254256
255257protected:
256- void setWasExpanded () { wasExpanded = true ; }
258+ void setWasExpanded () { parentAndWasExpanded. setInt ( 1 ) ; }
257259 virtual ASTScopeImpl *expandSpecifically (ScopeCreator &) = 0;
258260
259261public:
@@ -354,7 +356,7 @@ class ASTScopeImpl {
354356 // / what obtaines for scoping. However, guards are different. The scope after
355357 // / the guard else must hop into the innermoset scope of the guard condition.
356358 virtual NullablePtr<const ASTScopeImpl> getLookupParent () const {
357- return parent ;
359+ return getParent () ;
358360 }
359361
360362#pragma mark - - lookup- local bindings
0 commit comments