Mono.Cecil.Fluent.MethodBodyExtensions.ComputeStackDelta C# (CSharp) Method

ComputeStackDelta() static private method

static private ComputeStackDelta ( Instruction instruction, int &stackSize, bool addpush = true ) : void
instruction Mono.Cecil.Cil.Instruction
stackSize int
addpush bool
return void
		internal static void ComputeStackDelta(Instruction instruction, ref int stackSize, bool addpush = true)
		{
		    // ReSharper disable once SwitchStatementMissingSomeCases
			switch (instruction.OpCode.FlowControl)
			{
				case FlowControl.Call:
					{
						var method = (IMethodSignature)instruction.Operand;
						// pop 'this' argument
						if (method.HasImplicitThis() && instruction.OpCode.Code != Code.Newobj)
							stackSize--;
						// pop normal arguments
						if (method.HasParameters)
							stackSize -= method.Parameters.Count;
						// pop function pointer
						if (instruction.OpCode.Code == Code.Calli)
							stackSize--;
						// push return value
						if (!method.ReturnType.IsVoid() || instruction.OpCode.Code == Code.Newobj)
							if(addpush)
								stackSize++;
						break;
					}
				default:
					ComputePopDelta(instruction.OpCode.StackBehaviourPop, ref stackSize);
					if(addpush)
						ComputePushDelta(instruction.OpCode.StackBehaviourPush, ref stackSize);
					break;
			}
		}