Skip to content

Commit

Permalink
[libc++] Enable radability-identifier-naming for local variables and …
Browse files Browse the repository at this point in the history
…fix any problems

Fixes llvm#60658

Reviewed By: Mordante, #libc

Spies: aheejin, sstefan1, libcxx-commits

Differential Revision: https://reviews.llvm.org/D143737
  • Loading branch information
philnik777 committed Feb 11, 2023
1 parent cc236b6 commit d05f889
Show file tree
Hide file tree
Showing 29 changed files with 172 additions and 168 deletions.
4 changes: 4 additions & 0 deletions libcxx/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ CheckOptions:
value: __
- key: readability-identifier-naming.PrivateMemberSuffix
value: _
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.LocalVariablePrefix
value: __

# TODO: investigate these checks
# bugprone-branch-clone,
Expand Down
30 changes: 15 additions & 15 deletions libcxx/include/__algorithm/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos(
// Swap one pair on each iteration as long as both bitsets have at least one
// element for swapping.
while (__left_bitset != 0 && __right_bitset != 0) {
difference_type tz_left = __libcpp_ctz(__left_bitset);
__left_bitset = __libcpp_blsr(__left_bitset);
difference_type tz_right = __libcpp_ctz(__right_bitset);
__right_bitset = __libcpp_blsr(__right_bitset);
_Ops::iter_swap(__first + tz_left, __last - tz_right);
difference_type __tz_left = __libcpp_ctz(__left_bitset);
__left_bitset = __libcpp_blsr(__left_bitset);
difference_type __tz_right = __libcpp_ctz(__right_bitset);
__right_bitset = __libcpp_blsr(__right_bitset);
_Ops::iter_swap(__first + __tz_left, __last - __tz_right);
}
}

Expand Down Expand Up @@ -469,19 +469,19 @@ inline _LIBCPP_HIDE_FROM_ABI void __bitset_partition_partial_blocks(
// Record the comparison outcomes for the elements currently on the left side.
if (__left_bitset == 0) {
_RandomAccessIterator __iter = __first;
for (int j = 0; j < __l_size; j++) {
for (int __j = 0; __j < __l_size; __j++) {
bool __comp_result = !__comp(*__iter, __pivot);
__left_bitset |= (static_cast<uint64_t>(__comp_result) << j);
__left_bitset |= (static_cast<uint64_t>(__comp_result) << __j);
++__iter;
}
}
// Record the comparison outcomes for the elements currently on the right
// side.
if (__right_bitset == 0) {
_RandomAccessIterator __iter = __lm1;
for (int j = 0; j < __r_size; j++) {
for (int __j = 0; __j < __r_size; __j++) {
bool __comp_result = __comp(*__iter, __pivot);
__right_bitset |= (static_cast<uint64_t>(__comp_result) << j);
__right_bitset |= (static_cast<uint64_t>(__comp_result) << __j);
--__iter;
}
}
Expand All @@ -501,9 +501,9 @@ inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within(
while (__left_bitset != 0) {
difference_type __tz_left = __detail::__block_size - 1 - __libcpp_clz(__left_bitset);
__left_bitset &= (static_cast<uint64_t>(1) << __tz_left) - 1;
_RandomAccessIterator it = __first + __tz_left;
if (it != __lm1) {
_Ops::iter_swap(it, __lm1);
_RandomAccessIterator __it = __first + __tz_left;
if (__it != __lm1) {
_Ops::iter_swap(__it, __lm1);
}
--__lm1;
}
Expand All @@ -514,9 +514,9 @@ inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within(
while (__right_bitset != 0) {
difference_type __tz_right = __detail::__block_size - 1 - __libcpp_clz(__right_bitset);
__right_bitset &= (static_cast<uint64_t>(1) << __tz_right) - 1;
_RandomAccessIterator it = __lm1 - __tz_right;
if (it != __first) {
_Ops::iter_swap(it, __first);
_RandomAccessIterator __it = __lm1 - __tz_right;
if (__it != __first) {
_Ops::iter_swap(__it, __first);
}
++__first;
}
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__bit/bit_ceil.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {
return _Tp{1} << __n;
else {
const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;
const unsigned __retVal = 1u << (__n + __extra);
return (_Tp)(__retVal >> __extra);
const unsigned __ret_val = 1u << (__n + __extra);
return (_Tp)(__ret_val >> __extra);
}
}

Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__chrono/duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ round(const duration<_Rep, _Period>& __d)
{
_ToDuration __lower = chrono::floor<_ToDuration>(__d);
_ToDuration __upper = __lower + _ToDuration{1};
auto __lowerDiff = __d - __lower;
auto __upperDiff = __upper - __d;
if (__lowerDiff < __upperDiff)
auto __lower_diff = __d - __lower;
auto __upper_diff = __upper - __d;
if (__lower_diff < __upper_diff)
return __lower;
if (__lowerDiff > __upperDiff)
if (__lower_diff > __upper_diff)
return __upper;
return __lower.count() & 1 ? __upper : __lower;
}
Expand Down
10 changes: 5 additions & 5 deletions libcxx/include/__compare/common_comparison_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ _LIBCPP_HIDE_FROM_ABI
constexpr auto __get_comp_type() {
using _CCC = _ClassifyCompCategory;
constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
constexpr _CCC _Cat = __comp_detail::__compute_comp_type(__type_kinds);
if constexpr (_Cat == _None)
constexpr _CCC __cat = __comp_detail::__compute_comp_type(__type_kinds);
if constexpr (__cat == _None)
return void();
else if constexpr (_Cat == _PartialOrd)
else if constexpr (__cat == _PartialOrd)
return partial_ordering::equivalent;
else if constexpr (_Cat == _WeakOrd)
else if constexpr (__cat == _WeakOrd)
return weak_ordering::equivalent;
else if constexpr (_Cat == _StrongOrd)
else if constexpr (__cat == _StrongOrd)
return strong_ordering::equivalent;
else
static_assert(_False, "unhandled case");
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__functional/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ typename enable_if
>::type
__mu(_Ti&, _Uj& __uj)
{
const size_t _Indx = is_placeholder<_Ti>::value - 1;
return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
const size_t __indx = is_placeholder<_Ti>::value - 1;
return _VSTD::forward<typename tuple_element<__indx, _Uj>::type>(_VSTD::get<__indx>(__uj));
}

template <class _Ti, class _Uj>
Expand Down
18 changes: 9 additions & 9 deletions libcxx/include/__functional/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,15 @@ struct __policy
_LIBCPP_INLINE_VISIBILITY
static const __policy* __create_empty()
{
static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
true,
static const _LIBCPP_CONSTEXPR __policy __policy = {nullptr, nullptr,
true,
#ifndef _LIBCPP_HAS_NO_RTTI
&typeid(void)
&typeid(void)
#else
nullptr
nullptr
#endif
};
return &__policy_;
return &__policy;
}

private:
Expand All @@ -640,30 +640,30 @@ struct __policy
template <typename _Fun>
_LIBCPP_INLINE_VISIBILITY static const __policy*
__choose_policy(/* is_small = */ false_type) {
static const _LIBCPP_CONSTEXPR __policy __policy_ = {
static const _LIBCPP_CONSTEXPR __policy __policy = {
&__large_clone<_Fun>, &__large_destroy<_Fun>, false,
#ifndef _LIBCPP_HAS_NO_RTTI
&typeid(typename _Fun::_Target)
#else
nullptr
#endif
};
return &__policy_;
return &__policy;
}

template <typename _Fun>
_LIBCPP_INLINE_VISIBILITY static const __policy*
__choose_policy(/* is_small = */ true_type)
{
static const _LIBCPP_CONSTEXPR __policy __policy_ = {
static const _LIBCPP_CONSTEXPR __policy __policy = {
nullptr, nullptr, false,
#ifndef _LIBCPP_HAS_NO_RTTI
&typeid(typename _Fun::_Target)
#else
nullptr
#endif
};
return &__policy_;
return &__policy;
}
};

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__iterator/advance.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ struct __fn {
__a > 0 ? __a >= __b :
__a <= __b;
};
if (const auto __M = __bound_sentinel - __i; __magnitude_geq(__n, __M)) {
if (const auto __m = __bound_sentinel - __i; __magnitude_geq(__n, __m)) {
(*this)(__i, __bound_sentinel);
return __n - __M;
return __n - __m;
}

// Otherwise, equivalent to `ranges::advance(i, n)`.
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__random/clamp_to_integral.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ template <class _IntT, class _RealT>
_LIBCPP_INLINE_VISIBILITY
_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
using _Lim = numeric_limits<_IntT>;
const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>();
if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
const _IntT __max_val = __max_representable_int_for_float<_IntT, _RealT>();
if (__r >= ::nextafter(static_cast<_RealT>(__max_val), INFINITY)) {
return _Lim::max();
} else if (__r <= _Lim::lowest()) {
return _Lim::min();
Expand Down
22 changes: 11 additions & 11 deletions libcxx/include/__random/generate_canonical.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ template<class _RealType, size_t __bits, class _URNG>
_LIBCPP_HIDE_FROM_ABI _RealType
generate_canonical(_URNG& __g)
{
const size_t _Dt = numeric_limits<_RealType>::digits;
const size_t __b = _Dt < __bits ? _Dt : __bits;
const size_t __dt = numeric_limits<_RealType>::digits;
const size_t __b = __dt < __bits ? __dt : __bits;
#ifdef _LIBCPP_CXX03_LANG
const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
const size_t __log_r = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
#else
const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
const size_t __log_r = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
#endif
const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1);
_RealType __base = _Rp;
_RealType _Sp = __g() - _URNG::min();
for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
_Sp += (__g() - _URNG::min()) * __base;
return _Sp / __base;
const size_t __k = __b / __log_r + (__b % __log_r != 0) + (__b == 0);
const _RealType __rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1);
_RealType __base = __rp;
_RealType __sp = __g() - _URNG::min();
for (size_t __i = 1; __i < __k; ++__i, __base *= __rp)
__sp += (__g() - _URNG::min()) * __base;
return __sp / __base;
}

_LIBCPP_END_NAMESPACE_STD
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__random/independent_bits_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ template<class _Engine, size_t __w, class _UIntType>
_UIntType
independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
{
result_type _Sp = 0;
result_type __sp = 0;
for (size_t __k = 0; __k < __n0; ++__k)
{
_Engine_result_type __u;
do
{
__u = __e_() - _Engine::min();
} while (__u >= __y0);
_Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
__sp = static_cast<result_type>(__lshift<__w0>(__sp) + (__u & __mask0));
}
for (size_t __k = __n0; __k < __n; ++__k)
{
Expand All @@ -213,9 +213,9 @@ independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
{
__u = __e_() - _Engine::min();
} while (__u >= __y1);
_Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
__sp = static_cast<result_type>(__lshift<__w0+1>(__sp) + (__u & __mask1));
}
return _Sp;
return __sp;
}

template<class _Eng, size_t _Wp, class _UInt>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__random/mersenne_twister_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
const size_t __j = (__i_ + 1) % __n;
const result_type __mask = __r == _Dt ? result_type(~0) :
(result_type(1) << __r) - result_type(1);
const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
const result_type __yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
const size_t __k = (__i_ + __m) % __n;
__x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
__x_[__i_] = __x_[__k] ^ __rshift<1>(__yp) ^ (__a * (__yp & 1));
result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
__i_ = __j;
__z ^= __lshift<__s>(__z) & __b;
Expand Down
32 changes: 16 additions & 16 deletions libcxx/include/__random/normal_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,30 @@ _RealType
normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
result_type _Up;
result_type __up;
if (__v_hot_)
{
__v_hot_ = false;
_Up = __v_;
__up = __v_;
}
else
{
uniform_real_distribution<result_type> _Uni(-1, 1);
uniform_real_distribution<result_type> __uni(-1, 1);
result_type __u;
result_type __v;
result_type __s;
do
{
__u = _Uni(__g);
__v = _Uni(__g);
__u = __uni(__g);
__v = __uni(__g);
__s = __u * __u + __v * __v;
} while (__s > 1 || __s == 0);
result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
__v_ = __v * _Fp;
result_type __fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
__v_ = __v * __fp;
__v_hot_ = true;
_Up = __u * _Fp;
__up = __u * __fp;
}
return _Up * __p.stddev() + __p.mean();
return __up * __p.stddev() + __p.mean();
}

template <class _CharT, class _Traits, class _RT>
Expand Down Expand Up @@ -189,16 +189,16 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
__is.flags(_Istream::dec | _Istream::skipws);
result_type __mean;
result_type __stddev;
result_type _Vp = 0;
bool _V_hot = false;
__is >> __mean >> __stddev >> _V_hot;
if (_V_hot)
__is >> _Vp;
result_type __vp = 0;
bool __v_hot = false;
__is >> __mean >> __stddev >> __v_hot;
if (__v_hot)
__is >> __vp;
if (!__is.fail())
{
__x.param(param_type(__mean, __stddev));
__x.__v_hot_ = _V_hot;
__x.__v_ = _Vp;
__x.__v_hot_ = __v_hot;
__x.__v_ = __vp;
}
return __is;
}
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__random/piecewise_linear_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,23 @@ void
piecewise_linear_distribution<_RealType>::param_type::__init()
{
__areas_.assign(__densities_.size() - 1, result_type());
result_type _Sp = 0;
result_type __sp = 0;
for (size_t __i = 0; __i < __areas_.size(); ++__i)
{
__areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
(__b_[__i+1] - __b_[__i]) * .5;
_Sp += __areas_[__i];
__sp += __areas_[__i];
}
for (size_t __i = __areas_.size(); __i > 1;)
{
--__i;
__areas_[__i] = __areas_[__i-1] / _Sp;
__areas_[__i] = __areas_[__i-1] / __sp;
}
__areas_[0] = 0;
for (size_t __i = 1; __i < __areas_.size(); ++__i)
__areas_[__i] += __areas_[__i-1];
for (size_t __i = 0; __i < __densities_.size(); ++__i)
__densities_[__i] /= _Sp;
__densities_[__i] /= __sp;
}

template<class _RealType>
Expand Down
12 changes: 6 additions & 6 deletions libcxx/include/__random/poisson_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ poisson_distribution<_IntType>::param_type::param_type(double __mean)
__d_ = 6 * __mean_ * __mean_;
__l_ = _VSTD::trunc(__mean_ - 1.1484);
__omega_ = .3989423 / __s_;
double __b1_ = .4166667E-1 / __mean_;
double __b2_ = .3 * __b1_ * __b1_;
__c3_ = .1428571 * __b1_ * __b2_;
__c2_ = __b2_ - 15. * __c3_;
__c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
__c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
double __b1 = .4166667E-1 / __mean_;
double __b2 = .3 * __b1 * __b1;
__c3_ = .1428571 * __b1 * __b2;
__c2_ = __b2 - 15. * __c3_;
__c1_ = __b1 - 6. * __b2 + 45. * __c3_;
__c0_ = 1. - __b1 + 3. * __b2 - 15. * __c3_;
__c_ = .1069 / __mean_;
}
}
Expand Down
Loading

0 comments on commit d05f889

Please sign in to comment.