MCPcopy Create free account
hub / github.com/argotorg/solidity / binaryOperation

Method binaryOperation

libsolidity/codegen/ir/IRGeneratorForStatements.cpp:3052–3112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3050}
3051
3052std::string IRGeneratorForStatements::binaryOperation(
3053 langutil::Token _operator,
3054 Type const& _type,
3055 std::string const& _left,
3056 std::string const& _right
3057)
3058{
3059 solAssert(
3060 !TokenTraits::isShiftOp(_operator),
3061 "Have to use specific shift operation function for shifts."
3062 );
3063 std::string fun;
3064 if (TokenTraits::isBitOp(_operator))
3065 {
3066 solAssert(
3067 _type.category() == Type::Category::Integer ||
3068 _type.category() == Type::Category::FixedBytes,
3069 ""
3070 );
3071 switch (_operator)
3072 {
3073 case Token::BitOr: fun = "or"; break;
3074 case Token::BitXor: fun = "xor"; break;
3075 case Token::BitAnd: fun = "and"; break;
3076 default: break;
3077 }
3078 }
3079 else if (TokenTraits::isArithmeticOp(_operator))
3080 {
3081 solUnimplementedAssert(
3082 _type.category() != Type::Category::FixedPoint,
3083 "Not yet implemented - FixedPointType."
3084 );
3085 IntegerType const* type = dynamic_cast<IntegerType const*>(&_type);
3086 solAssert(type);
3087 bool checked = m_context.arithmetic() == Arithmetic::Checked;
3088 switch (_operator)
3089 {
3090 case Token::Add:
3091 fun = checked ? m_utils.overflowCheckedIntAddFunction(*type) : m_utils.wrappingIntAddFunction(*type);
3092 break;
3093 case Token::Sub:
3094 fun = checked ? m_utils.overflowCheckedIntSubFunction(*type) : m_utils.wrappingIntSubFunction(*type);
3095 break;
3096 case Token::Mul:
3097 fun = checked ? m_utils.overflowCheckedIntMulFunction(*type) : m_utils.wrappingIntMulFunction(*type);
3098 break;
3099 case Token::Div:
3100 fun = checked ? m_utils.overflowCheckedIntDivFunction(*type) : m_utils.wrappingIntDivFunction(*type);
3101 break;
3102 case Token::Mod:
3103 fun = m_utils.intModFunction(*type);
3104 break;
3105 default:
3106 break;
3107 }
3108 }
3109

Callers

nothing calls this directly

Calls 15

isShiftOpFunction · 0.85
isBitOpFunction · 0.85
isArithmeticOpFunction · 0.85
intModFunctionMethod · 0.80

Tested by

no test coverage detected