Added attributes to generated classes
このコミットが含まれているのは:
1 親
d06e8fd3ed
コミット
4e39eb0ab8
2ファイル変更
+40
-5
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
@@ -31,6 +32,19 @@ namespace ComputeSharp.SourceGenerators
|
||||
from structDeclaration in tree.GetRoot().DescendantNodes().OfType<StructDeclarationSyntax>()
|
||||
select structDeclaration).ToImmutableArray();
|
||||
|
||||
// Type attributes
|
||||
AttributeListSyntax[] attributes = new[]
|
||||
{
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
|
||||
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.StringLiteralExpression,
|
||||
Literal("This type is not intended to be used directly by user code"))))))
|
||||
};
|
||||
|
||||
foreach (StructDeclarationSyntax structDeclaration in structDeclarations)
|
||||
{
|
||||
SemanticModel semanticModel = context.Compilation.GetSemanticModel(structDeclaration.SyntaxTree);
|
||||
@@ -69,7 +83,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
ClassDeclaration("DispatchDataLoader").AddModifiers(
|
||||
Token(SyntaxKind.InternalKeyword),
|
||||
Token(SyntaxKind.StaticKeyword),
|
||||
Token(SyntaxKind.PartialKeyword)).AddMembers(
|
||||
Token(SyntaxKind.PartialKeyword)).AddAttributeLists(attributes).AddMembers(
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.IntKeyword)),
|
||||
Identifier("LoadDispatchData")).AddAttributeLists(
|
||||
@@ -87,10 +101,14 @@ namespace ComputeSharp.SourceGenerators
|
||||
Parameter(Identifier("shader")).WithModifiers(TokenList(Token(SyntaxKind.InKeyword))).WithType(shaderType),
|
||||
Parameter(Identifier("r0")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(PredefinedType(Token(SyntaxKind.ULongKeyword))),
|
||||
Parameter(Identifier("r1")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.WithBody(block))))
|
||||
.WithBody(block)))
|
||||
.WithNamespaceKeyword(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.NamespaceKeyword, TriviaList())))
|
||||
.NormalizeWhitespace()
|
||||
.ToFullString();
|
||||
|
||||
// Clear the attribute list to avoid duplicates
|
||||
attributes = Array.Empty<AttributeListSyntax>();
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName<IComputeShaderDataLoaderGenerator>(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする