misc: chore: Use explicit types & fix object creation

This commit is contained in:
KeatonTheBot committed 2026-05-30 16:26:50 -05:00
1 parent 9d3fecf334
commit 76a123b81d
454 files changed
+3042 -2961

No files matched your search

@@ -1,6 +1,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.Linq;
namespace Ryujinx.HLE.Generators
@@ -10,7 +11,7 @@ namespace Ryujinx.HLE.Generators
{
public void Execute(GeneratorExecutionContext context)
{
var syntaxReceiver = (ServiceSyntaxReceiver)context.SyntaxReceiver;
ServiceSyntaxReceiver syntaxReceiver = (ServiceSyntaxReceiver)context.SyntaxReceiver;
CodeGenerator generator = new();
generator.AppendLine("#nullable enable");
@@ -21,16 +22,16 @@ namespace Ryujinx.HLE.Generators
generator.EnterScope($"public IpcService? GetServiceInstance(Type type, ServiceCtx context, object? parameter = null)");
if (syntaxReceiver != null)
{
foreach (var className in syntaxReceiver.Types)
foreach (ClassDeclarationSyntax className in syntaxReceiver.Types)
{
if (className.Modifiers.Any(SyntaxKind.AbstractKeyword) ||
className.Modifiers.Any(SyntaxKind.PrivateKeyword) ||
!className.AttributeLists.Any(x => x.Attributes.Any(y => y.ToString().StartsWith("Service"))))
continue;
var name = GetFullName(className, context).Replace("global::", "");
string name = GetFullName(className, context).Replace("global::", "");
if (!name.StartsWith("Ryujinx.HLE.HOS.Services"))
continue;
var constructors = className.ChildNodes().Where(x => x.IsKind(SyntaxKind.ConstructorDeclaration))
IEnumerable<ConstructorDeclarationSyntax> constructors = className.ChildNodes().Where(x => x.IsKind(SyntaxKind.ConstructorDeclaration))
.Select(y => y as ConstructorDeclarationSyntax);
if (!constructors.Any(x => x?.ParameterList.Parameters.Count >= 1))
@@ -42,14 +43,14 @@ namespace Ryujinx.HLE.Generators
generator.EnterScope($"if (type == typeof({GetFullName(className, context)}))");
if (constructors.Any(x => x?.ParameterList.Parameters.Count == 2))
{
var type = constructors
TypeSyntax type = constructors
.FirstOrDefault(x => x?.ParameterList.Parameters.Count == 2).ParameterList
.Parameters[1].Type;
if (type?.SyntaxTree != null)
{
var model = context.Compilation.GetSemanticModel(type.SyntaxTree);
var typeSymbol = model.GetSymbolInfo(type).Symbol as INamedTypeSymbol;
var fullName = typeSymbol?.ToString();
SemanticModel model = context.Compilation.GetSemanticModel(type.SyntaxTree);
INamedTypeSymbol typeSymbol = model.GetSymbolInfo(type).Symbol as INamedTypeSymbol;
string fullName = typeSymbol?.ToString();
generator.EnterScope("if (parameter != null)");
generator.AppendLine($"return new {GetFullName(className, context)}(context, ({fullName})parameter);");
}
@@ -78,7 +79,7 @@ namespace Ryujinx.HLE.Generators
private string GetFullName(ClassDeclarationSyntax syntaxNode, GeneratorExecutionContext context)
{
var typeSymbol = context.Compilation.GetSemanticModel(syntaxNode.SyntaxTree).GetDeclaredSymbol(syntaxNode);
INamedTypeSymbol typeSymbol = context.Compilation.GetSemanticModel(syntaxNode.SyntaxTree).GetDeclaredSymbol(syntaxNode);
return typeSymbol?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
}