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

Method negateNumberCheckedFunction

libsolidity/codegen/YulUtilFunctions.cpp:4258–4279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4256}
4257
4258std::string YulUtilFunctions::negateNumberCheckedFunction(Type const& _type)
4259{
4260 solAssert(_type.category() == Type::Category::Integer, "");
4261 IntegerType const& type = dynamic_cast<IntegerType const&>(_type);
4262 solAssert(type.isSigned(), "Expected signed type!");
4263
4264 std::string const functionName = "negate_" + _type.identifier();
4265 return m_functionCollector.createFunction(functionName, [&]() {
4266 return Whiskers(R"(
4267 function <functionName>(value) -> ret {
4268 value := <cleanupFunction>(value)
4269 if eq(value, <minval>) { <panic>() }
4270 ret := sub(0, value)
4271 }
4272 )")
4273 ("functionName", functionName)
4274 ("minval", toCompactHexWithPrefix(type.min()))
4275 ("cleanupFunction", cleanupFunction(_type))
4276 ("panic", panicFunction(PanicCode::UnderOverflow))
4277 .render();
4278 });
4279}
4280
4281std::string YulUtilFunctions::negateNumberWrappingFunction(Type const& _type)
4282{

Callers 2

visitMethod · 0.80
visitMethod · 0.80

Calls 8

WhiskersClass · 0.85
toCompactHexWithPrefixFunction · 0.85
identifierMethod · 0.80
renderMethod · 0.80
categoryMethod · 0.45
isSignedMethod · 0.45
createFunctionMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected