Minor code refactoring
このコミットが含まれているのは:
1 親
fd07b6a89f
コミット
36d9a54d1b
2ファイル変更
+30
-9
検索条件に一致するファイルはありません
@@ -172,6 +172,7 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
/// Checks a <see cref="InvocationExpressionSyntax"/> instance and replaces it to be HLSL compatible, if needed
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="InvocationExpressionSyntax"/> to check and modify if needed</param>
|
||||
/// <param name="declaringType">The <see cref="Type"/> in which the input syntax tree is declared in</param>
|
||||
/// <param name="variable">The info on parsed static members, if any</param>
|
||||
/// <param name="method">The info on parsed static methods, if any</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that is compatible with HLSL</returns>
|
||||
@@ -183,15 +184,11 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
method = null;
|
||||
|
||||
// Explore the nested classes from bottom to top
|
||||
string cSharpName = node.Expression.ToString();
|
||||
while ((declaringType = declaringType.DeclaringType) != null)
|
||||
if (declaringType.TryFindAncestorMember(node.Expression.ToString(), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, out var result))
|
||||
{
|
||||
MemberInfo[] memberInfos = declaringType.GetMember(cSharpName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
if (!(memberInfos.FirstOrDefault() is MemberInfo first)) continue;
|
||||
|
||||
// If a static method or delegate is found, track it
|
||||
string name = $"{declaringType.Name}_{first.Name}";
|
||||
switch (first)
|
||||
string name = $"{result.Value.DeclaringType.Name}_{result.Value.MemberInfo.Name}";
|
||||
switch (result.Value.MemberInfo)
|
||||
{
|
||||
case FieldInfo fieldInfo:
|
||||
variable = (name, fieldInfo);
|
||||
@@ -200,10 +197,10 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
variable = (name, propertyInfo);
|
||||
break;
|
||||
case MethodInfo methodInfo:
|
||||
|
||||
|
||||
method = (name, methodInfo);
|
||||
return SyntaxFactory.InvocationExpression(SyntaxFactory.ParseExpression(name), node.ArgumentList).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
|
||||
default: throw new InvalidOperationException($"Invalid symbol kind: {memberInfos.First().GetType()}");
|
||||
default: throw new InvalidOperationException($"Invalid symbol kind: {result.Value.MemberInfo.GetType()}");
|
||||
}
|
||||
|
||||
// Return the mapped expression
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -29,6 +30,29 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsStatelessDelegateContainer(this Type type) => type.GetFields(BindingFlags.Static | BindingFlags.Public).Length > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find an ancestor member starting from the input <see cref="Type"/>
|
||||
/// </summary>
|
||||
/// <param name="type">The input type to start the search from</param>
|
||||
/// <param name="name">The name of the member to retrieve</param>
|
||||
/// <param name="bindingAttr">A bitmask comprised of one or more <see cref="BindingFlags"></see> that specify how the search is conducted</param>
|
||||
/// <returns><see langword="true"/> when a member with the given name is found, <see langword="false"/> otherwise</returns>
|
||||
public static bool TryFindAncestorMember(this Type type, string name, BindingFlags bindingAttr, [NotNullWhen(true)] out (Type DeclaringType, MemberInfo MemberInfo)? result)
|
||||
{
|
||||
while ((type = type.DeclaringType) != null)
|
||||
{
|
||||
MemberInfo[] memberInfos = type.GetMember(name, bindingAttr);
|
||||
if (memberInfos.Length > 0)
|
||||
{
|
||||
result = (type, memberInfos[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known types to display string
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする