public override void ExitMethodCall([NotNull] XP.MethodCallContext context)
        {
            // convert ClassName():New(...) to ClassName{...}
            var lhs = context.Expr as XP.AccessMemberContext;

            if (lhs != null)
            {
                if (lhs.Op.Type == XP.COLON && lhs.Name.GetText().ToLower() == "new")
                {
                    var operand = lhs.Expr as XP.MethodCallContext;
                    if (operand != null && operand.ArgList == null)
                    {
                        var primary = operand.Expr as XP.PrimaryExpressionContext;
                        if (primary != null)
                        {
                            var className  = primary.GetText();
                            var seperators = new char[] { '.', ':' };
                            if (className.IndexOfAny(seperators) == -1)
                            {
                                var args = context.ArgList.Get <ArgumentListSyntax>();
                                var type = GenerateQualifiedName(className);
                                var expr = CreateObject(type, args);
                                context.Put(expr);
                                return;
                            }
                        }
                    }
                }
            }
            base.ExitMethodCall(context);
        }
Пример #2
0
        public override void ExitMethodCall([NotNull] XP.MethodCallContext context)
        {
            var    expr = context.Expr.Get <ExpressionSyntax>();
            string name = null;

            if (expr is IdentifierNameSyntax)
            {
                // Intrinsic functions that depend on Vulcan types
                IdentifierNameSyntax ins = expr as IdentifierNameSyntax;
                name = ins.Identifier.Text.ToUpper();
                if (name == XSharpIntrinsicNames.DoDefault)
                {
                    var entity = CurrentEntity;
                    name = entity.ShortName;
                    var super  = GenerateSuper();
                    var member = MakeSimpleMemberAccess(super, GenerateSimpleName(name));
                    ArgumentListSyntax argList;
                    if (context.ArgList != null)
                    {
                        argList = context.ArgList.Get <ArgumentListSyntax>();
                    }
                    else
                    {
                        if (entity.Data.HasClipperCallingConvention)
                        {
                            argList = MakeArgumentList(MakeArgument(GenerateSimpleName(XSharpSpecialNames.ClipperArgs)));
                        }
                        else
                        {
                            argList = EmptyArgumentList();
                        }
                    }
                    expr = _syntaxFactory.InvocationExpression(member, argList);
                    context.Put(expr);
                    return;
                }
            }
            // all other method names or syntaxes
            base.ExitMethodCall(context);
            return;
        }