예제 #1
0
        // Public Methods 

        public override void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style)
        {
            style = PyEmitStyle.xClone(style);
            if (!style.AsIncrementor)
            {
                switch (Expression)
                {
                case PyEmptyExpression _:
                    return;

                case PyMethodCallExpression methodCallExpression:
                    break;
                }
            }

            var code = Expression.GetPyCode(style);

            if (style.AsIncrementor)
            {
                writer.Write(code);
            }
            else
            {
                writer.WriteLn(code);
            }
        }
예제 #2
0
        // Protected Methods 

        protected void EmitHeaderStatement(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style, string header, IPyStatement statement)
        {
            style = style ?? new PyEmitStyle();
            var iStyle = PyEmitStyle.xClone(style, ShowBracketsEnum.IfManyItems);

            if (style.UseBracketsEvenIfNotNecessary)
            {
                iStyle.Brackets = ShowBracketsEnum.Always;
            }

            var statementToEmit = PyCodeBlock.Reduce(statement);
            var emptyStatement  = !PyCodeBlock.HasAny(statementToEmit);


            if (emptyStatement)
            {
                header += "{}";
            }
            if (style.Compression == EmitStyleCompression.NearCrypto)
            {
                writer.Write(header);
            }
            else
            {
                writer.WriteLn(header);
            }
            if (emptyStatement)
            {
                return;
            }


            var myBracket = style.UseBracketsEvenIfNotNecessary;

            if (!myBracket)
            {
                var gf = statementToEmit.GetStatementEmitInfo(iStyle);
                if (gf != StatementEmitInfo.NormalSingleStatement)
                {
                    myBracket = true;
                }
            }
            writer.IncIndent();
            if (myBracket)
            {
                iStyle.Brackets = ShowBracketsEnum.Never;
                writer.OpenLn("{");
            }


            statementToEmit.Emit(emiter, writer, iStyle);
            if (myBracket)
            {
                writer.CloseLn("}");
            }

            writer.DecIndent();
        }
예제 #3
0
        // Public Methods 

        public override void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style)
        {
            var s = style?.Compression ?? EmitStyleCompression.Beauty;

            if (s == EmitStyleCompression.NearCrypto)
            {
                writer.Write("continue;");
            }
            else
            {
                writer.WriteLn("continue;");
            }
        }
예제 #4
0
        // Public Methods 

        public override void Emit(PySourceCodeEmiter emiter, PySourceCodeWriter writer, PyEmitStyle style)
        {
            var isBeauty = style == null || style.Compression == EmitStyleCompression.Beauty;

            var ifTrueAny  = PyCodeBlock.HasAny(_ifTrue);
            var ifFalseAny = PyCodeBlock.HasAny(_ifFalse);

            if (!ifTrueAny && !ifFalseAny)
            {
                return;
            }

            writer.OpenLnF("if{1}({0}){2}",
                           Condition.GetPyCode(style),
                           isBeauty ? " " : "",
                           ifTrueAny ? "" : "{}");
            if (ifTrueAny)
            {
                var iStyle = PyEmitStyle.xClone(style, ShowBracketsEnum.IfManyItems_OR_IfStatement);
                if (style != null && style.UseBracketsEvenIfNotNecessary)
                {
                    iStyle.Brackets = ShowBracketsEnum.Always;
                }
                var bound = PyCodeBlock.Bound(_ifTrue);
                bound.Emit(emiter, writer, iStyle);
            }

            writer.DecIndent();
            if (!ifFalseAny)
            {
                return;
            }
            var oneLine   = _ifFalse is PyIfStatement;
            var oldIndent = writer.Intent;

            {
                if (oneLine)
                {
                    writer.Write("else ");
                    writer.SkipIndent = true;
                }
                else
                {
                    writer.OpenLn("else");
                }

                var myBracket = style != null && style.UseBracketsEvenIfNotNecessary;

                var iStyle = PyEmitStyle.xClone(style,
                                                myBracket
                        ? ShowBracketsEnum.Never
                        : ShowBracketsEnum.IfManyItems_OR_IfStatement);

                if (!myBracket)
                {
                    var gf = _ifFalse.GetStatementEmitInfo(iStyle);
                    if (gf != StatementEmitInfo.NormalSingleStatement)
                    {
                        myBracket = true;
                    }
                }

                if (myBracket)
                {
                    iStyle.Brackets = ShowBracketsEnum.Never;
                    writer.OpenLn("{");
                }

                _ifFalse.Emit(emiter, writer, iStyle);
                if (myBracket)
                {
                    writer.CloseLn("}");
                }
            }
            writer.Intent = oldIndent;
        }