[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / libc / src / stdio / printf_core / ptr_converter.h
blob73c6e608a59a78445fc48805162e633dff437088
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H
10 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H
12 #include "src/__support/CPP/string_view.h"
13 #include "src/__support/common.h"
14 #include "src/stdio/printf_core/converter_utils.h"
15 #include "src/stdio/printf_core/core_structs.h"
16 #include "src/stdio/printf_core/int_converter.h"
17 #include "src/stdio/printf_core/string_converter.h"
18 #include "src/stdio/printf_core/writer.h"
20 namespace LIBC_NAMESPACE {
21 namespace printf_core {
23 LIBC_INLINE int convert_pointer(Writer *writer, const FormatSection &to_conv) {
24 FormatSection new_conv = to_conv;
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);
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);
40 } // namespace printf_core
41 } // namespace LIBC_NAMESPACE
43 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_CONVERTER_H