From 7788561096bb88d46653b966e080b6479ee69dbd Mon Sep 17 00:00:00 2001 From: OEOTYAN Date: Mon, 19 Aug 2024 16:00:27 +0800 Subject: [PATCH] refactor: replace msvc literal extends --- src-client/ll/core/gui/ImGuiAnsiColor.cpp | 18 +++++----- src-test/server/TestMolang.cpp | 4 +-- src-test/server/TestNbt.cpp | 16 ++++----- .../customWorldGenerator/MyWorldGenerator.cpp | 36 +++++++++---------- src/ll/api/io/Pipe_win.cpp | 7 ++-- src/ll/api/io/StdoutRedirector_win.cpp | 4 +-- src/ll/api/memory/Closure.h | 2 +- src/ll/api/utils/ErrorUtils.h | 2 +- src/ll/api/utils/HashUtils.h | 2 +- src/ll/core/CrashLogger_win.cpp | 2 +- src/ll/core/tweak/MemoryOperators_win.cpp | 4 +-- src/mc/deps/core/string/HashedString.h | 4 +-- 12 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src-client/ll/core/gui/ImGuiAnsiColor.cpp b/src-client/ll/core/gui/ImGuiAnsiColor.cpp index 51453dc011..e4779cf006 100644 --- a/src-client/ll/core/gui/ImGuiAnsiColor.cpp +++ b/src-client/ll/core/gui/ImGuiAnsiColor.cpp @@ -159,7 +159,7 @@ void ImFont_RenderAnsiText( const float scale = size / font->FontSize; const float line_height = font->FontSize * scale; const bool word_wrap_enabled = (wrap_width > 0.0f); - const char* word_wrap_eol = NULL; + const char* word_wrap_eol = nullptr; // Fast-forward to first visible line const char* s = text_begin; @@ -239,7 +239,7 @@ void ImFont_RenderAnsiText( if (s >= word_wrap_eol) { x = pos.x; y += line_height; - word_wrap_eol = NULL; + word_wrap_eol = nullptr; // Wrapping skips upcoming blanks while (s < text_end) { @@ -378,17 +378,17 @@ void ImDrawList_AddAnsiText( const ImVec2& pos, ImU32 col, const char* text_begin, - const char* text_end = NULL, + const char* text_end = nullptr, float wrap_width = 0.0f, - const ImVec4* cpu_fine_clip_rect = NULL + const ImVec4* cpu_fine_clip_rect = nullptr ) { if ((col & IM_COL32_A_MASK) == 0) return; - if (text_end == NULL) text_end = text_begin + strlen(text_begin); + if (text_end == nullptr) text_end = text_begin + strlen(text_begin); if (text_begin == text_end) return; // Pull default font/size from the shared ImDrawListSharedData instance - if (font == NULL) font = drawList->_Data->Font; + if (font == nullptr) font = drawList->_Data->Font; if (font_size == 0.0f) font_size = drawList->_Data->FontSize; IM_ASSERT(font->ContainerAtlas->TexID == drawList->_TextureIdStack.back()); // Use high-level ImGui::PushFont() @@ -413,7 +413,7 @@ void ImDrawList_AddAnsiText( text_begin, text_end, wrap_width, - cpu_fine_clip_rect != NULL + cpu_fine_clip_rect != nullptr ); } @@ -470,9 +470,9 @@ void textAnsiUnformatted(const char* text, const char* text_end) { if (window->SkipItems) return; ImGuiContext& g = *GImGui; - IM_ASSERT(text != NULL); + IM_ASSERT(text != nullptr); const char* text_begin = text; - if (text_end == NULL) text_end = text + strlen(text); // FIXME-OPT + if (text_end == nullptr) text_end = text + strlen(text); // FIXME-OPT const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); const float wrap_pos_x = window->DC.TextWrapPos; diff --git a/src-test/server/TestMolang.cpp b/src-test/server/TestMolang.cpp index c11636cbbb..e5ee3175de 100644 --- a/src-test/server/TestMolang.cpp +++ b/src-test/server/TestMolang.cpp @@ -33,7 +33,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK( MolangQueryFunctionReturnType::Bool, "default", 0, - ~0ui64, + ~0ull, {} ); ExpressionNode::registerQueryFunction( @@ -46,7 +46,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK( MolangQueryFunctionReturnType::Number, "default", 0, - ~0ui64, + ~0ull, {} ); auto parm = RenderParams(); diff --git a/src-test/server/TestNbt.cpp b/src-test/server/TestNbt.cpp index 8e63041366..bece2aea55 100644 --- a/src-test/server/TestNbt.cpp +++ b/src-test/server/TestNbt.cpp @@ -18,14 +18,14 @@ LL_AUTO_TYPE_INSTANCE_HOOK(NbtTest, HookPriority::Normal, ServerInstance, &Serve auto nbt = CompoundTag{ {"anull", nullptr }, {"string?", R"(streee _ _o-ix 我超, utf8 "\asfa%"*)##q)$\\"\Q34\\""'':)"_tag}, - {"1num", 1 }, - {"nums", 3i16 }, - {"byte", 127i8 }, + {"1num", 1 }, + {"nums", (int16)3 }, + {"byte", (int8)127 }, {"list", ListTag{5_b, ByteTag{true}, ByteTag{false}, -2_b} }, {"compound", CompoundTag{ {"float", 0.1f}, - {"long", 10000ui64}, + {"long", 10000ull}, {"double", 0.3}, {"sdouble", 1.0}, } }, @@ -38,9 +38,9 @@ LL_AUTO_TYPE_INSTANCE_HOOK(NbtTest, HookPriority::Normal, ServerInstance, &Serve nlohmann::json j{ - {"num", 1 }, - {"nums", 3i16 }, - {"byte", 127i8} + {"num", 1 }, + {"nums", (int16)3 }, + {"byte", (int8)127} }; j["some"]["new"]["json"] = 2; @@ -108,7 +108,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK(NbtTest, HookPriority::Normal, ServerInstance, &Serve "{}, at: \"{}\"", nbt2.error().message(), std::string_view{ - snbt2.data() + std::max(0i64, (int64)iter - 8i64), + snbt2.data() + std::max(0ll, (int64)iter - 8ll), snbt2.data() + std::min(snbt2.size() - 1, iter + 8) } ); diff --git a/src-test/server/customWorldGenerator/MyWorldGenerator.cpp b/src-test/server/customWorldGenerator/MyWorldGenerator.cpp index a16e9aca31..5815b0522e 100644 --- a/src-test/server/customWorldGenerator/MyWorldGenerator.cpp +++ b/src-test/server/customWorldGenerator/MyWorldGenerator.cpp @@ -327,7 +327,7 @@ // // v113.mRandom.mObject.mTest_OnlyUsedDeterministically = 0; // // Core::Random::_setSeed(&v113.mRandom.mObject, (unsigned int)v12); // // v113.mRandom.mThreadIdInitialized = 0; -// //*(_QWORD*)&v113.mRandom.mThreadId._Id = 0i64; +// //*(_QWORD*)&v113.mRandom.mThreadId._Id = 0ll; // // LODWORD(v12) = this->mLevel->getSeed(this->mLevel); // // Bedrock::Application::ThreadOwner::_assertSameThreadID(&v113.mRandom); // // Core::Random::_setSeed(&v113.mRandom.mObject, (unsigned int)v12); @@ -354,10 +354,10 @@ // // if (_TSS3 == -1) { // // if (label_305._Mypair._Myval2._Myres >= 0x10) v18 = // (std::string*)label_305._Mypair._Myval2._Bx._Ptr; -// // v91._Mypair._Myval2._Bx._Ptr = 0i64; -// // v91._Mypair._Myval2._Mysize = 0i64; -// // v91._Mypair._Myval2._Myres = 15i64; -// // v25 = -1i64; +// // v91._Mypair._Myval2._Bx._Ptr = 0ll; +// // v91._Mypair._Myval2._Mysize = 0ll; +// // v91._Mypair._Myval2._Myres = 15ll; +// // v25 = -1ll; // // do ++v25; // // while (Core::Profile::Area::CHUNK_LOAD_SYSTEM_2[v25]); // // std::string::assign(&v91, "Chunk load system", v25); @@ -405,7 +405,7 @@ // // v22 = 44 * (spikes._Mypair._Myval2._Myend - Myfirst); // // v23 = Myfirst; // // if (v22 >= 0x1000) { -// // v22 += 39i64; +// // v22 += 39ll; // // Myfirst = *(SpikeFeature::EndSpike**)&Myfirst[-1].mTopBoundingBox.max.y; // // if ((unsigned __int64)((char*)v23 - (char*)Myfirst - 8) > 0x1F) // _invalid_parameter_noinfo_noreturn(); @@ -431,10 +431,10 @@ // // if (_TSS6 == -1) { // // if (label_323._Mypair._Myval2._Myres >= 0x10) // // v27 = (std::string*)label_323._Mypair._Myval2._Bx._Ptr; -// // v92._Mypair._Myval2._Bx._Ptr = 0i64; -// // v92._Mypair._Myval2._Mysize = 0i64; -// // v92._Mypair._Myval2._Myres = 15i64; -// // v31 = -1i64; +// // v92._Mypair._Myval2._Bx._Ptr = 0ll; +// // v92._Mypair._Myval2._Mysize = 0ll; +// // v92._Mypair._Myval2._Myres = 15ll; +// // v31 = -1ll; // // do ++v31; // // while (Core::Profile::Area::CHUNK_LOAD_SYSTEM_2[v31]); // // std::string::assign(&v92, "Chunk load system", v31); @@ -471,7 +471,7 @@ // // featurePlacement.y = v29 + origin.y; // // featurePlacement.z = (v30 & 0xF) + 8 + origin.z; // // memset(&endIslands, 0, sizeof(endIslands)); -// // Feature::Feature(&endIslands, 0i64); +// // Feature::Feature(&endIslands, 0ll); // // endIslands.__vftable = (EndIslandFeature_vtbl*)EndIslandFeature::`vftable'; // // EndIslandFeature::place( // // &endIslands, @@ -501,10 +501,10 @@ // // if (_TSS8 == -1) { // // if (label_338._Mypair._Myval2._Myres >= 0x10) // // v32 = (std::string*)label_338._Mypair._Myval2._Bx._Ptr; -// // v93._Mypair._Myval2._Bx._Ptr = 0i64; -// // v93._Mypair._Myval2._Mysize = 0i64; -// // v93._Mypair._Myval2._Myres = 15i64; -// // v57 = -1i64; +// // v93._Mypair._Myval2._Bx._Ptr = 0ll; +// // v93._Mypair._Myval2._Mysize = 0ll; +// // v93._Mypair._Myval2._Myres = 15ll; +// // v57 = -1ll; // // do ++v57; // // while (Core::Profile::Area::CHUNK_LOAD_SYSTEM_2[v57]); // // std::string::assign(&v93, "Chunk load system", v57); @@ -549,7 +549,7 @@ // // v85.y = v38 + origin.y; // // v85.z = v36 + origin.z; // // v39 = BlockSource::getBlock(&source, &v85)->mLegacyBlock.ptr_; -// // if (!v39) gsl::details::terminate(0i64); +// // if (!v39) gsl::details::terminate(0ll); // // Hash = HashedString::getHash(&v39->mNameInfo.mFullName); // // if (Hash == HashedString::getHash(&VanillaBlockTypeIds::EndStone)) { // // target.x = v35 + origin.x; @@ -582,7 +582,7 @@ // // gatewayPos.y = v45 + v46 % 7 + 3 + origin.y; // // gatewayPos.z = v43 + origin.z; // // memset(&v89, 0, sizeof(v89)); -// // Feature::Feature(&v89, 0i64); +// // Feature::Feature(&v89, 0ll); // // v89.__vftable = (Feature_vtbl*)EndGatewayFeature::`vftable'; EndGatewayFeature::place( // // (EndGatewayFeature*)&v89, // // &source, @@ -960,7 +960,7 @@ // // void // prepareHeights(TheEndGenerator* this, BlockVolume* box, const ChunkPos* chunkPos, bool factorInBeardsAndShavers) { -// TheEndGenerator::_prepareHeights(this, box, chunkPos, factorInBeardsAndShavers, 0i64, 0); +// TheEndGenerator::_prepareHeights(this, box, chunkPos, factorInBeardsAndShavers, 0ll, 0); // } //}; // diff --git a/src/ll/api/io/Pipe_win.cpp b/src/ll/api/io/Pipe_win.cpp index db5c63839f..cc87a0bb1e 100644 --- a/src/ll/api/io/Pipe_win.cpp +++ b/src/ll/api/io/Pipe_win.cpp @@ -22,9 +22,10 @@ static void createWinPipe(HANDLE& hRead, HANDLE& hWrite, size_t size, bool nowai &attributes ); SECURITY_ATTRIBUTES attributes2 = {sizeof(SECURITY_ATTRIBUTES), 0, true}; - hWrite = ::CreateFile(pipeName.c_str(), GENERIC_WRITE, 0, &attributes2, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + hWrite = + ::CreateFile(pipeName.c_str(), GENERIC_WRITE, 0, &attributes2, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr); - ::ConnectNamedPipe(hRead, NULL); + ::ConnectNamedPipe(hRead, nullptr); } Pipe::Pipe(size_t size, bool nowait) { createWinPipe(hRead, hWrite, size, nowait); } @@ -39,7 +40,7 @@ std::string Pipe::read() { DWORD cbRead{0}; // Read from the pipe. - fSuccess = ReadFile(hRead, buf, sizeof(buf), &cbRead, NULL); + fSuccess = ReadFile(hRead, buf, sizeof(buf), &cbRead, nullptr); if (cbRead > 0) result.append(buf, cbRead); diff --git a/src/ll/api/io/StdoutRedirector_win.cpp b/src/ll/api/io/StdoutRedirector_win.cpp index fe79f211f6..7bdd07d86e 100644 --- a/src/ll/api/io/StdoutRedirector_win.cpp +++ b/src/ll/api/io/StdoutRedirector_win.cpp @@ -9,11 +9,11 @@ StdoutRedirector::StdoutRedirector(void* outputHandle, ProcessChannel channels) : outputHandle(outputHandle), m_channels(channels) { if (m_channels & StandardOutput) { - setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stdout, nullptr, _IONBF, 0); ::SetStdHandle(STD_OUTPUT_HANDLE, outputHandle); } if (m_channels & StandardError) { - setvbuf(stderr, NULL, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); ::SetStdHandle(STD_ERROR_HANDLE, outputHandle); } int fd = _open_osfhandle((intptr_t)outputHandle, _O_WRONLY | _O_U8TEXT); diff --git a/src/ll/api/memory/Closure.h b/src/ll/api/memory/Closure.h index 0bb964bf27..c6c1e81ab7 100644 --- a/src/ll/api/memory/Closure.h +++ b/src/ll/api/memory/Closure.h @@ -10,7 +10,7 @@ namespace ll::memory { namespace detail { -static constexpr size_t closureMagicNumber = 0x58ffffbffdffffafui64; +static constexpr size_t closureMagicNumber = 0x58ffffbffdffffafull; LLAPI size_t getVolatileOffset(void*); LLAPI void initNativeClosure(void* self, void* impl, size_t offset); diff --git a/src/ll/api/utils/ErrorUtils.h b/src/ll/api/utils/ErrorUtils.h index cf51fe8d7e..3f2949627c 100644 --- a/src/ll/api/utils/ErrorUtils.h +++ b/src/ll/api/utils/ErrorUtils.h @@ -48,7 +48,7 @@ LLNDAPI std::system_error getLastSystemError() noexcept; LLNDAPI std::exception_ptr createExceptionPtr(void*) noexcept; #ifdef __cpp_lib_stacktrace -LLNDAPI std::stacktrace stacktraceFromCurrentException(size_t skip = 0, size_t maxDepth = ~0ui64); +LLNDAPI std::stacktrace stacktraceFromCurrentException(size_t skip = 0, size_t maxDepth = ~0ull); #endif LLNDAPI std::string makeExceptionString(std::exception_ptr ePtr) noexcept; diff --git a/src/ll/api/utils/HashUtils.h b/src/ll/api/utils/HashUtils.h index 5881bbc740..2005024b15 100644 --- a/src/ll/api/utils/HashUtils.h +++ b/src/ll/api/utils/HashUtils.h @@ -11,7 +11,7 @@ namespace ll::inline utils::hash_utils { template constexpr void hashCombine(T const& v, size_t& seed) { - seed ^= v + 0x9e3779b9ULL + (seed << 6ULL) + (seed >> 2ULL); + seed ^= v + 0x9e3779b9ull + (seed << 6ull) + (seed >> 2ull); } [[nodiscard]] constexpr uint64 doHash(std::string_view x) { diff --git a/src/ll/core/CrashLogger_win.cpp b/src/ll/core/CrashLogger_win.cpp index 6c05136044..1cdbbfa900 100644 --- a/src/ll/core/CrashLogger_win.cpp +++ b/src/ll/core/CrashLogger_win.cpp @@ -21,7 +21,7 @@ #include "DbgHelp.h" namespace ll::inline utils::error_utils { -std::stacktrace stacktraceFromContext(optional_ref<_CONTEXT const> context, size_t skip = 0, size_t maxDepth = ~0ui64); +std::stacktrace stacktraceFromContext(optional_ref<_CONTEXT const> context, size_t skip = 0, size_t maxDepth = ~0ull); } namespace ll { diff --git a/src/ll/core/tweak/MemoryOperators_win.cpp b/src/ll/core/tweak/MemoryOperators_win.cpp index c7cd4998ea..f5f379ad6b 100644 --- a/src/ll/core/tweak/MemoryOperators_win.cpp +++ b/src/ll/core/tweak/MemoryOperators_win.cpp @@ -84,7 +84,7 @@ class StdMemoryAllocator : public ::Bedrock::Memory::IMemoryAllocator { virtual void alignedRelease(void* ptr) { _aligned_free(ptr); } - virtual uint64 getUsableSize(void* ptr) { return ptr ? _msize(ptr) : 0ui64; } + virtual uint64 getUsableSize(void* ptr) { return ptr ? _msize(ptr) : 0ull; } virtual void logCurrentState() { HEAP_SUMMARY summary{.cb = sizeof(HEAP_SUMMARY)}; @@ -125,7 +125,7 @@ class MimallocMemoryAllocatorWithCheck : public MimallocMemoryAllocator { if (mi_is_in_heap_region(ptr)) [[likely]] { return mi_usable_size(ptr); } else { - return ptr ? _msize(ptr) : 0ui64; + return ptr ? _msize(ptr) : 0ull; } } diff --git a/src/mc/deps/core/string/HashedString.h b/src/mc/deps/core/string/HashedString.h index 6c0b55594b..ebd63b1713 100644 --- a/src/mc/deps/core/string/HashedString.h +++ b/src/mc/deps/core/string/HashedString.h @@ -10,9 +10,9 @@ class HashedString { [[nodiscard]] constexpr static uint64 computeHash(std::string_view str) { if (str.empty()) return 0; - uint64 hash = 0xCBF29CE484222325ULL; + uint64 hash = 0xCBF29CE484222325ull; for (char s : str) { - hash = s ^ (0x100000001B3ULL * hash); + hash = s ^ (0x100000001B3ull * hash); } return hash; }