Remove conditional paths for raw multiline strings

このコミットが含まれているのは:
Sergio Pedri committed 2022-09-16 23:03:35 +02:00
1 親 bbc06bf90a
コミット 5cd53f3077
4ファイル変更
+26 -49

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

@@ -19,25 +19,19 @@ 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, bool useRawMultiLineStringLiteralExpression)
public static MethodDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth)
{
// If raw multiline string literal expressions are used, create a token to represent it. Here some spaces are
// Create a token to represent the raw multiline string literal expression with the HLSL source. Here some spaces are
// also added to properly align the resulting text with one indentation below the declaring string constant.
// The spaces are: 4 for each containing type, 4 for the containing method, and 4 for the one additional indentation.
string indentation = new(' ', 4 * hierarchyDepth + 4 + 4);
SyntaxToken hlslSourceLiteralToken = useRawMultiLineStringLiteralExpression switch
{
true =>
Token(
TriviaList(),
SyntaxKind.MultiLineRawStringLiteralToken,
$"\"\"\"\n{indentation}{hlslSource.Replace("\n", $"\n{indentation}")}\"\"\"",
hlslSource,
TriviaList()),
false => Literal(hlslSource)
};
SyntaxToken hlslSourceLiteralToken = Token(
TriviaList(),
SyntaxKind.MultiLineRawStringLiteralToken,
$"\"\"\"\n{indentation}{hlslSource.Replace("\n", $"\n{indentation}")}\"\"\"",
hlslSource,
TriviaList());
// This code produces a method declaration as follows:
//
+4 -9
ファイルの表示
@@ -218,18 +218,13 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
.Select(static (item, token) => (item.Hierarchy, item.Source.HlslSource))
.WithComparers(HierarchyInfo.Comparer.Default, EqualityComparer<string>.Default);
// Check whether raw multiline string literals can be used (C# preview)
IncrementalValueProvider<bool> canUseRawMultiLineStringLiterals =
context.ParseOptionsProvider
.Select((item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.Preview });
// Generate the BuildHlslSource() methods
context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseRawMultiLineStringLiterals), static (context, item) =>
context.RegisterSourceOutput(hlslSourceInfo, static (context, item) =>
{
MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.Left.HlslSource, item.Left.Hierarchy.Hierarchy.Length, item.Right);
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, buildHlslStringMethod, canUseSkipLocalsInit: false);
MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.HlslSource, item.Hierarchy.Hierarchy.Length);
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, buildHlslStringMethod, canUseSkipLocalsInit: false);
context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(BuildHlslSource)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
context.AddSource($"{item.Hierarchy.FilenameHint}.{nameof(BuildHlslSource)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
});
// Get a filtered sequence to enable caching