Added support for out discard expressions

このコミットが含まれているのは:
Sergio Pedri committed 2020-12-02 14:49:12 +01:00
1 親 4d9e46060e
コミット 00f1b8d911
3ファイル変更
+42 -3

検索条件に一致するファイルはありません

+26 -1
ファイルの表示
@@ -1,7 +1,11 @@
using System.Diagnostics.Contracts;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using ComputeSharp.SourceGenerators.Mappings;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ComputeSharp.SourceGenerators.Extensions
{
@@ -95,5 +99,26 @@ namespace ComputeSharp.SourceGenerators.Extensions
return $"[{nameof(ComputeSharp)}]_[{typeof(TGenerator).Name}]_[{fixedName}]";
}
/// <summary>
/// Tracks an <see cref="ITypeSymbol"/> instance and returns an HLSL compatible <see cref="TypeSyntax"/> object.
/// </summary>
/// <param name="typeSymbol">The input <see cref="ITypeSymbol"/> instance to process.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
[Pure]
public static TypeSyntax TrackType(this ITypeSymbol typeSymbol, ICollection<INamedTypeSymbol> discoveredTypes)
{
string typeName = typeSymbol.ToDisplayString(SyntaxNodeExtensions.FullyQualifiedWithoutGlobalFormat);
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
{
return ParseTypeName(mappedName!);
}
return ParseTypeName(typeName.Replace(".", "__"));
}
}
}
+1 -1
ファイルの表示
@@ -17,7 +17,7 @@ namespace ComputeSharp.SourceGenerators.Extensions
/// <summary>
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global::.
/// </summary>
private static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalFormat = new(
internal static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalFormat = new(
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters);
+15 -1
ファイルの表示
@@ -348,7 +348,21 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
var updatedNode = (ArgumentSyntax)base.VisitArgument(node)!;
// Strip the ref keywords from arguments
return updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
updatedNode = updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
// Track and rewrite the discarded declaration
if (this.semanticModel.GetOperation(node.Expression) is IDiscardOperation operation)
{
TypeSyntax typeSyntax = operation.Type.TrackType(this.discoveredTypes);
string identifier = $"__implicit{this.implicitVariables.Count}";
// Add the variable to the list of implicit declarations
this.implicitVariables.Add(VariableDeclaration(typeSyntax).AddVariables(VariableDeclarator(identifier)));
return updatedNode.WithExpression(IdentifierName(identifier));
}
return updatedNode;
}
/// <inheritdoc/>