From 180183ec13ac3e9a0d8271af874db8673b48593b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 17 Dec 2023 18:29:15 +0100 Subject: [PATCH] Remove leftover syntax factory helpers --- .../Models/HierarchyInfo.cs | 90 ------------------- .../Models/TypeInfo.cs | 30 ------- 2 files changed, 120 deletions(-) diff --git a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs index 82c5d47f9..30e9f8e7b 100644 --- a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs @@ -2,9 +2,6 @@ using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; using static Microsoft.CodeAnalysis.SymbolDisplayTypeQualificationStyle; namespace ComputeSharp.SourceGeneration.Models; @@ -135,91 +132,4 @@ public string GetFullyQualifiedTypeName() return fullyQualifiedTypeName.ToString(); } - - /// - /// Creates a instance for the current hierarchy. - /// - /// The member declarations to add to the generated type. - /// A instance for the current hierarchy. - public CompilationUnitSyntax GetSyntax(params MemberDeclarationSyntax[] memberDeclarations) - { - return GetSyntax(memberDeclarations, []); - } - - /// - /// Creates a instance for the current hierarchy. - /// - /// The member declarations to add to the generated type. - /// Additional top-level member declarations, if any. - /// A instance for the current hierarchy. - public CompilationUnitSyntax GetSyntax(MemberDeclarationSyntax[] memberDeclarations, params MemberDeclarationSyntax[] additionalMemberDeclarations) - { - // Create the partial type declaration with for the current hierarchy. - // This code produces a type declaration as follows: - // - // partial - // { - // - // } - TypeDeclarationSyntax typeDeclarationSyntax = - Hierarchy[0].GetSyntax() - .AddModifiers(Token(SyntaxKind.PartialKeyword)) - .AddMembers(memberDeclarations); - - // Add all parent types in ascending order, if any - foreach (TypeInfo parentType in Hierarchy.AsSpan().Slice(1)) - { - typeDeclarationSyntax = - parentType.GetSyntax() - .AddModifiers(Token(SyntaxKind.PartialKeyword)) - .AddMembers(typeDeclarationSyntax); - } - - // Prepare the leading trivia for the generated compilation unit. - // This will produce code as follows: - // - // // - // #pragma warning disable - SyntaxTriviaList syntaxTriviaList = TriviaList( - Comment("// "), - Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))); - - CompilationUnitSyntax compilationUnitSyntax; - - if (Namespace is "") - { - // If there is no namespace, attach the pragma directly to the declared type, - // and skip the namespace declaration. This will produce code as follows: - // - // - // - compilationUnitSyntax = - CompilationUnit() - .AddMembers(typeDeclarationSyntax.WithLeadingTrivia(syntaxTriviaList)); - } - else - { - // Create the compilation unit with disabled warnings, target namespace and generated type. - // This will produce code as follows: - // - // - // namespace ; - // - // - compilationUnitSyntax = - CompilationUnit().AddMembers( - FileScopedNamespaceDeclaration(IdentifierName(Namespace)) - .WithLeadingTrivia(syntaxTriviaList) - .AddMembers(typeDeclarationSyntax)); - } - - // Add any additional members, if any - if (additionalMemberDeclarations.Length > 0) - { - compilationUnitSyntax = compilationUnitSyntax.AddMembers(additionalMemberDeclarations); - } - - // Normalize and return the tree - return compilationUnitSyntax.NormalizeWhitespace(eol: "\n"); - } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration/Models/TypeInfo.cs b/src/ComputeSharp.SourceGeneration/Models/TypeInfo.cs index 771e110e2..d94cb1969 100644 --- a/src/ComputeSharp.SourceGeneration/Models/TypeInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/TypeInfo.cs @@ -1,7 +1,4 @@ using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace ComputeSharp.SourceGeneration.Models; @@ -28,31 +25,4 @@ public string GetTypeKeyword() _ => "class" }; } - - /// - /// Creates a instance for the current info. - /// - /// A instance for the current info. - public TypeDeclarationSyntax GetSyntax() - { - // Create the partial type declaration with the kind. - // This code produces a class declaration as follows: - // - // - // { - // } - // - // Note that specifically for record declarations, we also need to explicitly add the open - // and close brace tokens, otherwise member declarations will not be formatted correctly. - return Kind switch - { - TypeKind.Struct => StructDeclaration(QualifiedName), - TypeKind.Interface => InterfaceDeclaration(QualifiedName), - TypeKind.Class when IsRecord => - RecordDeclaration(Token(SyntaxKind.RecordKeyword), QualifiedName) - .WithOpenBraceToken(Token(SyntaxKind.OpenBraceToken)) - .WithCloseBraceToken(Token(SyntaxKind.CloseBraceToken)), - _ => ClassDeclaration(QualifiedName) - }; - } } \ No newline at end of file