<commit_before>#include <bashclass/BArithOperation.h>
#include <iostream>
#include <bashclass/BException.h>
#include <bashclass/BReport.h>
#include <bashclass/BVariableAccess.h>
#include <bashclass/BTypeFactory.h>

const std::string BArithOperation::OP_LOGICAL_OR = "logical_or";
const std::string BArithOperation::OP_LOGICAL_AND = "logical_and";
const std::string BArithOperation::OP_IS_EQUAL = "is_equal";
const std::string BArithOperation::OP_IS_NOT_EQUAL = "is_not_equal";
const std::string BArithOperation::OP_LESS_THAN = "less_than";
const std::string BArithOperation::OP_GREATER_THAN = "greater_than";
const std::string BArithOperation::OP_LESS_OR_EQUAL = "less_equal_than";
const std::string BArithOperation::OP_GREATER_OR_EQUAL = "greater_equal_than";
const std::string BArithOperation::OP_NOT = "not";
const std::string BArithOperation::OP_BIT_OR = "bit_or";
const std::string BArithOperation::OP_BIT_XOR = "bit_xor";
const std::string BArithOperation::OP_BIT_AND = "bit_and";
const std::string BArithOperation::OP_LEFT_SHIFT = "left_shift";
const std::string BArithOperation::OP_RIGHT_SHIFT = "right_shift";
const std::string BArithOperation::OP_MINUS = "minus";
const std::string BArithOperation::OP_MULTIPLY = "multiply";
const std::string BArithOperation::OP_DIVIDE = "divide";
const std::string BArithOperation::OP_MOD = "mod";
const std::string BArithOperation::OP_EXPONENTIAL = "exponential";
const std::string BArithOperation::OP_PLUS = "plus";
const std::string BArithOperation::OP_ASSIGN = "assign";


std::shared_ptr<IBType> BArithOperation::_evaluateRightOperand() {
    std::shared_ptr<IBType> singleOperandType = m_rightOperand->getType();

    // UNDEFINED
    if(singleOperandType->isUndefined()) {
        return singleOperandType;
    }

    // !
    if(m_operatorToken->getName() == OP_NOT) {
        if(singleOperandType->isBoolean() && !singleOperandType->isArray()) {
            return singleOperandType;
        }

        BReport::getInstance().error()
                << "Operator " << m_operatorToken->getValue()
                << " expects operand to be a boolean" << std::endl;
        BReport::getInstance().printError();
        return BTypeFactory::createUndefinedExpressionType();
    }

    // +, -
    if(m_operatorToken->getName() == OP_PLUS || m_operatorToken->getName() == OP_MINUS) {
        if(singleOperandType->isInt() && !singleOperandType->isArray()) {
            return singleOperandType;
        }

        BReport::getInstance().error()
                << "Operator " << m_operatorToken->getValue()
                << " expects operand to be an integer" << std::endl;
        BReport::getInstance().printError();
        return BTypeFactory::createUndefinedExpressionType();
    }

    throw BException("Undefined operator in an expression with one operand");
}

std::shared_ptr<IBType> BArithOperation::_evaluateTwoOperands() {
    std::shared_ptr<IBType> leftType = m_leftOperand->getType();
    std::shared_ptr<IBType> rightType = m_rightOperand->getType();

    // UNDEFINED
    if(leftType->isUndefined() || rightType->isUndefined()) {
        return leftType;
    }

    // ==, !=
    if(m_operatorToken->getName() == OP_IS_EQUAL || m_operatorToken->getName() == OP_IS_NOT_EQUAL) {
        if((leftType->getTypeValue() == rightType->getTypeValue()
            && leftType->getDimension() == rightType->getDimension())
           || (leftType->isIdentifier() && rightType->isNull())<commit_msg>Fixed comaprison btw null and array<commit_after>#include <bashclass/BArithOperation.h>
#include <iostream>
#include <bashclass/BException.h>
#include <bashclass/BReport.h>
#include <bashclass/BVariableAccess.h>
#include <bashclass/BTypeFactory.h>

const std::string BArithOperation::OP_LOGICAL_OR = "logical_or";
const std::string BArithOperation::OP_LOGICAL_AND = "logical_and";
const std::string BArithOperation::OP_IS_EQUAL = "is_equal";
const std::string BArithOperation::OP_IS_NOT_EQUAL = "is_not_equal";
const std::string BArithOperation::OP_LESS_THAN = "less_than";
const std::string BArithOperation::OP_GREATER_THAN = "greater_than";
const std::string BArithOperation::OP_LESS_OR_EQUAL = "less_equal_than";
const std::string BArithOperation::OP_GREATER_OR_EQUAL = "greater_equal_than";
const std::string BArithOperation::OP_NOT = "not";
const std::string BArithOperation::OP_BIT_OR = "bit_or";
const std::string BArithOperation::OP_BIT_XOR = "bit_xor";
const std::string BArithOperation::OP_BIT_AND = "bit_and";
const std::string BArithOperation::OP_LEFT_SHIFT = "left_shift";
const std::string BArithOperation::OP_RIGHT_SHIFT = "right_shift";
const std::string BArithOperation::OP_MINUS = "minus";
const std::string BArithOperation::OP_MULTIPLY = "multiply";
const std::string BArithOperation::OP_DIVIDE = "divide";
const std::string BArithOperation::OP_MOD = "mod";
const std::string BArithOperation::OP_EXPONENTIAL = "exponential";
const std::string BArithOperation::OP_PLUS = "plus";
const std::string BArithOperation::OP_ASSIGN = "assign";


std::shared_ptr<IBType> BArithOperation::_evaluateRightOperand() {
    std::shared_ptr<IBType> singleOperandType = m_rightOperand->getType();

    // UNDEFINED
    if(singleOperandType->isUndefined()) {
        return singleOperandType;
    }

    // !
    if(m_operatorToken->getName() == OP_NOT) {
        if(singleOperandType->isBoolean() && !singleOperandType->isArray()) {
            return singleOperandType;
        }

        BReport::getInstance().error()
                << "Operator " << m_operatorToken->getValue()
                << " expects operand to be a boolean" << std::endl;
        BReport::getInstance().printError();
        return BTypeFactory::createUndefinedExpressionType();
    }

    // +, -
    if(m_operatorToken->getName() == OP_PLUS || m_operatorToken->getName() == OP_MINUS) {
        if(singleOperandType->isInt() && !singleOperandType->isArray()) {
            return singleOperandType;
        }

        BReport::getInstance().error()
                << "Operator " << m_operatorToken->getValue()
                << " expects operand to be an integer" << std::endl;
        BReport::getInstance().printError();
        return BTypeFactory::createUndefinedExpressionType();
    }

    throw BException("Undefined operator in an expression with one operand");
}

std::shared_ptr<IBType> BArithOperation::_evaluateTwoOperands() {
    std::shared_ptr<IBType> leftType = m_leftOperand->getType();
    std::shared_ptr<IBType> rightType = m_rightOperand->getType();

    // UNDEFINED
    if(leftType->isUndefined() || rightType->isUndefined()) {
        return leftType;
    }

    // ==, !=
    if(m_operatorToken->getName() == OP_IS_EQUAL || m_operatorToken->getName() == OP_IS_NOT_EQUAL) {
        if((leftType->getTypeValue() == rightType->getTypeValue()
            && leftType->getDimension() == rightType->getDimension())
           || (leftType->isArray() && rightType->isNull())
           || (rightType->isArray() && leftType->isNull())
           || (leftType->isIdentifier() && rightType->isNull())
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0, 'mean_word_length': 4.691129032258065, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 75, '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': '7229801', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2196, 'n_words': 362}