chromium/v8/src/numbers/conversions.cc

// Copyright 2011 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/numbers/conversions.h"

#include <limits.h>
#include <stdarg.h>

#include <cmath>
#include <optional>

#include "src/base/numbers/dtoa.h"
#include "src/base/numbers/strtod.h"
#include "src/base/small-vector.h"
#include "src/bigint/bigint.h"
#include "src/common/assert-scope.h"
#include "src/handles/handles.h"
#include "src/heap/factory.h"
#include "src/objects/bigint.h"
#include "src/objects/objects-inl.h"
#include "src/objects/string-inl.h"
#include "src/strings/char-predicates-inl.h"
#include "src/utils/allocation.h"

#define FASTFLOAT_ALLOWS_LEADING_PLUS

#include "third_party/fast_float/src/include/fast_float/fast_float.h"
#include "third_party/fast_float/src/include/fast_float/float_common.h"

#if defined(_STLP_VENDOR_CSTD)
// STLPort doesn't import fpclassify into the std namespace.
#define FPCLASSIFY_NAMESPACE
#else
#define FPCLASSIFY_NAMESPACE
#endif

namespace v8 {
namespace internal {

// Helper class for building result strings in a character buffer. The
// purpose of the class is to use safe operations that checks the
// buffer bounds on all operations in debug mode.
// This simple base class does not allow formatted output.
class SimpleStringBuilder {};

inline double JunkStringValue() {}

inline double SignedZero(bool negative) {}

inline bool isDigit(int x, int radix) {}

inline bool isBinaryDigit(int x) {}

template <class Char>
bool SubStringEquals(const Char** current, const Char* end,
                     const char* substring) {}

// Returns true if a nonspace character has been found and false if the
// end was been reached before finding a nonspace character.
template <class Char>
inline bool AdvanceToNonspace(const Char** current, const Char* end) {}

// Parsing integers with radix 2, 4, 8, 16, 32. Assumes current != end.
template <int radix_log_2, class Char>
double InternalStringToIntDouble(const Char* start, const Char* end,
                                 bool negative, bool allow_trailing_junk) {}

namespace {

// Subclasses of StringToIntHelper get access to internal state:
enum class State {};

enum class Sign {};

}  // namespace

// ES6 18.2.5 parseInt(string, radix) (with NumberParseIntHelper subclass);
// and BigInt parsing cases from https://tc39.github.io/proposal-bigint/
// (with StringToBigIntHelper subclass).
class StringToIntHelper {};

void StringToIntHelper::ParseInt() {}

template <class Char>
void StringToIntHelper::DetectRadixInternal(const Char* current, int length) {}

class NumberParseIntHelper : public StringToIntHelper {};

template <class Char>
void NumberParseIntHelper::HandleGenericCase(const Char* current,
                                             const Char* end) {}

// Converts a string to a double value.
template <class Char>
double InternalStringToDouble(const Char* current, const Char* end,
                              ConversionFlag flag, double empty_string_val) {}

double StringToDouble(const char* str, ConversionFlag flags,
                      double empty_string_val) {}

double StringToDouble(base::Vector<const uint8_t> str, ConversionFlag flags,
                      double empty_string_val) {}

double StringToDouble(base::Vector<const base::uc16> str, ConversionFlag flags,
                      double empty_string_val) {}

double BinaryStringToDouble(base::Vector<const uint8_t> str) {}

double OctalStringToDouble(base::Vector<const uint8_t> str) {}

double HexStringToDouble(base::Vector<const uint8_t> str) {}

double ImplicitOctalStringToDouble(base::Vector<const uint8_t> str) {}

double StringToInt(Isolate* isolate, Handle<String> string, int radix) {}

template <typename IsolateT>
class StringToBigIntHelper : public StringToIntHelper {};

MaybeHandle<BigInt> StringToBigInt(Isolate* isolate, Handle<String> string) {}

template <typename IsolateT>
MaybeHandle<BigInt> BigIntLiteral(IsolateT* isolate, const char* string) {}
template EXPORT_TEMPLATE_DEFINE()
    MaybeHandle<BigInt> BigIntLiteral(Isolate* isolate, const char* string);
template EXPORT_TEMPLATE_DEFINE()
    MaybeHandle<BigInt> BigIntLiteral(LocalIsolate* isolate,
                                      const char* string);

std::unique_ptr<char[]> BigIntLiteralToDecimal(
    LocalIsolate* isolate, base::Vector<const uint8_t> literal) {}

const char* DoubleToCString(double v, base::Vector<char> buffer) {}

const char* IntToCString(int n, base::Vector<char> buffer) {}

char* DoubleToFixedCString(double value, int f) {}

static char* CreateExponentialRepresentation(char* decimal_rep, int exponent,
                                             bool negative,
                                             int significant_digits) {}

char* DoubleToExponentialCString(double value, int f) {}

char* DoubleToPrecisionCString(double value, int p) {}

char* DoubleToRadixCString(double value, int radix) {}

// ES6 18.2.4 parseFloat(string)
double StringToDouble(Isolate* isolate, Handle<String> string,
                      ConversionFlag flag, double empty_string_val) {}

double FlatStringToDouble(Tagged<String> string, ConversionFlag flag,
                          double empty_string_val) {}

std::optional<double> TryStringToDouble(LocalIsolate* isolate,
                                        DirectHandle<String> object,
                                        int max_length_for_conversion) {}

std::optional<double> TryStringToInt(LocalIsolate* isolate,
                                     DirectHandle<String> object, int radix) {}

bool IsSpecialIndex(Tagged<String> string) {}

bool IsSpecialIndex(Tagged<String> string,
                    SharedStringAccessGuardIfNeeded& access_guard) {}

float DoubleToFloat32_NoInline(double x) {}

int32_t DoubleToInt32_NoInline(double x) {}

}  // namespace internal
}  // namespace v8

#undef FPCLASSIFY_NAMESPACE