Split Common.h into Numeric.h.

This commit is contained in:
chriseth
2021-09-23 15:27:29 +02:00
parent c8e6ef9657
commit 1531863835
65 changed files with 318 additions and 215 deletions
+5 -4
View File
@@ -40,6 +40,7 @@
#include <range/v3/view/transform.hpp>
#include <cstdlib>
#include <limits>
using namespace std;
using namespace solidity;
@@ -102,8 +103,8 @@ std::pair<bool, string> ExecutionFramework::compareAndCreateMessage(
std::string message =
"Invalid encoded data\n"
" Result Expectation\n";
auto resultHex = boost::replace_all_copy(toHex(_result), "0", ".");
auto expectedHex = boost::replace_all_copy(toHex(_expectation), "0", ".");
auto resultHex = boost::replace_all_copy(util::toHex(_result), "0", ".");
auto expectedHex = boost::replace_all_copy(util::toHex(_expectation), "0", ".");
for (size_t i = 0; i < std::max(resultHex.size(), expectedHex.size()); i += 0x40)
{
std::string result{i >= resultHex.size() ? string{} : resultHex.substr(i, 0x40)};
@@ -163,7 +164,7 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
cout << "CALL " << m_sender.hex() << " -> " << m_contractAddress.hex() << ":" << endl;
if (_value > 0)
cout << " value: " << _value << endl;
cout << " in: " << toHex(_data) << endl;
cout << " in: " << util::toHex(_data) << endl;
}
evmc_message message = {};
message.input_data = _data.data();
@@ -194,7 +195,7 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
if (m_showMessages)
{
cout << " out: " << toHex(m_output) << endl;
cout << " out: " << util::toHex(m_output) << endl;
cout << " result: " << static_cast<size_t>(result.status_code) << endl;
cout << " gas used: " << m_gasUsed.str() << endl;
}
+1 -1
View File
@@ -169,7 +169,7 @@ public:
static bytes encode(size_t _value) { return encode(u256(_value)); }
static bytes encode(char const* _value) { return encode(std::string(_value)); }
static bytes encode(uint8_t _value) { return bytes(31, 0) + bytes{_value}; }
static bytes encode(u256 const& _value) { return util::toBigEndian(_value); }
static bytes encode(u256 const& _value) { return toBigEndian(_value); }
/// @returns the fixed-point encoding of a rational number with a given
/// number of fractional bits.
static bytes encode(std::pair<rational, int> const& _valueAndPrecision)
+1
View File
@@ -25,6 +25,7 @@
#include <string>
#include <set>
#include <iostream>
using namespace std;
using namespace solidity;
+3 -3
View File
@@ -131,7 +131,7 @@ map<string, Builtin> SemanticTest::makeBuiltins()
"isoltest_builtin_test",
[](FunctionCall const&) -> optional<bytes>
{
return util::toBigEndian(u256(0x1234));
return toBigEndian(u256(0x1234));
}
},
{
@@ -139,7 +139,7 @@ map<string, Builtin> SemanticTest::makeBuiltins()
[](FunctionCall const& _call) -> optional<bytes>
{
if (_call.arguments.parameters.empty())
return util::toBigEndian(0);
return toBigEndian(0);
else
return _call.arguments.rawBytes();
}
@@ -154,7 +154,7 @@ map<string, Builtin> SemanticTest::makeBuiltins()
address = h160(_call.arguments.parameters.at(0).rawString);
else
address = m_contractAddress;
return util::toBigEndian(balanceAt(address));
return toBigEndian(balanceAt(address));
}
},
{
+1
View File
@@ -32,6 +32,7 @@
#include <string>
#include <tuple>
#include <memory>
#include <limits>
using namespace std;
using namespace solidity::util;
+3 -2
View File
@@ -21,6 +21,7 @@
#include <test/libsolidity/util/SoltestErrors.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/CommonIO.h>
#include <boost/algorithm/string.hpp>
@@ -108,7 +109,7 @@ bytes BytesUtils::convertFixedPoint(string const& _literal, size_t& o_fractional
u256 value(valueInteger);
if (negative)
value = s2u(-u2s(value));
return util::toBigEndian(value);
return toBigEndian(value);
}
catch (std::exception const&)
{
@@ -193,7 +194,7 @@ string BytesUtils::formatHexString(bytes const& _bytes)
{
stringstream os;
os << "hex\"" << toHex(_bytes) << "\"";
os << "hex\"" << util::toHex(_bytes) << "\"";
return os.str();
}
@@ -963,7 +963,7 @@ BOOST_AUTO_TEST_CASE(call_effects)
std::map<std::string, Builtin> builtins;
builtins["builtin_returning_call_effect"] = [](FunctionCall const&) -> std::optional<bytes>
{
return util::toBigEndian(u256(0x1234));
return toBigEndian(u256(0x1234));
};
builtins["builtin_returning_call_effect_no_ret"] = [](FunctionCall const&) -> std::optional<bytes>
{
+2 -2
View File
@@ -81,7 +81,7 @@ TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _li
solAssert(obj.bytecode, "");
m_obtainedResult = "Text:\n" + obj.assembly + "\n";
m_obtainedResult += "Binary:\n" + toHex(obj.bytecode->bytecode) + "\n";
m_obtainedResult += "Binary:\n" + util::toHex(obj.bytecode->bytecode) + "\n";
}
else
{
@@ -95,7 +95,7 @@ TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _li
else
m_obtainedResult +=
"Bytecode: " +
toHex(obj.bytecode->bytecode) +
util::toHex(obj.bytecode->bytecode) +
"\nOpcodes: " +
boost::trim_copy(evmasm::disassemble(obj.bytecode->bytecode)) +
"\nSourceMappings:" +
+2 -1
View File
@@ -6,6 +6,7 @@
#include <libsolutil/Keccak256.h>
#include <libsolutil/StringUtils.h>
#include <libsolutil/Whiskers.h>
#include <libsolutil/Numeric.h>
#include <liblangutil/Exceptions.h>
@@ -505,7 +506,7 @@ public:
// Note: Don't change HexPrefix::Add. See comment in fixedByteValueAsString().
static std::string maskUnsignedIntToHex(unsigned _counter, unsigned _numMaskNibbles)
{
return toHex(maskUnsignedInt(_counter, _numMaskNibbles), util::HexPrefix::Add);
return "0x" + toHex(maskUnsignedInt(_counter, _numMaskNibbles));
}
/// Dynamically sized arrays can have a length of at least zero
@@ -29,6 +29,9 @@
#include <libevmasm/Instruction.h>
#include <libsolutil/Keccak256.h>
#include <libsolutil/Numeric.h>
#include <limits>
using namespace std;
using namespace solidity;
@@ -511,7 +514,7 @@ void EVMInstructionInterpreter::logTrace(std::string const& _pseudoInstruction,
{
string message = _pseudoInstruction + "(";
for (size_t i = 0; i < _arguments.size(); ++i)
message += (i > 0 ? ", " : "") + util::formatNumber(_arguments[i]);
message += (i > 0 ? ", " : "") + formatNumber(_arguments[i]);
message += ")";
if (!_data.empty())
message += " [" + util::toHex(_data) + "]";
@@ -24,6 +24,7 @@
#include <libyul/ASTForward.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/Numeric.h>
#include <vector>
@@ -29,6 +29,9 @@
#include <libevmasm/Instruction.h>
#include <libsolutil/Keccak256.h>
#include <libsolutil/Numeric.h>
#include <limits>
using namespace std;
using namespace solidity;
@@ -601,7 +604,7 @@ void EwasmBuiltinInterpreter::logTrace(std::string const& _pseudoInstruction, st
{
string message = _pseudoInstruction + "(";
for (size_t i = 0; i < _arguments.size(); ++i)
message += (i > 0 ? ", " : "") + util::formatNumber(_arguments[i]);
message += (i > 0 ? ", " : "") + formatNumber(_arguments[i]);
message += ")";
if (!_data.empty())
message += " [" + util::toHex(_data) + "]";