mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-11-19 17:21:15 +01:00
misc: chore: Use explicit types & fix object creation
This commit is contained in:
1 parent
69c088004a
commit
88cef7e853
461 files changed
+3163
-3082
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();
|
||||
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);");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user