bool ASTPrinter::visit(BinaryOperation const& _node) { writeLine(string("BinaryOperation using operator ") + Token::toString(_node.getOperator())); printType(_node); printSourcePart(_node); return goDeeper(); }
bool Why3Translator::visit(BinaryOperation const& _binaryOperation) { Expression const& leftExpression = _binaryOperation.leftExpression(); Expression const& rightExpression = _binaryOperation.rightExpression(); solAssert(!!_binaryOperation.annotation().commonType, ""); Type const& commonType = *_binaryOperation.annotation().commonType; Token::Value const c_op = _binaryOperation.getOperator(); if (commonType.category() == Type::Category::RationalNumber) { auto const& constantNumber = dynamic_cast<RationalNumberType const&>(commonType); if (constantNumber.isFractional()) error(_binaryOperation, "Fractional numbers not supported."); else add("(of_int " + toString(commonType.literalValue(nullptr)) + ")"); return false; } static const map<Token::Value, char const*> optrans({ {Token::And, " && "}, {Token::Or, " || "}, {Token::BitOr, " lor "}, {Token::BitXor, " lxor "}, {Token::BitAnd, " land "}, {Token::Add, " + "}, {Token::Sub, " - "}, {Token::Mul, " * "}, {Token::Div, " / "}, {Token::Mod, " mod "}, {Token::Equal, " = "}, {Token::NotEqual, " <> "}, {Token::LessThan, " < "}, {Token::GreaterThan, " > "}, {Token::LessThanOrEqual, " <= "}, {Token::GreaterThanOrEqual, " >= "} }); if (!optrans.count(c_op)) { error(_binaryOperation, "Operator not supported."); return true; } add("("); leftExpression.accept(*this); add(optrans.at(c_op)); rightExpression.accept(*this); add(")"); return false; }