Only emit raw multiline string literals when possible

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-08 15:05:52 +02:00
1 親 5c83ac3c58
コミット dab94bdae7
6ファイル変更
+81 -21

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

@@ -1,5 +1,6 @@
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
@@ -19,9 +20,16 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="hlslSource">The input HLSL source.</param>
/// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
/// <param name="useRawMultiLineStringLiteralExpression">Whether to use a raw multiline string literal expression</param>
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.</returns>
public static MethodDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth)
public static MethodDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth, bool useRawMultiLineStringLiteralExpression)
{
SyntaxToken hlslSourceLiteralExpression = useRawMultiLineStringLiteralExpression switch
{
true => SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth),
false => Literal(hlslSource)
};
// This code produces a method declaration as follows:
//
// readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BuildHlslSource(out string hlslSource)
@@ -38,9 +46,7 @@ partial class ID2D1ShaderGenerator
AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
IdentifierName("hlslSource"),
LiteralExpression(
SyntaxKind.StringLiteralExpression,
SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth))))));
LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));
}
}
}