1 //===-- PrintfMatcher.cpp ---------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "PrintfMatcher.h"
11 #include "src/__support/FPUtil/FPBits.h"
12 #include "src/__support/macros/config.h"
13 #include "src/stdio/printf_core/core_structs.h"
15 #include "test/UnitTest/StringUtils.h"
16 #include "test/UnitTest/Test.h"
20 namespace LIBC_NAMESPACE_DECL
{
23 using printf_core::FormatFlags
;
24 using printf_core::FormatSection
;
25 using printf_core::LengthModifier
;
27 bool FormatSectionMatcher::match(FormatSection actualValue
) {
29 return expected
== actual
;
34 #define IF_FLAG_SHOW_FLAG(flag_name) \
36 if ((form.flags & FormatFlags::flag_name) == FormatFlags::flag_name) \
37 tlog << "\n\t\t" << #flag_name; \
40 case (LengthModifier::lm): \
43 #define CASE_LM_BIT_WIDTH(lm, bw) \
44 case (LengthModifier::lm): \
45 tlog << #lm << "\n\tbit width: :" << bw; \
48 static void display(FormatSection form
) {
49 tlog
<< "Raw String (len " << form
.raw_string
.size() << "): \"";
50 for (size_t i
= 0; i
< form
.raw_string
.size(); ++i
) {
51 tlog
<< form
.raw_string
[i
];
55 tlog
<< "\n\tHas Conv\n\tFlags:";
56 IF_FLAG_SHOW_FLAG(LEFT_JUSTIFIED
);
57 IF_FLAG_SHOW_FLAG(FORCE_SIGN
);
58 IF_FLAG_SHOW_FLAG(SPACE_PREFIX
);
59 IF_FLAG_SHOW_FLAG(ALTERNATE_FORM
);
60 IF_FLAG_SHOW_FLAG(LEADING_ZEROES
);
62 tlog
<< "\tmin width: " << form
.min_width
<< "\n";
63 tlog
<< "\tprecision: " << form
.precision
<< "\n";
64 tlog
<< "\tlength modifier: ";
65 switch (form
.length_modifier
) {
75 CASE_LM_BIT_WIDTH(w
, form
.bit_width
);
76 CASE_LM_BIT_WIDTH(wf
, form
.bit_width
);
79 tlog
<< "\tconversion name: " << form
.conv_name
<< "\n";
80 if (form
.conv_name
== 'p' || form
.conv_name
== 'n' || form
.conv_name
== 's')
81 tlog
<< "\tpointer value: "
82 << int_to_hex
<uintptr_t>(
83 reinterpret_cast<uintptr_t>(form
.conv_val_ptr
))
85 else if (form
.conv_name
!= '%')
87 << int_to_hex
<fputil::FPBits
<long double>::StorageType
>(
92 } // anonymous namespace
94 void FormatSectionMatcher::explainError() {
95 tlog
<< "expected format section: ";
98 tlog
<< "actual format section : ";
103 } // namespace testing
104 } // namespace LIBC_NAMESPACE_DECL