Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ genericParameter is INamedTypeSymbol genericParameterIface &&
genericParameters.Add(new GenericParameter(
ToFullyQualifiedString(genericParameter),
GeneratorHelper.GetAbiType(genericParameter, mapper),
isNullable ? TypeKind.Interface : genericParameter.TypeKind));
isNullable ? TypeKind.Interface : genericParameter.TypeKind,
ComputeTypeFlags(genericParameter, compilation)));
}

genericInterfacesToAddToVtable.Add(new GenericInterface(
Expand Down Expand Up @@ -773,6 +774,25 @@ void CheckForInterfaceToUseForRuntimeClassName(INamedTypeSymbol iface)
}
}

private static TypeFlags ComputeTypeFlags(ITypeSymbol symbol, Compilation compilation)
{
TypeFlags typeFlags = TypeFlags.None;

// Check for exception types
if (symbol.TypeKind is TypeKind.Class)
{
var exceptionType = compilation.GetTypeByMetadataName("System.Exception")!;

if (SymbolEqualityComparer.Default.Equals(symbol, exceptionType) ||
symbol.InheritsFromType(exceptionType))
{
typeFlags |= TypeFlags.Exception;
}
}

return typeFlags;
}

private static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(INamedTypeSymbol type, TypeMapper mapper, Stack<INamedTypeSymbol> typeStack, Func<ISymbol, TypeMapper, bool> isWinRTType, INamedTypeSymbol objectType, out IList<INamedTypeSymbol> compatibleTypes)
{
compatibleTypes = null;
Expand Down Expand Up @@ -1873,7 +1893,8 @@ namespace {{bindableCustomProperties.Namespace}}
internal readonly record struct GenericParameter(
string ProjectedType,
string AbiType,
TypeKind TypeKind);
TypeKind TypeKind,
TypeFlags TypeFlags);

internal readonly record struct GenericInterface(
string Interface,
Expand Down Expand Up @@ -1923,6 +1944,20 @@ internal readonly record struct CsWinRTAotOptimizerProperties(
bool IsCsWinRTCcwLookupTableGeneratorEnabled,
bool IsCsWinRTAotOptimizerInAutoMode);

/// <summary>
/// Additional flags for discovered types.
/// </summary>
[Flags]
internal enum TypeFlags
{
None = 0x0,

/// <summary>
/// The type derives from <see cref="System.Exception"/>.
/// </summary>
Exception = 0x1 << 0
}

/// <summary>
/// A model describing a type info in a type hierarchy.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions src/Authoring/WinRT.SourceGenerator/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,27 @@ public static bool IsAccessibleFromCompilationAssembly(this ISymbol symbol, Comp
{
return compilation.IsSymbolAccessibleWithin(symbol, compilation.Assembly);
}

/// <summary>
/// Checks whether or not a given <see cref="ITypeSymbol"/> inherits from a specified type.
/// </summary>
/// <param name="typeSymbol">The target <see cref="ITypeSymbol"/> instance to check.</param>
/// <param name="baseTypeSymbol">The <see cref="ITypeSymbol"/> instane to check for inheritance from.</param>
/// <returns>Whether or not <paramref name="typeSymbol"/> inherits from <paramref name="baseTypeSymbol"/>.</returns>
public static bool InheritsFromType(this ITypeSymbol typeSymbol, ITypeSymbol baseTypeSymbol)
{
INamedTypeSymbol? currentBaseTypeSymbol = typeSymbol.BaseType;

while (currentBaseTypeSymbol is not null)
{
if (SymbolEqualityComparer.Default.Equals(currentBaseTypeSymbol, baseTypeSymbol))
{
return true;
}

currentBaseTypeSymbol = currentBaseTypeSymbol.BaseType;
}

return false;
}
}
3,488 changes: 1,750 additions & 1,738 deletions src/Authoring/WinRT.SourceGenerator/GenericVtableInitializerStrings.cs

Large diffs are not rendered by default.

Loading