Warning: This file is not a C or C++ file. It does not have highlighting.
| 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/__support/macros/config.h" |
| 13 | #include "src/stdio/printf_core/core_structs.h" |
| 14 | #include "src/stdio/printf_core/int_converter.h" |
| 15 | #include "src/stdio/printf_core/string_converter.h" |
| 16 | #include "src/stdio/printf_core/writer.h" |
| 17 | |
| 18 | namespace LIBC_NAMESPACE_DECL { |
| 19 | namespace printf_core { |
| 20 | |
| 21 | template <WriteMode write_mode> |
| 22 | LIBC_INLINE int convert_pointer(Writer<write_mode> *writer, |
| 23 | const FormatSection &to_conv) { |
| 24 | FormatSection new_conv = to_conv; |
| 25 | |
| 26 | if (to_conv.conv_val_ptr == nullptr) { |
| 27 | constexpr char NULLPTR_STR[] = "(nullptr)"; |
| 28 | new_conv.conv_name = 's'; |
| 29 | new_conv.conv_val_ptr = const_cast<char *>(NULLPTR_STR); |
| 30 | return convert_string(writer, new_conv); |
| 31 | } |
| 32 | new_conv.conv_name = 'x'; |
| 33 | new_conv.flags = |
| 34 | static_cast<FormatFlags>(to_conv.flags | FormatFlags::ALTERNATE_FORM); |
| 35 | new_conv.length_modifier = LengthModifier::t; |
| 36 | new_conv.conv_val_raw = reinterpret_cast<uintptr_t>(to_conv.conv_val_ptr); |
| 37 | return convert_int(writer, new_conv); |
| 38 | } |
| 39 | |
| 40 | } // namespace printf_core |
| 41 | } // namespace LIBC_NAMESPACE_DECL |
| 42 | |
| 43 | #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H |
| 44 |
Warning: This file is not a C or C++ file. It does not have highlighting.
