Reduce code duplication for type hierarchy generation
このコミットが含まれているのは:
1 親
910df14429
コミット
9609cb6607
4ファイル変更
+71
-173
検索条件に一致するファイルはありません
@@ -5,7 +5,6 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
using TypeInfo = ComputeSharp.SourceGeneration.Models.TypeInfo;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
@@ -80,62 +79,6 @@ partial class IShaderGenerator
|
||||
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Runtime.CompilerServices.SkipLocalsInit")))));
|
||||
}
|
||||
|
||||
// Create the partial shader type declaration with the given method implementation.
|
||||
// This code produces a struct declaration as follows:
|
||||
//
|
||||
// partial struct <SHADER_TYPE>
|
||||
// {
|
||||
// <METHOD>
|
||||
// }
|
||||
TypeDeclarationSyntax typeDeclarationSyntax =
|
||||
StructDeclaration(hierarchyInfo.Hierarchy[0].QualifiedName)
|
||||
.AddModifiers(Token(SyntaxKind.PartialKeyword))
|
||||
.AddMembers(methodDeclaration.AddAttributeLists(attributes.ToArray()));
|
||||
|
||||
// Add all parent types in ascending order, if any
|
||||
foreach (TypeInfo parentType in hierarchyInfo.Hierarchy.AsSpan().Slice(1))
|
||||
{
|
||||
typeDeclarationSyntax =
|
||||
parentType.GetSyntax()
|
||||
.AddModifiers(Token(SyntaxKind.PartialKeyword))
|
||||
.AddMembers(typeDeclarationSyntax);
|
||||
}
|
||||
|
||||
if (hierarchyInfo.Namespace is "")
|
||||
{
|
||||
// If there is no namespace, attach the pragma directly to the declared type,
|
||||
// and skip the namespace declaration. This is the same additional path also
|
||||
// used when generating custom constructors. This will produce code as follows:
|
||||
//
|
||||
// #pragma warning disable
|
||||
//
|
||||
// <TYPE_HIERARCHY>
|
||||
return
|
||||
CompilationUnit().AddMembers(
|
||||
typeDeclarationSyntax
|
||||
.WithModifiers(TokenList(Token(
|
||||
TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))),
|
||||
SyntaxKind.PartialKeyword,
|
||||
TriviaList()))))
|
||||
.NormalizeWhitespace(eol: "\n");
|
||||
}
|
||||
|
||||
// Create the compilation unit with disabled warnings, target namespace and generated type.
|
||||
// This will produce code as follows:
|
||||
//
|
||||
// #pragma warning disable
|
||||
//
|
||||
// namespace <NAMESPACE>;
|
||||
//
|
||||
// <TYPE_HIERARCHY>
|
||||
return
|
||||
CompilationUnit().AddMembers(
|
||||
FileScopedNamespaceDeclaration(IdentifierName(hierarchyInfo.Namespace))
|
||||
.AddMembers(typeDeclarationSyntax)
|
||||
.WithNamespaceKeyword(Token(TriviaList(
|
||||
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))),
|
||||
SyntaxKind.NamespaceKeyword,
|
||||
TriviaList())))
|
||||
.NormalizeWhitespace(eol: "\n");
|
||||
return hierarchyInfo.GetSyntax(methodDeclaration.AddAttributeLists(attributes.ToArray()));
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする