Skip to content

Commit aa59310

Browse files
authored
Fix class name mapping for WUX types (#1679)
1 parent fa224c3 commit aa59310

File tree

2 files changed

+10
-65
lines changed

2 files changed

+10
-65
lines changed

src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ private static string ToVtableLookupString(ISymbol symbol, List<string> genericA
288288
}
289289
}
290290

291-
private static string GetRuntimeClassName(INamedTypeSymbol type, Func<ISymbol, bool> isWinRTType)
291+
private static string GetRuntimeClassName(
292+
INamedTypeSymbol type,
293+
Func<ISymbol, TypeMapper, bool> isWinRTType,
294+
TypeMapper mapper)
292295
{
293296
if (type == null)
294297
{
@@ -300,7 +303,7 @@ private static string GetRuntimeClassName(INamedTypeSymbol type, Func<ISymbol, b
300303
{
301304
StringBuilder builder = new();
302305

303-
builder.Append(GetRuntimeClassName(type.OriginalDefinition, isWinRTType));
306+
builder.Append(GetRuntimeClassName(type.OriginalDefinition, isWinRTType, mapper));
304307
builder.Append("<");
305308

306309
bool first = true;
@@ -311,7 +314,7 @@ private static string GetRuntimeClassName(INamedTypeSymbol type, Func<ISymbol, b
311314
builder.Append(", ");
312315
}
313316

314-
builder.Append(GetRuntimeClassName(genericArg as INamedTypeSymbol, isWinRTType));
317+
builder.Append(GetRuntimeClassName(genericArg as INamedTypeSymbol, isWinRTType, mapper));
315318
first = false;
316319
}
317320

@@ -331,16 +334,16 @@ private static string GetRuntimeClassName(INamedTypeSymbol type, Func<ISymbol, b
331334
{
332335
return "Int8";
333336
}
334-
else if (GeneratorHelper.MappedCSharpTypes.ContainsKey(metadataName))
337+
else if (mapper.HasMappingForType(metadataName))
335338
{
336-
var mapping = GeneratorHelper.MappedCSharpTypes[metadataName].GetMapping();
339+
var mapping = mapper.GetMappedType(metadataName).GetMapping();
337340
return mapping.Item1 + "." + mapping.Item2;
338341
}
339342
else if (type.SpecialType != SpecialType.None)
340343
{
341344
return type.Name;
342345
}
343-
else if (isWinRTType(type))
346+
else if (isWinRTType(type, mapper))
344347
{
345348
return metadataName;
346349
}
@@ -475,7 +478,7 @@ internal static VtableAttribute GetVtableAttributeToAdd(
475478
symbol is IArrayTypeSymbol,
476479
isDelegate,
477480
symbol.DeclaredAccessibility == Accessibility.Public,
478-
GetRuntimeClassName(interfaceToUseForRuntimeClassName, type => isWinRTType(type, mapper)));
481+
GetRuntimeClassName(interfaceToUseForRuntimeClassName, isWinRTType, mapper));
479482

480483
void AddGenericInterfaceInstantiation(INamedTypeSymbol iface)
481484
{

src/Authoring/WinRT.SourceGenerator/Helper.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -964,63 +964,5 @@ public bool IsBlittable()
964964
return isValueType && isBlittable;
965965
}
966966
}
967-
968-
// Based on whether System.Type is used in an attribute declaration or elsewhere, we need to choose the correct custom mapping
969-
// as attributes don't use the TypeName mapping.
970-
internal static (string, string, string, bool, bool) GetSystemTypeCustomMapping(ISymbol containingSymbol)
971-
{
972-
bool isDefinedInAttribute =
973-
containingSymbol != null &&
974-
string.CompareOrdinal((containingSymbol as INamedTypeSymbol).BaseType?.ToString(), "System.Attribute") == 0;
975-
return isDefinedInAttribute ?
976-
("System", "Type", "mscorlib", true, false) :
977-
("Windows.UI.Xaml.Interop", "TypeName", "Windows.Foundation.UniversalApiContract", false, true);
978-
}
979-
980-
// This should be in sync with the reverse mapping from WinRT.Runtime/Projections.cs and cswinrt/helpers.h.
981-
public static readonly Dictionary<string, MappedType> MappedCSharpTypes = new(StringComparer.Ordinal)
982-
{
983-
{ "System.DateTimeOffset", new MappedType("Windows.Foundation", "DateTime", "Windows.Foundation.FoundationContract", true, false) },
984-
{ "System.Exception", new MappedType("Windows.Foundation", "HResult", "Windows.Foundation.FoundationContract", true, false) },
985-
{ "System.EventHandler`1", new MappedType("Windows.Foundation", "EventHandler`1", "Windows.Foundation.FoundationContract") },
986-
{ "System.FlagsAttribute", new MappedType("System", "FlagsAttribute", "mscorlib" ) },
987-
{ "System.IDisposable", new MappedType("Windows.Foundation", "IClosable", "Windows.Foundation.FoundationContract") },
988-
{ "System.IServiceProvider", new MappedType("Microsoft.UI.Xaml", "IXamlServiceProvider", "Microsoft.UI") },
989-
{ "System.Nullable`1", new MappedType("Windows.Foundation", "IReference`1", "Windows.Foundation.FoundationContract" ) },
990-
{ "System.Object", new MappedType("System", "Object", "mscorlib" ) },
991-
{ "System.TimeSpan", new MappedType("Windows.Foundation", "TimeSpan", "Windows.Foundation.FoundationContract", true, false) },
992-
{ "System.Uri", new MappedType("Windows.Foundation", "Uri", "Windows.Foundation.FoundationContract") },
993-
{ "System.ComponentModel.DataErrorsChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Data", "DataErrorsChangedEventArgs", "Microsoft.UI") },
994-
{ "System.ComponentModel.INotifyDataErrorInfo", new MappedType("Microsoft.UI.Xaml.Data", "INotifyDataErrorInfo", "Microsoft.UI") },
995-
{ "System.ComponentModel.INotifyPropertyChanged", new MappedType("Microsoft.UI.Xaml.Data", "INotifyPropertyChanged", "Microsoft.UI") },
996-
{ "System.ComponentModel.PropertyChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Data", "PropertyChangedEventArgs", "Microsoft.UI") },
997-
{ "System.ComponentModel.PropertyChangedEventHandler", new MappedType("Microsoft.UI.Xaml.Data", "PropertyChangedEventHandler", "Microsoft.UI") },
998-
{ "System.Windows.Input.ICommand", new MappedType("Microsoft.UI.Xaml.Input", "ICommand", "Microsoft.UI") },
999-
{ "System.Collections.IEnumerable", new MappedType("Microsoft.UI.Xaml.Interop", "IBindableIterable", "Microsoft.UI") },
1000-
{ "System.Collections.IList", new MappedType("Microsoft.UI.Xaml.Interop", "IBindableVector", "Microsoft.UI") },
1001-
{ "System.Collections.Specialized.INotifyCollectionChanged", new MappedType("Microsoft.UI.Xaml.Interop", "INotifyCollectionChanged", "Microsoft.UI") },
1002-
{ "System.Collections.Specialized.NotifyCollectionChangedAction", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedAction", "Microsoft.UI") },
1003-
{ "System.Collections.Specialized.NotifyCollectionChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedEventArgs", "Microsoft.UI") },
1004-
{ "System.Collections.Specialized.NotifyCollectionChangedEventHandler", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedEventHandler", "Microsoft.UI") },
1005-
{ "WinRT.EventRegistrationToken", new MappedType("Windows.Foundation", "EventRegistrationToken", "Windows.Foundation.FoundationContract", true, true) },
1006-
{ "System.AttributeTargets", new MappedType("Windows.Foundation.Metadata", "AttributeTargets", "Windows.Foundation.FoundationContract", true, true) },
1007-
{ "System.AttributeUsageAttribute", new MappedType("Windows.Foundation.Metadata", "AttributeUsageAttribute", "Windows.Foundation.FoundationContract") },
1008-
{ "System.Numerics.Matrix3x2", new MappedType("Windows.Foundation.Numerics", "Matrix3x2", "Windows.Foundation.FoundationContract", true, true) },
1009-
{ "System.Numerics.Matrix4x4", new MappedType("Windows.Foundation.Numerics", "Matrix4x4", "Windows.Foundation.FoundationContract", true, true) },
1010-
{ "System.Numerics.Plane", new MappedType("Windows.Foundation.Numerics", "Plane", "Windows.Foundation.FoundationContract", true, true) },
1011-
{ "System.Numerics.Quaternion", new MappedType("Windows.Foundation.Numerics", "Quaternion", "Windows.Foundation.FoundationContract", true, true) },
1012-
{ "System.Numerics.Vector2", new MappedType("Windows.Foundation.Numerics", "Vector2", "Windows.Foundation.FoundationContract", true, true) },
1013-
{ "System.Numerics.Vector3", new MappedType("Windows.Foundation.Numerics", "Vector3", "Windows.Foundation.FoundationContract", true, true) },
1014-
{ "System.Numerics.Vector4", new MappedType("Windows.Foundation.Numerics", "Vector4", "Windows.Foundation.FoundationContract", true, true) },
1015-
{ "System.Type", new MappedType(GetSystemTypeCustomMapping) },
1016-
{ "System.Collections.Generic.IEnumerable`1", new MappedType("Windows.Foundation.Collections", "IIterable`1", "Windows.Foundation.FoundationContract") },
1017-
{ "System.Collections.Generic.IEnumerator`1", new MappedType("Windows.Foundation.Collections", "IIterator`1", "Windows.Foundation.FoundationContract") },
1018-
{ "System.Collections.Generic.KeyValuePair`2", new MappedType("Windows.Foundation.Collections", "IKeyValuePair`2", "Windows.Foundation.FoundationContract") },
1019-
{ "System.Collections.Generic.IReadOnlyDictionary`2", new MappedType("Windows.Foundation.Collections", "IMapView`2", "Windows.Foundation.FoundationContract") },
1020-
{ "System.Collections.Generic.IDictionary`2", new MappedType("Windows.Foundation.Collections", "IMap`2", "Windows.Foundation.FoundationContract") },
1021-
{ "System.Collections.Generic.IReadOnlyList`1", new MappedType("Windows.Foundation.Collections", "IVectorView`1", "Windows.Foundation.FoundationContract") },
1022-
{ "System.Collections.Generic.IList`1", new MappedType("Windows.Foundation.Collections", "IVector`1", "Windows.Foundation.FoundationContract") },
1023-
{ "Windows.UI.Color", new MappedType("Windows.UI", "Color", "Windows.Foundation.UniversalApiContract", true, true) },
1024-
};
1025967
}
1026968
}

0 commit comments

Comments
 (0)