Пример #1
0
        public override string GetPyCode(PyEmitStyle style)
        {
            var join      = style == null || style.Compression == EmitStyleCompression.Beauty ? ", " : ",";
            var xstyle    = PyEmitStyle.xClone(style);
            var arguments = string.Join(join, Arguments.Select(i => i.GetPyCode(xstyle)));

            if (IsConstructorCall)
            {
                var a = string.Format("new {0}({1})", _className.NameForEmit(style), arguments);
                return(a);
            }

            var name = _name;

            if (!_className.IsEmpty)
            {
                name = _className.NameForEmit(style) + "::" + name;
            }
            else if (TargetObject != null)
            {
                var to = TargetObject;
                if (TargetObject is PyMethodCallExpression &&
                    (TargetObject as PyMethodCallExpression).IsConstructorCall)
                {
                    to = new PyParenthesizedExpression(to);
                }
                name = to.GetPyCode(style) + "." + name;
            }

            // Arguments
            var skipBrackets = CanSkipBrackets();
            var code         = string.Format(skipBrackets ? "{0} {1}" : "{0}({1})", name, arguments);

            return(code);
        }
Пример #2
0
        public override string GetPyCode(PyEmitStyle style)
        {
            if (Expression == null)
            {
                throw new Exception("Unable to get code from empty expression");
            }
            var ex = PyParenthesizedExpression.Strip(Expression);
            var a  = Expression.GetPyCode(style);

            if (ByRef)
            {
                throw new NotSupportedException("'By ref' argument is not supported");
            }
            if (!string.IsNullOrEmpty(Name))
            {
                a = Name + "=" + a;
            }
            return(a);
        }