From 10dfef9a5c1efbba568a084ff0eac756d1c2dc4f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 14 Nov 2020 16:35:24 +0100 Subject: [PATCH] Fixed nullability warnings --- .../Extensions/TypeExtensions.cs | 4 +- .../Extensions/DynamicMethod{T}.cs | 2 +- .../Extensions/ILGeneratorExtensions.cs | 2 +- .../Extensions/SyntaxNodeExtensions.cs | 18 +++--- .../Extensions/TypeExtensions.cs | 2 +- .../Mappings/HlslKnownMethods.cs | 2 +- .../Mappings/HlslKnownTypes.cs | 60 +++++++++---------- .../Renderer/ShaderRenderer.cs | 2 +- src/ComputeSharp.Shaders/ShaderRunner{T}.cs | 2 +- .../Translation/MethodDecompiler.cs | 6 +- .../Translation/Models/ReadableMember.cs | 8 +-- .../Translation/ShaderHashCodeProvider.cs | 4 +- .../Translation/ShaderLoader{T}.cs | 10 ++-- .../Translation/ShaderSyntaxRewriter.cs | 24 ++++---- 14 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/ComputeSharp.Graphics/Extensions/TypeExtensions.cs b/src/ComputeSharp.Graphics/Extensions/TypeExtensions.cs index 09001460..b309017d 100644 --- a/src/ComputeSharp.Graphics/Extensions/TypeExtensions.cs +++ b/src/ComputeSharp.Graphics/Extensions/TypeExtensions.cs @@ -33,11 +33,11 @@ namespace ComputeSharp.Graphics.Extensions if (type.IsArray) { int rank = type.GetArrayRank(); - return $"{type.GetElementType().ToFriendlyString()}[{new string(Enumerable.Repeat(',', rank - 1).ToArray())}]"; + return $"{type.GetElementType()!.ToFriendlyString()}[{new string(Enumerable.Repeat(',', rank - 1).ToArray())}]"; } // Non generic types - string name; + string? name; if (type.GetGenericArguments().Length == 0) return KnownTypes.TryGetValue(type, out name) ? name : type.Name; // Generic types diff --git a/src/ComputeSharp.Shaders/Extensions/DynamicMethod{T}.cs b/src/ComputeSharp.Shaders/Extensions/DynamicMethod{T}.cs index 3b08edd3..0d5c89c2 100644 --- a/src/ComputeSharp.Shaders/Extensions/DynamicMethod{T}.cs +++ b/src/ComputeSharp.Shaders/Extensions/DynamicMethod{T}.cs @@ -30,7 +30,7 @@ namespace System.Reflection.Emit /// static DynamicMethod() { - MethodInfo method = typeof(T).GetMethod("Invoke"); + MethodInfo method = typeof(T).GetMethod("Invoke")!; ReturnType = method.ReturnType; ParameterTypes = method.GetParameters().Select(p => p.ParameterType).ToArray(); } diff --git a/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs b/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs index eb251143..9aa9af8f 100644 --- a/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs @@ -21,7 +21,7 @@ namespace System.Reflection.Emit il.Emit(field.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, field); break; case PropertyInfo property when property.CanRead: - il.EmitCall(property.GetMethod.IsStatic ? OpCodes.Call : OpCodes.Callvirt, property.GetMethod, null); + il.EmitCall(property.GetMethod!.IsStatic ? OpCodes.Call : OpCodes.Callvirt, property.GetMethod, null); break; default: throw new ArgumentException($"The input {member.GetType()} instance can't be read"); } diff --git a/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs index 1f00c8b9..c5c50b6e 100644 --- a/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs @@ -94,7 +94,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax memberInfo = propertyInfo; break; case MethodInfo methodInfo: - string methodName = $"{methodInfo.DeclaringType.Name}_{methodInfo.Name}"; + string methodName = $"{methodInfo.DeclaringType!.Name}_{methodInfo.Name}"; method = (methodName, methodInfo); return SyntaxFactory.IdentifierName(methodName).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()); default: throw new InvalidOperationException($"Invalid symbol kind: {memberInfos.First().GetType()}"); @@ -113,7 +113,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax } // Process the input node if it's a known method invocation - if (HlslKnownMethods.TryGetMappedName(containingMemberSymbolInfo.Symbol, memberSymbol, out string? mappedName)) + if (HlslKnownMethods.TryGetMappedName(containingMemberSymbolInfo.Symbol!, memberSymbol, out string? mappedName)) { string expression = memberSymbol.IsStatic ? mappedName : $"{node.Expression}{mappedName}"; return SyntaxFactory.IdentifierName(expression).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()); @@ -127,9 +127,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax { // Get the containing type string - typeFullname = memberSymbol.ContainingType.ToString(), - assemblyFullname = memberSymbol.ContainingAssembly.ToString(); - Type memberDeclaringType = Type.GetType($"{typeFullname}, {assemblyFullname}"); + typeFullname = memberSymbol.ContainingType.ToString()!, + assemblyFullname = memberSymbol.ContainingAssembly.ToString()!; + Type memberDeclaringType = Type.GetType($"{typeFullname}, {assemblyFullname}")!; // Static field or property if (memberSymbol.Kind == SymbolKind.Field || memberSymbol.Kind == SymbolKind.Property) @@ -139,12 +139,12 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax switch (memberSymbol.Kind) { case SymbolKind.Field: - FieldInfo fieldInfo = memberDeclaringType.GetField(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); + FieldInfo fieldInfo = memberDeclaringType.GetField(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)!; isReadonly = fieldInfo.IsInitOnly; memberInfo = fieldInfo; break; case SymbolKind.Property: - PropertyInfo propertyInfo = memberDeclaringType.GetProperty(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); + PropertyInfo propertyInfo = memberDeclaringType.GetProperty(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)!; isReadonly = !propertyInfo.CanWrite; memberInfo = propertyInfo; break; @@ -156,8 +156,8 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax } // Static method - MethodInfo methodInfo = memberDeclaringType.GetMethod(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); - string name = $"{methodInfo.DeclaringType.Name}_{methodInfo.Name}"; + MethodInfo methodInfo = memberDeclaringType.GetMethod(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)!; + string name = $"{methodInfo.DeclaringType!.Name}_{methodInfo.Name}"; method = (name, methodInfo); return SyntaxFactory.IdentifierName(name).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()); diff --git a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs index 56b40454..081a27c0 100644 --- a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs @@ -36,7 +36,7 @@ namespace System /// when a member with the given name is found, otherwise public static bool TryFindAncestorMember(this Type type, string name, BindingFlags bindingAttr, [NotNullWhen(true)] out (Type DeclaringType, MemberInfo MemberInfo)? result) { - while ((type = type.DeclaringType) != null) + while ((type = type.DeclaringType!) != null) { MemberInfo[] memberInfos = type.GetMember(name, bindingAttr); if (memberInfos.Length > 0) diff --git a/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs index 8f8e92dd..a673abf9 100644 --- a/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs @@ -276,7 +276,7 @@ namespace ComputeSharp.Shaders.Mappings [Pure] public static bool TryGetMappedName(ISymbol containingMemberSymbol, ISymbol memberSymbol, [NotNullWhen(true)] out string? mapped) { - string fullTypeName = containingMemberSymbol.IsStatic ? containingMemberSymbol.ToString() : memberSymbol.ContainingType.ToString(); + string fullTypeName = containingMemberSymbol.IsStatic ? containingMemberSymbol.ToString()! : memberSymbol.ContainingType.ToString()!; // Check if the target method is a known method return KnownMethods.TryGetValue($"{fullTypeName}{Type.Delimiter}{memberSymbol.Name}", out mapped); diff --git a/src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs index 170953b0..9cf7fb83 100644 --- a/src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs @@ -16,33 +16,33 @@ namespace ComputeSharp.Shaders.Mappings /// private static readonly IReadOnlyDictionary KnownTypes = new Dictionary { - [typeof(bool).FullName] = "bool", - [typeof(Bool).FullName] = "bool", - [typeof(Bool2).FullName] = "bool2", - [typeof(Bool3).FullName] = "bool3", - [typeof(Bool4).FullName] = "bool4", - [typeof(int).FullName] = "int", - [typeof(Int2).FullName] = "int2", - [typeof(Int3).FullName] = "int3", - [typeof(Int4).FullName] = "int4", - [typeof(uint).FullName] = "uint", - [typeof(UInt2).FullName] = "uint2", - [typeof(UInt3).FullName] = "uint3", - [typeof(UInt4).FullName] = "uint4", - [typeof(float).FullName] = "float", - [typeof(Float2).FullName] = "float2", - [typeof(Float3).FullName] = "float3", - [typeof(Float4).FullName] = "float4", - [typeof(Vector2).FullName] = "float2", - [typeof(Vector3).FullName] = "float3", - [typeof(Vector4).FullName] = "float4", - [typeof(double).FullName] = "double", - [typeof(Double2).FullName] = "double2", - [typeof(Double3).FullName] = "double3", - [typeof(Double4).FullName] = "double4", - [typeof(ThreadIds).FullName] = "uint3", - [typeof(ReadOnlyBuffer<>).FullName] = "StructuredBuffer", - [typeof(ReadWriteBuffer<>).FullName] = "RWStructuredBuffer" + [typeof(bool).FullName!] = "bool", + [typeof(Bool).FullName!] = "bool", + [typeof(Bool2).FullName!] = "bool2", + [typeof(Bool3).FullName!] = "bool3", + [typeof(Bool4).FullName!] = "bool4", + [typeof(int).FullName!] = "int", + [typeof(Int2).FullName!] = "int2", + [typeof(Int3).FullName!] = "int3", + [typeof(Int4).FullName!] = "int4", + [typeof(uint).FullName!] = "uint", + [typeof(UInt2).FullName!] = "uint2", + [typeof(UInt3).FullName!] = "uint3", + [typeof(UInt4).FullName!] = "uint4", + [typeof(float).FullName!] = "float", + [typeof(Float2).FullName!] = "float2", + [typeof(Float3).FullName!] = "float3", + [typeof(Float4).FullName!] = "float4", + [typeof(Vector2).FullName!] = "float2", + [typeof(Vector3).FullName!] = "float3", + [typeof(Vector4).FullName!] = "float4", + [typeof(double).FullName!] = "double", + [typeof(Double2).FullName!] = "double2", + [typeof(Double3).FullName!] = "double3", + [typeof(Double4).FullName!] = "double4", + [typeof(ThreadIds).FullName!] = "uint3", + [typeof(ReadOnlyBuffer<>).FullName!] = "StructuredBuffer", + [typeof(ReadWriteBuffer<>).FullName!] = "RWStructuredBuffer" }; private static HashSet _HlslMappedVectorTypes { get; } = new HashSet(new[] @@ -140,10 +140,10 @@ namespace ComputeSharp.Shaders.Mappings [Pure] public static string GetMappedName(Type type) { - Type declaredType = type.IsArray ? type.GetElementType() : type; + Type declaredType = type.IsArray ? type.GetElementType()! : type; string fullname = $"{declaredType.Namespace}{Type.Delimiter}{declaredType.Name}", - mappedName = KnownTypes.TryGetValue(fullname, out string mapped) ? mapped : declaredType.Name, + mappedName = KnownTypes.TryGetValue(fullname, out string? mapped) ? mapped : declaredType.Name, hlslName = declaredType.IsGenericType ? mappedName + $"<{GetMappedName(declaredType.GetGenericArguments()[0])}>" : mappedName; return hlslName; @@ -161,7 +161,7 @@ namespace ComputeSharp.Shaders.Mappings string genericArguments = indexOfOpenBracket >= 0 ? name.Substring(indexOfOpenBracket) : string.Empty, polishedName = indexOfOpenBracket >= 0 ? name.Remove(indexOfOpenBracket) + "`1" : name, - mappedName = KnownTypes.TryGetValue(polishedName, out string mapped) ? mapped : Regex.Match(polishedName, @"[^\.]+$").Value; + mappedName = KnownTypes.TryGetValue(polishedName, out string? mapped) ? mapped : Regex.Match(polishedName, @"[^\.]+$").Value; return $"{mappedName}{genericArguments}"; } diff --git a/src/ComputeSharp.Shaders/Renderer/ShaderRenderer.cs b/src/ComputeSharp.Shaders/Renderer/ShaderRenderer.cs index 8b7339de..e7a5df56 100644 --- a/src/ComputeSharp.Shaders/Renderer/ShaderRenderer.cs +++ b/src/ComputeSharp.Shaders/Renderer/ShaderRenderer.cs @@ -25,7 +25,7 @@ namespace ComputeSharp.Shaders.Renderer Assembly assembly = Assembly.GetExecutingAssembly(); string filename = assembly.GetManifestResourceNames().First(name => name.EndsWith("ShaderTemplate.mustache")); - using Stream stream = assembly.GetManifestResourceStream(filename); + using Stream stream = assembly.GetManifestResourceStream(filename)!; using StreamReader reader = new StreamReader(stream); Template = reader.ReadToEnd(); diff --git a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs index e60f27db..7d1a6e81 100644 --- a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs @@ -91,7 +91,7 @@ namespace ComputeSharp.Shaders // Create the shader key ShaderKey key = new ShaderKey(ShaderHashCodeProvider.GetHashCode(shader), threadsX, threadsY, threadsZ); CachedShader shaderData; - PipelineState pipelineState; + PipelineState? pipelineState; lock (ShadersCache) { diff --git a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs index abf4038c..ac0b4854 100644 --- a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs @@ -70,7 +70,7 @@ namespace ComputeSharp.Shaders.Translation _Compilation = CSharpCompilation.Create("ShaderAssembly").WithReferences(metadataReferences); // Monitor for new assemblies being loaded - AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad; + AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad!; } // Increment the shader assembly when a new assembly is loaded @@ -117,7 +117,7 @@ namespace ComputeSharp.Shaders.Translation EntityHandle typeHandle = MetadataTokenHelpers.TryAsEntityHandle(metadataToken) ?? throw new InvalidOperationException(); // Get or create a decompiler for the target assembly, and decompile the type - if (!Decompilers.TryGetValue(assemblyPath, out CSharpDecompiler decompiler)) + if (!Decompilers.TryGetValue(assemblyPath, out CSharpDecompiler? decompiler)) { decompiler = CreateDecompiler(assemblyPath); Decompilers.Add(assemblyPath, decompiler); @@ -241,7 +241,7 @@ namespace ComputeSharp.Shaders.Translation select declaration).ToArray(); // Insert the explicit declarations at the start of the method - int start = rootNode.Body.ChildNodes().First().SpanStart; + int start = rootNode.Body!.ChildNodes().First().SpanStart; foreach (var declaration in outs.Reverse()) { source = source.Insert(start, $"{declaration}{Environment.NewLine} "); diff --git a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs index d20dd74e..1e816f38 100644 --- a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs +++ b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs @@ -24,7 +24,7 @@ namespace ComputeSharp.Shaders.Translation.Models // General properties Member = memberInfo; Name = memberInfo.Name; - DeclaringType = memberInfo.DeclaringType; + DeclaringType = memberInfo.DeclaringType!; // Type specific properties if (memberInfo is FieldInfo fieldInfo) @@ -36,7 +36,7 @@ namespace ComputeSharp.Shaders.Translation.Models else if (memberInfo is PropertyInfo propertyInfo) { Member = propertyInfo; - IsStatic = propertyInfo.GetMethod.IsStatic; + IsStatic = propertyInfo.GetMethod!.IsStatic; MemberType = propertyInfo.PropertyType; } else throw new InvalidOperationException("Field and property can't both be null at the same time"); @@ -76,8 +76,8 @@ namespace ComputeSharp.Shaders.Translation.Models { return Member switch { - FieldInfo field => field.GetValue(instance), - PropertyInfo property => property.GetValue(instance), + FieldInfo field => field.GetValue(instance)!, + PropertyInfo property => property.GetValue(instance)!, _ => throw new InvalidOperationException("Field and property can't both be null at the same time") }; } diff --git a/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs b/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs index c0421fde..bc07e89d 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs @@ -92,8 +92,8 @@ namespace ComputeSharp.Shaders.Translation return DynamicMethod>.New(il => { MethodInfo - getMethodInfo = typeof(Delegate).GetProperty(nameof(Delegate.Method)).GetMethod, - getHashCodeInfo = typeof(object).GetMethod(nameof(object.GetHashCode)); + getMethodInfo = typeof(Delegate).GetProperty(nameof(Delegate.Method))!.GetMethod!, + getHashCodeInfo = typeof(object).GetMethod(nameof(object.GetHashCode))!; foreach (FieldInfo fieldInfo in fieldInfos) { // (hashcode << 5) + hashcode diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs index 0541da9a..355f0350 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs @@ -193,7 +193,7 @@ namespace ComputeSharp.Shaders.Translation } else if (fieldType.IsDelegate() && memberInfo.GetValue(shader) is Delegate func && - (func.Method.IsStatic || func.Method.DeclaringType.IsStatelessDelegateContainer()) && + (func.Method.IsStatic || func.Method.DeclaringType!.IsStatelessDelegateContainer()) && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || HlslKnownTypes.IsKnownVectorType(type))) @@ -211,7 +211,7 @@ namespace ComputeSharp.Shaders.Translation private void LoadMethodSource(object shader) { // Decompile the shader method - MethodInfo methodInfo = typeof(T).GetMethod(nameof(IComputeShader.Execute)); + MethodInfo methodInfo = typeof(T).GetMethod(nameof(IComputeShader.Execute))!; MethodDecompiler.Instance.GetSyntaxTree(methodInfo, MethodType.Execute, out MethodDeclarationSyntax root, out SemanticModel semanticModel); // Rewrite the shader method (eg. to fix the type declarations) @@ -220,7 +220,7 @@ namespace ComputeSharp.Shaders.Translation // Extract the implicit local functions var locals = root.DescendantNodes().OfType().ToArray(); - root = root.RemoveNodes(locals, SyntaxRemoveOptions.KeepNoTrivia); + root = root.RemoveNodes(locals, SyntaxRemoveOptions.KeepNoTrivia)!; foreach (var local in locals) { string alignedLocal = local.ToFullString().RemoveLeftPadding().Trim(' ', '\r', '\n'); @@ -264,7 +264,7 @@ namespace ComputeSharp.Shaders.Translation MethodDecompiler.Instance.GetSyntaxTree(methodInfo, MethodType.Static, out MethodDeclarationSyntax root, out SemanticModel semanticModel); // Rewrite the method - ShaderSyntaxRewriter syntaxRewriter = new ShaderSyntaxRewriter(semanticModel, methodInfo.DeclaringType); + ShaderSyntaxRewriter syntaxRewriter = new ShaderSyntaxRewriter(semanticModel, methodInfo.DeclaringType!); root = (MethodDeclarationSyntax)syntaxRewriter.Visit(root); // Register the captured static members @@ -297,7 +297,7 @@ namespace ComputeSharp.Shaders.Translation // Get the final function info instance FunctionInfo functionInfo = new FunctionInfo( methodInfo.ReturnType, - $"{methodInfo.DeclaringType.FullName}{Type.Delimiter}{methodInfo.Name}", + $"{methodInfo.DeclaringType!.FullName}{Type.Delimiter}{methodInfo.Name}", string.Join(", ", methodInfo.GetParameters().Select(p => $"{p.ParameterType.ToFriendlyString()} {p.Name}")), root.ReturnType.ToString(), name, diff --git a/src/ComputeSharp.Shaders/Translation/ShaderSyntaxRewriter.cs b/src/ComputeSharp.Shaders/Translation/ShaderSyntaxRewriter.cs index 37d1f584..4e62fb13 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderSyntaxRewriter.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderSyntaxRewriter.cs @@ -51,7 +51,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node) { - node = (IdentifierNameSyntax)base.VisitIdentifierName(node); + node = (IdentifierNameSyntax)base.VisitIdentifierName(node)!; node = node.ReplaceIdentifierName(DeclaringType, out var variable); // Register the captured member, if any @@ -66,9 +66,9 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitParameter(ParameterSyntax node) { - node = (ParameterSyntax)base.VisitParameter(node); + node = (ParameterSyntax)base.VisitParameter(node)!; node = node.WithAttributeLists(default); - node = node.ReplaceType(node.Type); + node = node.ReplaceType(node.Type!); return node; } @@ -76,7 +76,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitArgument(ArgumentSyntax node) { - node = (ArgumentSyntax)base.VisitArgument(node); + node = (ArgumentSyntax)base.VisitArgument(node)!; if (node.RefKindKeyword.IsKind(SyntaxKind.RefKeyword)) { @@ -89,7 +89,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitCastExpression(CastExpressionSyntax node) { - node = (CastExpressionSyntax)base.VisitCastExpression(node); + node = (CastExpressionSyntax)base.VisitCastExpression(node)!; return node.ReplaceType(node.Type); } @@ -97,7 +97,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) { - node = (LocalDeclarationStatementSyntax)base.VisitLocalDeclarationStatement(node); + node = (LocalDeclarationStatementSyntax)base.VisitLocalDeclarationStatement(node)!; return node.ReplaceType(node.Declaration.Type); } @@ -105,10 +105,10 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) { - node = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node); + node = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!; node = node.ReplaceType(node.Type); - if (node.ArgumentList.Arguments.Count == 0) + if (node.ArgumentList!.Arguments.Count == 0) { return SyntaxFactory.CastExpression(node.Type, SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(0))); } @@ -119,7 +119,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitDefaultExpression(DefaultExpressionSyntax node) { - node = (DefaultExpressionSyntax)base.VisitDefaultExpression(node); + node = (DefaultExpressionSyntax)base.VisitDefaultExpression(node)!; node = node.ReplaceType(node.Type); return SyntaxFactory.CastExpression(node.Type, SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(0))); @@ -128,7 +128,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node) { - node = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node); + node = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!; SyntaxNode syntaxNode = node.ReplaceMember(SemanticModel, out var variable, out var method); // Register the captured members, if any @@ -147,7 +147,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node) { - node = (InvocationExpressionSyntax)base.VisitInvocationExpression(node); + node = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!; node = node.ReplaceInvocation(DeclaringType, out var variable, out var method); // Register the captured members, if any @@ -166,7 +166,7 @@ namespace ComputeSharp.Shaders.Translation /// public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node) { - node = (MethodDeclarationSyntax)base.VisitMethodDeclaration(node); + node = (MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!; // Replace the return type node, if needed if (!node.ReturnType.ToString().Equals("void"))