win32 icon indicating copy to clipboard operation
win32 copied to clipboard

Support generic collections in `implementsMappers`

Open halildurmus opened this issue 3 years ago • 4 comments

Noticed this while working on #479. Take IXmlNodeList for example. It requires two interfaces: IVectorView<IXmlNode> and IIterable<IXmlNode>.

The problem is that the typeDef of these interfaces returns an empty name. This is breaking a lot of things, as we rely heavily on typeDef.name for classDeclaration and implementsMappers. I ignored them for now in #479.

In order to get the names of these types, we can call typeDef like this:

print(typeDef.interfaces.first.typeSpec?.type?.name); // Prints Windows.Foundation.Collections.IVectorView`1
print(typeDef.interfaces.first.typeSpec?.typeArg?.name); // Prints Windows.Data.Xml.Dom.IXmlNode

The difficulty is that these types can be nested and/or has multiple typeArgs (e.g. IVectorView<IMapView<String, Object>>, IMap<String, IVector<String>>).

In a couple of days, I'll continue my work on #465. In that, I'll have to modify the generator to expose Pointer<COMObject> types to their respective types (e.g. IFileOpenPicker's pickMultipleFilesAsync() will be exposed as Future<List<StorageFile>?> instead of Pointer<COMObject> or Calendar's Clone() will return Calendar). This will probably help to support this as well.

halildurmus avatar Jun 03 '22 14:06 halildurmus

Yeah, I've been puzzling over how to represent generics for a while from the winmd side. The code isn't super clean there, mostly because WinMD is a spidery mess of circular type references.

What would you like to see represented? I could give you one big blob like IMap<String, IVector<String>>, but all that does is push the parsing work to the generator. I'll make the changes on the winmd side as needed.

timsneath avatar Jun 03 '22 17:06 timsneath

I was thinking of writing a function that returns a String like IMap<String, IVector<String> by parsing the TypeDef. I'll look into this tomorrow and share my progress.

EDIT: Thank you for the invitation :)

halildurmus avatar Jun 03 '22 18:06 halildurmus

That's easy enough -- but is that String useful from a mapping perspective? Or do you then need to decompose it again? I'd like to give you what you need from the first!

timsneath avatar Jun 03 '22 18:06 timsneath

I won't know until I dig deeper into this tomorrow. Hopefully, I won't need to decompose it again.

halildurmus avatar Jun 03 '22 18:06 halildurmus