V8 Project
v8::base::internal::CheckedNumeric< T > Class Template Reference

#include <safe_math.h>

+ Collaboration diagram for v8::base::internal::CheckedNumeric< T >:

Public Types

typedef T type
 

Public Member Functions

 CheckedNumeric ()
 
template<typename Src >
 CheckedNumeric (const CheckedNumeric< Src > &rhs)
 
template<typename Src >
 CheckedNumeric (Src value, RangeConstraint validity)
 
template<typename Src >
 CheckedNumeric (Src value)
 
bool IsValid () const
 
T ValueOrDie () const
 
T ValueOrDefault (T default_value) const
 
T ValueFloating () const
 
RangeConstraint validity () const
 
T ValueUnsafe () const
 
template<typename Src >
CheckedNumericoperator+= (Src rhs)
 
template<typename Src >
CheckedNumericoperator-= (Src rhs)
 
template<typename Src >
CheckedNumericoperator*= (Src rhs)
 
template<typename Src >
CheckedNumericoperator/= (Src rhs)
 
template<typename Src >
CheckedNumericoperator%= (Src rhs)
 
CheckedNumeric operator- () const
 
CheckedNumeric Abs () const
 
CheckedNumericoperator++ ()
 
CheckedNumeric operator++ (int)
 
CheckedNumericoperator-- ()
 
CheckedNumeric operator-- (int)
 

Static Public Member Functions

template<typename Src >
static CheckedNumeric< Tcast (Src u, typename enable_if< std::numeric_limits< Src >::is_specialized, int >::type=0)
 
template<typename Src >
static CheckedNumeric< Tcast (const CheckedNumeric< Src > &u, typename enable_if<!is_same< Src, T >::value, int >::type=0)
 
static const CheckedNumeric< T > & cast (const CheckedNumeric< T > &u)
 

Private Attributes

CheckedNumericState< Tstate_
 

Detailed Description

template<typename T>
class v8::base::internal::CheckedNumeric< T >

Definition at line 48 of file safe_math.h.

Member Typedef Documentation

◆ type

template<typename T >
typedef T v8::base::internal::CheckedNumeric< T >::type

Definition at line 50 of file safe_math.h.

Constructor & Destructor Documentation

◆ CheckedNumeric() [1/4]

template<typename T >
v8::base::internal::CheckedNumeric< T >::CheckedNumeric ( )
inline

Definition at line 52 of file safe_math.h.

52 {}

◆ CheckedNumeric() [2/4]

template<typename T >
template<typename Src >
v8::base::internal::CheckedNumeric< T >::CheckedNumeric ( const CheckedNumeric< Src > &  rhs)
inline

Definition at line 56 of file safe_math.h.

57  : state_(rhs.ValueUnsafe(), rhs.validity()) {}
CheckedNumericState< T > state_
Definition: safe_math.h:188

◆ CheckedNumeric() [3/4]

template<typename T >
template<typename Src >
v8::base::internal::CheckedNumeric< T >::CheckedNumeric ( Src  value,
RangeConstraint  validity 
)
inline

Definition at line 60 of file safe_math.h.

61  : state_(value, validity) {}
RangeConstraint validity() const
Definition: safe_math.h:105

◆ CheckedNumeric() [4/4]

template<typename T >
template<typename Src >
v8::base::internal::CheckedNumeric< T >::CheckedNumeric ( Src  value)
inline

Definition at line 66 of file safe_math.h.

67  : state_(value) {
68  // Argument must be numeric.
69  STATIC_ASSERT(std::numeric_limits<Src>::is_specialized);
70  }
#define STATIC_ASSERT(test)
Definition: macros.h:311

References STATIC_ASSERT.

Member Function Documentation

◆ Abs()

template<typename T >
CheckedNumeric v8::base::internal::CheckedNumeric< T >::Abs ( ) const
inline

Definition at line 134 of file safe_math.h.

134  {
136  T value = CheckedAbs(state_.value(), &validity);
137  // Absolute value is always valid for floating point.
138  if (std::numeric_limits<T>::is_iec559)
139  return CheckedNumeric<T>(value);
140 
141  validity = GetRangeConstraint(state_.validity() | validity);
142  return CheckedNumeric<T>(value, validity);
143  }
enable_if< std::numeric_limits< T >::is_integer &&std::numeric_limits< T >::is_signed, T >::type CheckedAbs(T value, RangeConstraint *validity)
RangeConstraint GetRangeConstraint(int integer_range_constraint)
#define T(name, string, precedence)
Definition: token.cc:25

References v8::base::internal::CheckedAbs(), v8::base::internal::GetRangeConstraint(), v8::base::internal::CheckedNumeric< T >::state_, T, and v8::base::internal::CheckedNumeric< T >::validity().

+ Here is the call graph for this function:

◆ cast() [1/3]

template<typename T >
template<typename Src >
static CheckedNumeric<T> v8::base::internal::CheckedNumeric< T >::cast ( const CheckedNumeric< Src > &  u,
typename enable_if<!is_same< Src, T >::value, int >::type  = 0 
)
inlinestatic

Definition at line 179 of file safe_math.h.

181  {
182  return u;
183  }

◆ cast() [2/3]

template<typename T >
static const CheckedNumeric<T>& v8::base::internal::CheckedNumeric< T >::cast ( const CheckedNumeric< T > &  u)
inlinestatic

Definition at line 185 of file safe_math.h.

185 { return u; }

◆ cast() [3/3]

template<typename T >
template<typename Src >
static CheckedNumeric<T> v8::base::internal::CheckedNumeric< T >::cast ( Src  u,
typename enable_if< std::numeric_limits< Src >::is_specialized, int >::type  = 0 
)
inlinestatic

Definition at line 171 of file safe_math.h.

174  {
175  return u;
176  }

Referenced by v8::base::internal::CheckedNumeric< T >::ValueFloating().

+ Here is the caller graph for this function:

◆ IsValid()

template<typename T >
bool v8::base::internal::CheckedNumeric< T >::IsValid ( ) const
inline

Definition at line 73 of file safe_math.h.

References v8::base::internal::RANGE_VALID, and v8::base::internal::CheckedNumeric< T >::validity().

Referenced by v8::internal::DehoistArrayIndex(), v8::base::internal::CheckedNumeric< T >::ValueOrDefault(), and v8::base::internal::CheckedNumeric< T >::ValueOrDie().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator%=()

template<typename T >
template<typename Src >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator%= ( Src  rhs)

◆ operator*=()

template<typename T >
template<typename Src >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator*= ( Src  rhs)

◆ operator++() [1/2]

template<typename T >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator++ ( )
inline

Definition at line 145 of file safe_math.h.

145  {
146  *this += 1;
147  return *this;
148  }

◆ operator++() [2/2]

template<typename T >
CheckedNumeric v8::base::internal::CheckedNumeric< T >::operator++ ( int  )
inline

Definition at line 150 of file safe_math.h.

150  {
151  CheckedNumeric value = *this;
152  *this += 1;
153  return value;
154  }

◆ operator+=()

template<typename T >
template<typename Src >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator+= ( Src  rhs)

◆ operator-()

template<typename T >
CheckedNumeric v8::base::internal::CheckedNumeric< T >::operator- ( ) const
inline

Definition at line 123 of file safe_math.h.

123  {
125  T value = CheckedNeg(state_.value(), &validity);
126  // Negation is always valid for floating point.
127  if (std::numeric_limits<T>::is_iec559)
128  return CheckedNumeric<T>(value);
129 
130  validity = GetRangeConstraint(state_.validity() | validity);
131  return CheckedNumeric<T>(value, validity);
132  }
enable_if< std::numeric_limits< T >::is_integer &&std::numeric_limits< T >::is_signed, T >::type CheckedNeg(T value, RangeConstraint *validity)

References v8::base::internal::CheckedNeg(), v8::base::internal::GetRangeConstraint(), v8::base::internal::CheckedNumeric< T >::state_, T, and v8::base::internal::CheckedNumeric< T >::validity().

+ Here is the call graph for this function:

◆ operator--() [1/2]

template<typename T >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator-- ( )
inline

Definition at line 156 of file safe_math.h.

156  {
157  *this -= 1;
158  return *this;
159  }

◆ operator--() [2/2]

template<typename T >
CheckedNumeric v8::base::internal::CheckedNumeric< T >::operator-- ( int  )
inline

Definition at line 161 of file safe_math.h.

161  {
162  CheckedNumeric value = *this;
163  *this -= 1;
164  return value;
165  }

◆ operator-=()

template<typename T >
template<typename Src >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator-= ( Src  rhs)

◆ operator/=()

template<typename T >
template<typename Src >
CheckedNumeric& v8::base::internal::CheckedNumeric< T >::operator/= ( Src  rhs)

◆ validity()

template<typename T >
RangeConstraint v8::base::internal::CheckedNumeric< T >::validity ( ) const
inline

Definition at line 105 of file safe_math.h.

105 { return state_.validity(); }

References v8::base::internal::CheckedNumeric< T >::state_.

Referenced by v8::base::internal::CheckedNumeric< T >::Abs(), v8::base::internal::CheckedNumeric< T >::IsValid(), and v8::base::internal::CheckedNumeric< T >::operator-().

+ Here is the caller graph for this function:

◆ ValueFloating()

template<typename T >
T v8::base::internal::CheckedNumeric< T >::ValueFloating ( ) const
inline

Definition at line 92 of file safe_math.h.

92  {
93  // Argument must be a floating-point value.
94  STATIC_ASSERT(std::numeric_limits<T>::is_iec559);
95  return CheckedNumeric<T>::cast(*this).ValueUnsafe();
96  }
static CheckedNumeric< T > cast(Src u, typename enable_if< std::numeric_limits< Src >::is_specialized, int >::type=0)
Definition: safe_math.h:171

References v8::base::internal::CheckedNumeric< T >::cast(), and STATIC_ASSERT.

+ Here is the call graph for this function:

◆ ValueOrDefault()

template<typename T >
T v8::base::internal::CheckedNumeric< T >::ValueOrDefault ( T  default_value) const
inline

Definition at line 85 of file safe_math.h.

85  {
86  return IsValid() ? state_.value() : default_value;
87  }

References v8::base::internal::CheckedNumeric< T >::IsValid(), and v8::base::internal::CheckedNumeric< T >::state_.

+ Here is the call graph for this function:

◆ ValueOrDie()

template<typename T >
T v8::base::internal::CheckedNumeric< T >::ValueOrDie ( ) const
inline

Definition at line 77 of file safe_math.h.

77  {
78  CHECK(IsValid());
79  return state_.value();
80  }
#define CHECK(condition)
Definition: logging.h:36

References CHECK, v8::base::internal::CheckedNumeric< T >::IsValid(), and v8::base::internal::CheckedNumeric< T >::state_.

Referenced by v8::internal::DehoistArrayIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ValueUnsafe()

template<typename T >
T v8::base::internal::CheckedNumeric< T >::ValueUnsafe ( ) const
inline

Definition at line 114 of file safe_math.h.

114 { return state_.value(); }

References v8::base::internal::CheckedNumeric< T >::state_.

Member Data Documentation

◆ state_


The documentation for this class was generated from the following file: