Esempio n. 1
0
        private JST.Expression TranslateConditionalExpression(MethodCompilerEnvironment methCompEnv, ISeq<JST.Statement> optBody, CST.Expression expr)
        {
            var e = TranslateExpression(methCompEnv, optBody, null, false, expr);

            var type = expr.Type(methCompEnv);
            var s = type.Style(methCompEnv);
            if (s is CST.ObjectTypeStyle || s is CST.StringTypeStyle || s is CST.ParameterTypeStyle || s is CST.NullTypeStyle)
            {
                if (e.IsDuplicatable)
                    return StringIsTrue(e);
                else
                {
                    var body = optBody ?? new Seq<JST.Statement>();
                    var id = nameSupply.GenSym();
                    body.Add(JST.Statement.Var(id, e));
                    if (optBody == null)
                        return new JST.StatementsPseudoExpression(new JST.Statements(body), StringIsTrue(id.ToE()));
                    else
                        return StringIsTrue(id.ToE());
                }
            }
            else
                return e;
        }