-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx][libc] Hand in Hand PoC with from_chars (#91651)
Implements std::from_chars for float and double. The implementation uses LLVM-libc to do the real parsing. Since this is the first time libc++ uses LLVM-libc there is a bit of additional infrastructure code. The patch is based on the [RFC] Project Hand In Hand (LLVM-libc/libc++ code sharing) https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
- Loading branch information
1 parent
9b7be3e
commit 6c4267f
Showing
36 changed files
with
2,365 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Floating point number utils -----------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SHARED_FP_BITS_H | ||
#define LLVM_LIBC_SHARED_FP_BITS_H | ||
|
||
#include "src/__support/FPUtil/FPBits.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
namespace shared { | ||
|
||
using fputil::FPBits; | ||
|
||
} // namespace shared | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SHARED_FP_BITS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===-- String to float conversion utils ------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SHARED_STR_TO_FLOAT_H | ||
#define LLVM_LIBC_SHARED_STR_TO_FLOAT_H | ||
|
||
#include "src/__support/str_to_float.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
namespace shared { | ||
|
||
using internal::ExpandedFloat; | ||
using internal::FloatConvertReturn; | ||
using internal::RoundDirection; | ||
|
||
using internal::binary_exp_to_float; | ||
using internal::decimal_exp_to_float; | ||
|
||
} // namespace shared | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SHARED_STR_TO_FLOAT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===-- String to int conversion utils --------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SHARED_STR_TO_INTEGER_H | ||
#define LLVM_LIBC_SHARED_STR_TO_INTEGER_H | ||
|
||
#include "src/__support/str_to_integer.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
namespace shared { | ||
|
||
using LIBC_NAMESPACE::StrToNumResult; | ||
|
||
using internal::strtointeger; | ||
|
||
} // namespace shared | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SHARED_STR_TO_INTEGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// -*- C++ -*- | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H | ||
#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H | ||
|
||
#include <__assert> | ||
#include <__charconv/chars_format.h> | ||
#include <__charconv/from_chars_result.h> | ||
#include <__config> | ||
#include <__system_error/errc.h> | ||
#include <cstddef> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_PUSH_MACROS | ||
#include <__undef_macros> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 17 | ||
|
||
template <class _Fp> | ||
struct __from_chars_result { | ||
_Fp __value; | ||
ptrdiff_t __n; | ||
errc __ec; | ||
}; | ||
|
||
template <class _Fp> | ||
_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point( | ||
[[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt); | ||
|
||
extern template __from_chars_result<float> __from_chars_floating_point( | ||
[[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt); | ||
|
||
extern template __from_chars_result<double> __from_chars_floating_point( | ||
[[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt); | ||
|
||
template <class _Fp> | ||
_LIBCPP_HIDE_FROM_ABI from_chars_result | ||
__from_chars(const char* __first, const char* __last, _Fp& __value, chars_format __fmt) { | ||
__from_chars_result<_Fp> __r = std::__from_chars_floating_point<_Fp>(__first, __last, __fmt); | ||
if (__r.__ec != errc::invalid_argument) | ||
__value = __r.__value; | ||
return {__first + __r.__n, __r.__ec}; | ||
} | ||
|
||
_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result | ||
from_chars(const char* __first, const char* __last, float& __value, chars_format __fmt = chars_format::general) { | ||
return std::__from_chars<float>(__first, __last, __value, __fmt); | ||
} | ||
|
||
_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result | ||
from_chars(const char* __first, const char* __last, double& __value, chars_format __fmt = chars_format::general) { | ||
return std::__from_chars<double>(__first, __last, __value, __fmt); | ||
} | ||
|
||
#endif // _LIBCPP_STD_VER >= 17 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.