Skip to content

Commit

Permalink
improves test case to add constructor as well
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbrix committed Dec 6, 2023
1 parent 2060f85 commit a1d1a7a
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 28 deletions.
3 changes: 2 additions & 1 deletion swiftwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ namespace swiftwinrt
auto full_names = w.push_full_type_names(true);

auto returnStatement = isInitializer ?
w.write_temp(" -> %", bind_type_abi(classType)) :
w.write_temp(" -> %", bind_type_abi(classType->default_interface)) :
w.write_temp("%", bind<write_return_type_declaration>(function, write_type_params::swift));

std::vector<function_param> params = composableFactory ? get_projected_params(factory_info.value(), function) : function.params;
Expand Down Expand Up @@ -455,6 +455,7 @@ bind<write_abi_args>(function));
w.write("}\n");
}


if (function.return_type && !isInitializer)
{
w.write("%\n", bind<write_consume_return_statement>(function));
Expand Down
14 changes: 11 additions & 3 deletions swiftwinrt/type_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,18 @@ namespace swiftwinrt
}
}
}
// In generics, don't use the ABI name or we get IVectorIBase instead of IVectorBase
else if (abi_types && !writing_generic)
else if (abi_types)
{
write(type->cpp_abi_name());
// In generics, don't use the ABI name or we get IVectorIBase instead of IVectorBase
if (!writing_generic)
{
write(type->cpp_abi_name());
}
else
{
// Otherwise, write the swift type name when writing a swift abi generic type
write(type->swift_type_name());
}
}
else if (type->swift_logical_namespace() != type_namespace || full_type_names)
{
Expand Down
42 changes: 23 additions & 19 deletions tests/test_component/Sources/CWinRT/include/test_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ typedef interface __x_ABI_Ctest__component_CIVoidToVoidDelegate __x_ABI_Ctest__c

#endif // ____x_ABI_Ctest__component_CIBase_FWD_DEFINED__

#ifndef ____x_ABI_Ctest__component_CIBaseCollectionFactory_FWD_DEFINED__
#define ____x_ABI_Ctest__component_CIBaseCollectionFactory_FWD_DEFINED__
typedef interface __x_ABI_Ctest__component_CIBaseCollectionFactory __x_ABI_Ctest__component_CIBaseCollectionFactory;
#ifndef ____x_ABI_Ctest__component_CIBaseCollectionProtectedFactory_FWD_DEFINED__
#define ____x_ABI_Ctest__component_CIBaseCollectionProtectedFactory_FWD_DEFINED__
typedef interface __x_ABI_Ctest__component_CIBaseCollectionProtectedFactory __x_ABI_Ctest__component_CIBaseCollectionProtectedFactory;

#endif // ____x_ABI_Ctest__component_CIBaseCollectionFactory_FWD_DEFINED__
#endif // ____x_ABI_Ctest__component_CIBaseCollectionProtectedFactory_FWD_DEFINED__

#ifndef ____x_ABI_Ctest__component_CIBaseNoOverrides_FWD_DEFINED__
#define ____x_ABI_Ctest__component_CIBaseNoOverrides_FWD_DEFINED__
Expand Down Expand Up @@ -2479,36 +2479,40 @@ struct __x_ABI_Ctest__component_CStructWithEnum
EXTERN_C const IID IID___x_ABI_Ctest__component_CIBase;
#endif /* !defined(____x_ABI_Ctest__component_CIBase_INTERFACE_DEFINED__) */

#if !defined(____x_ABI_Ctest__component_CIBaseCollectionFactory_INTERFACE_DEFINED__)
#define ____x_ABI_Ctest__component_CIBaseCollectionFactory_INTERFACE_DEFINED__
typedef struct __x_ABI_Ctest__component_CIBaseCollectionFactoryVtbl
#if !defined(____x_ABI_Ctest__component_CIBaseCollectionProtectedFactory_INTERFACE_DEFINED__)
#define ____x_ABI_Ctest__component_CIBaseCollectionProtectedFactory_INTERFACE_DEFINED__
typedef struct __x_ABI_Ctest__component_CIBaseCollectionProtectedFactoryVtbl
{
BEGIN_INTERFACE

HRESULT (STDMETHODCALLTYPE* QueryInterface)(__x_ABI_Ctest__component_CIBaseCollectionFactory* This,
HRESULT (STDMETHODCALLTYPE* QueryInterface)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This,
REFIID riid,
void** ppvObject);
ULONG (STDMETHODCALLTYPE* AddRef)(__x_ABI_Ctest__component_CIBaseCollectionFactory* This);
ULONG (STDMETHODCALLTYPE* Release)(__x_ABI_Ctest__component_CIBaseCollectionFactory* This);
HRESULT (STDMETHODCALLTYPE* GetIids)(__x_ABI_Ctest__component_CIBaseCollectionFactory* This,
ULONG (STDMETHODCALLTYPE* AddRef)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This);
ULONG (STDMETHODCALLTYPE* Release)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This);
HRESULT (STDMETHODCALLTYPE* GetIids)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This,
ULONG* iidCount,
IID** iids);
HRESULT (STDMETHODCALLTYPE* GetRuntimeClassName)(__x_ABI_Ctest__component_CIBaseCollectionFactory* This,
HRESULT (STDMETHODCALLTYPE* GetRuntimeClassName)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This,
HSTRING* className);
HRESULT (STDMETHODCALLTYPE* GetTrustLevel)(__x_ABI_Ctest__component_CIBaseCollectionFactory* This,
HRESULT (STDMETHODCALLTYPE* GetTrustLevel)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This,
TrustLevel* trustLevel);

HRESULT (STDMETHODCALLTYPE* CreateInstance)(__x_ABI_Ctest__component_CIBaseCollectionProtectedFactory* This,
IInspectable* baseInterface,
IInspectable** innerInterface,
__x_ABI_C__FIVector_1___x_ABI_Ctest__zcomponent__CBase** value);

END_INTERFACE
} __x_ABI_Ctest__component_CIBaseCollectionFactoryVtbl;
} __x_ABI_Ctest__component_CIBaseCollectionProtectedFactoryVtbl;

interface __x_ABI_Ctest__component_CIBaseCollectionFactory
interface __x_ABI_Ctest__component_CIBaseCollectionProtectedFactory
{
CONST_VTBL struct __x_ABI_Ctest__component_CIBaseCollectionFactoryVtbl* lpVtbl;
CONST_VTBL struct __x_ABI_Ctest__component_CIBaseCollectionProtectedFactoryVtbl* lpVtbl;
};


EXTERN_C const IID IID___x_ABI_Ctest__component_CIBaseCollectionFactory;
#endif /* !defined(____x_ABI_Ctest__component_CIBaseCollectionFactory_INTERFACE_DEFINED__) */
EXTERN_C const IID IID___x_ABI_Ctest__component_CIBaseCollectionProtectedFactory;
#endif /* !defined(____x_ABI_Ctest__component_CIBaseCollectionProtectedFactory_INTERFACE_DEFINED__) */

#if !defined(____x_ABI_Ctest__component_CIBaseNoOverrides_INTERFACE_DEFINED__)
#define ____x_ABI_Ctest__component_CIBaseNoOverrides_INTERFACE_DEFINED__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ private var IID___x_ABI_Ctest__component_CIBase: test_component.IID {
.init(Data1: 0xE9FE0BB2, Data2: 0xE1F6, Data3: 0x5E39, Data4: ( 0x92,0xBB,0x2F,0x19,0xFF,0xDE,0x3F,0xDC ))// E9FE0BB2-E1F6-5E39-92BB-2F19FFDE3FDC
}

private var IID___x_ABI_Ctest__component_CIBaseCollectionFactory: test_component.IID {
.init(Data1: 0xD6996627, Data2: 0x615A, Data3: 0x565D, Data4: ( 0x85,0xF2,0x04,0x69,0x6E,0xD2,0x88,0xD0 ))// D6996627-615A-565D-85F2-04696ED288D0
private var IID___x_ABI_Ctest__component_CIBaseCollectionProtectedFactory: test_component.IID {
.init(Data1: 0xB5581456, Data2: 0xA980, Data3: 0x5851, Data4: ( 0xAD,0xA4,0x0A,0x7B,0x27,0x0F,0x6C,0xD9 ))// B5581456-A980-5851-ADA4-0A7B270F6CD9
}

private var IID___x_ABI_Ctest__component_CIBaseNoOverrides: test_component.IID {
Expand Down Expand Up @@ -354,8 +354,21 @@ public enum __ABI_test_component {

}

public class IBaseCollectionFactory: test_component.IInspectable {
override public class var IID: test_component.IID { IID___x_ABI_Ctest__component_CIBaseCollectionFactory }
public class IBaseCollectionProtectedFactory: test_component.IInspectable {
override public class var IID: test_component.IID { IID___x_ABI_Ctest__component_CIBaseCollectionProtectedFactory }

internal func CreateInstanceImpl(_ baseInterface: UnsealedWinRTClassWrapper<test_component.BaseCollection.Composable>?, _ innerInterface: inout test_component.IInspectable?) throws -> IVectorBase {
let (value) = try ComPtrs.initialize { valueAbi in
let _baseInterface = baseInterface?.toIInspectableABI { $0 }
let (_innerInterface) = try ComPtrs.initialize { _innerInterfaceAbi in
_ = try perform(as: __x_ABI_Ctest__component_CIBaseCollectionProtectedFactory.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateInstance(pThis, _baseInterface, &_innerInterfaceAbi, &valueAbi))
}
}
innerInterface = test_component.IInspectable(_innerInterface!)
}
return IVectorBase(value!)
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ open class BaseCollection : WinRTClass, IVector, IIterable {
override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
private static var _IBaseCollectionFactory : __ABI_test_component.IBaseCollectionFactory = try! RoGetActivationFactory(HString("test_component.BaseCollection"))
private static var _IBaseCollectionProtectedFactory : __ABI_test_component.IBaseCollectionProtectedFactory = try! RoGetActivationFactory(HString("test_component.BaseCollection"))

override public init() {
super.init()
MakeComposed(composing: Self.Composable.self, self) { baseInterface, innerInterface in
try! Self._IBaseCollectionProtectedFactory.CreateInstanceImpl(baseInterface, &innerInterface)
}
}

// MARK: Collection
public typealias Element = T
Expand Down
8 changes: 8 additions & 0 deletions tests/test_component/cpp/BaseCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ namespace winrt::test_component::implementation
void ReplaceAll(array_view<test_component::Base const> items);
};
}


namespace winrt::test_component::factory_implementation
{
struct BaseCollection : BaseCollectionT<BaseCollection, implementation::BaseCollection>
{
};
}
2 changes: 2 additions & 0 deletions tests/test_component/cpp/test_component.idl
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,10 @@ namespace test_component
}


// unsealed to verify composable type names for generic default interfaces
unsealed runtimeclass BaseCollection : [default] IVector<Base>
{
protected BaseCollection();
}

runtimeclass BaseMapCollection : [default] IMap<String, Base>
Expand Down

0 comments on commit a1d1a7a

Please sign in to comment.