<commit_before>﻿using Braille.Ast;
using Braille.JSAst;
using Braille.Loading.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Braille.JsTranslation.OpTranslators
{
    class ComparisonTranslator: OpTranslator
    {
        public ComparisonTranslator(Context context, CilAssembly assembly, CilType type, CilMethod method)
            : base(context, assembly, type, method)
        {
        }

        public JSExpression Translate(OpExpression node)
        {
            var opc = node.Instruction.OpCode.Name;

            var i = opc.IndexOf(".");
            var opc_ = i > 0 ? opc.Substring(0, i) : opc;

            var isUnsigned = opc.Contains(".un");

            switch (opc_)
            {
                case "ceq":
                    if (IsUInt64Operation(node) || IsInt64Operation(node))
                    {
                        return CreateXInt64BinaryOperation(node, "XInt64_Equality");
                    }
                    else
                    {
                        return new JSConditionalExpression
                        {
                            Condition = new JSBinaryExpression
                            {
                                Left = ProcessInternal(node.Arguments.First()),
                                Right = ProcessInternal(node.Arguments.Last()),
                                Operator = "==="
                            },
                            TrueValue = new JSNumberLiteral { Value = 1 },
                            FalseValue = new JSNumberLiteral { Value = 0 }
                        };
                    }
                case "cgt":
                    if (opc == "cgt.un" && ((OpExpression)node.Arguments.Last()).Instruction.OpCode.Name == "ldnull")
                    {<commit_msg>Generalize bgt.un check for null comparisons<commit_after>﻿using Braille.Ast;
using Braille.JSAst;
using Braille.Loading.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Braille.JsTranslation.OpTranslators
{
    class ComparisonTranslator: OpTranslator
    {
        public ComparisonTranslator(Context context, CilAssembly assembly, CilType type, CilMethod method)
            : base(context, assembly, type, method)
        {
        }

        public JSExpression Translate(OpExpression node)
        {
            var opc = node.Instruction.OpCode.Name;

            var i = opc.IndexOf(".");
            var opc_ = i > 0 ? opc.Substring(0, i) : opc;

            var isUnsigned = opc.Contains(".un");

            switch (opc_)
            {
                case "ceq":
                    if (IsUInt64Operation(node) || IsInt64Operation(node))
                    {
                        return CreateXInt64BinaryOperation(node, "XInt64_Equality");
                    }
                    else
                    {
                        return new JSConditionalExpression
                        {
                            Condition = new JSBinaryExpression
                            {
                                Left = ProcessInternal(node.Arguments.First()),
                                Right = ProcessInternal(node.Arguments.Last()),
                                Operator = "==="
                            },
                            TrueValue = new JSNumberLiteral { Value = 1 },
                            FalseValue = new JSNumberLiteral { Value = 0 }
                        };
                    }
                case "cgt":
                    if (opc == "cgt.un" && node.Arguments.Last().ResultType == context.SystemTypes.Null)
                    {
{'fraction_non_alphanumeric': 0.08545849158979923, 'fraction_numerical': 0.0065111231687466084, 'mean_word_length': 1.241337386018237, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '676472', 'n_tokens_mistral': 922, 'n_tokens_neox': 863, 'n_words': 187}