1 | //===-- Pointer Converter for printf ----------------------------*- C++ -*-===// |
---|---|
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H |
10 | #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H |
11 | |
12 | #include "src/stdio/printf_core/core_structs.h" |
13 | #include "src/stdio/printf_core/int_converter.h" |
14 | #include "src/stdio/printf_core/string_converter.h" |
15 | #include "src/stdio/printf_core/writer.h" |
16 | |
17 | namespace LIBC_NAMESPACE { |
18 | namespace printf_core { |
19 | |
20 | LIBC_INLINE int convert_pointer(Writer *writer, const FormatSection &to_conv) { |
21 | FormatSection new_conv = to_conv; |
22 | |
23 | if (to_conv.conv_val_ptr == nullptr) { |
24 | constexpr char NULLPTR_STR[] = "(nullptr)"; |
25 | new_conv.conv_name = 's'; |
26 | new_conv.conv_val_ptr = const_cast<char *>(NULLPTR_STR); |
27 | return convert_string(writer, to_conv: new_conv); |
28 | } |
29 | new_conv.conv_name = 'x'; |
30 | new_conv.flags = |
31 | static_cast<FormatFlags>(to_conv.flags | FormatFlags::ALTERNATE_FORM); |
32 | new_conv.length_modifier = LengthModifier::t; |
33 | new_conv.conv_val_raw = reinterpret_cast<uintptr_t>(to_conv.conv_val_ptr); |
34 | return convert_int(writer, to_conv: new_conv); |
35 | } |
36 | |
37 | } // namespace printf_core |
38 | } // namespace LIBC_NAMESPACE |
39 | |
40 | #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H |
41 |