Skip to content

Commit e3fde34

Browse files
authored
[lldb][libc++] Adds missing C++20 calendar data formatters. (#77954)
This is a followup of #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.
1 parent 8d817f6 commit e3fde34

File tree

5 files changed

+231
-0
lines changed

5 files changed

+231
-0
lines changed

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
10391039
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
10401040
eTypeOptionHideValue,
10411041
"day=${var.__d_%u}")));
1042+
10421043
AddCXXSummary(cpp_category_sp,
10431044
lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
10441045
"libc++ std::chrono::month summary provider",
@@ -1050,6 +1051,23 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
10501051
TypeSummaryImplSP(new StringSummaryFormat(
10511052
eTypeOptionHideChildren | eTypeOptionHideValue, "year=${var.__y_}")));
10521053

1054+
AddCXXSummary(cpp_category_sp,
1055+
lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider,
1056+
"libc++ std::chrono::weekday summary provider",
1057+
"^std::__[[:alnum:]]+::chrono::weekday$",
1058+
eTypeOptionHideChildren | eTypeOptionHideValue, true);
1059+
1060+
cpp_category_sp->AddTypeSummary(
1061+
"^std::__[[:alnum:]]+::chrono::weekday_indexed$", eFormatterMatchRegex,
1062+
TypeSummaryImplSP(new StringSummaryFormat(
1063+
eTypeOptionHideChildren | eTypeOptionHideValue,
1064+
"${var.__wd_} index=${var.__idx_%u}")));
1065+
1066+
cpp_category_sp->AddTypeSummary(
1067+
"^std::__[[:alnum:]]+::chrono::weekday_last$", eFormatterMatchRegex,
1068+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1069+
eTypeOptionHideValue,
1070+
"${var.__wd_} index=last")));
10531071
cpp_category_sp->AddTypeSummary(
10541072
"^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
10551073
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
@@ -1060,12 +1078,51 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
10601078
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
10611079
eTypeOptionHideValue,
10621080
"${var.__m_} day=last")));
1081+
1082+
cpp_category_sp->AddTypeSummary(
1083+
"^std::__[[:alnum:]]+::chrono::month_weekday$", eFormatterMatchRegex,
1084+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1085+
eTypeOptionHideValue,
1086+
"${var.__m_} ${var.__wdi_}")));
1087+
1088+
cpp_category_sp->AddTypeSummary(
1089+
"^std::__[[:alnum:]]+::chrono::month_weekday_last$", eFormatterMatchRegex,
1090+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1091+
eTypeOptionHideValue,
1092+
"${var.__m_} ${var.__wdl_}")));
1093+
1094+
cpp_category_sp->AddTypeSummary(
1095+
"^std::__[[:alnum:]]+::chrono::year_month$", eFormatterMatchRegex,
1096+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1097+
eTypeOptionHideValue,
1098+
"${var.__y_} ${var.__m_}")));
1099+
10631100
AddCXXSummary(
10641101
cpp_category_sp,
10651102
lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
10661103
"libc++ std::chrono::year_month_day summary provider",
10671104
"^std::__[[:alnum:]]+::chrono::year_month_day$",
10681105
eTypeOptionHideChildren | eTypeOptionHideValue, true);
1106+
1107+
cpp_category_sp->AddTypeSummary(
1108+
"^std::__[[:alnum:]]+::chrono::year_month_day_last$",
1109+
eFormatterMatchRegex,
1110+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1111+
eTypeOptionHideValue,
1112+
"${var.__y_} ${var.__mdl_}")));
1113+
1114+
cpp_category_sp->AddTypeSummary(
1115+
"^std::__[[:alnum:]]+::chrono::year_month_weekday$", eFormatterMatchRegex,
1116+
TypeSummaryImplSP(new StringSummaryFormat(
1117+
eTypeOptionHideChildren | eTypeOptionHideValue,
1118+
"${var.__y_} ${var.__m_} ${var.__wdi_}")));
1119+
1120+
cpp_category_sp->AddTypeSummary(
1121+
"^std::__[[:alnum:]]+::chrono::year_month_weekday_last$",
1122+
eFormatterMatchRegex,
1123+
TypeSummaryImplSP(new StringSummaryFormat(
1124+
eTypeOptionHideChildren | eTypeOptionHideValue,
1125+
"${var.__y_} ${var.__m_} ${var.__wdl_}")));
10691126
}
10701127

10711128
static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,27 @@ bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
11061106
return true;
11071107
}
11081108

1109+
bool lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider(
1110+
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
1111+
// FIXME: These are the names used in the C++20 ostream operator. Since LLVM
1112+
// uses C++17 it's not possible to use the ostream operator directly.
1113+
static const std::array<std::string_view, 7> weekdays = {
1114+
"Sunday", "Monday", "Tuesday", "Wednesday",
1115+
"Thursday", "Friday", "Saturday"};
1116+
1117+
ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__wd_");
1118+
if (!ptr_sp)
1119+
return false;
1120+
1121+
const unsigned weekday = ptr_sp->GetValueAsUnsigned(0);
1122+
if (weekday >= 0 && weekday < 7)
1123+
stream << "weekday=" << weekdays[weekday];
1124+
else
1125+
stream.Printf("weekday=%u", weekday);
1126+
1127+
return true;
1128+
}
1129+
11091130
bool lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider(
11101131
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
11111132
ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__y_");

lldb/source/Plugins/Language/CPlusPlus/LibCxx.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ bool LibcxxChronoMonthSummaryProvider(
265265
ValueObject &valobj, Stream &stream,
266266
const TypeSummaryOptions &options); // libc++ std::chrono::month
267267

268+
bool LibcxxChronoWeekdaySummaryProvider(
269+
ValueObject &valobj, Stream &stream,
270+
const TypeSummaryOptions &options); // libc++ std::chrono::weekday
271+
268272
bool LibcxxChronoYearMonthDaySummaryProvider(
269273
ValueObject &valobj, Stream &stream,
270274
const TypeSummaryOptions &options); // libc++ std::chrono::year_month_day

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,53 @@ def test_with_run_command(self):
6666
self.expect("frame variable month_13", substrs=["month_13 = month=13"])
6767
self.expect("frame variable month_255", substrs=["month_255 = month=255"])
6868

69+
self.expect("frame variable sun", substrs=["sun = weekday=Sunday"])
70+
self.expect("frame variable mon", substrs=["mon = weekday=Monday"])
71+
self.expect("frame variable tue", substrs=["tue = weekday=Tuesday"])
72+
self.expect("frame variable wed", substrs=["wed = weekday=Wednesday"])
73+
self.expect("frame variable thu", substrs=["thu = weekday=Thursday"])
74+
self.expect("frame variable fri", substrs=["fri = weekday=Friday"])
75+
self.expect("frame variable sat", substrs=["sat = weekday=Saturday"])
76+
77+
self.expect("frame variable weekday_0", substrs=["weekday_0 = weekday=Sunday"])
78+
self.expect("frame variable weekday_1", substrs=["weekday_1 = weekday=Monday"])
79+
self.expect("frame variable weekday_2", substrs=["weekday_2 = weekday=Tuesday"])
80+
self.expect(
81+
"frame variable weekday_3", substrs=["weekday_3 = weekday=Wednesday"]
82+
)
83+
self.expect(
84+
"frame variable weekday_4", substrs=["weekday_4 = weekday=Thursday"]
85+
)
86+
self.expect("frame variable weekday_5", substrs=["weekday_5 = weekday=Friday"])
87+
self.expect(
88+
"frame variable weekday_6", substrs=["weekday_6 = weekday=Saturday"]
89+
)
90+
self.expect("frame variable weekday_7", substrs=["weekday_7 = weekday=Sunday"])
91+
self.expect("frame variable weekday_8", substrs=["weekday_8 = weekday=8"])
92+
self.expect("frame variable weekday_255", substrs=["weekday_255 = weekday=255"])
93+
94+
self.expect(
95+
"frame variable wdi_saturday_0",
96+
substrs=["wdi_saturday_0 = weekday=Saturday index=0"],
97+
)
98+
self.expect(
99+
"frame variable wdi_monday_1",
100+
substrs=["wdi_monday_1 = weekday=Monday index=1"],
101+
)
102+
self.expect(
103+
"frame variable wdi_invalid",
104+
substrs=["wdi_invalid = weekday=255 index=255"],
105+
)
106+
107+
self.expect(
108+
"frame variable wdl_monday",
109+
substrs=["wdl_monday = weekday=Monday index=last"],
110+
)
111+
self.expect(
112+
"frame variable wdl_invalid",
113+
substrs=["wdl_invalid = weekday=255 index=last"],
114+
)
115+
69116
self.expect("frame variable y_min", substrs=["y_min = year=-32767"])
70117
self.expect("frame variable y_0", substrs=["y_0 = year=0"])
71118
self.expect("frame variable y_1970", substrs=["y_1970 = year=1970"])
@@ -91,6 +138,21 @@ def test_with_run_command(self):
91138
substrs=["mdl_new_years_eve = month=December day=last"],
92139
)
93140

141+
self.expect(
142+
"frame variable mwd_first_thursday",
143+
substrs=["mwd_first_thursday = month=January weekday=Thursday index=1"],
144+
)
145+
146+
self.expect(
147+
"frame variable mwdl_last_saturday",
148+
substrs=["mwdl_last_saturday = month=December weekday=Saturday index=last"],
149+
)
150+
151+
self.expect(
152+
"frame variable ym_year_zero",
153+
substrs=["ym_year_zero = year=0 month=January"],
154+
)
155+
94156
self.expect("frame variable ymd_bc", substrs=["ymd_bc = date=-0001-03-255"])
95157
self.expect(
96158
"frame variable ymd_year_zero", substrs=["ymd_year_zero = date=0000-255-25"]
@@ -99,3 +161,34 @@ def test_with_run_command(self):
99161
"frame variable ymd_unix_epoch",
100162
substrs=["ymd_unix_epoch = date=1970-01-01"],
101163
)
164+
165+
self.expect(
166+
"frame variable ymdl_bc",
167+
substrs=["ymdl_bc = year=-1 month=December day=last"],
168+
)
169+
self.expect(
170+
"frame variable ymdl_may_1970",
171+
substrs=["ymdl_may_1970 = year=1970 month=May day=last"],
172+
)
173+
174+
self.expect(
175+
"frame variable ymwd_bc",
176+
substrs=["ymwd_bc = year=-1 month=June weekday=Wednesday index=2"],
177+
)
178+
self.expect(
179+
"frame variable ymwd_forth_tuesday_2024",
180+
substrs=[
181+
"ymwd_forth_tuesday_2024 = year=2024 month=January weekday=Tuesday index=4"
182+
],
183+
)
184+
185+
self.expect(
186+
"frame variable ymwdl_bc",
187+
substrs=["ymwdl_bc = year=-1 month=April weekday=Friday index=last"],
188+
)
189+
self.expect(
190+
"frame variable ymwdl_2024_last_tuesday_january",
191+
substrs=[
192+
"ymwdl_2024_last_tuesday_january = year=2024 month=January weekday=Tuesday index=last"
193+
],
194+
)

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/main.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,75 @@ int main() {
5555
std::chrono::year y_2038{2038};
5656
std::chrono::year y_max{std::chrono::year::max()};
5757

58+
std::chrono::weekday sun = std::chrono::Sunday;
59+
std::chrono::weekday mon = std::chrono::Monday;
60+
std::chrono::weekday tue = std::chrono::Tuesday;
61+
std::chrono::weekday wed = std::chrono::Wednesday;
62+
std::chrono::weekday thu = std::chrono::Thursday;
63+
std::chrono::weekday fri = std::chrono::Friday;
64+
std::chrono::weekday sat = std::chrono::Saturday;
65+
66+
std::chrono::weekday weekday_0{0};
67+
std::chrono::weekday weekday_1{1};
68+
std::chrono::weekday weekday_2{2};
69+
std::chrono::weekday weekday_3{3};
70+
std::chrono::weekday weekday_4{4};
71+
std::chrono::weekday weekday_5{5};
72+
std::chrono::weekday weekday_6{6};
73+
std::chrono::weekday weekday_7{7};
74+
std::chrono::weekday weekday_8{8};
75+
std::chrono::weekday weekday_255{255};
76+
77+
std::chrono::weekday_indexed wdi_saturday_0{std::chrono::Saturday, 0};
78+
std::chrono::weekday_indexed wdi_monday_1{std::chrono::Monday, 1};
79+
std::chrono::weekday_indexed wdi_invalid{std::chrono::weekday{255}, 255};
80+
81+
std::chrono::weekday_last wdl_monday{std::chrono::Monday};
82+
std::chrono::weekday_last wdl_invalid{std::chrono::weekday{255}};
83+
5884
std::chrono::month_day md_new_years_eve{std::chrono::December / 31};
5985
std::chrono::month_day md_new_year{std::chrono::January / 1};
6086
std::chrono::month_day md_invalid{std::chrono::month{255} / 255};
6187

6288
std::chrono::month_day_last mdl_jan{std::chrono::January};
6389
std::chrono::month_day_last mdl_new_years_eve{std::chrono::December};
6490

91+
std::chrono::month_weekday mwd_first_thursday{
92+
std::chrono::January,
93+
std::chrono::weekday_indexed{std::chrono::Thursday, 1}};
94+
95+
std::chrono::month_weekday_last mwdl_last_saturday{
96+
std::chrono::December, std::chrono::weekday_last{std::chrono::Saturday}};
97+
98+
std::chrono::year_month ym_year_zero{std::chrono::year{0},
99+
std::chrono::January};
100+
65101
std::chrono::year_month_day ymd_bc{std::chrono::year{-1}, std::chrono::March,
66102
std::chrono::day{255}};
67103
std::chrono::year_month_day ymd_year_zero{
68104
std::chrono::year{0}, std::chrono::month{255}, std::chrono::day{25}};
69105
std::chrono::year_month_day ymd_unix_epoch{
70106
std::chrono::year{1970}, std::chrono::January, std::chrono::day{1}};
71107

108+
std::chrono::year_month_day_last ymdl_bc{
109+
std::chrono::year{-1},
110+
std::chrono::month_day_last{std::chrono::December}};
111+
std::chrono::year_month_day_last ymdl_may_1970{
112+
std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}};
113+
114+
std::chrono::year_month_weekday ymwd_bc{
115+
std::chrono::year{-1}, std::chrono::June,
116+
std::chrono::weekday_indexed{std::chrono::Wednesday, 2}};
117+
std::chrono::year_month_weekday ymwd_forth_tuesday_2024{
118+
std::chrono::year{2024}, std::chrono::January,
119+
std::chrono::weekday_indexed{std::chrono::Tuesday, 4}};
120+
121+
std::chrono::year_month_weekday_last ymwdl_bc{
122+
std::chrono::year{-1}, std::chrono::April,
123+
std::chrono::weekday_last{std::chrono::Friday}};
124+
std::chrono::year_month_weekday_last ymwdl_2024_last_tuesday_january{
125+
std::chrono::year{2024}, std::chrono::January,
126+
std::chrono::weekday_last{std::chrono::Tuesday}};
127+
72128
std::cout << "break here\n";
73129
}

0 commit comments

Comments
 (0)