-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][libc++] Adds missing C++20 calendar data formatters. #77954
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a followup of llvm#76983 and adds the data formatters for - weekday, - weekday_indexed, - weekday_last, - month_weekday, - month_weekday_last, - year_month, - year_month_day_last - year_month_weekday, and - year_month_weekday_last.
@llvm/pr-subscribers-lldb Author: Mark de Wever (mordante) ChangesThis is a followup of #76983 and adds the libc++ data formatters for
Full diff: https://github.com/llvm/llvm-project/pull/77954.diff 5 Files Affected:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index c6937ebca319fa..7131ccb9d05eca 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1039,6 +1039,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
eTypeOptionHideValue,
"day=${var.__d_%u}")));
+
AddCXXSummary(cpp_category_sp,
lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
"libc++ std::chrono::month summary provider",
@@ -1050,6 +1051,23 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
TypeSummaryImplSP(new StringSummaryFormat(
eTypeOptionHideChildren | eTypeOptionHideValue, "year=${var.__y_}")));
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider,
+ "libc++ std::chrono::weekday summary provider",
+ "^std::__[[:alnum:]]+::chrono::weekday$",
+ eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::weekday_indexed$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue,
+ "${var.__wd_} index=${var.__idx_%u}")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::weekday_last$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__wd_} index=last")));
cpp_category_sp->AddTypeSummary(
"^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
@@ -1060,12 +1078,51 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
eTypeOptionHideValue,
"${var.__m_} day=last")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::month_weekday$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__m_} ${var.__wdi_}")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::month_weekday_last$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__m_} ${var.__wdl_}")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::year_month$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__y_} ${var.__m_}")));
+
AddCXXSummary(
cpp_category_sp,
lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
"libc++ std::chrono::year_month_day summary provider",
"^std::__[[:alnum:]]+::chrono::year_month_day$",
eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::year_month_day_last$",
+ eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__y_} ${var.__mdl_}")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::year_month_weekday$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue,
+ "${var.__y_} ${var.__m_} ${var.__wdi_}")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::year_month_weekday_last$",
+ eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue,
+ "${var.__y_} ${var.__m_} ${var.__wdl_}")));
}
static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index f8be4f785dc401..d232a38adc029a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1106,6 +1106,27 @@ bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
return true;
}
+bool lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+ // FIXME: These are the names used in the C++20 ostream operator. Since LLVM
+ // uses C++17 it's not possible to use the ostream operator directly.
+ static const std::array<std::string_view, 7> weekdays = {
+ "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"};
+
+ ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__wd_");
+ if (!ptr_sp)
+ return false;
+
+ const unsigned weekday = ptr_sp->GetValueAsUnsigned(0);
+ if (weekday >= 0 && weekday < 7)
+ stream << "weekday=" << weekdays[weekday];
+ else
+ stream.Printf("weekday=%u", weekday);
+
+ return true;
+}
+
bool lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__y_");
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index c252ae382dd922..532d185b18543f 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -265,6 +265,10 @@ bool LibcxxChronoMonthSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::chrono::month
+bool LibcxxChronoWeekdaySummaryProvider(
+ ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options); // libc++ std::chrono::weekday
+
bool LibcxxChronoYearMonthDaySummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::chrono::year_month_day
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
index 38a31d2ddb4590..d4bc140015fbb7 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
@@ -66,6 +66,53 @@ def test_with_run_command(self):
self.expect("frame variable month_13", substrs=["month_13 = month=13"])
self.expect("frame variable month_255", substrs=["month_255 = month=255"])
+ self.expect("frame variable sun", substrs=["sun = weekday=Sunday"])
+ self.expect("frame variable mon", substrs=["mon = weekday=Monday"])
+ self.expect("frame variable tue", substrs=["tue = weekday=Tuesday"])
+ self.expect("frame variable wed", substrs=["wed = weekday=Wednesday"])
+ self.expect("frame variable thu", substrs=["thu = weekday=Thursday"])
+ self.expect("frame variable fri", substrs=["fri = weekday=Friday"])
+ self.expect("frame variable sat", substrs=["sat = weekday=Saturday"])
+
+ self.expect("frame variable weekday_0", substrs=["weekday_0 = weekday=Sunday"])
+ self.expect("frame variable weekday_1", substrs=["weekday_1 = weekday=Monday"])
+ self.expect("frame variable weekday_2", substrs=["weekday_2 = weekday=Tuesday"])
+ self.expect(
+ "frame variable weekday_3", substrs=["weekday_3 = weekday=Wednesday"]
+ )
+ self.expect(
+ "frame variable weekday_4", substrs=["weekday_4 = weekday=Thursday"]
+ )
+ self.expect("frame variable weekday_5", substrs=["weekday_5 = weekday=Friday"])
+ self.expect(
+ "frame variable weekday_6", substrs=["weekday_6 = weekday=Saturday"]
+ )
+ self.expect("frame variable weekday_7", substrs=["weekday_7 = weekday=Sunday"])
+ self.expect("frame variable weekday_8", substrs=["weekday_8 = weekday=8"])
+ self.expect("frame variable weekday_255", substrs=["weekday_255 = weekday=255"])
+
+ self.expect(
+ "frame variable wdi_saturday_0",
+ substrs=["wdi_saturday_0 = weekday=Saturday index=0"],
+ )
+ self.expect(
+ "frame variable wdi_monday_1",
+ substrs=["wdi_monday_1 = weekday=Monday index=1"],
+ )
+ self.expect(
+ "frame variable wdi_invalid",
+ substrs=["wdi_invalid = weekday=255 index=255"],
+ )
+
+ self.expect(
+ "frame variable wdl_monday",
+ substrs=["wdl_monday = weekday=Monday index=last"],
+ )
+ self.expect(
+ "frame variable wdl_invalid",
+ substrs=["wdl_invalid = weekday=255 index=last"],
+ )
+
self.expect("frame variable y_min", substrs=["y_min = year=-32767"])
self.expect("frame variable y_0", substrs=["y_0 = year=0"])
self.expect("frame variable y_1970", substrs=["y_1970 = year=1970"])
@@ -91,6 +138,21 @@ def test_with_run_command(self):
substrs=["mdl_new_years_eve = month=December day=last"],
)
+ self.expect(
+ "frame variable mwd_first_thursday",
+ substrs=["mwd_first_thursday = month=January weekday=Thursday index=1"],
+ )
+
+ self.expect(
+ "frame variable mwdl_last_saturday",
+ substrs=["mwdl_last_saturday = month=December weekday=Saturday index=last"],
+ )
+
+ self.expect(
+ "frame variable ym_year_zero",
+ substrs=["ym_year_zero = year=0 month=January"],
+ )
+
self.expect("frame variable ymd_bc", substrs=["ymd_bc = date=-0001-03-255"])
self.expect(
"frame variable ymd_year_zero", substrs=["ymd_year_zero = date=0000-255-25"]
@@ -99,3 +161,34 @@ def test_with_run_command(self):
"frame variable ymd_unix_epoch",
substrs=["ymd_unix_epoch = date=1970-01-01"],
)
+
+ self.expect(
+ "frame variable ymdl_bc",
+ substrs=["ymdl_bc = year=-1 month=December day=last"],
+ )
+ self.expect(
+ "frame variable ymdl_may_1970",
+ substrs=["ymdl_may_1970 = year=1970 month=May day=last"],
+ )
+
+ self.expect(
+ "frame variable ymwd_bc",
+ substrs=["ymwd_bc = year=-1 month=June weekday=Wednesday index=2"],
+ )
+ self.expect(
+ "frame variable ymwd_forth_tuesday_2024",
+ substrs=[
+ "ymwd_forth_tuesday_2024 = year=2024 month=January weekday=Tuesday index=4"
+ ],
+ )
+
+ self.expect(
+ "frame variable ymwdl_bc",
+ substrs=["ymwdl_bc = year=-1 month=April weekday=Friday index=last"],
+ )
+ self.expect(
+ "frame variable ymwdl_2024_last_tuesday_january",
+ substrs=[
+ "ymwdl_2024_last_tuesday_january = year=2024 month=January weekday=Tuesday index=last"
+ ],
+ )
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
index 9aa011c97d0c13..57215aaf343f64 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp
@@ -55,6 +55,32 @@ int main() {
std::chrono::year y_2038{2038};
std::chrono::year y_max{std::chrono::year::max()};
+ std::chrono::weekday sun = std::chrono::Sunday;
+ std::chrono::weekday mon = std::chrono::Monday;
+ std::chrono::weekday tue = std::chrono::Tuesday;
+ std::chrono::weekday wed = std::chrono::Wednesday;
+ std::chrono::weekday thu = std::chrono::Thursday;
+ std::chrono::weekday fri = std::chrono::Friday;
+ std::chrono::weekday sat = std::chrono::Saturday;
+
+ std::chrono::weekday weekday_0{0};
+ std::chrono::weekday weekday_1{1};
+ std::chrono::weekday weekday_2{2};
+ std::chrono::weekday weekday_3{3};
+ std::chrono::weekday weekday_4{4};
+ std::chrono::weekday weekday_5{5};
+ std::chrono::weekday weekday_6{6};
+ std::chrono::weekday weekday_7{7};
+ std::chrono::weekday weekday_8{8};
+ std::chrono::weekday weekday_255{255};
+
+ std::chrono::weekday_indexed wdi_saturday_0{std::chrono::Saturday, 0};
+ std::chrono::weekday_indexed wdi_monday_1{std::chrono::Monday, 1};
+ std::chrono::weekday_indexed wdi_invalid{std::chrono::weekday{255}, 255};
+
+ std::chrono::weekday_last wdl_monday{std::chrono::Monday};
+ std::chrono::weekday_last wdl_invalid{std::chrono::weekday{255}};
+
std::chrono::month_day md_new_years_eve{std::chrono::December / 31};
std::chrono::month_day md_new_year{std::chrono::January / 1};
std::chrono::month_day md_invalid{std::chrono::month{255} / 255};
@@ -62,6 +88,16 @@ int main() {
std::chrono::month_day_last mdl_jan{std::chrono::January};
std::chrono::month_day_last mdl_new_years_eve{std::chrono::December};
+ std::chrono::month_weekday mwd_first_thursday{
+ std::chrono::January,
+ std::chrono::weekday_indexed{std::chrono::Thursday, 1}};
+
+ std::chrono::month_weekday_last mwdl_last_saturday{
+ std::chrono::December, std::chrono::weekday_last{std::chrono::Saturday}};
+
+ std::chrono::year_month ym_year_zero{std::chrono::year{0},
+ std::chrono::January};
+
std::chrono::year_month_day ymd_bc{std::chrono::year{-1}, std::chrono::March,
std::chrono::day{255}};
std::chrono::year_month_day ymd_year_zero{
@@ -69,5 +105,25 @@ int main() {
std::chrono::year_month_day ymd_unix_epoch{
std::chrono::year{1970}, std::chrono::January, std::chrono::day{1}};
+ std::chrono::year_month_day_last ymdl_bc{
+ std::chrono::year{-1},
+ std::chrono::month_day_last{std::chrono::December}};
+ std::chrono::year_month_day_last ymdl_may_1970{
+ std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}};
+
+ std::chrono::year_month_weekday ymwd_bc{
+ std::chrono::year{-1}, std::chrono::June,
+ std::chrono::weekday_indexed{std::chrono::Wednesday, 2}};
+ std::chrono::year_month_weekday ymwd_forth_tuesday_2024{
+ std::chrono::year{2024}, std::chrono::January,
+ std::chrono::weekday_indexed{std::chrono::Tuesday, 4}};
+
+ std::chrono::year_month_weekday_last ymwdl_bc{
+ std::chrono::year{-1}, std::chrono::April,
+ std::chrono::weekday_last{std::chrono::Friday}};
+ std::chrono::year_month_weekday_last ymwdl_2024_last_tuesday_january{
+ std::chrono::year{2024}, std::chrono::January,
+ std::chrono::weekday_last{std::chrono::Tuesday}};
+
std::cout << "break here\n";
}
|
Michael137
approved these changes
Jan 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
justinfargnoli
pushed a commit
to justinfargnoli/llvm-project
that referenced
this pull request
Jan 28, 2024
This is a followup of llvm#76983 and adds the libc++ data formatters for - weekday, - weekday_indexed, - weekday_last, - month_weekday, - month_weekday_last, - year_month, - year_month_day_last - year_month_weekday, and - year_month_weekday_last.
Michael137
pushed a commit
to Michael137/llvm-project
that referenced
this pull request
Feb 16, 2024
This is a followup of llvm#76983 and adds the libc++ data formatters for - weekday, - weekday_indexed, - weekday_last, - month_weekday, - month_weekday_last, - year_month, - year_month_day_last - year_month_weekday, and - year_month_weekday_last. (cherry picked from commit e3fde34)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a followup of #76983 and adds the libc++ data formatters for