Skip to content

Commit da22828

Browse files
committed
style: cleanup
1 parent a20c5db commit da22828

111 files changed

Lines changed: 2001 additions & 2004 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/OTAPI.UnifiedServerProcess/Commons/IL.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static Instruction BuildParameterLoad(MethodDefinition method, MethodBody
1919
return Instruction.Create(OpCodes.Ldarg_0);
2020
}
2121
else {
22-
var index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
22+
int index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
2323
return index switch {
2424
-1 => throw new ArgumentException("Parameter not found in method", nameof(parameter)),
2525
0 => Instruction.Create(OpCodes.Ldarg_0),
@@ -35,7 +35,7 @@ public static Instruction BuildParameterSet(MethodDefinition method, MethodBody
3535
throw new ArgumentException("Cannot set \"this\" TracingParameter", nameof(parameter));
3636
}
3737
else {
38-
var index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
38+
int index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
3939
if (index < 0) {
4040
throw new ArgumentException("Parameter not found in method", nameof(parameter));
4141
}
@@ -47,15 +47,15 @@ public static Instruction BuildParameterLoadAddress(MethodDefinition method, Met
4747
return Instruction.Create(OpCodes.Ldarga_S, body?.ThisParameter ?? throw new InvalidOperationException());
4848
}
4949
else {
50-
var index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
50+
int index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
5151
if (index < 0) {
5252
throw new ArgumentException("Parameter not found in method", nameof(parameter));
5353
}
5454
return Instruction.Create(index < byte.MaxValue ? OpCodes.Ldarga_S : OpCodes.Ldarga, parameter);
5555
}
5656
}
5757
public static Instruction BuildVariableLoad(MethodDefinition method, MethodBody body, VariableDefinition variable) {
58-
var index = method.Body.Variables.IndexOf(variable);
58+
int index = method.Body.Variables.IndexOf(variable);
5959
if (index < 0) {
6060
throw new ArgumentException("Variable not found in method", nameof(variable));
6161
}
@@ -68,7 +68,7 @@ public static Instruction BuildVariableLoad(MethodDefinition method, MethodBody
6868
};
6969
}
7070
public static Instruction BuildVariableStore(MethodDefinition method, MethodBody body, VariableDefinition variable) {
71-
var index = method.Body.Variables.IndexOf(variable);
71+
int index = method.Body.Variables.IndexOf(variable);
7272
if (index < 0) {
7373
throw new ArgumentException("Variable not found in method", nameof(variable));
7474
}
@@ -81,15 +81,15 @@ public static Instruction BuildVariableStore(MethodDefinition method, MethodBody
8181
};
8282
}
8383
public static Instruction BuildVariableLoadAddress(MethodDefinition method, MethodBody body, VariableDefinition variable) {
84-
var index = method.Body.Variables.IndexOf(variable);
84+
int index = method.Body.Variables.IndexOf(variable);
8585
if (index < 0) {
8686
throw new ArgumentException("Variable not found in method", nameof(variable));
8787
}
8888
return Instruction.Create(index < byte.MaxValue ? OpCodes.Ldloca_S : OpCodes.Ldloca, variable);
8989
}
9090
public static ParameterDefinition GetReferencedParameter(MethodDefinition method, Instruction instruction) {
9191
ParameterDefinition? tmpCheck = null;
92-
var paramIndex = instruction.OpCode.Code switch {
92+
int paramIndex = instruction.OpCode.Code switch {
9393
Code.Ldarg_0 or
9494
Code.Ldarg_1 or
9595
Code.Ldarg_2 or
@@ -140,7 +140,7 @@ Code.Starg_S or
140140
parameter = method.Body?.ThisParameter ?? new ParameterDefinition("", ParameterAttributes.None, method.DeclaringType);
141141
}
142142
else {
143-
var paramIndex = paramInnerIndex - (method.HasThis ? 1 : 0);
143+
int paramIndex = paramInnerIndex - (method.HasThis ? 1 : 0);
144144
parameter = method.Parameters[paramIndex];
145145
if (tmpCheck is not null && tmpCheck.Name != parameter.Name) {
146146
throw new InvalidOperationException("Operand TracingParameter is invalid");
@@ -150,7 +150,7 @@ Code.Starg_S or
150150
}
151151
public static VariableDefinition GetReferencedVariable(MethodDefinition method, Instruction instruction) {
152152
VariableDefinition? tmpCheck = null;
153-
var localIndex = instruction.OpCode.Code switch {
153+
int localIndex = instruction.OpCode.Code switch {
154154
Code.Ldloc_0 or Code.Stloc_0 => 0,
155155
Code.Ldloc_1 or Code.Stloc_1 => 1,
156156
Code.Ldloc_2 or Code.Stloc_2 => 2,
@@ -207,7 +207,7 @@ Code.Stloc_S or
207207
public static bool MatchSetVariable(MethodDefinition method, Instruction instruction, [NotNullWhen(true)] out VariableDefinition? variable) {
208208
VariableDefinition? tmpCheck = null;
209209

210-
var localIndex = instruction.OpCode.Code switch {
210+
int localIndex = instruction.OpCode.Code switch {
211211
Code.Stloc_0 => 0,
212212
Code.Stloc_1 => 1,
213213
Code.Stloc_2 => 2,
@@ -233,7 +233,7 @@ Code.Stloc_S or
233233
public static bool MatchLoadVariableAddress(MethodDefinition method, Instruction instruction, [NotNullWhen(true)] out VariableDefinition? variable) {
234234
VariableDefinition? tmpCheck = null;
235235

236-
var localIndex = instruction.OpCode.Code switch {
236+
int localIndex = instruction.OpCode.Code switch {
237237
Code.Ldloca_S or
238238
Code.Ldloca => (tmpCheck = (VariableDefinition)instruction.Operand).Index,
239239
_ => -1
@@ -254,7 +254,7 @@ Code.Ldloca_S or
254254
public static bool MatchLoadVariable(MethodDefinition method, Instruction instruction, [NotNullWhen(true)] out VariableDefinition? variable) {
255255
VariableDefinition? tmpCheck = null;
256256

257-
var localIndex = instruction.OpCode.Code switch {
257+
int localIndex = instruction.OpCode.Code switch {
258258
Code.Ldloc_0 => 0,
259259
Code.Ldloc_1 => 1,
260260
Code.Ldloc_2 => 2,

src/OTAPI.UnifiedServerProcess/Commons/Stack.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public AnalysisContext(Instruction current, int position) {
3232
/// <param name="afterThisExec">Analyze after this instruction</param>
3333
/// <returns>Return all possible uses of the top value on the stack/returns>
3434
public static Instruction[] TraceStackValueConsumers(MethodDefinition caller, Instruction afterThisExec) {
35-
var visited = new HashSet<(Instruction, int)>();
36-
var results = new HashSet<Instruction>();
37-
var workStack = new Stack<AnalysisContext>();
35+
HashSet<(Instruction, int)> visited = new HashSet<(Instruction, int)>();
36+
HashSet<Instruction> results = new HashSet<Instruction>();
37+
Stack<AnalysisContext> workStack = new Stack<AnalysisContext>();
3838

3939
Instruction initialInstruction = afterThisExec.Next;
4040

@@ -126,7 +126,7 @@ private static IEnumerable<Instruction> GetNextInstructions(Instruction current)
126126
cachedJumpSitess ??= BuildJumpSitesMap(caller);
127127

128128
// initialize analysis queue
129-
var workStack = new Stack<(Instruction current, int stackBalance, HashSet<Instruction> visited)>();
129+
Stack<(Instruction current, int stackBalance, HashSet<Instruction> visited)> workStack = new Stack<(Instruction current, int stackBalance, HashSet<Instruction> visited)>();
130130

131131
workStack.Push((afterThisExec, -1, []));
132132

@@ -195,7 +195,7 @@ public static StackTopTypePath[] AnalyzeStackTopTypeAllPaths(MethodDefinition ca
195195
cachedJumpSitess ??= BuildJumpSitesMap(caller);
196196

197197
// initialize analysis queue
198-
var workStack = new Stack<(ReversibleLinkedList<Instruction> path, Instruction current, int stackBalance, HashSet<Instruction> visited)>();
198+
Stack<(ReversibleLinkedList<Instruction> path, Instruction current, int stackBalance, HashSet<Instruction> visited)> workStack = new Stack<(ReversibleLinkedList<Instruction> path, Instruction current, int stackBalance, HashSet<Instruction> visited)>();
199199

200200
workStack.Push((new(), afterThisExec, -1, []));
201201

@@ -345,7 +345,7 @@ public static bool CheckSinglePredecessor(
345345
}
346346

347347
static void FindEndpoints(IEnumerable<Instruction> nodes, out Instruction min, out Instruction max, out HashSet<Instruction> block) {
348-
var nodeSet = new HashSet<Instruction>(nodes);
348+
HashSet<Instruction> nodeSet = new HashSet<Instruction>(nodes);
349349

350350
if (nodeSet.Count == 0) throw new ArgumentException("Node set must contain at least one node");
351351

@@ -475,20 +475,20 @@ private static bool IsUnreachablePredecessor(Instruction instr) {
475475
var parameter = IL.GetReferencedParameter(method, instruction);
476476
return parameter.ParameterType;
477477
case Code.Ldfld:
478-
var field = (FieldReference)instruction.Operand;
478+
FieldReference field = (FieldReference)instruction.Operand;
479479
return field.FieldType;
480480
case Code.Ldsfld:
481481
field = (FieldReference)instruction.Operand;
482482
return field.FieldType;
483483
case Code.Call:
484484
case Code.Callvirt:
485-
var methodCall = (MethodReference)instruction.Operand;
485+
MethodReference methodCall = (MethodReference)instruction.Operand;
486486
return IL.GetMethodReturnType(methodCall, method);
487487
case Code.Calli:
488-
var sig = (CallSite)instruction.Operand;
488+
CallSite sig = (CallSite)instruction.Operand;
489489
return sig.ReturnType;
490490
case Code.Newobj:
491-
var ctor = (MethodReference)instruction.Operand;
491+
MethodReference ctor = (MethodReference)instruction.Operand;
492492
return ctor.DeclaringType;
493493
case Code.Newarr:
494494
return new ArrayType((TypeReference)instruction.Operand);
@@ -628,7 +628,7 @@ private static bool IsUnreachablePredecessor(Instruction instr) {
628628
case Code.Ldind_Ref:
629629
var referencePaths = AnalyzeInstructionArgsSources(method, instruction, cachedJumpSites).First();
630630
var referenceInstructions = referencePaths.ParametersSources[0].Instructions;
631-
var referenceType = (ByReferenceType)AnalyzeStackTopType(method, referenceInstructions.Last(), cachedJumpSites)!;
631+
ByReferenceType referenceType = (ByReferenceType)AnalyzeStackTopType(method, referenceInstructions.Last(), cachedJumpSites)!;
632632
return referenceType.ElementType;
633633

634634
case Code.Ldobj: return (TypeReference)instruction.Operand;
@@ -734,15 +734,15 @@ public static FlowPath<ParameterSource>[] AnalyzeParametersSources(MethodDefinit
734734
cachedJumpSitess ??= BuildJumpSitesMap(caller);
735735

736736
// Resolve method signature
737-
var callee = (MethodReference)target.Operand;
737+
MethodReference callee = (MethodReference)target.Operand;
738738
bool hasThis = (target.OpCode == OpCodes.Call || target.OpCode == OpCodes.Callvirt) && callee.HasThis;
739739
int paramCount = callee.Parameters.Count + (hasThis ? 1 : 0);
740740
if (target.OpCode == OpCodes.Newobj)
741741
paramCount = callee.Parameters.Count;
742742

743743
// Initialize analysis queue
744-
var workStack = new Stack<ReverseAnalysisContext>();
745-
var initialDemand = new StackDemand(paramCount, GetPushCount(caller.Body, target));
744+
Stack<ReverseAnalysisContext> workStack = new Stack<ReverseAnalysisContext>();
745+
StackDemand initialDemand = new StackDemand(paramCount, GetPushCount(caller.Body, target));
746746
workStack.Push(new ReverseAnalysisContext(
747747
current: target,
748748
previous: target.Previous,
@@ -765,7 +765,7 @@ public static FlowPath<ParameterSource>[] AnalyzeParametersSources(MethodDefinit
765765

766766
// Clone context to prevent state pollution
767767
var stackDemand = ctx.StackDemand.Clone();
768-
var path = new ReversibleLinkedList<Instruction>(ctx.Path);
768+
ReversibleLinkedList<Instruction> path = new ReversibleLinkedList<Instruction>(ctx.Path);
769769

770770
// Process tail instruction's reverse stack effect
771771
int originalPush = GetPushCount(caller.Body, ctx.Current);
@@ -860,8 +860,8 @@ public static FlowPath<InstructionArgsSource>[] AnalyzeInstructionArgsSources(Me
860860
var argsCount = GetInstructionArgCount(caller.Body, target);
861861

862862
// initialize analysis queue
863-
var workStack = new Stack<ReverseAnalysisContext>();
864-
var initialDemand = new StackDemand(argsCount, GetPushCount(caller.Body, target));
863+
Stack<ReverseAnalysisContext> workStack = new Stack<ReverseAnalysisContext>();
864+
StackDemand initialDemand = new StackDemand(argsCount, GetPushCount(caller.Body, target));
865865

866866
workStack.Push(new ReverseAnalysisContext(
867867
current: target,
@@ -885,7 +885,7 @@ public static FlowPath<InstructionArgsSource>[] AnalyzeInstructionArgsSources(Me
885885

886886
// Clone context to prevent polluting
887887
var stackDemand = ctx.StackDemand.Clone();
888-
var path = new ReversibleLinkedList<Instruction>(ctx.Path);
888+
ReversibleLinkedList<Instruction> path = new ReversibleLinkedList<Instruction>(ctx.Path);
889889

890890
// Process the reverse stack effect of the tail instruction
891891
int originalPush = GetPushCount(caller.Body, ctx.Current);
@@ -946,7 +946,7 @@ public static FlowPath<InstructionArgsSource>[] AnalyzeInstructionArgsSources(Me
946946
return BuildFlowPaths(caller.Body, paths);
947947
}
948948
public static Dictionary<Instruction, List<Instruction>> BuildJumpSitesMap(MethodDefinition method) {
949-
var jumpTargets = new Dictionary<Instruction, List<Instruction>>();
949+
Dictionary<Instruction, List<Instruction>> jumpTargets = new Dictionary<Instruction, List<Instruction>>();
950950
foreach (var instruction in method.Body.Instructions) {
951951
if (instruction.Operand is ILLabel label) {
952952
var target = label.Target;
@@ -997,7 +997,7 @@ private static List<ParameterSource> AnalyzeMethodCallPath(MethodDefinition call
997997
if (target.OpCode == OpCodes.Newobj)
998998
paramCount = callee.Parameters.Count;
999999

1000-
var parameters = new List<ParameterSource>();
1000+
List<ParameterSource> parameters = new List<ParameterSource>();
10011001
int currentIndex = path.Length - 1;
10021002

10031003
for (int i = 0; i < paramCount; i++) {
@@ -1006,7 +1006,7 @@ private static List<ParameterSource> AnalyzeMethodCallPath(MethodDefinition call
10061006
var (start, end) = FindArgRange(path, deltas, currentIndex);
10071007
if (start == -1) break;
10081008

1009-
var paramInstructions = new List<Instruction>();
1009+
List<Instruction> paramInstructions = new List<Instruction>();
10101010
for (int j = start; j <= end; j++)
10111011
paramInstructions.Add(path[j]);
10121012

@@ -1033,7 +1033,7 @@ private static List<ParameterSource> AnalyzeMethodCallPath(MethodDefinition call
10331033
private static List<InstructionArgsSource> AnalyzeInstructionArgs(MethodBody body, Instruction target, int argsCount, Instruction[] path) {
10341034
path = [.. path.Take(path.Length - 1)];
10351035
var deltas = ComputeStackDeltas(body, path);
1036-
var argsSources = new List<InstructionArgsSource>();
1036+
List<InstructionArgsSource> argsSources = new List<InstructionArgsSource>();
10371037

10381038
int currentIndex = path.Length - 1;
10391039

@@ -1043,7 +1043,7 @@ private static List<InstructionArgsSource> AnalyzeInstructionArgs(MethodBody bod
10431043
var (start, end) = FindArgRange(path, deltas, currentIndex);
10441044
if (start == -1) break;
10451045

1046-
var argInstructions = new List<Instruction>();
1046+
List<Instruction> argInstructions = new List<Instruction>();
10471047
for (int j = start; j <= end; j++)
10481048
argInstructions.Add(path[j]);
10491049

@@ -1148,7 +1148,7 @@ public static int GetPopCount(MethodBody body, Instruction instruction) {
11481148
return 0;
11491149
case StackBehaviour.Varpop:
11501150
if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt || instruction.OpCode == OpCodes.Newobj) {
1151-
var methodRef = (MethodReference)instruction.Operand;
1151+
MethodReference methodRef = (MethodReference)instruction.Operand;
11521152
int count = methodRef.Parameters.Count;
11531153
if (instruction.OpCode != OpCodes.Newobj && methodRef.HasThis)
11541154
count++;
@@ -1187,11 +1187,11 @@ public static int GetPushCount(MethodBody body, Instruction instruction) {
11871187
return 2;
11881188
case StackBehaviour.Varpush:
11891189
if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt) {
1190-
var method = (MethodReference)instruction.Operand;
1190+
MethodReference method = (MethodReference)instruction.Operand;
11911191
return method.ReturnType.FullName == "System.Void" ? 0 : 1;
11921192
}
11931193
else if (instruction.OpCode == OpCodes.Calli) {
1194-
var sig = (CallSite)instruction.Operand;
1194+
CallSite sig = (CallSite)instruction.Operand;
11951195
return sig.ReturnType.FullName == "System.Void" ? 0 : 1;
11961196
}
11971197
else if (instruction.OpCode == OpCodes.Newobj) {

0 commit comments

Comments
 (0)