@@ -107,11 +107,9 @@ LVScopeDispatch LVScope::Dispatch = {
107
107
{LVScopeKind::IsTryBlock, &LVScope::getIsTryBlock},
108
108
{LVScopeKind::IsUnion, &LVScope::getIsUnion}};
109
109
110
- void LVScope::addToChildren (LVElement *Element) {
111
- if (!Children)
112
- Children = std::make_unique<LVElements>();
113
- Children->push_back (Element);
114
- }
110
+ const LVTypes LVScope::EmptyTypes{};
111
+ const LVSymbols LVScope::EmptySymbols{};
112
+ const LVScopes LVScope::EmptyScopes{};
115
113
116
114
void LVScope::addElement (LVElement *Element) {
117
115
assert (Element && " Invalid element." );
@@ -175,7 +173,6 @@ void LVScope::addElement(LVScope *Scope) {
175
173
176
174
// Add it to parent.
177
175
Scopes->push_back (Scope);
178
- addToChildren (Scope);
179
176
Scope->setParent (this );
180
177
181
178
// Notify the reader about the new element being added.
@@ -202,7 +199,6 @@ void LVScope::addElement(LVSymbol *Symbol) {
202
199
203
200
// Add it to parent.
204
201
Symbols->push_back (Symbol);
205
- addToChildren (Symbol);
206
202
Symbol->setParent (this );
207
203
208
204
// Notify the reader about the new element being added.
@@ -229,7 +225,6 @@ void LVScope::addElement(LVType *Type) {
229
225
230
226
// Add it to parent.
231
227
Types->push_back (Type);
232
- addToChildren (Type);
233
228
Type->setParent (this );
234
229
235
230
// Notify the reader about the new element being added.
@@ -277,15 +272,12 @@ bool LVScope::removeElement(LVElement *Element) {
277
272
if (Element->getIsLine ())
278
273
return RemoveElement (Lines);
279
274
280
- if (RemoveElement (Children)) {
281
- if (Element->getIsSymbol ())
282
- return RemoveElement (Symbols);
283
- if (Element->getIsType ())
284
- return RemoveElement (Types);
285
- if (Element->getIsScope ())
286
- return RemoveElement (Scopes);
287
- llvm_unreachable (" Invalid element." );
288
- }
275
+ if (Element->getIsSymbol ())
276
+ return RemoveElement (Symbols);
277
+ if (Element->getIsType ())
278
+ return RemoveElement (Types);
279
+ if (Element->getIsScope ())
280
+ return RemoveElement (Scopes);
289
281
290
282
return false ;
291
283
}
@@ -356,8 +348,8 @@ void LVScope::updateLevel(LVScope *Parent, bool Moved) {
356
348
setLevel (Parent->getLevel () + 1 );
357
349
358
350
// Update the children.
359
- if (Children )
360
- for (LVElement *Element : *Children )
351
+ if (auto Elements = getChildren (); Elements. begin () != Elements. end () )
352
+ for (LVElement *Element : Elements )
361
353
Element->updateLevel (this , Moved);
362
354
363
355
// Update any lines.
@@ -374,8 +366,8 @@ void LVScope::resolve() {
374
366
LVElement::resolve ();
375
367
376
368
// Resolve the children.
377
- if (Children )
378
- for (LVElement *Element : *Children ) {
369
+ if (auto Elements = getChildren (); Elements. begin () != Elements. end () )
370
+ for (LVElement *Element : Elements ) {
379
371
if (getIsGlobalReference ())
380
372
// If the scope is a global reference, mark all its children as well.
381
373
Element->setIsGlobalReference ();
@@ -633,8 +625,9 @@ Error LVScope::doPrint(bool Split, bool Match, bool Print, raw_ostream &OS,
633
625
options ().getPrintFormatting () &&
634
626
getLevel () < options ().getOutputLevel ()) {
635
627
// Print the children.
636
- if (Children)
637
- for (const LVElement *Element : *Children) {
628
+ if (const auto Elements = getChildren ();
629
+ Elements.begin () != Elements.end ())
630
+ for (const LVElement *Element : Elements) {
638
631
if (Match && !Element->getHasPattern ())
639
632
continue ;
640
633
if (Error Err =
@@ -692,7 +685,6 @@ void LVScope::sort() {
692
685
Traverse (Parent->Symbols , SortFunction);
693
686
Traverse (Parent->Scopes , SortFunction);
694
687
Traverse (Parent->Ranges , compareRange);
695
- Traverse (Parent->Children , SortFunction);
696
688
697
689
if (Parent->Scopes )
698
690
for (LVScope *Scope : *Parent->Scopes )
@@ -978,8 +970,8 @@ bool LVScope::equals(const LVScopes *References, const LVScopes *Targets) {
978
970
void LVScope::report (LVComparePass Pass) {
979
971
getComparator ().printItem (this , Pass);
980
972
getComparator ().push (this );
981
- if (Children )
982
- for (LVElement *Element : *Children )
973
+ if (auto Elements = getChildren (); Elements. begin () != Elements. end () )
974
+ for (LVElement *Element : Elements )
983
975
Element->report (Pass);
984
976
985
977
if (Lines)
@@ -1656,8 +1648,9 @@ void LVScopeCompileUnit::printMatchedElements(raw_ostream &OS,
1656
1648
// Print the view for the matched scopes.
1657
1649
for (const LVScope *Scope : MatchedScopes) {
1658
1650
Scope->print (OS);
1659
- if (const LVElements *Elements = Scope->getChildren ())
1660
- for (LVElement *Element : *Elements)
1651
+ if (const auto Elements = Scope->getChildren ();
1652
+ Elements.begin () != Elements.end ())
1653
+ for (LVElement *Element : Elements)
1661
1654
Element->print (OS);
1662
1655
}
1663
1656
}
0 commit comments