コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
        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));
        }
コード例 #5
0
 public override sealed object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     this.BeginVisit(invocationExpression);
     object result = this.TrackedVisitInvocationExpression(invocationExpression, data);
     this.EndVisit(invocationExpression);
     return result;
 }
コード例 #6
0
 public virtual object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     return base.VisitInvocationExpression(invocationExpression, data);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 void CheckSimpleInvoke(InvocationExpression ie)
 {
     Assert.AreEqual(0, ie.Arguments.Count);
     Assert.IsTrue(ie.TargetObject is IdentifierExpression);
     Assert.AreEqual("myMethod", ((IdentifierExpression)ie.TargetObject).Identifier);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 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;
 }
コード例 #11
0
 public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     throw new global::System.NotImplementedException("InvocationExpression");
 }
コード例 #12
0
ファイル: Parser.cs プロジェクト: richardschneider/ILSpy
        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);
                }
            }
        }
コード例 #13
0
ファイル: Parser.cs プロジェクト: richardschneider/ILSpy
        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;
        }
コード例 #14
0
ファイル: Parser.cs プロジェクト: richardschneider/ILSpy
        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);
        }
コード例 #15
0
 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;
 }