mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2025-02-23 21:54:37 +01:00
misc: chore: Use explicit types in Generator projects
This commit is contained in:
parent
fe661dc750
commit
e6b393e420
@ -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);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
{
|
||||
HipcSyntaxReceiver syntaxReceiver = (HipcSyntaxReceiver)context.SyntaxReceiver;
|
||||
|
||||
foreach (var commandInterface in syntaxReceiver.CommandInterfaces)
|
||||
foreach (CommandInterface commandInterface in syntaxReceiver.CommandInterfaces)
|
||||
{
|
||||
if (!NeedsIServiceObjectImplementation(context.Compilation, commandInterface.ClassDeclarationSyntax))
|
||||
{
|
||||
@ -86,7 +86,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
|
||||
GenerateMethodTable(generator, context.Compilation, commandInterface);
|
||||
|
||||
foreach (var method in commandInterface.CommandImplementations)
|
||||
foreach (MethodDeclarationSyntax method in commandInterface.CommandImplementations)
|
||||
{
|
||||
generator.AppendLine();
|
||||
|
||||
@ -127,9 +127,9 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
{
|
||||
generator.EnterScope($"return FrozenDictionary.ToFrozenDictionary(new []");
|
||||
|
||||
foreach (var method in commandInterface.CommandImplementations)
|
||||
foreach (MethodDeclarationSyntax method in commandInterface.CommandImplementations)
|
||||
{
|
||||
foreach (var commandId in GetAttributeArguments(compilation, method, TypeCommandAttribute, 0))
|
||||
foreach (string commandId in GetAttributeArguments(compilation, method, TypeCommandAttribute, 0))
|
||||
{
|
||||
string[] args = new string[method.ParameterList.Parameters.Count];
|
||||
|
||||
@ -141,7 +141,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
foreach (var parameter in method.ParameterList.Parameters)
|
||||
foreach (ParameterSyntax parameter in method.ParameterList.Parameters)
|
||||
{
|
||||
string canonicalTypeName = GetCanonicalTypeNameWithGenericArguments(compilation, parameter.Type);
|
||||
CommandArgType argType = GetCommandArgType(compilation, parameter);
|
||||
@ -191,7 +191,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
{
|
||||
ISymbol symbol = compilation.GetSemanticModel(syntaxNode.SyntaxTree).GetDeclaredSymbol(syntaxNode);
|
||||
|
||||
foreach (var attribute in symbol.GetAttributes())
|
||||
foreach (AttributeData attribute in symbol.GetAttributes())
|
||||
{
|
||||
if (attribute.AttributeClass.ToDisplayString() == attributeName && (uint)argIndex < (uint)attribute.ConstructorArguments.Length)
|
||||
{
|
||||
@ -211,7 +211,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
int outObjectsCount = 0;
|
||||
int buffersCount = 0;
|
||||
|
||||
foreach (var parameter in method.ParameterList.Parameters)
|
||||
foreach (ParameterSyntax parameter in method.ParameterList.Parameters)
|
||||
{
|
||||
if (IsObject(compilation, parameter))
|
||||
{
|
||||
@ -285,7 +285,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
int inMoveHandleIndex = 0;
|
||||
int inObjectIndex = 0;
|
||||
|
||||
foreach (var parameter in method.ParameterList.Parameters)
|
||||
foreach (ParameterSyntax parameter in method.ParameterList.Parameters)
|
||||
{
|
||||
string name = parameter.Identifier.Text;
|
||||
string argName = GetPrefixedArgName(name);
|
||||
@ -555,11 +555,11 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
{
|
||||
ISymbol symbol = compilation.GetSemanticModel(syntaxNode.SyntaxTree).GetTypeInfo(syntaxNode).Type;
|
||||
|
||||
foreach (var attribute in symbol.GetAttributes())
|
||||
foreach (AttributeData attribute in symbol.GetAttributes())
|
||||
{
|
||||
if (attribute.AttributeClass.ToDisplayString() == attributeName)
|
||||
{
|
||||
foreach (var kv in attribute.NamedArguments)
|
||||
foreach (KeyValuePair<string, TypedConstant> kv in attribute.NamedArguments)
|
||||
{
|
||||
if (kv.Key == argName)
|
||||
{
|
||||
@ -764,9 +764,9 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
|
||||
private static bool HasAttribute(Compilation compilation, ParameterSyntax parameterSyntax, string fullAttributeName)
|
||||
{
|
||||
foreach (var attributeList in parameterSyntax.AttributeLists)
|
||||
foreach (AttributeListSyntax attributeList in parameterSyntax.AttributeLists)
|
||||
{
|
||||
foreach (var attribute in attributeList.Attributes)
|
||||
foreach (AttributeSyntax attribute in attributeList.Attributes)
|
||||
{
|
||||
if (GetCanonicalTypeName(compilation, attribute) == fullAttributeName)
|
||||
{
|
||||
@ -781,8 +781,8 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
private static bool NeedsIServiceObjectImplementation(Compilation compilation, ClassDeclarationSyntax classDeclarationSyntax)
|
||||
{
|
||||
ITypeSymbol type = compilation.GetSemanticModel(classDeclarationSyntax.SyntaxTree).GetDeclaredSymbol(classDeclarationSyntax);
|
||||
var serviceObjectInterface = type.AllInterfaces.FirstOrDefault(x => x.ToDisplayString() == TypeIServiceObject);
|
||||
var interfaceMember = serviceObjectInterface?.GetMembers().FirstOrDefault(x => x.Name == "GetCommandHandlers");
|
||||
INamedTypeSymbol serviceObjectInterface = type.AllInterfaces.FirstOrDefault(x => x.ToDisplayString() == TypeIServiceObject);
|
||||
ISymbol interfaceMember = serviceObjectInterface?.GetMembers().FirstOrDefault(x => x.Name == "GetCommandHandlers");
|
||||
|
||||
// Return true only if the class implements IServiceObject but does not actually implement the method
|
||||
// that the interface defines, since this is the only case we want to handle, if the method already exists
|
||||
|
@ -24,9 +24,9 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
return;
|
||||
}
|
||||
|
||||
CommandInterface commandInterface = new CommandInterface(classDeclaration);
|
||||
CommandInterface commandInterface = new(classDeclaration);
|
||||
|
||||
foreach (var memberDeclaration in classDeclaration.Members)
|
||||
foreach (MemberDeclarationSyntax memberDeclaration in classDeclaration.Members)
|
||||
{
|
||||
if (memberDeclaration is MethodDeclarationSyntax methodDeclaration)
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||
|
||||
if (methodDeclaration.AttributeLists.Count != 0)
|
||||
{
|
||||
foreach (var attributeList in methodDeclaration.AttributeLists)
|
||||
foreach (AttributeListSyntax attributeList in methodDeclaration.AttributeLists)
|
||||
{
|
||||
if (attributeList.Attributes.Any(x => x.Name.ToString().Contains(attributeName)))
|
||||
{
|
||||
|
@ -147,7 +147,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
||||
|
||||
List<SyscallIdAndName> syscalls = new List<SyscallIdAndName>();
|
||||
|
||||
foreach (var method in syntaxReceiver.SvcImplementations)
|
||||
foreach (MethodDeclarationSyntax method in syntaxReceiver.SvcImplementations)
|
||||
{
|
||||
GenerateMethod32(generator, context.Compilation, method);
|
||||
GenerateMethod64(generator, context.Compilation, method);
|
||||
@ -206,7 +206,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
||||
List<string> logInArgs = new List<string>();
|
||||
List<string> logOutArgs = new List<string>();
|
||||
|
||||
foreach (var methodParameter in method.ParameterList.Parameters)
|
||||
foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters)
|
||||
{
|
||||
string name = methodParameter.Identifier.Text;
|
||||
string argName = GetPrefixedArgName(name);
|
||||
@ -325,7 +325,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
||||
List<string> logInArgs = new List<string>();
|
||||
List<string> logOutArgs = new List<string>();
|
||||
|
||||
foreach (var methodParameter in method.ParameterList.Parameters)
|
||||
foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters)
|
||||
{
|
||||
string name = methodParameter.Identifier.Text;
|
||||
string argName = GetPrefixedArgName(name);
|
||||
@ -468,7 +468,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
||||
generator.EnterScope($"public static void Dispatch{suffix}(Syscall syscall, {TypeExecutionContext} context, int id)");
|
||||
generator.EnterScope("switch (id)");
|
||||
|
||||
foreach (var syscall in syscalls)
|
||||
foreach (SyscallIdAndName syscall in syscalls)
|
||||
{
|
||||
generator.AppendLine($"case {syscall.Id}:");
|
||||
generator.IncreaseIndentation();
|
||||
|
@ -27,7 +27,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var memberDeclaration in classDeclaration.Members)
|
||||
foreach (MemberDeclarationSyntax memberDeclaration in classDeclaration.Members)
|
||||
{
|
||||
if (memberDeclaration is MethodDeclarationSyntax methodDeclaration)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@ -9,19 +10,19 @@ namespace Ryujinx.UI.LocaleGenerator
|
||||
{
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
var localeFile = context.AdditionalTextsProvider.Where(static x => x.Path.EndsWith("locales.json"));
|
||||
IncrementalValuesProvider<AdditionalText> localeFile = context.AdditionalTextsProvider.Where(static x => x.Path.EndsWith("locales.json"));
|
||||
|
||||
IncrementalValuesProvider<string> contents = localeFile.Select((text, cancellationToken) => text.GetText(cancellationToken)!.ToString());
|
||||
|
||||
context.RegisterSourceOutput(contents, (spc, content) =>
|
||||
{
|
||||
var lines = content.Split('\n').Where(x => x.Trim().StartsWith("\"ID\":")).Select(x => x.Split(':')[1].Trim().Replace("\"", string.Empty).Replace(",", string.Empty));
|
||||
IEnumerable<string> lines = content.Split('\n').Where(x => x.Trim().StartsWith("\"ID\":")).Select(x => x.Split(':')[1].Trim().Replace("\"", string.Empty).Replace(",", string.Empty));
|
||||
|
||||
StringBuilder enumSourceBuilder = new();
|
||||
enumSourceBuilder.AppendLine("namespace Ryujinx.Ava.Common.Locale;");
|
||||
enumSourceBuilder.AppendLine("public enum LocaleKeys");
|
||||
enumSourceBuilder.AppendLine("{");
|
||||
foreach (var line in lines)
|
||||
foreach (string? line in lines)
|
||||
{
|
||||
enumSourceBuilder.AppendLine($" {line},");
|
||||
}
|
||||
|
@ -239,8 +239,8 @@ namespace Spv.Generator
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var labels = _operandLabels.TryGetValue(Opcode, out var opLabels) ? opLabels : Array.Empty<string>();
|
||||
var result = _resultType == null ? string.Empty : $"{_resultType} ";
|
||||
string[] labels = _operandLabels.TryGetValue(Opcode, out string[] opLabels) ? opLabels : Array.Empty<string>();
|
||||
string result = _resultType == null ? string.Empty : $"{_resultType} ";
|
||||
return $"{result}{Opcode}{_operands.ToString(labels)}";
|
||||
}
|
||||
}
|
||||
|
@ -63,9 +63,9 @@ namespace Spv.Generator
|
||||
|
||||
public readonly string ToString(string[] labels)
|
||||
{
|
||||
var labeledParams = AllOperands.Zip(labels, (op, label) => $"{label}: {op}");
|
||||
var unlabeledParams = AllOperands.Skip(labels.Length).Select(op => op.ToString());
|
||||
var paramsToPrint = labeledParams.Concat(unlabeledParams);
|
||||
IEnumerable<string> labeledParams = AllOperands.Zip(labels, (op, label) => $"{label}: {op}");
|
||||
IEnumerable<string> unlabeledParams = AllOperands.Skip(labels.Length).Select(op => op.ToString());
|
||||
IEnumerable<string> paramsToPrint = labeledParams.Concat(unlabeledParams);
|
||||
return $"({string.Join(", ", paramsToPrint)})";
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace Spv.Generator
|
||||
|
||||
public Instruction NewInstruction(Op opcode, uint id = Instruction.InvalidId, Instruction resultType = null)
|
||||
{
|
||||
var result = _instPool.Allocate();
|
||||
Instruction result = _instPool.Allocate();
|
||||
result.Set(opcode, id, resultType);
|
||||
|
||||
return result;
|
||||
@ -93,7 +93,7 @@ namespace Spv.Generator
|
||||
|
||||
public Instruction AddExtInstImport(string import)
|
||||
{
|
||||
var key = new DeterministicStringKey(import);
|
||||
DeterministicStringKey key = new DeterministicStringKey(import);
|
||||
|
||||
if (_extInstImports.TryGetValue(key, out Instruction extInstImport))
|
||||
{
|
||||
@ -113,7 +113,7 @@ namespace Spv.Generator
|
||||
|
||||
private void AddTypeDeclaration(Instruction instruction, bool forceIdAllocation)
|
||||
{
|
||||
var key = new TypeDeclarationKey(instruction);
|
||||
TypeDeclarationKey key = new TypeDeclarationKey(instruction);
|
||||
|
||||
if (!forceIdAllocation)
|
||||
{
|
||||
@ -214,7 +214,7 @@ namespace Spv.Generator
|
||||
constant.Opcode == Op.OpConstantNull ||
|
||||
constant.Opcode == Op.OpConstantComposite);
|
||||
|
||||
var key = new ConstantKey(constant);
|
||||
ConstantKey key = new ConstantKey(constant);
|
||||
|
||||
if (_constants.TryGetValue(key, out Instruction global))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user