@@ -136,18 +136,16 @@ class ASTScopeImpl {
136
136
// / storage declaration or is directly descended from it.
137
137
138
138
private:
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;
142
145
143
146
// / Child scopes, sorted by source range.
144
147
Children storedChildren;
145
148
146
- bool wasExpanded = false ;
147
-
148
- // / Can clear storedChildren, so must remember this
149
- bool haveAddedCleanup = false ;
150
-
151
149
mutable Optional<CharSourceRange> cachedCharSourceRange;
152
150
153
151
#pragma mark - constructor / destructor
@@ -177,8 +175,12 @@ class ASTScopeImpl {
177
175
178
176
#pragma mark - tree declarations
179
177
protected:
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
+ }
182
184
183
185
const Children &getChildren () const { return storedChildren; }
184
186
@@ -247,13 +249,13 @@ class ASTScopeImpl {
247
249
248
250
#pragma mark - Scope tree creation
249
251
public:
250
- // / Expand the scope. Asserts if it was already expanded .
252
+ // / Expand the scope if unexpanded .
251
253
ASTScopeImpl *expandAndBeCurrent (ScopeCreator &);
252
254
253
- bool getWasExpanded () const { return wasExpanded ; }
255
+ bool getWasExpanded () const { return parentAndWasExpanded. getInt () ; }
254
256
255
257
protected:
256
- void setWasExpanded () { wasExpanded = true ; }
258
+ void setWasExpanded () { parentAndWasExpanded. setInt ( 1 ) ; }
257
259
virtual ASTScopeImpl *expandSpecifically (ScopeCreator &) = 0;
258
260
259
261
public:
@@ -354,7 +356,7 @@ class ASTScopeImpl {
354
356
// / what obtaines for scoping. However, guards are different. The scope after
355
357
// / the guard else must hop into the innermoset scope of the guard condition.
356
358
virtual NullablePtr<const ASTScopeImpl> getLookupParent () const {
357
- return parent ;
359
+ return getParent () ;
358
360
}
359
361
360
362
#pragma mark - - lookup- local bindings
0 commit comments