Skip to content

Commit 4d9f38d

Browse files
authored
Merge pull request #1778 from apple/dl/lldb-formatters-Follow-up-option-set-formatter-cleanup-NFC-master-next
[lldb/formatters] Follow-up option set formatter cleanup (NFC)
2 parents 1938c90 + a9b28d6 commit 4d9f38d

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
@@ -158,66 +158,60 @@ bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
158158
return false;
159159

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

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

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

223217
bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::

0 commit comments

Comments
 (0)