Skip to content

Commit 8664d43

Browse files
authored
Merge pull request #1776 from apple/dl/lldb-formatters-Follow-up-option-set-formatter-cleanup-NFC
[lldb/formatters] Follow-up option set formatter cleanup (NFC)
2 parents 207e917 + 4595220 commit 8664d43

File tree

1 file changed

+48
-54
lines changed

1 file changed

+48
-54
lines changed

lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -156,66 +156,60 @@ bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
156156
return false;
157157

158158
llvm::APInt value;
159-
if (ReadValueIfAny(*rawValue_sp, value)) {
160-
FillCasesIfNeeded();
161-
162-
StreamString ss;
163-
bool first_match = true;
164-
bool any_match = false;
165-
166-
llvm::APInt matched_value(llvm::APInt::getNullValue(64));
167-
168-
for (auto val_name : *m_cases) {
169-
llvm::APInt case_value = val_name.first;
170-
// Print single valued sets without using enclosing brackets.
171-
// `WouldEvenConsiderFormatting` can't opt out early because it
172-
// has only the type, but needs the value for this case.
173-
if (case_value == value) {
174-
ss << '.' << val_name.second;
175-
dest.assign(ss.GetData());
176-
return true;
177-
}
178-
// Don't display the zero case in an option set unless it's the
179-
// only value.
180-
if (case_value == 0 && value != 0)
181-
continue;
182-
if ((case_value & value) == case_value) {
183-
// hey a case matched!!
184-
any_match = true;
185-
if (first_match) {
186-
ss.Printf("[.%s", val_name.second.AsCString());
187-
first_match = false;
188-
} else {
189-
ss.Printf(", .%s", val_name.second.AsCString());
190-
}
191-
192-
matched_value |= case_value;
193-
194-
// if we matched everything, get out
195-
if (matched_value == value)
196-
break;
197-
}
159+
if (!ReadValueIfAny(*rawValue_sp, value))
160+
return false;
161+
162+
FillCasesIfNeeded();
163+
164+
StreamString ss;
165+
bool first_match = true;
166+
bool any_match = false;
167+
168+
llvm::APInt matched_value(llvm::APInt::getNullValue(64));
169+
170+
for (auto val_name : *m_cases) {
171+
llvm::APInt case_value = val_name.first;
172+
// Print single valued sets without using enclosing brackets.
173+
// `WouldEvenConsiderFormatting` can't opt out early because it
174+
// has only the type, but needs the value for this case.
175+
if (case_value == value) {
176+
ss << '.' << val_name.second;
177+
dest.assign(ss.GetData());
178+
return true;
198179
}
180+
// Don't display the zero case in an option set unless it's the
181+
// only value.
182+
if (case_value == 0 && value != 0)
183+
continue;
184+
if ((case_value & value) == case_value) {
185+
any_match = true;
186+
if (first_match) {
187+
ss << "[." << val_name.second;
188+
first_match = false;
189+
} else {
190+
ss << ", ." << val_name.second;
191+
}
192+
193+
matched_value |= case_value;
199194

200-
if (any_match) {
201-
// if we found a full match, then close the list
195+
// If we matched everything, get out.
202196
if (matched_value == value)
203-
ss.PutChar(']');
204-
else {
205-
// print the unaccounted-for bits separately
206-
llvm::APInt residual = (value & ~matched_value);
207-
ss.Printf(", 0x%s]", residual.toString(16, false).c_str());
208-
}
197+
break;
209198
}
199+
}
210200

211-
// if we printed anything, use it
212-
const char *data = ss.GetData();
213-
if (data && data[0]) {
214-
dest.assign(data);
215-
return true;
216-
}
201+
if (!any_match)
202+
return false;
203+
204+
if (matched_value != value) {
205+
// Print the unaccounted-for bits separately.
206+
llvm::APInt residual = value & ~matched_value;
207+
ss << ", 0x" << residual.toString(16, false);
217208
}
218-
return false;
209+
ss << ']';
210+
211+
dest.assign(ss.GetData());
212+
return true;
219213
}
220214

221215
bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::

0 commit comments

Comments
 (0)