From ef5f1b07c6eba95e203915cce9133eaacd31540b Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 1 Feb 2021 00:33:12 +0200 Subject: [PATCH] Don't use fixed types. --- module/Library/Numeric/Long.cpp | 60 ++++++++++++++++----------------- module/Library/Numeric/Long.hpp | 26 +++++++------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/module/Library/Numeric/Long.cpp b/module/Library/Numeric/Long.cpp index ce39cfef..aaa40c00 100644 --- a/module/Library/Numeric/Long.cpp +++ b/module/Library/Numeric/Long.cpp @@ -15,28 +15,28 @@ SQMOD_DECL_TYPENAME(TypenameS, _SC("SLongInt")) SQMOD_DECL_TYPENAME(TypenameU, _SC("ULongInt")) // ------------------------------------------------------------------------------------------------ -LongInt< int64_t >::LongInt(const SQChar * text) +LongInt< signed long long >::LongInt(const SQChar * text) : m_Data(0), m_Text() { m_Data = std::strtoll(text, nullptr, 10); } // ------------------------------------------------------------------------------------------------ -LongInt< int64_t >::LongInt(const SQChar * text, uint32_t base) +LongInt< signed long long >::LongInt(const SQChar * text, uint32_t base) : m_Data(0), m_Text() { m_Data = std::strtoll(text, nullptr, base); } // ------------------------------------------------------------------------------------------------ -LongInt< int64_t > & LongInt< int64_t >::operator = (const SQChar * text) +LongInt< signed long long > & LongInt< signed long long >::operator = (const SQChar * text) { m_Data = std::strtoll(text, nullptr, 10); return *this; } // ------------------------------------------------------------------------------------------------ -const SQChar * LongInt< int64_t >::ToString() +const SQChar * LongInt< signed long long >::ToString() { if (std::snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0) { @@ -47,46 +47,46 @@ const SQChar * LongInt< int64_t >::ToString() } // ------------------------------------------------------------------------------------------------ -void LongInt< int64_t >::Random() +void LongInt< signed long long >::Random() { m_Data = GetRandomInt64(); } // ------------------------------------------------------------------------------------------------ -void LongInt< int64_t >::Random(Type n) +void LongInt< signed long long >::Random(Type n) { m_Data = GetRandomInt64(n); } // ------------------------------------------------------------------------------------------------ -void LongInt< int64_t >::Random(Type m, Type n) +void LongInt< signed long long >::Random(Type m, Type n) { m_Data = GetRandomInt64(m, n); } // ------------------------------------------------------------------------------------------------ -LongInt< uint64_t >::LongInt(const SQChar * text) +LongInt< unsigned long long >::LongInt(const SQChar * text) : m_Data(0), m_Text() { m_Data = std::strtoull(text, nullptr, 10); } // ------------------------------------------------------------------------------------------------ -LongInt< uint64_t >::LongInt(const SQChar * text, uint32_t base) +LongInt< unsigned long long >::LongInt(const SQChar * text, uint32_t base) : m_Data(0), m_Text() { m_Data = std::strtoull(text, nullptr, base); } // ------------------------------------------------------------------------------------------------ -LongInt< uint64_t > & LongInt< uint64_t >::operator = (const SQChar * text) +LongInt< unsigned long long > & LongInt< unsigned long long >::operator = (const SQChar * text) { m_Data = std::strtoull(text, nullptr, 10); return *this; } // ------------------------------------------------------------------------------------------------ -const SQChar * LongInt< uint64_t >::ToString() +const SQChar * LongInt< unsigned long long >::ToString() { if (std::snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0) { @@ -97,25 +97,25 @@ const SQChar * LongInt< uint64_t >::ToString() } // ------------------------------------------------------------------------------------------------ -void LongInt< uint64_t >::Random() +void LongInt< unsigned long long >::Random() { m_Data = GetRandomUint64(); } // ------------------------------------------------------------------------------------------------ -void LongInt< uint64_t >::Random(Type n) +void LongInt< unsigned long long >::Random(Type n) { m_Data = GetRandomUint64(n); } // ------------------------------------------------------------------------------------------------ -void LongInt< uint64_t >::Random(Type m, Type n) +void LongInt< unsigned long long >::Random(Type m, Type n) { m_Data = GetRandomUint64(m, n); } // ------------------------------------------------------------------------------------------------ -int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx) +signed long long PopStackSLong(HSQUIRRELVM vm, SQInteger idx) { // Identify which type must be extracted switch (sq_gettype(vm, idx)) @@ -124,19 +124,19 @@ int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx) { SQInteger val; sq_getinteger(vm, idx, &val); - return static_cast< int64_t >(val); + return static_cast< signed long long >(val); } case OT_FLOAT: { SQFloat val; sq_getfloat(vm, idx, &val); - return ConvTo< int64_t >::From(val); + return ConvTo< signed long long >::From(val); } case OT_BOOL: { SQBool val; sq_getbool(vm, idx, &val); - return static_cast< int64_t >(val); + return static_cast< signed long long >(val); } case OT_STRING: { @@ -152,7 +152,7 @@ int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx) case OT_CLASS: case OT_USERDATA: { - return static_cast< int64_t >(sq_getsize(vm, idx)); + return static_cast< signed long long >(sq_getsize(vm, idx)); } case OT_INSTANCE: { @@ -168,14 +168,14 @@ int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx) // Attempt to treat the value as a unsigned long instance try { - return ConvTo< int64_t >::From(Var< const ULongInt & >(vm, idx).value.GetNum()); + return ConvTo< signed long long >::From(Var< const ULongInt & >(vm, idx).value.GetNum()); } catch (...) { // Just ignore it... } // Attempt to get the size of the instance as a fall back - return static_cast< int64_t >(sq_getsize(vm, idx)); + return static_cast< signed long long >(sq_getsize(vm, idx)); } default: break; } @@ -184,7 +184,7 @@ int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx) } // ------------------------------------------------------------------------------------------------ -uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx) +unsigned long long PopStackULong(HSQUIRRELVM vm, SQInteger idx) { // Identify which type must be extracted switch (sq_gettype(vm, idx)) @@ -193,19 +193,19 @@ uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx) { SQInteger val; sq_getinteger(vm, idx, &val); - return ConvTo< uint64_t >::From(val); + return ConvTo< unsigned long long >::From(val); } case OT_FLOAT: { SQFloat val; sq_getfloat(vm, idx, &val); - return ConvTo< uint64_t >::From(val); + return ConvTo< unsigned long long >::From(val); } case OT_BOOL: { SQBool val; sq_getbool(vm, idx, &val); - return ConvTo< uint64_t >::From(val); + return ConvTo< unsigned long long >::From(val); } case OT_STRING: { @@ -221,14 +221,14 @@ uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx) case OT_CLASS: case OT_USERDATA: { - return ConvTo< uint64_t >::From(sq_getsize(vm, idx)); + return ConvTo< unsigned long long >::From(sq_getsize(vm, idx)); } case OT_INSTANCE: { // Attempt to treat the value as a signed long instance try { - return ConvTo< uint64_t >::From(Var< const SLongInt & >(vm, idx).value.GetNum()); + return ConvTo< unsigned long long >::From(Var< const SLongInt & >(vm, idx).value.GetNum()); } catch (...) { @@ -244,7 +244,7 @@ uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx) // Just ignore it... } // Attempt to get the size of the instance as a fall back - return ConvTo< uint64_t >::From(sq_getsize(vm, idx)); + return ConvTo< unsigned long long >::From(sq_getsize(vm, idx)); } default: break; } @@ -260,7 +260,7 @@ const SLongInt & GetSLongInt() return l; } -const SLongInt & GetSLongInt(int64_t n) +const SLongInt & GetSLongInt(signed long long n) { static SLongInt l; l.SetNum(n); @@ -281,7 +281,7 @@ const ULongInt & GetULongInt() return l; } -const ULongInt & GetULongInt(uint64_t n) +const ULongInt & GetULongInt(unsigned long long n) { static ULongInt l; l.SetNum(n); diff --git a/module/Library/Numeric/Long.hpp b/module/Library/Numeric/Long.hpp index e3d726f0..93502c5c 100644 --- a/module/Library/Numeric/Long.hpp +++ b/module/Library/Numeric/Long.hpp @@ -12,12 +12,12 @@ template < typename T > class LongInt; /* ------------------------------------------------------------------------------------------------ * Specialization of the Long int class for signed integers. */ -template <> class LongInt< int64_t > +template <> class LongInt< signed long long > { public: // -------------------------------------------------------------------------------------------- - typedef int64_t Type; // The specialized type. + typedef signed long long Type; // The specialized type. private: @@ -418,7 +418,7 @@ public: /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare an instance of this type with another one. */ - SQMOD_NODISCARD int32_t Cmp(const LongInt< uint64_t > & o) const; + SQMOD_NODISCARD int32_t Cmp(const LongInt< unsigned long long > & o) const; /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare an instance of this type with a scalar value. @@ -622,12 +622,12 @@ public: /* ------------------------------------------------------------------------------------------------ * Specialization of the Long int class for unsigned integers. */ -template <> class LongInt< uint64_t > +template <> class LongInt< unsigned long long > { public: // -------------------------------------------------------------------------------------------- - typedef uint64_t Type; // The specialized type. + typedef unsigned long long Type; // The specialized type. private: @@ -1028,7 +1028,7 @@ public: /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare an instance of this type with another one. */ - SQMOD_NODISCARD int32_t Cmp(const LongInt< int64_t > & o) const + SQMOD_NODISCARD int32_t Cmp(const LongInt< signed long long > & o) const { const Type v = ConvTo< Type >::From(o.GetNum()); @@ -1246,7 +1246,7 @@ public: }; // ------------------------------------------------------------------------------------------------ -inline int32_t LongInt< int64_t >::Cmp(const LongInt< uint64_t > & o) const +inline int32_t LongInt< signed long long >::Cmp(const LongInt< unsigned long long > & o) const { const Type v = ConvTo< Type >::From(o.GetNum()); @@ -1265,27 +1265,27 @@ inline int32_t LongInt< int64_t >::Cmp(const LongInt< uint64_t > & o) const } // ------------------------------------------------------------------------------------------------ -typedef LongInt< int64_t > SLongInt; -typedef LongInt< uint64_t > ULongInt; +typedef LongInt< signed long long > SLongInt; +typedef LongInt< unsigned long long > ULongInt; /* ------------------------------------------------------------------------------------------------ * Attempt to pop the value at the specified index on the stack as a signed long integer. */ -int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx); +signed long long PopStackSLong(HSQUIRRELVM vm, SQInteger idx); /* ------------------------------------------------------------------------------------------------ * Attempt to pop the value at the specified index on the stack as an unsigned long integer. */ -uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx); +unsigned long long PopStackULong(HSQUIRRELVM vm, SQInteger idx); /* ------------------------------------------------------------------------------------------------ * Get a persistent LongInt instance with the given values. */ const SLongInt & GetSLongInt(); -const SLongInt & GetSLongInt(int64_t n); +const SLongInt & GetSLongInt(signed long long n); const SLongInt & GetSLongInt(const SQChar * s); const ULongInt & GetULongInt(); -const ULongInt & GetULongInt(uint64_t n); +const ULongInt & GetULongInt(unsigned long long n); const ULongInt & GetULongInt(const SQChar * s); } // Namespace:: SqMod