1 //===-- ScanfMatcher.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 "ScanfMatcher.h"
11 #include "src/__support/FPUtil/FPBits.h"
12 #include "src/stdio/scanf_core/core_structs.h"
14 #include "test/UnitTest/StringUtils.h"
15 #include "test/UnitTest/Test.h"
19 namespace LIBC_NAMESPACE
{
22 using scanf_core::FormatFlags
;
23 using scanf_core::FormatSection
;
24 using scanf_core::LengthModifier
;
26 bool FormatSectionMatcher::match(FormatSection actualValue
) {
28 return expected
== actual
;
33 #define IF_FLAG_SHOW_FLAG(flag_name) \
35 if ((form.flags & FormatFlags::flag_name) == FormatFlags::flag_name) \
36 tlog << "\n\t\t" << #flag_name; \
39 case (LengthModifier::lm): \
43 void display(FormatSection form
) {
44 tlog
<< "Raw String (len " << form
.raw_string
.size() << "): \"";
45 for (size_t i
= 0; i
< form
.raw_string
.size(); ++i
) {
46 tlog
<< form
.raw_string
[i
];
50 tlog
<< "\n\tHas Conv\n\tFlags:";
51 IF_FLAG_SHOW_FLAG(NO_WRITE
);
52 IF_FLAG_SHOW_FLAG(ALLOCATE
);
54 tlog
<< "\tmax width: " << form
.max_width
<< "\n";
55 tlog
<< "\tlength modifier: ";
56 switch (form
.length_modifier
) {
68 // If the pointer is used (NO_WRITE is not set and the conversion isn't %).
69 if (((form
.flags
& FormatFlags::NO_WRITE
) == 0) &&
70 (form
.conv_name
!= '%')) {
71 tlog
<< "\tpointer value: "
72 << int_to_hex
<uintptr_t>(
73 reinterpret_cast<uintptr_t>(form
.output_ptr
))
77 tlog
<< "\tconversion name: " << form
.conv_name
<< "\n";
79 if (form
.conv_name
== '[') {
81 for (size_t i
= 0; i
< 256 /* char max */; ++i
) {
82 if (form
.scan_set
.test(i
)) {
83 tlog
<< static_cast<char>(i
);
90 } // anonymous namespace
92 void FormatSectionMatcher::explainError() {
93 tlog
<< "expected format section: ";
96 tlog
<< "actual format section : ";
101 } // namespace testing
102 } // namespace LIBC_NAMESPACE