Jelajahi Sumber

misc: chore: Use collection expressions in Generator projects

Evan Husted 1 tahun lalu
induk
melakukan
2853f5b426

+ 1 - 1
src/Ryujinx.Horizon.Generators/Hipc/CommandInterface.cs

@@ -11,7 +11,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
         public CommandInterface(ClassDeclarationSyntax classDeclarationSyntax)
         public CommandInterface(ClassDeclarationSyntax classDeclarationSyntax)
         {
         {
             ClassDeclarationSyntax = classDeclarationSyntax;
             ClassDeclarationSyntax = classDeclarationSyntax;
-            CommandImplementations = new List<MethodDeclarationSyntax>();
+            CommandImplementations = [];
         }
         }
     }
     }
 }
 }

+ 1 - 1
src/Ryujinx.Horizon.Generators/Hipc/HipcGenerator.cs

@@ -257,7 +257,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
                 generator.AppendLine();
                 generator.AppendLine();
             }
             }
 
 
-            List<OutParameter> outParameters = new();
+            List<OutParameter> outParameters = [];
 
 
             string[] args = new string[method.ParameterList.Parameters.Count];
             string[] args = new string[method.ParameterList.Parameters.Count];
 
 

+ 1 - 1
src/Ryujinx.Horizon.Generators/Hipc/HipcSyntaxReceiver.cs

@@ -12,7 +12,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
 
 
         public HipcSyntaxReceiver()
         public HipcSyntaxReceiver()
         {
         {
-            CommandInterfaces = new List<CommandInterface>();
+            CommandInterfaces = [];
         }
         }
 
 
         public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
         public void OnVisitSyntaxNode(SyntaxNode syntaxNode)

+ 7 - 7
src/Ryujinx.Horizon.Kernel.Generators/SyscallGenerator.cs

@@ -145,7 +145,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
             GenerateResultCheckHelper(generator);
             GenerateResultCheckHelper(generator);
             generator.AppendLine();
             generator.AppendLine();
 
 
-            List<SyscallIdAndName> syscalls = new();
+            List<SyscallIdAndName> syscalls = [];
 
 
             foreach (MethodDeclarationSyntax method in syntaxReceiver.SvcImplementations)
             foreach (MethodDeclarationSyntax method in syntaxReceiver.SvcImplementations)
             {
             {
@@ -202,9 +202,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
 
 
             RegisterAllocatorA32 regAlloc = new();
             RegisterAllocatorA32 regAlloc = new();
 
 
-            List<OutParameter> outParameters = new();
-            List<string> logInArgs = new();
-            List<string> logOutArgs = new();
+            List<OutParameter> outParameters = [];
+            List<string> logInArgs = [];
+            List<string> logOutArgs = [];
 
 
             foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters)
             foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters)
             {
             {
@@ -321,9 +321,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
             int registerIndex = 0;
             int registerIndex = 0;
             int index = 0;
             int index = 0;
 
 
-            List<OutParameter> outParameters = new();
-            List<string> logInArgs = new();
-            List<string> logOutArgs = new();
+            List<OutParameter> outParameters = [];
+            List<string> logInArgs = [];
+            List<string> logOutArgs = [];
 
 
             foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters)
             foreach (ParameterSyntax methodParameter in method.ParameterList.Parameters)
             {
             {

+ 1 - 1
src/Ryujinx.Horizon.Kernel.Generators/SyscallSyntaxReceiver.cs

@@ -11,7 +11,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
 
 
         public SyscallSyntaxReceiver()
         public SyscallSyntaxReceiver()
         {
         {
-            SvcImplementations = new List<MethodDeclarationSyntax>();
+            SvcImplementations = [];
         }
         }
 
 
         public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
         public void OnVisitSyntaxNode(SyntaxNode syntaxNode)

+ 4 - 4
src/Spv.Generator/Instruction.cs

@@ -232,14 +232,14 @@ namespace Spv.Generator
 
 
         private static readonly Dictionary<Specification.Op, string[]> _operandLabels = new()
         private static readonly Dictionary<Specification.Op, string[]> _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()
         public override string ToString()
         {
         {
-            string[] labels = _operandLabels.TryGetValue(Opcode, out string[] opLabels) ? opLabels : Array.Empty<string>();
+            string[] labels = _operandLabels.TryGetValue(Opcode, out string[] opLabels) ? opLabels : [];
             string result = _resultType == null ? string.Empty : $"{_resultType} ";
             string result = _resultType == null ? string.Empty : $"{_resultType} ";
             return $"{result}{Opcode}{_operands.ToString(labels)}";
             return $"{result}{Opcode}{_operands.ToString(labels)}";
         }
         }

+ 1 - 1
src/Spv.Generator/InstructionOperands.cs

@@ -53,7 +53,7 @@ namespace Spv.Generator
         }
         }
 
 
         private readonly IEnumerable<IOperand> AllOperands => new[] { Operand1, Operand2, Operand3, Operand4, Operand5 }
         private readonly IEnumerable<IOperand> AllOperands => new[] { Operand1, Operand2, Operand3, Operand4, Operand5 }
-            .Concat(Overflow ?? Array.Empty<IOperand>())
+            .Concat(Overflow ?? [])
             .Take(Count);
             .Take(Count);
 
 
         public readonly override string ToString()
         public readonly override string ToString()

+ 11 - 11
src/Spv.Generator/Module.cs

@@ -46,21 +46,21 @@ namespace Spv.Generator
         {
         {
             _version = version;
             _version = version;
             _bound = 1;
             _bound = 1;
-            _capabilities = new List<Capability>();
-            _extensions = new List<string>();
+            _capabilities = [];
+            _extensions = [];
             _extInstImports = new Dictionary<DeterministicStringKey, Instruction>();
             _extInstImports = new Dictionary<DeterministicStringKey, Instruction>();
             _addressingModel = AddressingModel.Logical;
             _addressingModel = AddressingModel.Logical;
             _memoryModel = MemoryModel.Simple;
             _memoryModel = MemoryModel.Simple;
-            _entrypoints = new List<Instruction>();
-            _executionModes = new List<Instruction>();
-            _debug = new List<Instruction>();
-            _annotations = new List<Instruction>();
+            _entrypoints = [];
+            _executionModes = [];
+            _debug = [];
+            _annotations = [];
             _typeDeclarations = new Dictionary<TypeDeclarationKey, Instruction>();
             _typeDeclarations = new Dictionary<TypeDeclarationKey, Instruction>();
-            _typeDeclarationsList = new List<Instruction>();
+            _typeDeclarationsList = [];
             _constants = new Dictionary<ConstantKey, Instruction>();
             _constants = new Dictionary<ConstantKey, Instruction>();
-            _globals = new List<Instruction>();
-            _functionsDeclarations = new List<Instruction>();
-            _functionsDefinitions = new List<Instruction>();
+            _globals = [];
+            _functionsDeclarations = [];
+            _functionsDefinitions = [];
 
 
             _instPool = instPool ?? new GeneratorPool<Instruction>();
             _instPool = instPool ?? new GeneratorPool<Instruction>();
             _integerPool = integerPool ?? new GeneratorPool<LiteralInteger>();
             _integerPool = integerPool ?? new GeneratorPool<LiteralInteger>();
@@ -333,7 +333,7 @@ namespace Spv.Generator
             }
             }
 
 
             // Ensure that everything is in the right order in the declarations section.
             // Ensure that everything is in the right order in the declarations section.
-            List<Instruction> declarations = new();
+            List<Instruction> declarations = [];
             declarations.AddRange(_typeDeclarationsList);
             declarations.AddRange(_typeDeclarationsList);
             declarations.AddRange(_globals);
             declarations.AddRange(_globals);
             declarations.AddRange(_constants.Values);
             declarations.AddRange(_constants.Values);