From 76d353487152f166fd04b7679e69113c2a2a63d2 Mon Sep 17 00:00:00 2001 From: Sabine Date: Fri, 3 Feb 2023 13:27:51 +0100 Subject: [PATCH] chore(developer): changes in UnrechableRules::VerifyUnreachableRules() to run test_6440_unreachable_code..kmn --- .../kmcmplib/src/CheckFilenameConsistency.cpp | 4 ++-- developer/src/kmcmplib/src/CompMsg.cpp | 3 ++- developer/src/kmcmplib/src/Compiler.cpp | 4 ++-- .../src/kmcmplib/src/UnreachableRules.cpp | 24 ++++++++++++++++--- developer/src/kmcmplib/src/kmcmpdll.h | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp b/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp index 7f3ddcacde..d1ae567a89 100644 --- a/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp +++ b/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp @@ -81,8 +81,8 @@ KMX_DWORD CheckFilenameConsistency(KMX_WCHAR const * Filename, bool ReportMissin } #if defined(_WIN32) || defined(_WIN64) - // convert char16_t to wchar_t* - // char16_t -> std::u16string + // convert char16_t* -> std::u16string -> std::string -> std::wstring -> wchar_t* + // char16_t* -> std::u16string std::u16string u16str(Name); // std::u16string -> std::string std::string stri = string_from_u16string(u16str); diff --git a/developer/src/kmcmplib/src/CompMsg.cpp b/developer/src/kmcmplib/src/CompMsg.cpp index c245881a4b..242fb4b5ed 100644 --- a/developer/src/kmcmplib/src/CompMsg.cpp +++ b/developer/src/kmcmplib/src/CompMsg.cpp @@ -110,7 +110,8 @@ const struct CompilerError CompilerErrors[] = { { CERR_DuplicateGroup , "A group with this name has already been defined."}, { CERR_DuplicateStore , "A store with this name has already been defined."}, { CERR_RepeatedBegin , "Begin has already been set"}, - { CHINT_FilenameHasDifferingCase , "HINT: Casing differences may fail on some platforms."}, + { CHINT_FilenameHasDifferingCase , "Casing differences may fail on some platforms."}, + { CHINT_UnreachableRule , "This rule will never be matched as another rule takes precedence"}, { 0, nullptr } }; diff --git a/developer/src/kmcmplib/src/Compiler.cpp b/developer/src/kmcmplib/src/Compiler.cpp index 056e88de95..a7a67bf216 100644 --- a/developer/src/kmcmplib/src/Compiler.cpp +++ b/developer/src/kmcmplib/src/Compiler.cpp @@ -66,12 +66,12 @@ */ #include "pch.h" -#include +#include "compfile.h" #include #include "../../../../common/windows/cpp/include/vkeys.h" #include #include -#include +#include "kmcmpdll.h" #include #include "virtualcharkeys.h" diff --git a/developer/src/kmcmplib/src/UnreachableRules.cpp b/developer/src/kmcmplib/src/UnreachableRules.cpp index f13a77d6a5..b209ffd185 100644 --- a/developer/src/kmcmplib/src/UnreachableRules.cpp +++ b/developer/src/kmcmplib/src/UnreachableRules.cpp @@ -1,10 +1,10 @@ #include "pch.h" -#include +#include "compfile.h" #include #include "../../../../common/windows/cpp/include/vkeys.h" -#include +#include "kmcmpdll.h" #include #include @@ -12,7 +12,25 @@ #include #include "UnreachableRules.h" + namespace kmcmp { + + WCHAR conv_KMX_WCHAR__TO__WCHAR(KMX_WCHAR in) { + // char16_t -> std::u16string -> std::string -> std::wstring -> wchar_t* + std::u16string u16str(&in); + std::string stri = string_from_u16string(u16str); + std::wstring wstr = wstring_from_string(stri); + return *wstring_from_string(stri).c_str(); + } + + std::wstring MakeHashKeyFromFileKey16(PFILE_KEY kp) { + std::wstringstream key16; + const WCHAR* ctxt = u16fmt((PKMX_WCHAR) kp->dpContext).c_str(); + key16 << conv_KMX_WCHAR__TO__WCHAR(kp->Key) << "," << (DWORD) kp->ShiftFlags << ","; + if (ctxt) key16 << ctxt; + return key16.str(); + }; + std::wstring MakeHashKeyFromFileKey(PFILE_KEY kp) { std::wstringstream key; key << kp->Key << "," << kp->ShiftFlags << ","; @@ -31,7 +49,7 @@ KMX_DWORD VerifyUnreachableRules(PFILE_GROUP gp) { std::unordered_set reportedLines; for (i = 0; i < gp->cxKeyArray; i++, kp++) { - std::wstring key = kmcmp::MakeHashKeyFromFileKey(kp); + std::wstring key = kmcmp::MakeHashKeyFromFileKey16(kp); if (map.count(key) > 0) { FILE_KEY const & k1 = map.at(key); if (kp->Line != k1.Line && reportedLines.count(kp->Line) == 0) { diff --git a/developer/src/kmcmplib/src/kmcmpdll.h b/developer/src/kmcmplib/src/kmcmpdll.h index 78f05abfcb..8a94f10ec7 100644 --- a/developer/src/kmcmplib/src/kmcmpdll.h +++ b/developer/src/kmcmplib/src/kmcmpdll.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "compfile.h" namespace kmcmp { KMX_BOOL AddCompileWarning(LPSTR buf);