From 2853f5b42673c228d8ca3c9836982d07df3fd3e1 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sun, 26 Jan 2025 15:45:43 -0600 Subject: [PATCH] misc: chore: Use collection expressions in Generator projects --- .../Hipc/CommandInterface.cs | 2 +- .../Hipc/HipcGenerator.cs | 2 +- .../Hipc/HipcSyntaxReceiver.cs | 2 +- .../SyscallGenerator.cs | 14 ++++++------ .../SyscallSyntaxReceiver.cs | 2 +- src/Spv.Generator/Instruction.cs | 8 +++---- src/Spv.Generator/InstructionOperands.cs | 2 +- src/Spv.Generator/Module.cs | 22 +++++++++---------- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Ryujinx.Horizon.Generators/Hipc/CommandInterface.cs b/src/Ryujinx.Horizon.Generators/Hipc/CommandInterface.cs index 2dcdfe5a2..8ed9669ba 100644 --- a/src/Ryujinx.Horizon.Generators/Hipc/CommandInterface.cs +++ b/src/Ryujinx.Horizon.Generators/Hipc/CommandInterface.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Horizon.Generators.Hipc public CommandInterface(ClassDeclarationSyntax classDeclarationSyntax) { ClassDeclarationSyntax = classDeclarationSyntax; - CommandImplementations = new List(); + CommandImplementations = []; } } } diff --git a/src/Ryujinx.Horizon.Generators/Hipc/HipcGenerator.cs b/src/Ryujinx.Horizon.Generators/Hipc/HipcGenerator.cs index 54ac9ccdd..b68e05681 100644 --- a/src/Ryujinx.Horizon.Generators/Hipc/HipcGenerator.cs +++ b/src/Ryujinx.Horizon.Generators/Hipc/HipcGenerator.cs @@ -257,7 +257,7 @@ namespace Ryujinx.Horizon.Generators.Hipc generator.AppendLine(); } - List outParameters = new(); + List outParameters = []; string[] args = new string[method.ParameterList.Parameters.Count]; diff --git a/src/Ryujinx.Horizon.Generators/Hipc/HipcSyntaxReceiver.cs b/src/Ryujinx.Horizon.Generators/Hipc/HipcSyntaxReceiver.cs index 5eced63ec..858b4a2a5 100644 --- a/src/Ryujinx.Horizon.Generators/Hipc/HipcSyntaxReceiver.cs +++ b/src/Ryujinx.Horizon.Generators/Hipc/HipcSyntaxReceiver.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Horizon.Generators.Hipc public HipcSyntaxReceiver() { - CommandInterfaces = new List(); + CommandInterfaces = []; } public void OnVisitSyntaxNode(SyntaxNode syntaxNode) diff --git a/src/Ryujinx.Horizon.Kernel.Generators/SyscallGenerator.cs b/src/Ryujinx.Horizon.Kernel.Generators/SyscallGenerator.cs index 5a81d8d80..b4063eda2 100644 --- a/src/Ryujinx.Horizon.Kernel.Generators/SyscallGenerator.cs +++ b/src/Ryujinx.Horizon.Kernel.Generators/SyscallGenerator.cs @@ -145,7 +145,7 @@ namespace Ryujinx.Horizon.Kernel.Generators GenerateResultCheckHelper(generator); generator.AppendLine(); - List syscalls = new(); + List syscalls = []; foreach (MethodDeclarationSyntax method in syntaxReceiver.SvcImplementations) { @@ -202,9 +202,9 @@ namespace Ryujinx.Horizon.Kernel.Generators RegisterAllocatorA32 regAlloc = new(); - List outParameters = new(); - List logInArgs = new(); - List logOutArgs = new(); + List outParameters = []; + List logInArgs = []; + List logOutArgs = []; foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters) { @@ -321,9 +321,9 @@ namespace Ryujinx.Horizon.Kernel.Generators int registerIndex = 0; int index = 0; - List outParameters = new(); - List logInArgs = new(); - List logOutArgs = new(); + List outParameters = []; + List logInArgs = []; + List logOutArgs = []; foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters) { diff --git a/src/Ryujinx.Horizon.Kernel.Generators/SyscallSyntaxReceiver.cs b/src/Ryujinx.Horizon.Kernel.Generators/SyscallSyntaxReceiver.cs index 76200713d..abeea4020 100644 --- a/src/Ryujinx.Horizon.Kernel.Generators/SyscallSyntaxReceiver.cs +++ b/src/Ryujinx.Horizon.Kernel.Generators/SyscallSyntaxReceiver.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Horizon.Kernel.Generators public SyscallSyntaxReceiver() { - SvcImplementations = new List(); + SvcImplementations = []; } public void OnVisitSyntaxNode(SyntaxNode syntaxNode) diff --git a/src/Spv.Generator/Instruction.cs b/src/Spv.Generator/Instruction.cs index a19677a93..49c9c2d90 100644 --- a/src/Spv.Generator/Instruction.cs +++ b/src/Spv.Generator/Instruction.cs @@ -232,14 +232,14 @@ namespace Spv.Generator private static readonly Dictionary _operandLabels = new() { - { Specification.Op.OpConstant, new [] { "Value" } }, - { Specification.Op.OpTypeInt, new [] { "Width", "Signed" } }, - { Specification.Op.OpTypeFloat, new [] { "Width" } }, + { Specification.Op.OpConstant, ["Value"] }, + { Specification.Op.OpTypeInt, ["Width", "Signed"] }, + { Specification.Op.OpTypeFloat, ["Width"] }, }; public override string ToString() { - string[] labels = _operandLabels.TryGetValue(Opcode, out string[] opLabels) ? opLabels : Array.Empty(); + string[] labels = _operandLabels.TryGetValue(Opcode, out string[] opLabels) ? opLabels : []; string result = _resultType == null ? string.Empty : $"{_resultType} "; return $"{result}{Opcode}{_operands.ToString(labels)}"; } diff --git a/src/Spv.Generator/InstructionOperands.cs b/src/Spv.Generator/InstructionOperands.cs index 06feb300f..38c2b1f2c 100644 --- a/src/Spv.Generator/InstructionOperands.cs +++ b/src/Spv.Generator/InstructionOperands.cs @@ -53,7 +53,7 @@ namespace Spv.Generator } private readonly IEnumerable AllOperands => new[] { Operand1, Operand2, Operand3, Operand4, Operand5 } - .Concat(Overflow ?? Array.Empty()) + .Concat(Overflow ?? []) .Take(Count); public readonly override string ToString() diff --git a/src/Spv.Generator/Module.cs b/src/Spv.Generator/Module.cs index 951494619..cb63633be 100644 --- a/src/Spv.Generator/Module.cs +++ b/src/Spv.Generator/Module.cs @@ -46,21 +46,21 @@ namespace Spv.Generator { _version = version; _bound = 1; - _capabilities = new List(); - _extensions = new List(); + _capabilities = []; + _extensions = []; _extInstImports = new Dictionary(); _addressingModel = AddressingModel.Logical; _memoryModel = MemoryModel.Simple; - _entrypoints = new List(); - _executionModes = new List(); - _debug = new List(); - _annotations = new List(); + _entrypoints = []; + _executionModes = []; + _debug = []; + _annotations = []; _typeDeclarations = new Dictionary(); - _typeDeclarationsList = new List(); + _typeDeclarationsList = []; _constants = new Dictionary(); - _globals = new List(); - _functionsDeclarations = new List(); - _functionsDefinitions = new List(); + _globals = []; + _functionsDeclarations = []; + _functionsDefinitions = []; _instPool = instPool ?? new GeneratorPool(); _integerPool = integerPool ?? new GeneratorPool(); @@ -333,7 +333,7 @@ namespace Spv.Generator } // Ensure that everything is in the right order in the declarations section. - List declarations = new(); + List declarations = []; declarations.AddRange(_typeDeclarationsList); declarations.AddRange(_globals); declarations.AddRange(_constants.Values);