diff --git a/Generator/Sources/ProjectionModel/CAbi/CAbi+writing.swift b/Generator/Sources/ProjectionModel/CAbi/CAbi+writing.swift index 2faaa5a..726ac51 100644 --- a/Generator/Sources/ProjectionModel/CAbi/CAbi+writing.swift +++ b/Generator/Sources/ProjectionModel/CAbi/CAbi+writing.swift @@ -20,8 +20,9 @@ extension CAbi { } public static func writeEnumTypedef(_ enumDefinition: EnumDefinition, to writer: CSourceFileWriter) throws { - let mangledName = try CAbi.mangleName(type: enumDefinition.bindType()) - writer.writeTypedef(type: .reference(name: "int32_t"), name: mangledName) + try writer.writeTypedef( + type: .reference(name: enumDefinition.isFlags ? "uint32_t" : "int32_t"), + name: CAbi.mangleName(type: enumDefinition.bindType())) } public static func writeStruct(_ structDefinition: StructDefinition, to writer: CSourceFileWriter) throws { diff --git a/InteropTests/Tests/EnumTests.swift b/InteropTests/Tests/EnumTests.swift index 2cb0b66..36c2efe 100644 --- a/InteropTests/Tests/EnumTests.swift +++ b/InteropTests/Tests/EnumTests.swift @@ -16,4 +16,12 @@ class EnumTests: WinRTTestCase { XCTAssertEqual(Flags.bit16.rawValue, 0x10000) XCTAssertEqual(Flags.all.rawValue, 0xFFFFFFFF) } + + func testFlagsSetAlgebra() throws { + XCTAssert(try Enums.hasFlags(Flags.bit0.union(Flags.bit16), Flags.bit0)) + XCTAssert(try Enums.hasFlags(Flags.bit0.union(Flags.bit16), Flags.bit16)) + XCTAssert(try Enums.hasFlags(Flags.all.intersection(Flags.bit0), Flags.bit0)) + XCTAssertFalse(try Enums.hasFlags(Flags.all.intersection(Flags.bit0), Flags.bit16)) + XCTAssertFalse(try Enums.hasFlags(Flags.bit0, Flags.bit16)) + } } \ No newline at end of file diff --git a/InteropTests/WinRTComponent/Dll/Enums.cpp b/InteropTests/WinRTComponent/Dll/Enums.cpp new file mode 100644 index 0000000..5c6259e --- /dev/null +++ b/InteropTests/WinRTComponent/Dll/Enums.cpp @@ -0,0 +1,11 @@ +#include "pch.h" +#include "Enums.h" +#include "Enums.g.cpp" + +namespace winrt::WinRTComponent::implementation +{ + boolean Enums::HasFlags(Flags value, Flags flags) + { + return (value & flags) == flags; + } +} diff --git a/InteropTests/WinRTComponent/Dll/Enums.h b/InteropTests/WinRTComponent/Dll/Enums.h new file mode 100644 index 0000000..50fc080 --- /dev/null +++ b/InteropTests/WinRTComponent/Dll/Enums.h @@ -0,0 +1,18 @@ +#pragma once +#include "Enums.g.h" + +namespace winrt::WinRTComponent::implementation +{ + struct Enums + { + Enums() = default; + + static boolean HasFlags(Flags value, Flags flags); + }; +} +namespace winrt::WinRTComponent::factory_implementation +{ + struct Enums : EnumsT + { + }; +} diff --git a/InteropTests/WinRTComponent/IDL/Enums.idl b/InteropTests/WinRTComponent/IDL/Enums.idl index 6eb9daf..265eb43 100644 --- a/InteropTests/WinRTComponent/IDL/Enums.idl +++ b/InteropTests/WinRTComponent/IDL/Enums.idl @@ -15,4 +15,9 @@ namespace WinRTComponent Bit16 = 0x10000, All = 0xFFFFFFFF, }; + + static runtimeclass Enums + { + static Boolean HasFlags(Flags value, Flags flags); + }; } \ No newline at end of file