From 2d2dde8147aa5574a1149763d8bc36a59eeac5c5 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 25 Nov 2019 11:25:11 -0800 Subject: [PATCH 1/2] auto intellisense --- cppwinrt/code_writers.h | 11 +++++++---- strings/base_macros.h | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 2efef96ec..c6449d5d2 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -916,8 +916,9 @@ namespace cppwinrt auto method_name = get_name(method); auto type = method.Parent(); - w.write(" %auto %(%) const%;\n", + w.write(" %WINRT_IMPL_AUTO(%) %(%) const%;\n", is_get_overload(method) ? "[[nodiscard]] " : "", + signature.return_signature(), method_name, bind(signature), is_noexcept(method) ? " noexcept" : ""); @@ -1054,7 +1055,7 @@ namespace cppwinrt if (is_noexcept(method)) { - format = R"( template auto consume_%::%(%) const noexcept + format = R"( template WINRT_IMPL_AUTO(%) consume_%::%(%) const noexcept {% WINRT_VERIFY_(0, WINRT_IMPL_SHIM(%)->%(%));% } @@ -1062,7 +1063,7 @@ namespace cppwinrt } else { - format = R"( template auto consume_%::%(%) const + format = R"( template WINRT_IMPL_AUTO(%) consume_%::%(%) const {% check_hresult(WINRT_IMPL_SHIM(%)->%(%));% } @@ -1071,6 +1072,7 @@ namespace cppwinrt w.write(format, bind(generics), + signature.return_signature(), type_impl_name, bind(generics), method_name, @@ -1118,13 +1120,14 @@ namespace cppwinrt // return static_cast<% const&>(*this).%(%); // - std::string_view format = R"( inline auto %::%(%) const% + std::string_view format = R"( inline WINRT_IMPL_AUTO(%) %::%(%) const% { return [&](% const& winrt_impl_base) { return winrt_impl_base.%(%); }(*this); } )"; w.write(format, + signature.return_signature(), class_type.TypeName(), method_name, bind(signature), diff --git a/strings/base_macros.h b/strings/base_macros.h index 5ee85b070..c54ed4014 100644 --- a/strings/base_macros.h +++ b/strings/base_macros.h @@ -15,6 +15,12 @@ #define WINRT_IMPL_SHIM(...) (*(abi_t<__VA_ARGS__>**)&static_cast<__VA_ARGS__ const&>(static_cast(*this))) +#ifdef __INTELLISENSE__ +#define WINRT_IMPL_AUTO(...) __VA_ARGS__ +#else +#define WINRT_IMPL_AUTO(...) auto +#endif + // Note: this is a workaround for a false-positive warning produced by the Visual C++ 15.9 compiler. #pragma warning(disable : 5046) From 28c8ec31019049b853d3a1418b440609e51f11d8 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 27 Nov 2019 12:09:38 -0800 Subject: [PATCH 2/2] workarounds --- cppwinrt/code_writers.h | 4 +- strings/base_foundation.h | 20 +++--- strings/base_identity.h | 86 ++++++++++++------------- test/old_tests/UnitTests/IReference.cpp | 17 ----- 4 files changed, 55 insertions(+), 72 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index c6449d5d2..968724dfa 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -366,14 +366,14 @@ namespace cppwinrt if (empty(generics)) { - auto format = R"( template <> inline constexpr auto& name_v<%>{ L"%.%" }; + auto format = R"( template <> inline constexpr auto& name_v<%> = L"%.%"; )"; w.write(format, type, type_name.name_space, type_name.name); } else { - auto format = R"( template <%> inline constexpr auto name_v<%>{ zcombine(L"%.%<"%, L">") }; + auto format = R"( template <%> inline constexpr auto name_v<%> = zcombine(L"%.%<"%, L">"); )"; w.write(format, diff --git a/strings/base_foundation.h b/strings/base_foundation.h index 26d6f8d18..ea8881edc 100644 --- a/strings/base_foundation.h +++ b/strings/base_foundation.h @@ -102,9 +102,9 @@ WINRT_EXPORT namespace winrt::Windows::Foundation namespace winrt::impl { - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Point" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Size" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Rect" }; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Point"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Size"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Rect"; template <> struct category { @@ -123,13 +123,13 @@ namespace winrt::impl #ifdef WINRT_IMPL_NUMERICS - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Vector2" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Vector3" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Vector4" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Matrix3x2" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Matrix4x4" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Quaternion" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.Numerics.Plane" }; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Vector2"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Vector3"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Vector4"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Matrix3x2"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Matrix4x4"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Quaternion"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.Numerics.Plane"; template <> struct category { diff --git a/strings/base_identity.h b/strings/base_identity.h index 69d50dae3..da7116335 100644 --- a/strings/base_identity.h +++ b/strings/base_identity.h @@ -271,12 +271,12 @@ namespace winrt::impl } template - constexpr std::array process_msg_block(std::array const& input, uint32_t start_pos, std::array const& intermediate_hash) noexcept + constexpr std::array process_msg_block(std::array const& input, size_t start_pos, std::array const& intermediate_hash) noexcept { uint32_t const K[4] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 }; std::array W = {}; - uint32_t t = 0; + size_t t = 0; uint32_t temp = 0; for (t = 0; t < 16; t++) @@ -357,13 +357,13 @@ namespace winrt::impl } template - constexpr std::array make_remaining([[maybe_unused]] std::array const& input, [[maybe_unused]] uint32_t start_pos, std::index_sequence) noexcept + constexpr std::array make_remaining([[maybe_unused]] std::array const& input, [[maybe_unused]] size_t start_pos, std::index_sequence) noexcept { return { input[Index + start_pos]..., 0x80 }; } template - constexpr auto make_remaining(std::array const& input, uint32_t start_pos) noexcept + constexpr auto make_remaining(std::array const& input, size_t start_pos) noexcept { constexpr auto remaining_size = Size % 64; return make_remaining(input, start_pos, std::make_index_sequence()); @@ -409,7 +409,7 @@ namespace winrt::impl constexpr auto calculate_sha1(std::array const& input) noexcept { std::array intermediate_hash{ 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; - uint32_t i = 0; + size_t i = 0; while (i + 64 <= Size) { @@ -536,44 +536,44 @@ namespace winrt::impl constexpr guid generic_guid_v{}; template - constexpr auto& basic_signature_v{""}; - - template <> inline constexpr auto& basic_signature_v{"b1"}; - template <> inline constexpr auto& basic_signature_v{"i1"}; - template <> inline constexpr auto& basic_signature_v{"i2"}; - template <> inline constexpr auto& basic_signature_v{"i4"}; - template <> inline constexpr auto& basic_signature_v{"i8"}; - template <> inline constexpr auto& basic_signature_v{"u1"}; - template <> inline constexpr auto& basic_signature_v{"u2"}; - template <> inline constexpr auto& basic_signature_v{"u4"}; - template <> inline constexpr auto& basic_signature_v{"u8"}; - template <> inline constexpr auto& basic_signature_v{"f4"}; - template <> inline constexpr auto& basic_signature_v{"f8"}; - template <> inline constexpr auto& basic_signature_v{"c2"}; - template <> inline constexpr auto& basic_signature_v{"g16"}; - template <> inline constexpr auto& basic_signature_v{"string"}; - template <> inline constexpr auto& basic_signature_v{"cinterface(IInspectable)"}; - - template <> inline constexpr auto& name_v{ L"Boolean" }; - template <> inline constexpr auto& name_v{ L"Int8" }; - template <> inline constexpr auto& name_v{ L"Int16" }; - template <> inline constexpr auto& name_v{ L"Int32" }; - template <> inline constexpr auto& name_v{ L"Int64" }; - template <> inline constexpr auto& name_v{ L"UInt8" }; - template <> inline constexpr auto& name_v{ L"UInt16" }; - template <> inline constexpr auto& name_v{ L"UInt32" }; - template <> inline constexpr auto& name_v{ L"UInt64" }; - template <> inline constexpr auto& name_v{ L"Single" }; - template <> inline constexpr auto& name_v{ L"Double" }; - template <> inline constexpr auto& name_v{ L"Char16" }; - template <> inline constexpr auto& name_v{ L"Guid" }; - template <> inline constexpr auto& name_v{ L"String" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.HResult" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.EventRegistrationToken" }; - template <> inline constexpr auto& name_v{ L"Object" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.TimeSpan" }; - template <> inline constexpr auto& name_v{ L"Windows.Foundation.DateTime" }; - template <> inline constexpr auto& name_v{ L"IAgileObject" }; + constexpr auto& basic_signature_v = ""; + + template <> inline constexpr auto& basic_signature_v = "b1"; + template <> inline constexpr auto& basic_signature_v = "i1"; + template <> inline constexpr auto& basic_signature_v = "i2"; + template <> inline constexpr auto& basic_signature_v = "i4"; + template <> inline constexpr auto& basic_signature_v = "i8"; + template <> inline constexpr auto& basic_signature_v = "u1"; + template <> inline constexpr auto& basic_signature_v = "u2"; + template <> inline constexpr auto& basic_signature_v = "u4"; + template <> inline constexpr auto& basic_signature_v = "u8"; + template <> inline constexpr auto& basic_signature_v = "f4"; + template <> inline constexpr auto& basic_signature_v = "f8"; + template <> inline constexpr auto& basic_signature_v = "c2"; + template <> inline constexpr auto& basic_signature_v = "g16"; + template <> inline constexpr auto& basic_signature_v = "string"; + template <> inline constexpr auto& basic_signature_v = "cinterface(IInspectable)"; + + template <> inline constexpr auto& name_v = L"Boolean"; + template <> inline constexpr auto& name_v = L"Int8"; + template <> inline constexpr auto& name_v = L"Int16"; + template <> inline constexpr auto& name_v = L"Int32"; + template <> inline constexpr auto& name_v = L"Int64"; + template <> inline constexpr auto& name_v = L"UInt8"; + template <> inline constexpr auto& name_v = L"UInt16"; + template <> inline constexpr auto& name_v = L"UInt32"; + template <> inline constexpr auto& name_v = L"UInt64"; + template <> inline constexpr auto& name_v = L"Single"; + template <> inline constexpr auto& name_v = L"Double"; + template <> inline constexpr auto& name_v = L"Char16"; + template <> inline constexpr auto& name_v = L"Guid"; + template <> inline constexpr auto& name_v = L"String"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.HResult"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.EventRegistrationToken"; + template <> inline constexpr auto& name_v = L"Object"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.TimeSpan"; + template <> inline constexpr auto& name_v = L"Windows.Foundation.DateTime"; + template <> inline constexpr auto& name_v = L"IAgileObject"; template <> struct category { using type = basic_category; }; template <> struct category { using type = basic_category; }; diff --git a/test/old_tests/UnitTests/IReference.cpp b/test/old_tests/UnitTests/IReference.cpp index dfff6ae91..50a349f89 100644 --- a/test/old_tests/UnitTests/IReference.cpp +++ b/test/old_tests/UnitTests/IReference.cpp @@ -30,23 +30,6 @@ TEST_CASE("IReference guids") REQUIRE(guid_of>() == ireference_matrix4x4); REQUIRE(guid_of>() == ireference_plane); REQUIRE(guid_of>() == ireference_quaternion); - - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference))); - - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::Point>))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::Rect>))); - - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::DateTime>))); - REQUIRE(guid_of>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::TimeSpan>))); } TEST_CASE("IReference, constructor and getter")