diff --git a/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs b/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs
index 7cf3d8d0..49f6bb66 100644
--- a/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs
+++ b/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs
@@ -1,6 +1,5 @@
using System.Diagnostics.Contracts;
using System.Text;
-using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGenerators.Extensions
diff --git a/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs b/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs
index 9dee6682..c549a814 100644
--- a/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs
+++ b/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs
@@ -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(".", "__")));
}
///
@@ -71,13 +71,14 @@ namespace ComputeSharp.SourceGenerators.Extensions
///
/// The type of the input instance.
/// The input to check and modify if needed.
+ /// The original node in the input source tree.
/// The instance with info on the input tree.
/// The collection of currently discovered types.
/// A instance that represents a type compatible with HLSL.
[Pure]
- public static TypeSyntax ReplaceAndTrackType(this LiteralExpressionSyntax node, SemanticModel semanticModel, ICollection discoveredTypes)
+ public static TypeSyntax ReplaceAndTrackType(this LiteralExpressionSyntax node, SyntaxNode sourceNode, SemanticModel semanticModel, ICollection 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(".", "__"));
}
///
diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs
index 54c57acf..1f9fc5de 100644
--- a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs
+++ b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs
@@ -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())
{
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();
}
}
}