diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index e4a161bce..73f564d5c 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1721,18 +1721,18 @@ namespace ICSharpCode.Decompiler.CSharp protected internal override TranslatedExpression VisitBlock(Block block, TranslationContext context) { - switch (block.Type) { - case BlockType.ArrayInitializer: + switch (block.Kind) { + case BlockKind.ArrayInitializer: return TranslateArrayInitializer(block); - case BlockType.CollectionInitializer: - case BlockType.ObjectInitializer: + case BlockKind.CollectionInitializer: + case BlockKind.ObjectInitializer: return TranslateObjectAndCollectionInitializer(block); - case BlockType.PostfixOperator: + case BlockKind.PostfixOperator: return TranslatePostfixOperator(block); - case BlockType.CallInlineAssign: + case BlockKind.CallInlineAssign: return TranslateSetterCallAssignment(block); default: - return ErrorExpression("Unknown block type: " + block.Type); + return ErrorExpression("Unknown block type: " + block.Kind); } } diff --git a/ICSharpCode.Decompiler/IL/Instructions.cs b/ICSharpCode.Decompiler/IL/Instructions.cs index 6748f7b84..a50a307d2 100644 --- a/ICSharpCode.Decompiler/IL/Instructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions.cs @@ -690,7 +690,7 @@ namespace ICSharpCode.Decompiler.IL protected internal override bool PerformMatch(ILInstruction other, ref Patterns.Match match) { 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); } } } diff --git a/ICSharpCode.Decompiler/IL/Instructions/Block.cs b/ICSharpCode.Decompiler/IL/Instructions/Block.cs index 480851e59..9eabfe9d2 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Block.cs +++ b/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 FinalInstructionSlot = new SlotInfo("FinalInstruction"); - public readonly BlockType Type; + public readonly BlockKind Kind; public readonly InstructionCollection Instructions; ILInstruction finalInstruction; @@ -88,16 +88,16 @@ namespace ICSharpCode.Decompiler.IL 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(this, 0); this.FinalInstruction = new Nop(); } public override ILInstruction Clone() { - Block clone = new Block(Type); + Block clone = new Block(Kind); clone.ILRange = this.ILRange; clone.Instructions.AddRange(this.Instructions.Select(inst => inst.Clone())); clone.FinalInstruction = this.FinalInstruction.Clone(); @@ -111,11 +111,11 @@ namespace ICSharpCode.Decompiler.IL // only the last instruction may have an unreachable endpoint Debug.Assert(!Instructions[i].HasFlag(InstructionFlags.EndPointUnreachable)); } - switch (this.Type) { - case BlockType.ControlFlow: + switch (this.Kind) { + case BlockKind.ControlFlow: Debug.Assert(finalInstruction.OpCode == OpCode.Nop); break; - case BlockType.CallInlineAssign: + case BlockKind.CallInlineAssign: Debug.Assert(MatchInlineAssignBlock(out _, out _)); break; } @@ -264,7 +264,7 @@ namespace ICSharpCode.Decompiler.IL { call = null; value = null; - if (this.Type != BlockType.CallInlineAssign) + if (this.Kind != BlockKind.CallInlineAssign) return false; if (this.Instructions.Count != 1) return false; @@ -279,7 +279,7 @@ namespace ICSharpCode.Decompiler.IL } } - public enum BlockType + public enum BlockKind { /// /// Block is used for control flow. diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index 3308e709c..244c048bb 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -169,7 +169,7 @@ namespace ICSharpCode.Decompiler.IL Debug.Assert(EntryPoint == Blocks[0]); Debug.Assert(!IsConnected || EntryPoint.IncomingEdgeCount >= 1); 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() diff --git a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs index 70d7e5f9f..f52189c6e 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs @@ -331,10 +331,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms return true; } 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. - switch (block.Type) { - case BlockType.ArrayInitializer: - case BlockType.CollectionInitializer: - case BlockType.ObjectInitializer: + switch (block.Kind) { + case BlockKind.ArrayInitializer: + case BlockKind.CollectionInitializer: + case BlockKind.ObjectInitializer: return FindLoadInNext(block.Instructions[0], v, expressionBeingMoved, out loadInst) ?? false; // If FindLoadInNext() returns null, we still can't continue searching // because we can't inline over the remainder of the block. diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs index aaac03af8..801871925 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs @@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms int instructionsToRemove; if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out values, out instructionsToRemove)) { 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); block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray()))); 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)) { 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); 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))); @@ -266,7 +266,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms 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()))); int step = arrayLength.Length + 1; for (int i = 0; i < values.Length / step; i++) { diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs index 47dff8a0a..66a9e1674 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs @@ -147,7 +147,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms block.Instructions.Remove(call); var newVar = context.Function.RegisterVariable(VariableKind.StackSlot, call.Method.Parameters.Last().Type); 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 }, FinalInstruction = new LdLoc(newVar) }; @@ -395,7 +395,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; context.Step($"TransformPostIncDecOperatorLocal", inst); 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(nextInst.Variable, new BinaryNumericInstruction(binary.Operator, new LdLoc(tempStore), new LdcI4(1), binary.CheckForOverflow, binary.Sign))); assignment.FinalInstruction = new LdLoc(tempStore); diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index 12f9db004..2e16ecc9d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -78,7 +78,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; } int initializerItemsCount = 0; - var blockType = BlockType.CollectionInitializer; + var blockKind = BlockKind.CollectionInitializer; possibleIndexVariables = new Dictionary(); currentPath = new List(); 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 named Add and has at least 2 arguments we're dealing with a collection/dictionary initializer 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++; } // 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; context.Step("CollectionOrObjectInitializer", inst); // 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); initializerBlock.FinalInstruction = new LdLoc(finalSlot); initializerBlock.Instructions.Add(new StLoc(finalSlot, initInst.Clone())); @@ -161,7 +161,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms bool isCollection; Stack> pathStack; - bool IsPartOfInitializer(InstructionCollection instructions, int pos, ILVariable target, IType rootType, ref BlockType blockType) + bool IsPartOfInitializer(InstructionCollection 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 // in the list of possible index variables. @@ -206,7 +206,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (isCollection || !pathStack.Peek().Add(lastElement)) return false; if (values.Count == 1) { - blockType = BlockType.ObjectInitializer; + blockKind = BlockKind.ObjectInitializer; return true; } return false;