Skip to content

[lldb/formatter] Format single valued OptionSets w/o brackets #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::

for (auto val_name : *m_cases) {
llvm::APInt case_value = val_name.first;
// Print single valued sets without using enclosing brackets.
// `WouldEvenConsiderFormatting` can't opt out early because it
// has only the type, but needs the value for this case.
if (case_value == value) {
ss << '.' << val_name.second;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to also make this change on line 184 and 187 in a follow-up commit.

dest.assign(ss.GetData());
return true;
}
// Don't display the zero case in an option set unless it's the
// only value.
if (case_value == 0 && value != 0)
Expand Down
9 changes: 8 additions & 1 deletion lldb/test/API/lang/swift/optionset/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ func use<T>(_ t: T) {}
func main() {
var user_option = Options(rawValue: 123456)
var computed_option = ComputedOptions(rawValue: 789)
var sdk_option_single_valued: NSBinarySearchingOptions = .insertionIndex
var sdk_option_exhaustive: NSBinarySearchingOptions = [.firstEqual, .insertionIndex]
var sdk_option_nonexhaustive = NSBinarySearchingOptions(rawValue: 257)
var sdk_option_nonevalid = NSBinarySearchingOptions(rawValue: 12)
use((user_option, computed_option, // break here
sdk_option_single_valued,
sdk_option_exhaustive, sdk_option_nonexhaustive,
sdk_option_nonevalid)) //%self.expect('frame variable user_option', substrs=['rawValue = 123456'])
sdk_option_nonevalid))
//%self.expect('frame variable user_option', substrs=['rawValue = 123456'])
//%self.expect('frame variable computed_option', substrs=['storedValue', '789'])
//%self.expect('expression user_option', substrs=['rawValue = 123456'])
//%self.expect('frame variable sdk_option_single_valued', substrs=['.insertionIndex'])
//%self.expect('frame variable sdk_option_single_valued', matching=False, substrs=['['])
//%self.expect('expression sdk_option_single_valued', substrs=['.insertionIndex'])
//%self.expect('expression sdk_option_single_valued', matching=False, substrs=['['])
//%self.expect('frame variable sdk_option_exhaustive', substrs=['[.firstEqual, .insertionIndex]'])
//%self.expect('expression sdk_option_exhaustive', substrs=['[.firstEqual, .insertionIndex]'])
//%self.expect('frame variable sdk_option_nonexhaustive', substrs=['[.firstEqual, 0x1]'])
Expand Down
5 changes: 2 additions & 3 deletions lldb/test/Shell/Swift/Inputs/No.swiftmodule-ObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ func f() {
// The Objective-C runtime recognizes this as a tagged pointer.
// CHECK-DAG: (NSNumber) inlined = {{.*}}Int64(42)
let inlined = NSNumber(value: 42)
// FIXME: The dataformatters wrongly think this is an OptionSet.
// CHECK-DAG: (CMYK) enumerator = [.yellow]
// CHECK-DAG: (CMYK) enumerator = .yellow
let enumerator = yellow
// CHECK-DAG: (FourColors) typedef = [.cyan]
// CHECK-DAG: (FourColors) typedef = .cyan
let typedef = FourColors(0)
let union = Union(i: 23)
// CHECK-DAG: (OBJCSTUFF_MyString) renamed = {{.*}} "with swift_name"
Expand Down