public override void Visit(ConditionalBranchInstruction instruction) { if (instruction.LeftOperand.Type != null && instruction.RightOperand.Type == null) { instruction.RightOperand.Type = instruction.LeftOperand.Type; } else if (instruction.LeftOperand.Type == null && instruction.RightOperand.Type != null) { instruction.LeftOperand.Type = instruction.RightOperand.Type; } if (instruction.Operation == BranchOperation.Eq && instruction.RightOperand is Constant && instruction.LeftOperand.Type != null && instruction.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Boolean) { var constant = instruction.RightOperand as Constant; if (constant.Value is bool) { var value = (bool)constant.Value; if (value) { // Change num == true to num != true instruction.Operation = BranchOperation.Neq; } if (instruction.LeftOperand.Type.IsValueType) { // Change num == false to num == 0 or // num != true to num != 0 constant.Value = 0; } else { // Change num == false to num == null or // num != true to num != null constant.Value = null; } constant.Type = instruction.LeftOperand.Type; } } }
public virtual void Visit(ConditionalBranchInstruction instruction) { }