Skip to content

Commit

Permalink
fix uuid name (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbrix authored Jan 19, 2024
1 parent 7e42cb0 commit e6b363b
Show file tree
Hide file tree
Showing 11 changed files with 1,125 additions and 82 deletions.
9 changes: 5 additions & 4 deletions swiftwinrt/code_writers/type_writers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ void write_swift_type_identifier_ex(writer& w, metadata_type const& type, bool e
}
else if (auto systype = dynamic_cast<const system_type*>(&type))
{
if (systype->swift_type_name() == "GUID")
if (systype->category() == param_category::guid_type)
{
w.write("%.GUID", w.support);
// GUID requires full type name due to collisions with WinSDK
w.write(systype->swift_full_name());
}
else
{
Expand All @@ -101,7 +102,7 @@ void write_swift_type_identifier_ex(writer& w, metadata_type const& type, bool e
// Make sure the module gets imported
w.add_depends(type);

// Module
// Module
if (type_def->is_generic())
{
// Generic instances are always in the support module
Expand All @@ -123,7 +124,7 @@ void write_swift_type_identifier_ex(writer& w, metadata_type const& type, bool e
// to avoid needing parens in (any IFoo)?
w.write("Any");
}

w.write(remove_backtick(type.swift_type_name()));

if (omit_generic_args == false && !type_def->generic_params.empty())
Expand Down
2 changes: 1 addition & 1 deletion swiftwinrt/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ namespace swiftwinrt
}
if (auto sysType = dynamic_cast<const system_type*>(type))
{
return param_category::guid_type;
return sysType->category();
}
if (auto mapped = dynamic_cast<const mapped_type*>(type))
{
Expand Down
2 changes: 1 addition & 1 deletion swiftwinrt/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ namespace swiftwinrt
{
if (typeName == "Guid"sv)
{
static system_type const guid_type{ "Foundation.UUID"sv, "GUID"sv, "g16"sv };
static system_type const guid_type{ "Foundation"sv, "UUID"sv, "Foundation.UUID"sv, "GUID"sv, "g16"sv, param_category::guid_type };
return guid_type;
}

Expand Down
29 changes: 22 additions & 7 deletions swiftwinrt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,19 @@ namespace swiftwinrt

struct system_type final : metadata_type
{
system_type(std::string_view swiftName, std::string_view cppName, std::string_view signature) :
m_swiftName(swiftName),
system_type(
std::string_view swiftModule,
std::string_view swiftTypeName,
std::string_view swiftFullName,
std::string_view cppName,
std::string_view signature,
param_category category) :
m_swiftModuleName(swiftModule),
m_swiftTypeName(swiftTypeName),
m_swiftFullName(swiftFullName),
m_cppName(cppName),
m_signature(signature)
m_signature(signature),
m_category(category)
{
}

Expand All @@ -190,19 +199,20 @@ namespace swiftwinrt
return {};
}


virtual std::string_view swift_logical_namespace() const override
{
return "Foundation";
return m_swiftModuleName;
}

virtual std::string_view swift_full_name() const override
{
return m_swiftName;
return m_swiftFullName;
}

virtual std::string_view swift_type_name() const override
{
return m_swiftName;
return m_swiftTypeName;
}

virtual std::string_view cpp_abi_name() const override
Expand Down Expand Up @@ -249,9 +259,14 @@ namespace swiftwinrt
{
// no special declaration necessary
}

param_category category() const { return m_category; }
private:

std::string_view m_swiftName;
std::string_view m_swiftModuleName;
std::string_view m_swiftTypeName;
std::string_view m_swiftFullName;
param_category m_category;
std::string_view m_cppName;
std::string_view m_signature;
};
Expand Down
240 changes: 240 additions & 0 deletions tests/test_component/Sources/CWinRT/include/test_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ typedef interface __x_ABI_Ctest__component_CIVoidToVoidDelegate __x_ABI_Ctest__c

#endif // ____x_ABI_Ctest__component_CInterfaceWithReturnDelegate_FWD_DEFINED__

#ifndef ____x_ABI_Ctest__component_CWithIterableGuids_FWD_DEFINED__
#define ____x_ABI_Ctest__component_CWithIterableGuids_FWD_DEFINED__
typedef interface __x_ABI_Ctest__component_CWithIterableGuids __x_ABI_Ctest__component_CWithIterableGuids;

#endif // ____x_ABI_Ctest__component_CWithIterableGuids_FWD_DEFINED__

#ifndef ____x_ABI_Ctest__component_CWithKeyword_FWD_DEFINED__
#define ____x_ABI_Ctest__component_CWithKeyword_FWD_DEFINED__
typedef interface __x_ABI_Ctest__component_CWithKeyword __x_ABI_Ctest__component_CWithKeyword;
Expand Down Expand Up @@ -571,6 +577,90 @@ typedef interface __x_ABI_C__FIAsyncOperationWithProgress_2_int_double __x_ABI_C

#endif // ____x_ABI_C__FIIterable_1_IInspectable_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIIterator_1_GUID_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIIterator_1_GUID_INTERFACE_DEFINED__

typedef interface __x_ABI_C__FIIterator_1_GUID __x_ABI_C__FIIterator_1_GUID;

// Declare the parameterized interface IID.
EXTERN_C const IID IID___x_ABI_C__FIIterator_1_GUID;

typedef struct __x_ABI_C__FIIterator_1_GUIDVtbl
{
BEGIN_INTERFACE

HRESULT (STDMETHODCALLTYPE* QueryInterface)(__x_ABI_C__FIIterator_1_GUID* This,
REFIID riid,
void** ppvObject);
ULONG (STDMETHODCALLTYPE* AddRef)(__x_ABI_C__FIIterator_1_GUID* This);
ULONG (STDMETHODCALLTYPE* Release)(__x_ABI_C__FIIterator_1_GUID* This);
HRESULT (STDMETHODCALLTYPE* GetIids)(__x_ABI_C__FIIterator_1_GUID* This,
ULONG* iidCount,
IID** iids);
HRESULT (STDMETHODCALLTYPE* GetRuntimeClassName)(__x_ABI_C__FIIterator_1_GUID* This,
HSTRING* className);
HRESULT (STDMETHODCALLTYPE* GetTrustLevel)(__x_ABI_C__FIIterator_1_GUID* This,
TrustLevel* trustLevel);
HRESULT (STDMETHODCALLTYPE* get_Current)(__x_ABI_C__FIIterator_1_GUID* This,
GUID* result);
HRESULT (STDMETHODCALLTYPE* get_HasCurrent)(__x_ABI_C__FIIterator_1_GUID* This,
boolean* result);
HRESULT (STDMETHODCALLTYPE* MoveNext)(__x_ABI_C__FIIterator_1_GUID* This,
boolean* result);
HRESULT (STDMETHODCALLTYPE* GetMany)(__x_ABI_C__FIIterator_1_GUID* This,
UINT32 itemsLength,
GUID* items,
UINT32* result);

END_INTERFACE
} __x_ABI_C__FIIterator_1_GUIDVtbl;

interface __x_ABI_C__FIIterator_1_GUID
{
CONST_VTBL struct __x_ABI_C__FIIterator_1_GUIDVtbl* lpVtbl;
};


#endif // ____x_ABI_C__FIIterator_1_GUID_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIIterable_1_GUID_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIIterable_1_GUID_INTERFACE_DEFINED__

typedef interface __x_ABI_C__FIIterable_1_GUID __x_ABI_C__FIIterable_1_GUID;

// Declare the parameterized interface IID.
EXTERN_C const IID IID___x_ABI_C__FIIterable_1_GUID;

typedef struct __x_ABI_C__FIIterable_1_GUIDVtbl
{
BEGIN_INTERFACE

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

END_INTERFACE
} __x_ABI_C__FIIterable_1_GUIDVtbl;

interface __x_ABI_C__FIIterable_1_GUID
{
CONST_VTBL struct __x_ABI_C__FIIterable_1_GUIDVtbl* lpVtbl;
};


#endif // ____x_ABI_C__FIIterable_1_GUID_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIIterator_1_HSTRING_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIIterator_1_HSTRING_INTERFACE_DEFINED__

Expand Down Expand Up @@ -1709,6 +1799,56 @@ typedef interface __x_ABI_C__FIObservableVector_1___x_ABI_Ctest__zcomponent__CIB

#endif // ____x_ABI_C__FIVectorView_1_IInspectable_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIVectorView_1_GUID_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIVectorView_1_GUID_INTERFACE_DEFINED__

typedef interface __x_ABI_C__FIVectorView_1_GUID __x_ABI_C__FIVectorView_1_GUID;

// Declare the parameterized interface IID.
EXTERN_C const IID IID___x_ABI_C__FIVectorView_1_GUID;

typedef struct __x_ABI_C__FIVectorView_1_GUIDVtbl
{
BEGIN_INTERFACE

HRESULT (STDMETHODCALLTYPE* QueryInterface)(__x_ABI_C__FIVectorView_1_GUID* This,
REFIID riid,
void** ppvObject);
ULONG (STDMETHODCALLTYPE* AddRef)(__x_ABI_C__FIVectorView_1_GUID* This);
ULONG (STDMETHODCALLTYPE* Release)(__x_ABI_C__FIVectorView_1_GUID* This);
HRESULT (STDMETHODCALLTYPE* GetIids)(__x_ABI_C__FIVectorView_1_GUID* This,
ULONG* iidCount,
IID** iids);
HRESULT (STDMETHODCALLTYPE* GetRuntimeClassName)(__x_ABI_C__FIVectorView_1_GUID* This,
HSTRING* className);
HRESULT (STDMETHODCALLTYPE* GetTrustLevel)(__x_ABI_C__FIVectorView_1_GUID* This,
TrustLevel* trustLevel);
HRESULT (STDMETHODCALLTYPE* GetAt)(__x_ABI_C__FIVectorView_1_GUID* This,
UINT32 index,
GUID* result);
HRESULT (STDMETHODCALLTYPE* get_Size)(__x_ABI_C__FIVectorView_1_GUID* This,
UINT32* result);
HRESULT (STDMETHODCALLTYPE* IndexOf)(__x_ABI_C__FIVectorView_1_GUID* This,
GUID value,
UINT32* index,
boolean* result);
HRESULT (STDMETHODCALLTYPE* GetMany)(__x_ABI_C__FIVectorView_1_GUID* This,
UINT32 startIndex,
UINT32 itemsLength,
GUID* items,
UINT32* result);

END_INTERFACE
} __x_ABI_C__FIVectorView_1_GUIDVtbl;

interface __x_ABI_C__FIVectorView_1_GUID
{
CONST_VTBL struct __x_ABI_C__FIVectorView_1_GUIDVtbl* lpVtbl;
};


#endif // ____x_ABI_C__FIVectorView_1_GUID_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIVectorView_1_HSTRING_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIVectorView_1_HSTRING_INTERFACE_DEFINED__

Expand Down Expand Up @@ -1826,6 +1966,73 @@ typedef interface __x_ABI_C__FIObservableVector_1___x_ABI_Ctest__zcomponent__CIB

#endif // ____x_ABI_C__FIVector_1_IInspectable_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIVector_1_GUID_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIVector_1_GUID_INTERFACE_DEFINED__

typedef interface __x_ABI_C__FIVector_1_GUID __x_ABI_C__FIVector_1_GUID;

// Declare the parameterized interface IID.
EXTERN_C const IID IID___x_ABI_C__FIVector_1_GUID;

typedef struct __x_ABI_C__FIVector_1_GUIDVtbl
{
BEGIN_INTERFACE

HRESULT (STDMETHODCALLTYPE* QueryInterface)(__x_ABI_C__FIVector_1_GUID* This,
REFIID riid,
void** ppvObject);
ULONG (STDMETHODCALLTYPE* AddRef)(__x_ABI_C__FIVector_1_GUID* This);
ULONG (STDMETHODCALLTYPE* Release)(__x_ABI_C__FIVector_1_GUID* This);
HRESULT (STDMETHODCALLTYPE* GetIids)(__x_ABI_C__FIVector_1_GUID* This,
ULONG* iidCount,
IID** iids);
HRESULT (STDMETHODCALLTYPE* GetRuntimeClassName)(__x_ABI_C__FIVector_1_GUID* This,
HSTRING* className);
HRESULT (STDMETHODCALLTYPE* GetTrustLevel)(__x_ABI_C__FIVector_1_GUID* This,
TrustLevel* trustLevel);
HRESULT (STDMETHODCALLTYPE* GetAt)(__x_ABI_C__FIVector_1_GUID* This,
UINT32 index,
GUID* result);
HRESULT (STDMETHODCALLTYPE* get_Size)(__x_ABI_C__FIVector_1_GUID* This,
UINT32* result);
HRESULT (STDMETHODCALLTYPE* GetView)(__x_ABI_C__FIVector_1_GUID* This,
__x_ABI_C__FIVectorView_1_GUID** result);
HRESULT (STDMETHODCALLTYPE* IndexOf)(__x_ABI_C__FIVector_1_GUID* This,
GUID value,
UINT32* index,
boolean* result);
HRESULT (STDMETHODCALLTYPE* SetAt)(__x_ABI_C__FIVector_1_GUID* This,
UINT32 index,
GUID value);
HRESULT (STDMETHODCALLTYPE* InsertAt)(__x_ABI_C__FIVector_1_GUID* This,
UINT32 index,
GUID value);
HRESULT (STDMETHODCALLTYPE* RemoveAt)(__x_ABI_C__FIVector_1_GUID* This,
UINT32 index);
HRESULT (STDMETHODCALLTYPE* Append)(__x_ABI_C__FIVector_1_GUID* This,
GUID value);
HRESULT (STDMETHODCALLTYPE* RemoveAtEnd)(__x_ABI_C__FIVector_1_GUID* This);
HRESULT (STDMETHODCALLTYPE* Clear)(__x_ABI_C__FIVector_1_GUID* This);
HRESULT (STDMETHODCALLTYPE* GetMany)(__x_ABI_C__FIVector_1_GUID* This,
UINT32 startIndex,
UINT32 itemsLength,
GUID* items,
UINT32* result);
HRESULT (STDMETHODCALLTYPE* ReplaceAll)(__x_ABI_C__FIVector_1_GUID* This,
UINT32 itemsLength,
GUID* items);

END_INTERFACE
} __x_ABI_C__FIVector_1_GUIDVtbl;

interface __x_ABI_C__FIVector_1_GUID
{
CONST_VTBL struct __x_ABI_C__FIVector_1_GUIDVtbl* lpVtbl;
};


#endif // ____x_ABI_C__FIVector_1_GUID_INTERFACE_DEFINED__

#if !defined(____x_ABI_C__FIVector_1_HSTRING_INTERFACE_DEFINED__)
#define ____x_ABI_C__FIVector_1_HSTRING_INTERFACE_DEFINED__

Expand Down Expand Up @@ -4105,6 +4312,39 @@ struct __x_ABI_Ctest__component_CStructWithIReference
EXTERN_C const IID IID___x_ABI_Ctest__component_CInterfaceWithReturnDelegate;
#endif /* !defined(____x_ABI_Ctest__component_CInterfaceWithReturnDelegate_INTERFACE_DEFINED__) */

#if !defined(____x_ABI_Ctest__component_CWithIterableGuids_INTERFACE_DEFINED__)
#define ____x_ABI_Ctest__component_CWithIterableGuids_INTERFACE_DEFINED__
typedef struct __x_ABI_Ctest__component_CWithIterableGuidsVtbl
{
BEGIN_INTERFACE

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

END_INTERFACE
} __x_ABI_Ctest__component_CWithIterableGuidsVtbl;

interface __x_ABI_Ctest__component_CWithIterableGuids
{
CONST_VTBL struct __x_ABI_Ctest__component_CWithIterableGuidsVtbl* lpVtbl;
};


EXTERN_C const IID IID___x_ABI_Ctest__component_CWithIterableGuids;
#endif /* !defined(____x_ABI_Ctest__component_CWithIterableGuids_INTERFACE_DEFINED__) */

#if !defined(____x_ABI_Ctest__component_CWithKeyword_INTERFACE_DEFINED__)
#define ____x_ABI_Ctest__component_CWithKeyword_INTERFACE_DEFINED__
typedef struct __x_ABI_Ctest__component_CWithKeywordVtbl
Expand Down
Loading

0 comments on commit e6b363b

Please sign in to comment.