Skip to content

Commit

Permalink
fix: adding namespace for sonar bug
Browse files Browse the repository at this point in the history
  • Loading branch information
uweeby committed Oct 4, 2020
1 parent 41ba643 commit 2ed0859
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions Assets/Mirror/Editor/Weaver/Processors/CodePass.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,74 @@


using System;
using Mono.Cecil;
using Mono.Cecil.Cil;

/// <summary>
/// Algorithm for doing a pass over the code
/// </summary>
public static class CodePass
namespace Mirror.Weaver
{
/// <summary>
/// Process an instruction, it can replace the instruction and return new instruction
/// else it should return the same instruction
/// Algorithm for doing a pass over the code
/// </summary>
/// <param name="md">The method containing the instruction</param>
/// <param name="instruction">The instruction being processed</param>
/// <returns>return the same instruction, or replace the instruction and return the replacement</returns>
public delegate Instruction InstructionProcessor(MethodDefinition md, Instruction instruction);

/// <summary>
/// Executes a method for every instruction in a module
/// </summary>
/// <param name="module">The module to be passed over</param>
/// <param name="selector">A predicate that indicates if we should pass over a method or not</param>
/// <param name="processor">The function that processes each instruction</param>
public static void ForEachInstruction(ModuleDefinition module, Predicate<MethodDefinition> selector, InstructionProcessor processor)
public static class CodePass
{
foreach (TypeDefinition td in module.Types)
/// <summary>
/// Process an instruction, it can replace the instruction and return new instruction
/// else it should return the same instruction
/// </summary>
/// <param name="md">The method containing the instruction</param>
/// <param name="instruction">The instruction being processed</param>
/// <returns>return the same instruction, or replace the instruction and return the replacement</returns>
public delegate Instruction InstructionProcessor(MethodDefinition md, Instruction instruction);

/// <summary>
/// Executes a method for every instruction in a module
/// </summary>
/// <param name="module">The module to be passed over</param>
/// <param name="selector">A predicate that indicates if we should pass over a method or not</param>
/// <param name="processor">The function that processes each instruction</param>
public static void ForEachInstruction(ModuleDefinition module, Predicate<MethodDefinition> selector, InstructionProcessor processor)
{
if (td.IsClass)
foreach (TypeDefinition td in module.Types)
{
InstructionPass(td, selector, processor);
if (td.IsClass)
{
InstructionPass(td, selector, processor);
}
}
}
}

public static void ForEachInstruction(ModuleDefinition module, InstructionProcessor processor) =>
ForEachInstruction(module, md => true, processor);
public static void ForEachInstruction(ModuleDefinition module, InstructionProcessor processor) =>
ForEachInstruction(module, md => true, processor);

private static void InstructionPass(TypeDefinition td, Predicate<MethodDefinition> selector, InstructionProcessor processor)
{
foreach (MethodDefinition md in td.Methods)
private static void InstructionPass(TypeDefinition td, Predicate<MethodDefinition> selector, InstructionProcessor processor)
{
InstructionPass(md, selector, processor);
}
foreach (MethodDefinition md in td.Methods)
{
InstructionPass(md, selector, processor);
}

foreach (TypeDefinition nested in td.NestedTypes)
{
InstructionPass(nested, selector, processor);
foreach (TypeDefinition nested in td.NestedTypes)
{
InstructionPass(nested, selector, processor);
}
}
}

private static void InstructionPass(MethodDefinition md, Predicate<MethodDefinition> selector, InstructionProcessor processor)
{
// process all references to replaced members with properties
if (md.IsAbstract || md.Body == null || md.Body.Instructions == null)
private static void InstructionPass(MethodDefinition md, Predicate<MethodDefinition> selector, InstructionProcessor processor)
{
return;
}

if (selector(md))
{
Instruction instr = md.Body.Instructions[0];
// process all references to replaced members with properties
if (md.IsAbstract || md.Body == null || md.Body.Instructions == null)
{
return;
}

while (instr != null)
if (selector(md))
{
instr = processor(md, instr);
instr = instr.Next;
Instruction instr = md.Body.Instructions[0];

while (instr != null)
{
instr = processor(md, instr);
instr = instr.Next;
}
}
}
}
Expand Down

0 comments on commit 2ed0859

Please sign in to comment.