Esempio n. 1
0
        // Public Methods 

        public override void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style)
        {
            if (ReturnValue == null)
            {
                writer.WriteLn("return");
            }
            else
            {
                writer.WriteLnF("return {0}", ReturnValue.GetPyCode(style));
            }
        }
Esempio n. 2
0
        // Public Methods 

        public override void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style)
        {
            //   with tf.name_scope('hidden2') as name:
            writer.WriteLnF("with {0}:", Variable.GetPyCode(style));
            writer.Intent++;
            foreach (var sec in Statements)
            {
                sec.Emit(emiter, writer, style);
            }
            writer.Intent--;
        }
Esempio n. 3
0
        // Public Methods 

        public override void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style)
        {
            writer.OpenLnF("switch ({0}) {{", Expression.GetPyCode(style));
            foreach (var sec in Sections)
            {
                foreach (var l in sec.Labels)
                {
                    writer.WriteLnF("{0}{1}:",
                                    l.IsDefault ? "" : "case ",
                                    l.IsDefault ? "default" : l.Value.GetPyCode(style));
                }
                writer.IncIndent();
                sec.Statement.Emit(emiter, writer, style);
                writer.DecIndent();
            }

            writer.CloseLn("}");
        }
Esempio n. 4
0
        public virtual void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter code, PyEmitStyle style)
        {
            // public function addFunction($function, $namespace = '')
            var argumentsCode = Arguments.Select(u => u.GetPyCode(style)).ToList();
            var mk            = GetPyMethodKind();

            switch (mk)
            {
            case PyMethodKind.ClassStatic:
                code.WriteLn("@staticmethod");
                argumentsCode.Insert(0, GetCurrentClassAlias());
                break;

            case PyMethodKind.OutOfClass:
                break;

            case PyMethodKind.ClassInstance:
                argumentsCode.Insert(0, "self");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var param = Arguments == null ? "" : string.Join(", ", argumentsCode);

            code.OpenLnF("def {0}({1}):", Name, param);
            {
                var g = GetGlobals();
                if (!string.IsNullOrEmpty(g))
                {
                    code.WriteLnF("global {0};", g);
                }
            }
            foreach (var statement in Statements)
            {
                var g = PyEmitStyle.xClone(style);
                g.Brackets      = ShowBracketsEnum.Never;
                g.CurrentMethod = this;
                statement.Emit(emiter, code, g);
            }

            code.CloseLn("");
        }