public static bool NeedsHiddenMethodInfo(MethodReference method, MethodCallType callType, bool isConstructor) { if (IntrinsicRemap.ShouldRemap(method)) { return(false); } if (method.DeclaringType.IsArray && ((isConstructor || (method.Name == "Set")) || ((method.Name == "Get") || (method.Name == "Address")))) { return(false); } if (method.DeclaringType.IsSystemArray() && ((method.Name == "GetGenericValueImpl") || (method.Name == "SetGenericValueImpl"))) { return(false); } if (GenericsUtilities.IsGenericInstanceOfCompareExchange(method)) { return(false); } if (GenericsUtilities.IsGenericInstanceOfExchange(method)) { return(false); } if ((callType == MethodCallType.Virtual) && !CanDevirtualizeMethodCall(method.Resolve())) { return(false); } return(true); }
public MethodCallInfo(int calleeIndex, int[] parameterIndices, string calleeFullName, MethodCallType callType) { CalleeIndex = calleeIndex; ParameterIndices = parameterIndices; CalleeFullName = calleeFullName; CallType = callType; }
/// <summary> /// 访问方法表达式 /// </summary> /// <param name="node">方法表达式</param> /// <param name="method">方法类型</param> /// <returns></returns> protected Expression VisitMethodCall(Expression node, MethodCallType method) { if (_methodCallVisitor == null) { _methodCallVisitor = _provider.CreateMethodCallVisitor(this); } _methodCallVisitor.Visit(node, method); return(node); }
public MethodCallExpression(MethodCallType type, Method method, params Expression[] arguments) : base(ExpressionType.MethodCall) { Require.NotNull(method, "method"); Require.NotNull(arguments, "arguments"); MethodCallType = type; Method = method; Arguments = arguments; }
/// <summary> /// 将调度到此类中更专用的访问方法之一的表达式。 /// </summary> /// <param name="node">方法节点</param> /// <param name="router">方法路由</param> /// <returns></returns> public Expression Visit(Expression node, MethodCallType router) { int visitedQty = _visitedStack.Count; Expression newNode = null; if (router == MethodCallType.Coalesce) { newNode = this.VisitCoalesce((BinaryExpression)node); } else if (router == MethodCallType.EqualNull) { newNode = this.VisitEqualNull((BinaryExpression)node); } else if (router == MethodCallType.MethodCall) { newNode = this.VisitMethodCall((MethodCallExpression)node); } else if (router == MethodCallType.BinaryCall) { newNode = this.VisitMethodCall((BinaryExpression)node); } else if (router == MethodCallType.MemberMember) { newNode = this.VisitMemberMember((MemberExpression)node); } else if (router == MethodCallType.Unary) { newNode = this.VisitUnary((UnaryExpression)node); } // 自身已构成布尔表达式的则需要删除它本身所产生的访问链 if (_visitedStack.Count != visitedQty) { bool b = router != MethodCallType.Unary; if (b && router == MethodCallType.MethodCall) { var m = (MethodCallExpression)node; b = _removeVisitedMethods.Contains(m.Method.Name); } if (b) { _visitedStack.Remove(_visitedStack.Count - visitedQty); } } return(newNode); }
public void DisassembleBody_single_basic_block_with_call(MethodCallType callType, string expectedSuffix) { var graphBuilder = new BasicBlockGraphBuilder(); var blockBuilder = graphBuilder.GetInitialBlockBuilder(); blockBuilder.AppendInstruction(Opcode.Call, 0, 0, 1); blockBuilder.AppendInstruction(Opcode.Return, 2, 0, 0); var method = new CompiledMethod("Test::Method") { Body = graphBuilder.Build() }; method.AddCallInfo(17, new[] { 3, 6, 9, 12 }, "Test::Callee", callType); string expected = "BB_0:\n" + " Call Test::Callee(#3, #6, #9, #12)" + expectedSuffix + " -> #1\n" + " Return #2\n\n"; var builder = new StringBuilder(); MethodDisassembler.DisassembleBody(method, builder); Assert.That(builder.ToString().Replace("\r\n", "\n"), Is.EqualTo(expected)); }
/// <summary> /// Creates and adds new <see cref="MethodCallInfo"/> to <see cref="CallInfos"/> and returns its index. /// </summary> /// <param name="calleeIndex">The body index of the called method.</param> /// <param name="parameterLocals">Local indices for the parameters.</param> /// <param name="calleeName">The full name of the called method, used for debugging.</param> public uint AddCallInfo(int calleeIndex, int[] parameterLocals, string calleeName, MethodCallType callType) { _callInfos.Add(new MethodCallInfo(calleeIndex, parameterLocals, calleeName, callType)); return((uint)(_callInfos.Count - 1)); }