Fixed handling and generation of custom types
このコミットが含まれているのは:
1 親
1a8e653a39
コミット
84dd569989
3ファイル変更
+16
-19
検索条件に一致するファイルはありません
@@ -1,6 +1,5 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Extensions
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace ComputeSharp.SourceGenerators.Extensions
|
||||
return node.ReplaceNode(targetType, newType);
|
||||
}
|
||||
|
||||
return node.ReplaceNode(targetType, ParseTypeName(typeName.Replace(".", "::")));
|
||||
return node.ReplaceNode(targetType, ParseTypeName(typeName.Replace(".", "__")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -71,13 +71,14 @@ namespace ComputeSharp.SourceGenerators.Extensions
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoot">The type of the input <see cref="SyntaxNode"/> instance.</typeparam>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
|
||||
/// <param name="sourceNode">The original node in the input source tree.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</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 ReplaceAndTrackType(this LiteralExpressionSyntax node, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
public static TypeSyntax ReplaceAndTrackType(this LiteralExpressionSyntax node, SyntaxNode sourceNode, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(node).Type!;
|
||||
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(sourceNode).Type!;
|
||||
string typeName = typeSymbol.ToDisplayString(FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
@@ -87,7 +88,7 @@ namespace ComputeSharp.SourceGenerators.Extensions
|
||||
return ParseTypeName(mappedName!);
|
||||
}
|
||||
|
||||
return ParseTypeName(typeName.Replace(".", "::"));
|
||||
return ParseTypeName(typeName.Replace(".", "__"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -175,30 +175,27 @@ namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
foreach (var type in HlslKnownTypes.GetCustomTypes(types))
|
||||
{
|
||||
var structDeclaration = StructDeclaration(type.Name).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
var structType = type.GetFullMetadataName().Replace(".", "__");
|
||||
var structDeclaration = StructDeclaration(structType).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
|
||||
// Declare the fields of the current type
|
||||
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type;
|
||||
|
||||
// Convert the name to the fully qualified HLSL version
|
||||
if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mapped))
|
||||
{
|
||||
mapped = fieldType.GetFullMetadataName().Replace(".", "__");
|
||||
}
|
||||
|
||||
structDeclaration = structDeclaration.AddMembers(
|
||||
FieldDeclaration(VariableDeclaration(IdentifierName(
|
||||
fieldType.GetFullMetadataName())).AddVariables(
|
||||
FieldDeclaration(VariableDeclaration(
|
||||
IdentifierName(mapped!)).AddVariables(
|
||||
VariableDeclarator(Identifier(field.Name)))));
|
||||
}
|
||||
|
||||
MemberDeclarationSyntax memberDeclaration = structDeclaration;
|
||||
INamespaceSymbol? currentNamespace = type.ContainingNamespace;
|
||||
|
||||
// Recursively declare the containing namespaces
|
||||
while (currentNamespace is { IsGlobalNamespace: false })
|
||||
{
|
||||
memberDeclaration = NamespaceDeclaration(IdentifierName(currentNamespace.Name)).AddMembers(memberDeclaration);
|
||||
currentNamespace = currentNamespace.ContainingNamespace;
|
||||
}
|
||||
|
||||
yield return memberDeclaration.NormalizeWhitespace().ToFullString();
|
||||
yield return structDeclaration.NormalizeWhitespace().ToFullString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする