void CheckGenericInvoke(InvocationExpression expr) { Assert.AreEqual(1, expr.Arguments.Count); Assert.IsTrue(expr.TargetObject is IdentifierExpression); IdentifierExpression ident = (IdentifierExpression)expr.TargetObject; Assert.AreEqual("myMethod", ident.Identifier); Assert.AreEqual(1, ident.TypeArguments.Count); Assert.AreEqual("System.Char", ident.TypeArguments[0].Type); }
public void IdentifierOnlyInvocation() { // InitializeComponents(); IdentifierExpression identifier = new IdentifierExpression("InitializeComponents"); InvocationExpression invocation = new InvocationExpression(identifier, new List<Expression>()); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); Assert.IsTrue(output is CodeMethodInvokeExpression); CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; Assert.AreEqual("InitializeComponents", mie.Method.MethodName); Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); }
public void MethodOnThisReferenceInvocation() { // InitializeComponents(); MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents"); InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); Assert.IsTrue(output is CodeMethodInvokeExpression); CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; Assert.AreEqual("InitializeComponents", mie.Method.MethodName); Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); }
void CheckGenericInvoke2(InvocationExpression expr) { Assert.AreEqual(0, expr.Arguments.Count); Assert.IsTrue(expr.TargetObject is IdentifierExpression); IdentifierExpression ident = (IdentifierExpression)expr.TargetObject; Assert.AreEqual("myMethod", ident.Identifier); Assert.AreEqual(2, ident.TypeArguments.Count); Assert.AreEqual("T", ident.TypeArguments[0].Type); Assert.IsFalse(ident.TypeArguments[0].IsKeyword); Assert.AreEqual("System.Boolean", ident.TypeArguments[1].Type); Assert.IsTrue(ident.TypeArguments[1].IsKeyword); }
public void InvocationOfStaticMethod() { // System.Drawing.Color.FromArgb(); MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing"); field = new MemberReferenceExpression(field, "Color"); field = new MemberReferenceExpression(field, "FromArgb"); InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); Assert.IsTrue(output is CodeMethodInvokeExpression); CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; Assert.AreEqual("FromArgb", mie.Method.MethodName); Assert.IsTrue(mie.Method.TargetObject is CodeTypeReferenceExpression); Assert.AreEqual("System.Drawing.Color", (mie.Method.TargetObject as CodeTypeReferenceExpression).Type.BaseType); }
void CheckSimpleInvoke(InvocationExpression ie) { Assert.AreEqual(0, ie.Arguments.Count); Assert.IsTrue(ie.TargetObject is IdentifierExpression); Assert.AreEqual("myMethod", ((IdentifierExpression)ie.TargetObject).Identifier); }
public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { Debug.Assert((invocationExpression != null)); Debug.Assert((invocationExpression.TargetObject != null)); Debug.Assert((invocationExpression.Arguments != null)); invocationExpression.TargetObject.AcceptVisitor(this, data); foreach (Expression o in invocationExpression.Arguments) { Debug.Assert(o != null); o.AcceptVisitor(this, data); } return null; }
public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { throw new global::System.NotImplementedException("InvocationExpression"); }
void ReDimClauseInternal(ref Expression expr) { List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; Location startLocation = la.Location; while (la.kind == 26 || (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)) { if (la.kind == 26) { Get(); IdentifierOrKeyword(out name); expr = new MemberReferenceExpression(expr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else { InvocationExpression(ref expr); expr.StartLocation = startLocation; expr.EndLocation = t.EndLocation; } } Expect(37); NormalOrReDimArgumentList(out arguments, out canBeNormal, out canBeRedim); Expect(38); expr = new InvocationExpression(expr, arguments); if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) { if (this.Errors.Count == 0) { // don't recurse on parse errors - could result in endless recursion ReDimClauseInternal(ref expr); } } }
public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { Debug.Assert((invocationExpression != null)); Debug.Assert((invocationExpression.TargetObject != null)); Debug.Assert((invocationExpression.Arguments != null)); nodeStack.Push(invocationExpression.TargetObject); invocationExpression.TargetObject.AcceptVisitor(this, data); invocationExpression.TargetObject = ((Expression)(nodeStack.Pop())); for (int i = 0; i < invocationExpression.Arguments.Count; i++) { Expression o = invocationExpression.Arguments[i]; Debug.Assert(o != null); nodeStack.Push(o); o.AcceptVisitor(this, data); o = (Expression)nodeStack.Pop(); if (o == null) invocationExpression.Arguments.RemoveAt(i--); else invocationExpression.Arguments[i] = o; } return null; }
void ExpressionStatement(out Statement statement) { Expression expr = null; Expression val = null; AssignmentOperatorType op; Location startLoc = la.Location; bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.Times; SimpleExpr(out expr); if (StartOf(46)) { AssignmentOperator(out op); Expr(out val); expr = new AssignmentExpression(expr, op, val); expr.StartLocation = startLoc; expr.EndLocation = t.EndLocation; } else if (la.kind == 1 || la.kind == 21 || la.kind == 111) { if (mustBeAssignment) Error("error in assignment."); } else SynErr(312); if(expr is MemberReferenceExpression || expr is IdentifierExpression) { Location endLocation = expr.EndLocation; expr = new InvocationExpression(expr); expr.StartLocation = startLoc; expr.EndLocation = endLocation; } statement = new ExpressionStatement(expr); }
void InvocationExpression(ref Expression pexpr) { List<Expression> parameters = null; Expect(37); Location start = t.Location; ArgumentList(out parameters); Expect(38); pexpr = new InvocationExpression(pexpr, parameters); pexpr.StartLocation = start; pexpr.EndLocation = t.Location; }
public virtual object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data) { return base.VisitInvocationExpression(invocationExpression, data); }
public sealed override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { this.BeginVisit(invocationExpression); object result = this.TrackedVisitInvocationExpression(invocationExpression, data); this.EndVisit(invocationExpression); return result; }
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { Expression target = invocationExpression.TargetObject; CodeExpression targetExpr; string methodName = null; if (target == null) { targetExpr = new CodeThisReferenceExpression(); } else if (target is MemberReferenceExpression) { MemberReferenceExpression fRef = (MemberReferenceExpression)target; targetExpr = null; if (fRef.TargetObject is MemberReferenceExpression) { if (IsPossibleTypeReference((MemberReferenceExpression)fRef.TargetObject)) { targetExpr = ConvertToTypeReference((MemberReferenceExpression)fRef.TargetObject); } } if (targetExpr == null) targetExpr = (CodeExpression)fRef.TargetObject.AcceptVisitor(this, data); methodName = fRef.MemberName; // HACK for : Microsoft.VisualBasic.ChrW(NUMBER) if (methodName == "ChrW") { return new CodeCastExpression("System.Char", GetExpressionList(invocationExpression.Arguments)[0]); } } else if (target is IdentifierExpression) { targetExpr = new CodeThisReferenceExpression(); methodName = ((IdentifierExpression)target).Identifier; } else { targetExpr = (CodeExpression)target.AcceptVisitor(this, data); } return new CodeMethodInvokeExpression(targetExpr, methodName, GetExpressionList(invocationExpression.Arguments)); }