Codechange: automatic adding of _t to (u)int types, and WChar to char32_t

for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
This commit is contained in:
Rubidium
2023-05-08 19:01:06 +02:00
committed by rubidium42
parent 4f4810dc28
commit eaae0bb5e7
564 changed files with 4561 additions and 4561 deletions

View File

@@ -12,7 +12,7 @@
#include "../safeguards.h"
const uint8 _ffb_64[64] = {
const uint8_t _ffb_64[64] = {
0, 0, 1, 0, 2, 0, 1, 0,
3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0,
@@ -34,13 +34,13 @@ const uint8 _ffb_64[64] = {
* @param x The value to search
* @return The position of the first bit set
*/
uint8 FindFirstBit(uint64 x)
uint8_t FindFirstBit(uint64_t x)
{
if (x == 0) return 0;
/* The macro FIND_FIRST_BIT is better to use when your x is
not more than 128. */
uint8 pos = 0;
uint8_t pos = 0;
if ((x & 0xffffffffULL) == 0) { x >>= 32; pos += 32; }
if ((x & 0x0000ffffULL) == 0) { x >>= 16; pos += 16; }
@@ -63,11 +63,11 @@ uint8 FindFirstBit(uint64 x)
* @param x The value to search
* @return The position of the last bit set
*/
uint8 FindLastBit(uint64 x)
uint8_t FindLastBit(uint64_t x)
{
if (x == 0) return 0;
uint8 pos = 0;
uint8_t pos = 0;
if ((x & 0xffffffff00000000ULL) != 0) { x >>= 32; pos += 32; }
if ((x & 0x00000000ffff0000ULL) != 0) { x >>= 16; pos += 16; }

View File

@@ -29,7 +29,7 @@
* @return The selected bits, aligned to a LSB.
*/
template <typename T>
debug_inline constexpr static uint GB(const T x, const uint8 s, const uint8 n)
debug_inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
{
return (x >> s) & (((T)1U << n) - 1);
}
@@ -55,7 +55,7 @@ debug_inline constexpr static uint GB(const T x, const uint8 s, const uint8 n)
* @return The new value of \a x
*/
template <typename T, typename U>
static inline T SB(T &x, const uint8 s, const uint8 n, const U d)
static inline T SB(T &x, const uint8_t s, const uint8_t n, const U d)
{
x &= (T)(~((((T)1U << n) - 1) << s));
x |= (T)(d << s);
@@ -80,7 +80,7 @@ static inline T SB(T &x, const uint8 s, const uint8 n, const U d)
* @return The new value of \a x
*/
template <typename T, typename U>
static inline T AB(T &x, const uint8 s, const uint8 n, const U i)
static inline T AB(T &x, const uint8_t s, const uint8_t n, const U i)
{
const T mask = ((((T)1U << n) - 1) << s);
x = (T)((x & ~mask) | ((x + (i << s)) & mask));
@@ -100,7 +100,7 @@ static inline T AB(T &x, const uint8 s, const uint8 n, const U i)
* @return True if the bit is set, false else.
*/
template <typename T>
debug_inline static bool HasBit(const T x, const uint8 y)
debug_inline static bool HasBit(const T x, const uint8_t y)
{
return (x & ((T)1U << y)) != 0;
}
@@ -118,7 +118,7 @@ debug_inline static bool HasBit(const T x, const uint8 y)
* @return The new value of the old value with the bit set
*/
template <typename T>
static inline T SetBit(T &x, const uint8 y)
static inline T SetBit(T &x, const uint8_t y)
{
return x = (T)(x | ((T)1U << y));
}
@@ -148,7 +148,7 @@ static inline T SetBit(T &x, const uint8 y)
* @return The new value of the old value with the bit cleared
*/
template <typename T>
static inline T ClrBit(T &x, const uint8 y)
static inline T ClrBit(T &x, const uint8_t y)
{
return x = (T)(x & ~((T)1U << y));
}
@@ -178,14 +178,14 @@ static inline T ClrBit(T &x, const uint8 y)
* @return The new value of the old value with the bit toggled
*/
template <typename T>
static inline T ToggleBit(T &x, const uint8 y)
static inline T ToggleBit(T &x, const uint8_t y)
{
return x = (T)(x ^ ((T)1U << y));
}
/** Lookup table to check which bit is set in a 6 bit variable */
extern const uint8 _ffb_64[64];
extern const uint8_t _ffb_64[64];
/**
* Returns the first non-zero bit in a 6-bit value (from right).
@@ -213,7 +213,7 @@ extern const uint8 _ffb_64[64];
* @return The position of the first bit which is set
* @see FIND_FIRST_BIT
*/
static inline uint8 FindFirstBit2x64(const int value)
static inline uint8_t FindFirstBit2x64(const int value)
{
if ((value & 0xFF) == 0) {
return FIND_FIRST_BIT((value >> 8) & 0x3F) + 8;
@@ -222,8 +222,8 @@ static inline uint8 FindFirstBit2x64(const int value)
}
}
uint8 FindFirstBit(uint64 x);
uint8 FindLastBit(uint64 x);
uint8_t FindFirstBit(uint64_t x);
uint8_t FindLastBit(uint64_t x);
/**
* Clear the first bit in an integer.
@@ -298,7 +298,7 @@ static inline bool HasAtMostOneBit(T value)
* @return A bit rotated number
*/
template <typename T>
static inline T ROL(const T x, const uint8 n)
static inline T ROL(const T x, const uint8_t n)
{
if (n == 0) return x;
return (T)(x << n | x >> (sizeof(x) * 8 - n));
@@ -314,7 +314,7 @@ static inline T ROL(const T x, const uint8 n)
* @return A bit rotated number
*/
template <typename T>
static inline T ROR(const T x, const uint8 n)
static inline T ROR(const T x, const uint8_t n)
{
if (n == 0) return x;
return (T)(x >> n | x << (sizeof(x) * 8 - n));
@@ -373,10 +373,10 @@ private:
#if defined(__APPLE__)
/* Make endian swapping use Apple's macros to increase speed
* (since it will use hardware swapping if available).
* Even though they should return uint16 and uint32, we get
* Even though they should return uint16_t and uint32_t, we get
* warnings if we don't cast those (why?) */
# define BSWAP32(x) (static_cast<uint32>(CFSwapInt32(x)))
# define BSWAP16(x) (static_cast<uint16>(CFSwapInt16(x)))
# define BSWAP32(x) (static_cast<uint32_t>(CFSwapInt32(x)))
# define BSWAP16(x) (static_cast<uint16_t>(CFSwapInt16(x)))
#elif defined(_MSC_VER)
/* MSVC has intrinsics for swapping, resulting in faster code */
# define BSWAP32(x) (_byteswap_ulong(x))
@@ -387,11 +387,11 @@ private:
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint32 BSWAP32(uint32 x)
static inline uint32_t BSWAP32(uint32_t x)
{
#if !defined(__ICC) && defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ >= 3))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return static_cast<uint32>(__builtin_bswap32(static_cast<int32>(x)));
return static_cast<uint32_t>(__builtin_bswap32(static_cast<int32_t>(x)));
#else
return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
#endif /* defined(__GNUC__) */
@@ -402,7 +402,7 @@ private:
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint16 BSWAP16(uint16 x)
static inline uint16_t BSWAP16(uint16_t x)
{
return (x >> 8) | (x << 8);
}

View File

@@ -38,17 +38,17 @@
# define TO_LE32X(x) (x)
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
static inline uint16 ReadLE16Aligned(const void *x)
static inline uint16_t ReadLE16Aligned(const void *x)
{
return FROM_LE16(*(const uint16*)x);
return FROM_LE16(*(const uint16_t*)x);
}
static inline uint16 ReadLE16Unaligned(const void *x)
static inline uint16_t ReadLE16Unaligned(const void *x)
{
#if OTTD_ALIGNMENT == 1
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
#else
return FROM_LE16(*(const uint16*)x);
return FROM_LE16(*(const uint16_t*)x);
#endif /* OTTD_ALIGNMENT == 1 */
}

View File

@@ -45,10 +45,10 @@ struct Dimension {
/** Padding dimensions to apply to each side of a Rect. */
struct RectPadding {
uint8 left;
uint8 top;
uint8 right;
uint8 bottom;
uint8_t left;
uint8_t top;
uint8_t right;
uint8_t bottom;
static const RectPadding zero;

View File

@@ -74,10 +74,10 @@ int DivideApprox(int a, int b)
* @return Rounded integer square root.
* @note Algorithm taken from http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
*/
uint32 IntSqrt(uint32 num)
uint32_t IntSqrt(uint32_t num)
{
uint32 res = 0;
uint32 bit = 1UL << 30; // Second to top bit number.
uint32_t res = 0;
uint32_t bit = 1UL << 30; // Second to top bit number.
/* 'bit' starts at the highest power of four <= the argument. */
while (bit > num) bit >>= 2;

View File

@@ -355,6 +355,6 @@ static inline int DivAwayFromZero(int a, uint b)
}
}
uint32 IntSqrt(uint32 num);
uint32_t IntSqrt(uint32_t num);
#endif /* MATH_FUNC_HPP */

View File

@@ -93,11 +93,11 @@ public:
/* Operators for addition and subtraction. */
inline constexpr OverflowSafeInt operator + (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result += other; return result; }
inline constexpr OverflowSafeInt operator + (const int other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
inline constexpr OverflowSafeInt operator + (const uint other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
inline constexpr OverflowSafeInt operator + (const int other) const { OverflowSafeInt result = *this; result += (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator + (const uint other) const { OverflowSafeInt result = *this; result += (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator - (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result -= other; return result; }
inline constexpr OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
inline constexpr OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
inline constexpr OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64_t)other; return result; }
inline constexpr OverflowSafeInt& operator ++ () { return *this += 1; }
inline constexpr OverflowSafeInt& operator -- () { return *this += -1; }
@@ -136,14 +136,14 @@ public:
}
/* Operators for multiplication. */
inline constexpr OverflowSafeInt operator * (const int64 factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
inline constexpr OverflowSafeInt operator * (const int factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint16 factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const int64_t factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
inline constexpr OverflowSafeInt operator * (const int factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint16_t factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
/* Operators for division. */
inline constexpr OverflowSafeInt& operator /= (const int64 divisor) { this->m_value /= divisor; return *this; }
inline constexpr OverflowSafeInt& operator /= (const int64_t divisor) { this->m_value /= divisor; return *this; }
inline constexpr OverflowSafeInt operator / (const OverflowSafeInt& divisor) const { OverflowSafeInt result = *this; result /= divisor.m_value; return result; }
inline constexpr OverflowSafeInt operator / (const int divisor) const { OverflowSafeInt result = *this; result /= divisor; return result; }
inline constexpr OverflowSafeInt operator / (const uint divisor) const { OverflowSafeInt result = *this; result /= (int)divisor; return result; }
@@ -181,11 +181,11 @@ public:
};
/* Sometimes we got int64 operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int64 a, const OverflowSafeInt<T> b) { return b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator - (const int64 a, const OverflowSafeInt<T> b) { return -b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator * (const int64 a, const OverflowSafeInt<T> b) { return b * a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const int64 a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
/* Sometimes we got int64_t operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int64_t a, const OverflowSafeInt<T> b) { return b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator - (const int64_t a, const OverflowSafeInt<T> b) { return -b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator * (const int64_t a, const OverflowSafeInt<T> b) { return b * a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const int64_t a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
/* Sometimes we got int operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int a, const OverflowSafeInt<T> b) { return b + a; }
@@ -205,8 +205,8 @@ template <class T> inline constexpr OverflowSafeInt<T> operator - (const byte a
template <class T> inline constexpr OverflowSafeInt<T> operator * (const byte a, const OverflowSafeInt<T> b) { return b * (uint)a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const byte a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
typedef OverflowSafeInt<int64> OverflowSafeInt64;
typedef OverflowSafeInt<int32> OverflowSafeInt32;
typedef OverflowSafeInt<int64_t> OverflowSafeInt64;
typedef OverflowSafeInt<int32_t> OverflowSafeInt32;
/* Some basic "unit tests". Also has the bonus of confirming that constexpr is working. */
static_assert(OverflowSafeInt32(INT32_MIN) - 1 == OverflowSafeInt32(INT32_MIN));

View File

@@ -79,7 +79,7 @@ private:
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
/* Ensure Tmax_size is within the bounds of Tindex. */
static_assert((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static_assert((uint64_t)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static constexpr size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside

View File

@@ -28,10 +28,10 @@ Randomizer _random, _interactive_random;
* Generate the next pseudo random number
* @return the random number
*/
uint32 Randomizer::Next()
uint32_t Randomizer::Next()
{
const uint32 s = this->state[0];
const uint32 t = this->state[1];
const uint32_t s = this->state[0];
const uint32_t t = this->state[1];
this->state[0] = s + ROR(t ^ 0x1234567F, 7) + 1;
return this->state[1] = ROR(s, 3) - 1;
@@ -43,16 +43,16 @@ uint32 Randomizer::Next()
* @param limit Limit of the range to be generated from.
* @return Random number in [0,\a limit)
*/
uint32 Randomizer::Next(uint32 limit)
uint32_t Randomizer::Next(uint32_t limit)
{
return ((uint64)this->Next() * (uint64)limit) >> 32;
return ((uint64_t)this->Next() * (uint64_t)limit) >> 32;
}
/**
* (Re)set the state of the random number generator.
* @param seed the new state
*/
void Randomizer::SetSeed(uint32 seed)
void Randomizer::SetSeed(uint32_t seed)
{
this->state[0] = seed;
this->state[1] = seed;
@@ -62,14 +62,14 @@ void Randomizer::SetSeed(uint32 seed)
* (Re)set the state of the random number generators.
* @param seed the new state
*/
void SetRandomSeed(uint32 seed)
void SetRandomSeed(uint32_t seed)
{
_random.SetSeed(seed);
_interactive_random.SetSeed(seed * 0x1234567);
}
#ifdef RANDOM_DEBUG
uint32 DoRandom(int line, const char *file)
uint32_t DoRandom(int line, const char *file)
{
if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) {
Debug(random, 0, "{:08x}; {:02x}; {:04x}; {:02x}; {}:{}", TimerGameCalendar::date, TimerGameCalendar::date_fract, _frame_counter, (byte)_current_company, file, line);
@@ -78,8 +78,8 @@ uint32 DoRandom(int line, const char *file)
return _random.Next();
}
uint32 DoRandomRange(uint32 limit, int line, const char *file)
uint32_t DoRandomRange(uint32_t limit, int line, const char *file)
{
return ((uint64)DoRandom(line, file) * (uint64)limit) >> 32;
return ((uint64_t)DoRandom(line, file) * (uint64_t)limit) >> 32;
}
#endif /* RANDOM_DEBUG */

View File

@@ -20,11 +20,11 @@
*/
struct Randomizer {
/** The state of the randomizer */
uint32 state[2];
uint32_t state[2];
uint32 Next();
uint32 Next(uint32 limit);
void SetSeed(uint32 seed);
uint32_t Next();
uint32_t Next(uint32_t limit);
void SetSeed(uint32_t seed);
};
extern Randomizer _random; ///< Random used in the game state calculations
extern Randomizer _interactive_random; ///< Random used everywhere else, where it does not (directly) influence the game state
@@ -55,18 +55,18 @@ static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
_interactive_random = storage.interactive_random;
}
void SetRandomSeed(uint32 seed);
void SetRandomSeed(uint32_t seed);
#ifdef RANDOM_DEBUG
# ifdef __APPLE__
# define OTTD_Random() DoRandom(__LINE__, __FILE__)
# else
# define Random() DoRandom(__LINE__, __FILE__)
# endif
uint32 DoRandom(int line, const char *file);
uint32_t DoRandom(int line, const char *file);
# define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
uint32 DoRandomRange(uint32 limit, int line, const char *file);
uint32_t DoRandomRange(uint32_t limit, int line, const char *file);
#else
static inline uint32 Random()
static inline uint32_t Random()
{
return _random.Next();
}
@@ -78,18 +78,18 @@ void SetRandomSeed(uint32 seed);
* @param limit Limit for the range to be picked from.
* @return A random number in [0,\a limit).
*/
static inline uint32 RandomRange(uint32 limit)
static inline uint32_t RandomRange(uint32_t limit)
{
return _random.Next(limit);
}
#endif
static inline uint32 InteractiveRandom()
static inline uint32_t InteractiveRandom()
{
return _interactive_random.Next();
}
static inline uint32 InteractiveRandomRange(uint32 limit)
static inline uint32_t InteractiveRandomRange(uint32_t limit)
{
return _interactive_random.Next(limit);
}
@@ -109,10 +109,10 @@ static inline uint32 InteractiveRandomRange(uint32 limit)
* @param r The given randomize-number
* @return True if the probability given by r is less or equal to (a/b)
*/
static inline bool Chance16I(const uint a, const uint b, const uint32 r)
static inline bool Chance16I(const uint a, const uint b, const uint32_t r)
{
assert(b != 0);
return (((uint16)r * b + b / 2) >> 16) < a;
return (((uint16_t)r * b + b / 2) >> 16) < a;
}
/**
@@ -152,7 +152,7 @@ static inline bool Chance16(const uint a, const uint b)
#ifdef RANDOM_DEBUG
# define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
#else
static inline bool Chance16R(const uint a, const uint b, uint32 &r)
static inline bool Chance16R(const uint a, const uint b, uint32_t &r)
{
r = Random();
return Chance16I(a, b, r);