Browse Source

Rename BlockType to BlockKind

pull/976/head
Siegfried Pammer 8 years ago
parent
commit
349183544a
  1. 14
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 2
      ICSharpCode.Decompiler/IL/Instructions.cs
  3. 18
      ICSharpCode.Decompiler/IL/Instructions/Block.cs
  4. 2
      ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs
  5. 8
      ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs
  6. 6
      ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs
  7. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs
  8. 10
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

14
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1721,18 +1721,18 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitBlock(Block block, TranslationContext context) protected internal override TranslatedExpression VisitBlock(Block block, TranslationContext context)
{ {
switch (block.Type) { switch (block.Kind) {
case BlockType.ArrayInitializer: case BlockKind.ArrayInitializer:
return TranslateArrayInitializer(block); return TranslateArrayInitializer(block);
case BlockType.CollectionInitializer: case BlockKind.CollectionInitializer:
case BlockType.ObjectInitializer: case BlockKind.ObjectInitializer:
return TranslateObjectAndCollectionInitializer(block); return TranslateObjectAndCollectionInitializer(block);
case BlockType.PostfixOperator: case BlockKind.PostfixOperator:
return TranslatePostfixOperator(block); return TranslatePostfixOperator(block);
case BlockType.CallInlineAssign: case BlockKind.CallInlineAssign:
return TranslateSetterCallAssignment(block); return TranslateSetterCallAssignment(block);
default: default:
return ErrorExpression("Unknown block type: " + block.Type); return ErrorExpression("Unknown block type: " + block.Kind);
} }
} }

2
ICSharpCode.Decompiler/IL/Instructions.cs

@ -690,7 +690,7 @@ namespace ICSharpCode.Decompiler.IL
protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match)
{ {
var o = other as Block; var o = other as Block;
return o != null && this.Type == o.Type && Patterns.ListMatch.DoMatch(this.Instructions, o.Instructions, ref match) && this.FinalInstruction.PerformMatch(o.FinalInstruction, ref match); return o != null && this.Kind == o.Kind && Patterns.ListMatch.DoMatch(this.Instructions, o.Instructions, ref match) && this.FinalInstruction.PerformMatch(o.FinalInstruction, ref match);
} }
} }
} }

18
ICSharpCode.Decompiler/IL/Instructions/Block.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.IL
public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true); public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true);
public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction"); public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction");
public readonly BlockType Type; public readonly BlockKind Kind;
public readonly InstructionCollection<ILInstruction> Instructions; public readonly InstructionCollection<ILInstruction> Instructions;
ILInstruction finalInstruction; ILInstruction finalInstruction;
@ -88,16 +88,16 @@ namespace ICSharpCode.Decompiler.IL
finalInstruction.ChildIndex = Instructions.Count; finalInstruction.ChildIndex = Instructions.Count;
} }
public Block(BlockType type = BlockType.ControlFlow) : base(OpCode.Block) public Block(BlockKind kind = BlockKind.ControlFlow) : base(OpCode.Block)
{ {
this.Type = type; this.Kind = kind;
this.Instructions = new InstructionCollection<ILInstruction>(this, 0); this.Instructions = new InstructionCollection<ILInstruction>(this, 0);
this.FinalInstruction = new Nop(); this.FinalInstruction = new Nop();
} }
public override ILInstruction Clone() public override ILInstruction Clone()
{ {
Block clone = new Block(Type); Block clone = new Block(Kind);
clone.ILRange = this.ILRange; clone.ILRange = this.ILRange;
clone.Instructions.AddRange(this.Instructions.Select(inst => inst.Clone())); clone.Instructions.AddRange(this.Instructions.Select(inst => inst.Clone()));
clone.FinalInstruction = this.FinalInstruction.Clone(); clone.FinalInstruction = this.FinalInstruction.Clone();
@ -111,11 +111,11 @@ namespace ICSharpCode.Decompiler.IL
// only the last instruction may have an unreachable endpoint // only the last instruction may have an unreachable endpoint
Debug.Assert(!Instructions[i].HasFlag(InstructionFlags.EndPointUnreachable)); Debug.Assert(!Instructions[i].HasFlag(InstructionFlags.EndPointUnreachable));
} }
switch (this.Type) { switch (this.Kind) {
case BlockType.ControlFlow: case BlockKind.ControlFlow:
Debug.Assert(finalInstruction.OpCode == OpCode.Nop); Debug.Assert(finalInstruction.OpCode == OpCode.Nop);
break; break;
case BlockType.CallInlineAssign: case BlockKind.CallInlineAssign:
Debug.Assert(MatchInlineAssignBlock(out _, out _)); Debug.Assert(MatchInlineAssignBlock(out _, out _));
break; break;
} }
@ -264,7 +264,7 @@ namespace ICSharpCode.Decompiler.IL
{ {
call = null; call = null;
value = null; value = null;
if (this.Type != BlockType.CallInlineAssign) if (this.Kind != BlockKind.CallInlineAssign)
return false; return false;
if (this.Instructions.Count != 1) if (this.Instructions.Count != 1)
return false; return false;
@ -279,7 +279,7 @@ namespace ICSharpCode.Decompiler.IL
} }
} }
public enum BlockType public enum BlockKind
{ {
/// <summary> /// <summary>
/// Block is used for control flow. /// Block is used for control flow.

2
ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs

@ -169,7 +169,7 @@ namespace ICSharpCode.Decompiler.IL
Debug.Assert(EntryPoint == Blocks[0]); Debug.Assert(EntryPoint == Blocks[0]);
Debug.Assert(!IsConnected || EntryPoint.IncomingEdgeCount >= 1); Debug.Assert(!IsConnected || EntryPoint.IncomingEdgeCount >= 1);
Debug.Assert(Blocks.All(b => b.HasFlag(InstructionFlags.EndPointUnreachable))); Debug.Assert(Blocks.All(b => b.HasFlag(InstructionFlags.EndPointUnreachable)));
Debug.Assert(Blocks.All(b => b.Type == BlockType.ControlFlow)); // this also implies that the blocks don't use FinalInstruction Debug.Assert(Blocks.All(b => b.Kind == BlockKind.ControlFlow)); // this also implies that the blocks don't use FinalInstruction
} }
protected override InstructionFlags ComputeFlags() protected override InstructionFlags ComputeFlags()

8
ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

@ -331,10 +331,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true; return true;
} else if (expr is Block block && block.Instructions.Count > 0) { } else if (expr is Block block && block.Instructions.Count > 0) {
// Inlining into inline-blocks? only for some block types, and only into the first instruction. // Inlining into inline-blocks? only for some block types, and only into the first instruction.
switch (block.Type) { switch (block.Kind) {
case BlockType.ArrayInitializer: case BlockKind.ArrayInitializer:
case BlockType.CollectionInitializer: case BlockKind.CollectionInitializer:
case BlockType.ObjectInitializer: case BlockKind.ObjectInitializer:
return FindLoadInNext(block.Instructions[0], v, expressionBeingMoved, out loadInst) ?? false; return FindLoadInNext(block.Instructions[0], v, expressionBeingMoved, out loadInst) ?? false;
// If FindLoadInNext() returns null, we still can't continue searching // If FindLoadInNext() returns null, we still can't continue searching
// because we can't inline over the remainder of the block. // because we can't inline over the remainder of the block.

6
ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
int instructionsToRemove; int instructionsToRemove;
if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out values, out instructionsToRemove)) { if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out values, out instructionsToRemove)) {
context.Step("HandleSimpleArrayInitializer", inst); context.Step("HandleSimpleArrayInitializer", inst);
var block = new Block(BlockType.ArrayInitializer); var block = new Block(BlockKind.ArrayInitializer);
var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type);
block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray()))); block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
block.Instructions.AddRange(values.SelectWithIndex( block.Instructions.AddRange(values.SelectWithIndex(
@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
if (HandleJaggedArrayInitializer(body, pos + 1, v, arrayLength[0], out ILVariable finalStore, out values, out instructionsToRemove)) { if (HandleJaggedArrayInitializer(body, pos + 1, v, arrayLength[0], out ILVariable finalStore, out values, out instructionsToRemove)) {
context.Step("HandleJaggedArrayInitializer", inst); context.Step("HandleJaggedArrayInitializer", inst);
var block = new Block(BlockType.ArrayInitializer); var block = new Block(BlockKind.ArrayInitializer);
var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type);
block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray()))); block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
block.Instructions.AddRange(values.SelectWithIndex((i, value) => StElem(new LdLoc(tempStore), new[] { new LdcI4(i) }, value, elementType))); block.Instructions.AddRange(values.SelectWithIndex((i, value) => StElem(new LdLoc(tempStore), new[] { new LdcI4(i) }, value, elementType)));
@ -266,7 +266,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block BlockFromInitializer(ILVariable v, IType elementType, int[] arrayLength, ILInstruction[] values) Block BlockFromInitializer(ILVariable v, IType elementType, int[] arrayLength, ILInstruction[] values)
{ {
var block = new Block(BlockType.ArrayInitializer); var block = new Block(BlockKind.ArrayInitializer);
block.Instructions.Add(new StLoc(v, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray()))); block.Instructions.Add(new StLoc(v, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
int step = arrayLength.Length + 1; int step = arrayLength.Length + 1;
for (int i = 0; i < values.Length / step; i++) { for (int i = 0; i < values.Length / step; i++) {

4
ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

@ -147,7 +147,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
block.Instructions.Remove(call); block.Instructions.Remove(call);
var newVar = context.Function.RegisterVariable(VariableKind.StackSlot, call.Method.Parameters.Last().Type); var newVar = context.Function.RegisterVariable(VariableKind.StackSlot, call.Method.Parameters.Last().Type);
call.Arguments[call.Arguments.Count - 1] = new StLoc(newVar, inst.Value); call.Arguments[call.Arguments.Count - 1] = new StLoc(newVar, inst.Value);
var inlineBlock = new Block(BlockType.CallInlineAssign) { var inlineBlock = new Block(BlockKind.CallInlineAssign) {
Instructions = { call }, Instructions = { call },
FinalInstruction = new LdLoc(newVar) FinalInstruction = new LdLoc(newVar)
}; };
@ -395,7 +395,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
context.Step($"TransformPostIncDecOperatorLocal", inst); context.Step($"TransformPostIncDecOperatorLocal", inst);
var tempStore = context.Function.RegisterVariable(VariableKind.StackSlot, inst.Variable.Type); var tempStore = context.Function.RegisterVariable(VariableKind.StackSlot, inst.Variable.Type);
var assignment = new Block(BlockType.PostfixOperator); var assignment = new Block(BlockKind.PostfixOperator);
assignment.Instructions.Add(new StLoc(tempStore, new LdLoc(nextInst.Variable))); assignment.Instructions.Add(new StLoc(tempStore, new LdLoc(nextInst.Variable)));
assignment.Instructions.Add(new StLoc(nextInst.Variable, new BinaryNumericInstruction(binary.Operator, new LdLoc(tempStore), new LdcI4(1), binary.CheckForOverflow, binary.Sign))); assignment.Instructions.Add(new StLoc(nextInst.Variable, new BinaryNumericInstruction(binary.Operator, new LdLoc(tempStore), new LdcI4(1), binary.CheckForOverflow, binary.Sign)));
assignment.FinalInstruction = new LdLoc(tempStore); assignment.FinalInstruction = new LdLoc(tempStore);

10
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
} }
int initializerItemsCount = 0; int initializerItemsCount = 0;
var blockType = BlockType.CollectionInitializer; var blockKind = BlockKind.CollectionInitializer;
possibleIndexVariables = new Dictionary<ILVariable, (int Index, ILInstruction Value)>(); possibleIndexVariables = new Dictionary<ILVariable, (int Index, ILInstruction Value)>();
currentPath = new List<AccessPathElement>(); currentPath = new List<AccessPathElement>();
isCollection = false; isCollection = false;
@ -89,7 +89,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// if the method is a setter we're dealing with an object initializer // if the method is a setter we're dealing with an object initializer
// if the method is named Add and has at least 2 arguments we're dealing with a collection/dictionary initializer // if the method is named Add and has at least 2 arguments we're dealing with a collection/dictionary initializer
while (pos + initializerItemsCount + 1 < body.Instructions.Count while (pos + initializerItemsCount + 1 < body.Instructions.Count
&& IsPartOfInitializer(body.Instructions, pos + initializerItemsCount + 1, v, instType, ref blockType)) { && IsPartOfInitializer(body.Instructions, pos + initializerItemsCount + 1, v, instType, ref blockKind)) {
initializerItemsCount++; initializerItemsCount++;
} }
// Do not convert the statements into an initializer if there's an incompatible usage of the initializer variable // Do not convert the statements into an initializer if there's an incompatible usage of the initializer variable
@ -109,7 +109,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
context.Step("CollectionOrObjectInitializer", inst); context.Step("CollectionOrObjectInitializer", inst);
// Create a new block and final slot (initializer target variable) // Create a new block and final slot (initializer target variable)
var initializerBlock = new Block(blockType); var initializerBlock = new Block(blockKind);
ILVariable finalSlot = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); ILVariable finalSlot = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type);
initializerBlock.FinalInstruction = new LdLoc(finalSlot); initializerBlock.FinalInstruction = new LdLoc(finalSlot);
initializerBlock.Instructions.Add(new StLoc(finalSlot, initInst.Clone())); initializerBlock.Instructions.Add(new StLoc(finalSlot, initInst.Clone()));
@ -161,7 +161,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
bool isCollection; bool isCollection;
Stack<HashSet<AccessPathElement>> pathStack; Stack<HashSet<AccessPathElement>> pathStack;
bool IsPartOfInitializer(InstructionCollection<ILInstruction> instructions, int pos, ILVariable target, IType rootType, ref BlockType blockType) bool IsPartOfInitializer(InstructionCollection<ILInstruction> instructions, int pos, ILVariable target, IType rootType, ref BlockKind blockKind)
{ {
// Include any stores to local variables that are single-assigned and do not reference the initializer-variable // Include any stores to local variables that are single-assigned and do not reference the initializer-variable
// in the list of possible index variables. // in the list of possible index variables.
@ -206,7 +206,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (isCollection || !pathStack.Peek().Add(lastElement)) if (isCollection || !pathStack.Peek().Add(lastElement))
return false; return false;
if (values.Count == 1) { if (values.Count == 1) {
blockType = BlockType.ObjectInitializer; blockKind = BlockKind.ObjectInitializer;
return true; return true;
} }
return false; return false;

Loading…
Cancel
Save