Fixed source generator handling of nested types

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-25 01:16:24 +01:00
1 親 939a4b1186
コミット f4066f6c68
2ファイル変更
+36 -15

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

+16 -7
ファイルの表示
@@ -73,17 +73,26 @@ namespace ComputeSharp.SourceGenerators
// this.c = c;
// ...
// }
//
// This will be placed inside the original namespace, and with all the
// necessary using directive at the top for the input parameters.
var source =
CompilationUnit().AddMembers(
NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(
var structDeclarationSyntax =
StructDeclaration(structName).WithModifiers(structModifiers).AddMembers(
ConstructorDeclaration(structName)
.AddModifiers(Token(SyntaxKind.PublicKeyword))
.AddParameterListParameters(fields.Select(field => Parameter(field.Identifier).WithType(field.Type)).ToArray())
.AddBodyStatements(fields.Select(field => ParseStatement($"this.{field.Identifier} = {field.Identifier};")).ToArray()))))
.AddBodyStatements(fields.Select(field => ParseStatement($"this.{field.Identifier} = {field.Identifier};")).ToArray()));
TypeDeclarationSyntax typeDeclarationSyntax = structDeclarationSyntax;
// Add all parent types in ascending order, if any
foreach (var parentType in structDeclaration.Ancestors().OfType<TypeDeclarationSyntax>())
{
typeDeclarationSyntax = parentType.WithMembers(SingletonList<MemberDeclarationSyntax>(typeDeclarationSyntax));
}
// Create the compilation unit with the namespace and target member.
// From this, we can finally generate the source code to output.
var source =
CompilationUnit().AddMembers(
NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax))
.NormalizeWhitespace()
.ToFullString();
+20 -8
ファイルの表示
@@ -29,23 +29,35 @@ namespace ComputeSharp.Tests.Internals
namespace MyFancyApp.Sample
{
[AutoConstructor]
public readonly partial struct MyShader
public partial interface IFoo<T>
{
private readonly Buffer<Vector4> A;
private readonly float B;
public partial class Foo
{
[AutoConstructor]
public readonly partial struct MyShader
{
private readonly Buffer<Vector4> A;
private readonly float B;
}
}
}
}";
string expected = @"
namespace MyFancyApp.Sample
{
public readonly partial struct MyShader
public partial interface IFoo<T>
{
public MyShader(MyLibrary.Buffer<System.Numerics.Vector4> A, float B)
public partial class Foo
{
this.A = A;
this.B = B;
public readonly partial struct MyShader
{
public MyShader(MyLibrary.Buffer<System.Numerics.Vector4> A, float B)
{
this.A = A;
this.B = B;
}
}
}
}
}";