// Build a method invocation statement (foo(1))
        public static void BuildMethodInvocation(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var methodInvocation = new MethodInvocation(parentExpression, currentNode.FindToken().Convert());
            methodInvocation.Name = currentNode.ChildNodes[0].FindTokenAndGetText();
            parentExpression.ChildExpressions.Add(methodInvocation);

            // interpret the expressions that are passed to the invocation as arguments
            if (currentNode.ChildNodes[1].ChildNodes.Count > 0)
            {
                foreach (var n in currentNode.ChildNodes[1].ChildNodes)
                {
                    parser.ConsumeParseTree(root, methodInvocation.Parameters, n);

                }
            }
        }
Beispiel #2
0
        // Generate the codedom expression for a method invocation.
        public static CodeExpression Emit(MethodInvocation methodInvocation)
        {
            CodeTypeReferenceExpression t = null;

            // Check if it's a method owned by a variable.
            if (methodInvocation.Prefix != "")
                t = new CodeTypeReferenceExpression(methodInvocation.Prefix);

            // Create the codedom method invcation.
            var mi = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(t, methodInvocation.Name));

            // Add the parameters of the method invocation.
            foreach (var a in methodInvocation.Parameters.ChildExpressions)
                mi.Parameters.Add(CodeDomEmitter.EmitCodeExpression(a));

            return mi;
        }