mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-21 19:57:11 +02:00
misc: chore: Use explicit types in Generator projects
This commit is contained in:
parent
fe661dc750
commit
e6b393e420
9 changed files with 45 additions and 44 deletions
|
@ -10,8 +10,8 @@ namespace Ryujinx.HLE.Generators
|
|||
{
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
var syntaxReceiver = (ServiceSyntaxReceiver)context.SyntaxReceiver;
|
||||
CodeGenerator generator = new CodeGenerator();
|
||||
ServiceSyntaxReceiver syntaxReceiver = (ServiceSyntaxReceiver)context.SyntaxReceiver;
|
||||
CodeGenerator generator = new();
|
||||
|
||||
generator.AppendLine("#nullable enable");
|
||||
generator.AppendLine("using System;");
|
||||
|
@ -19,14 +19,14 @@ namespace Ryujinx.HLE.Generators
|
|||
generator.EnterScope($"partial class IUserInterface");
|
||||
|
||||
generator.EnterScope($"public IpcService? GetServiceInstance(Type type, ServiceCtx context, object? parameter = 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.Empty);
|
||||
string name = GetFullName(className, context).Replace("global::", string.Empty);
|
||||
if (!name.StartsWith("Ryujinx.HLE.HOS.Services"))
|
||||
continue;
|
||||
var constructors = className.ChildNodes().Where(x => x.IsKind(SyntaxKind.ConstructorDeclaration)).Select(y => y as ConstructorDeclarationSyntax).ToArray();
|
||||
ConstructorDeclarationSyntax[] constructors = className.ChildNodes().Where(x => x.IsKind(SyntaxKind.ConstructorDeclaration)).Select(y => y as ConstructorDeclarationSyntax).ToArray();
|
||||
|
||||
if (!constructors.Any(x => x.ParameterList.Parameters.Count >= 1))
|
||||
continue;
|
||||
|
@ -36,10 +36,10 @@ namespace Ryujinx.HLE.Generators
|
|||
generator.EnterScope($"if (type == typeof({GetFullName(className, context)}))");
|
||||
if (constructors.Any(x => x.ParameterList.Parameters.Count == 2))
|
||||
{
|
||||
var type = constructors.Where(x => x.ParameterList.Parameters.Count == 2).FirstOrDefault().ParameterList.Parameters[1].Type;
|
||||
var model = context.Compilation.GetSemanticModel(type.SyntaxTree);
|
||||
var typeSymbol = model.GetSymbolInfo(type).Symbol as INamedTypeSymbol;
|
||||
var fullName = typeSymbol.ToString();
|
||||
TypeSyntax type = constructors.Where(x => x.ParameterList.Parameters.Count == 2).FirstOrDefault().ParameterList.Parameters[1].Type;
|
||||
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);");
|
||||
generator.LeaveScope();
|
||||
|
@ -65,7 +65,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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue