Skip to content

Commit a5de9f5

Browse files
Merge pull request #1728 from kastiglione/dl/lldb-formatter-Format-single-valued-OptionSets-w-o-brackets
[lldb/formatter] Format single valued OptionSets w/o brackets
2 parents fd6439e + 449dc6e commit a5de9f5

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
167167

168168
for (auto val_name : *m_cases) {
169169
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+
}
170178
// Don't display the zero case in an option set unless it's the
171179
// only value.
172180
if (case_value == 0 && value != 0)

lldb/test/API/lang/swift/optionset/main.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ func use<T>(_ t: T) {}
2828
func main() {
2929
var user_option = Options(rawValue: 123456)
3030
var computed_option = ComputedOptions(rawValue: 789)
31+
var sdk_option_single_valued: NSBinarySearchingOptions = .insertionIndex
3132
var sdk_option_exhaustive: NSBinarySearchingOptions = [.firstEqual, .insertionIndex]
3233
var sdk_option_nonexhaustive = NSBinarySearchingOptions(rawValue: 257)
3334
var sdk_option_nonevalid = NSBinarySearchingOptions(rawValue: 12)
3435
use((user_option, computed_option, // break here
36+
sdk_option_single_valued,
3537
sdk_option_exhaustive, sdk_option_nonexhaustive,
36-
sdk_option_nonevalid)) //%self.expect('frame variable user_option', substrs=['rawValue = 123456'])
38+
sdk_option_nonevalid))
39+
//%self.expect('frame variable user_option', substrs=['rawValue = 123456'])
3740
//%self.expect('frame variable computed_option', substrs=['storedValue', '789'])
3841
//%self.expect('expression user_option', substrs=['rawValue = 123456'])
42+
//%self.expect('frame variable sdk_option_single_valued', substrs=['.insertionIndex'])
43+
//%self.expect('frame variable sdk_option_single_valued', matching=False, substrs=['['])
44+
//%self.expect('expression sdk_option_single_valued', substrs=['.insertionIndex'])
45+
//%self.expect('expression sdk_option_single_valued', matching=False, substrs=['['])
3946
//%self.expect('frame variable sdk_option_exhaustive', substrs=['[.firstEqual, .insertionIndex]'])
4047
//%self.expect('expression sdk_option_exhaustive', substrs=['[.firstEqual, .insertionIndex]'])
4148
//%self.expect('frame variable sdk_option_nonexhaustive', substrs=['[.firstEqual, 0x1]'])

lldb/test/Shell/Swift/Inputs/No.swiftmodule-ObjC.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ func f() {
1313
// The Objective-C runtime recognizes this as a tagged pointer.
1414
// CHECK-DAG: (NSNumber) inlined = {{.*}}Int64(42)
1515
let inlined = NSNumber(value: 42)
16-
// FIXME: The dataformatters wrongly think this is an OptionSet.
17-
// CHECK-DAG: (CMYK) enumerator = [.yellow]
16+
// CHECK-DAG: (CMYK) enumerator = .yellow
1817
let enumerator = yellow
19-
// CHECK-DAG: (FourColors) typedef = [.cyan]
18+
// CHECK-DAG: (FourColors) typedef = .cyan
2019
let typedef = FourColors(0)
2120
let union = Union(i: 23)
2221
// CHECK-DAG: (OBJCSTUFF_MyString) renamed = {{.*}} "with swift_name"

0 commit comments

Comments
 (0)