C++ namespace cleanup (except tests).

This commit is contained in:
Christian Parpart 2019-12-11 17:31:36 +01:00 committed by Daniel Kirchner
parent 8385256bdc
commit 6b23412fae
403 changed files with 1656 additions and 1926 deletions

View File

@ -20,7 +20,7 @@
#include <functional>
#include <set>
namespace dev
namespace solidity::util
{
/**

View File

@ -20,7 +20,7 @@
#include <ostream>
#include <vector>
namespace dev
namespace solidity::util
{
namespace formatting

View File

@ -26,7 +26,7 @@
#include <libdevcore/Exceptions.h>
namespace dev
namespace solidity::util
{
#if defined(_MSC_VER)
@ -46,7 +46,7 @@ namespace dev
if (!(_condition)) \
::boost::throw_exception( \
_ExceptionType() << \
::dev::errinfo_comment(_description) << \
::solidity::util::errinfo_comment(_description) << \
::boost::throw_function(ETH_FUNC) << \
::boost::throw_file(__FILE__) << \
::boost::throw_line(__LINE__) \

View File

@ -51,13 +51,13 @@
#include <functional>
#include <string>
namespace dev
namespace solidity
{
// Binary data types.
using bytes = std::vector<uint8_t>;
using bytesRef = vector_ref<uint8_t>;
using bytesConstRef = vector_ref<uint8_t const>;
using bytesRef = util::vector_ref<uint8_t>;
using bytesConstRef = util::vector_ref<uint8_t const>;
// Numeric types.
using bigint = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>>;

View File

@ -28,7 +28,8 @@
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace dev;
using namespace solidity;
using namespace solidity::util;
namespace
{
@ -38,7 +39,7 @@ static char const* lowerHexChars = "0123456789abcdef";
}
string dev::toHex(uint8_t _data, HexCase _case)
string solidity::util::toHex(uint8_t _data, HexCase _case)
{
assertThrow(_case != HexCase::Mixed, BadHexCase, "Mixed case can only be used for byte arrays.");
@ -50,7 +51,7 @@ string dev::toHex(uint8_t _data, HexCase _case)
};
}
string dev::toHex(bytes const& _data, HexPrefix _prefix, HexCase _case)
string solidity::util::toHex(bytes const& _data, HexPrefix _prefix, HexCase _case)
{
std::string ret(_data.size() * 2 + (_prefix == HexPrefix::Add ? 2 : 0), 0);
@ -78,7 +79,7 @@ string dev::toHex(bytes const& _data, HexPrefix _prefix, HexCase _case)
return ret;
}
int dev::fromHex(char _i, WhenError _throw)
int solidity::util::fromHex(char _i, WhenError _throw)
{
if (_i >= '0' && _i <= '9')
return _i - '0';
@ -92,7 +93,7 @@ int dev::fromHex(char _i, WhenError _throw)
return -1;
}
bytes dev::fromHex(std::string const& _s, WhenError _throw)
bytes solidity::util::fromHex(std::string const& _s, WhenError _throw)
{
unsigned s = (_s.size() >= 2 && _s[0] == '0' && _s[1] == 'x') ? 2 : 0;
std::vector<uint8_t> ret;
@ -119,7 +120,7 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw)
}
bool dev::passesAddressChecksum(string const& _str, bool _strict)
bool solidity::util::passesAddressChecksum(string const& _str, bool _strict)
{
string s = _str.substr(0, 2) == "0x" ? _str : "0x" + _str;
@ -132,10 +133,10 @@ bool dev::passesAddressChecksum(string const& _str, bool _strict)
))
return true;
return s == dev::getChecksummedAddress(s);
return s == solidity::util::getChecksummedAddress(s);
}
string dev::getChecksummedAddress(string const& _addr)
string solidity::util::getChecksummedAddress(string const& _addr)
{
string s = _addr.substr(0, 2) == "0x" ? _addr.substr(2) : _addr;
assertThrow(s.length() == 40, InvalidAddress, "");
@ -156,7 +157,7 @@ string dev::getChecksummedAddress(string const& _addr)
return ret;
}
bool dev::isValidHex(string const& _string)
bool solidity::util::isValidHex(string const& _string)
{
if (_string.substr(0, 2) != "0x")
return false;
@ -165,7 +166,7 @@ bool dev::isValidHex(string const& _string)
return true;
}
bool dev::isValidDecimal(string const& _string)
bool solidity::util::isValidDecimal(string const& _string)
{
if (_string.empty())
return false;
@ -179,7 +180,7 @@ bool dev::isValidDecimal(string const& _string)
return true;
}
string dev::formatAsStringOrNumber(string const& _value)
string solidity::util::formatAsStringOrNumber(string const& _value)
{
assertThrow(_value.length() <= 32, StringTooLong, "String to be formatted longer than 32 bytes.");

View File

@ -138,7 +138,7 @@ inline std::multiset<T...>& operator-=(std::multiset<T...>& _a, C const& _b)
return _a;
}
namespace dev
namespace solidity::util
{
template <class T, class U>

View File

@ -35,7 +35,7 @@
#endif
using namespace std;
using namespace dev;
using namespace solidity::util;
namespace
{
@ -63,12 +63,12 @@ inline _T readFile(std::string const& _file)
}
string dev::readFileAsString(string const& _file)
string solidity::util::readFileAsString(string const& _file)
{
return readFile<string>(_file);
}
string dev::readStandardInput()
string solidity::util::readStandardInput()
{
string ret;
while (!cin.eof())
@ -124,13 +124,13 @@ private:
};
#endif
int dev::readStandardInputChar()
int solidity::util::readStandardInputChar()
{
DisableConsoleBuffering disableConsoleBuffering;
return cin.get();
}
string dev::absolutePath(string const& _path, string const& _reference)
string solidity::util::absolutePath(string const& _path, string const& _reference)
{
boost::filesystem::path p(_path);
// Anything that does not start with `.` is an absolute path.
@ -146,6 +146,6 @@ string dev::absolutePath(string const& _path, string const& _reference)
return result.generic_string();
}
string dev::sanitizePath(string const& _path) {
string solidity::util::sanitizePath(string const& _path) {
return boost::filesystem::path(_path).generic_string();
}

View File

@ -28,7 +28,7 @@
#include <sstream>
#include <string>
namespace dev
namespace solidity::util
{
/// Retrieve and returns the contents of the given file as a std::string.

View File

@ -18,7 +18,7 @@
#include <libdevcore/Exceptions.h>
using namespace std;
using namespace dev;
using namespace solidity::util;
char const* Exception::what() const noexcept
{

View File

@ -25,7 +25,7 @@
#include <exception>
#include <string>
namespace dev
namespace solidity::util
{
/// Base class for all exceptions.
@ -42,7 +42,7 @@ struct Exception: virtual std::exception, virtual boost::exception
private:
};
#define DEV_SIMPLE_EXCEPTION(X) struct X: virtual Exception { const char* what() const noexcept override { return #X; } }
#define DEV_SIMPLE_EXCEPTION(X) struct X: virtual ::solidity::util::Exception { const char* what() const noexcept override { return #X; } }
DEV_SIMPLE_EXCEPTION(InvalidAddress);
DEV_SIMPLE_EXCEPTION(BadHexCharacter);

View File

@ -32,7 +32,7 @@
#include <cstdint>
#include <algorithm>
namespace dev
namespace solidity::util
{
/// Fixed-size raw-byte array container type, with an API optimised for storing hashes.
@ -73,7 +73,7 @@ public:
explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } }
/// Explicitly construct, copying from a string.
explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : dev::asBytes(_s), _ht) {}
explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : solidity::util::asBytes(_s), _ht) {}
/// Convert to arithmetic type.
operator Arith() const { return fromBigEndian<Arith>(m_data); }

View File

@ -23,7 +23,7 @@
#include <libdevcore/Assertions.h>
using namespace std;
using namespace dev;
using namespace solidity::util;
string IndentedWriter::format() const
{

View File

@ -26,7 +26,7 @@
#include <libdevcore/Exceptions.h>
namespace dev
namespace solidity::util
{
DEV_SIMPLE_EXCEPTION(IndentedWriterError);

View File

@ -23,7 +23,8 @@
#include <libdevcore/CommonData.h>
using namespace std;
using namespace dev;
using namespace solidity;
using namespace solidity::util;
namespace
{
@ -54,7 +55,7 @@ string base58Encode(bytes const& _data)
}
}
bytes dev::ipfsHash(string _data)
bytes solidity::util::ipfsHash(string _data)
{
assertThrow(_data.length() < 1024 * 256, DataTooLong, "IPFS hash for large (chunked) files not yet implemented.");
@ -84,7 +85,7 @@ bytes dev::ipfsHash(string _data)
return hash;
}
string dev::ipfsHashBase58(string _data)
string solidity::util::ipfsHashBase58(string _data)
{
return base58Encode(ipfsHash(std::move(_data)));
}

View File

@ -21,7 +21,7 @@
#include <string>
namespace dev
namespace solidity::util
{
/// Compute the "ipfs hash" of a file with the content @a _data.

View File

@ -36,7 +36,7 @@ static_assert(
"Unexpected jsoncpp version: " JSONCPP_VERSION_STRING ". Expecting 1.9.2."
);
namespace dev
namespace solidity::util
{
namespace
@ -111,4 +111,4 @@ bool jsonParseStrict(string const& _input, Json::Value& _json, string* _errs /*
return parse(readerBuilder, _input, _json, _errs);
}
} // namespace dev
} // namespace solidity::util

View File

@ -26,7 +26,7 @@
#include <string>
namespace dev {
namespace solidity::util {
/// Serialise the JSON object (@a _input) with indentation
std::string jsonPrettyPrint(Json::Value const& _input);

View File

@ -27,9 +27,8 @@
#include <cstring>
using namespace std;
using namespace dev;
namespace dev
namespace solidity::util
{
namespace

View File

@ -27,7 +27,7 @@
#include <string>
namespace dev
namespace solidity::util
{
/// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash.

View File

@ -18,7 +18,7 @@
#include <string>
namespace dev
namespace solidity::util
{
/// Simple generic result that holds a value and an optional error message.

View File

@ -27,9 +27,9 @@
#include <vector>
using namespace std;
using namespace dev;
using namespace solidity::util;
bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance, size_t _lenThreshold)
bool solidity::util::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance, size_t _lenThreshold)
{
if (_str1 == _str2)
return true;
@ -46,7 +46,7 @@ bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t
return distance <= _maxDistance && distance < n1 && distance < n2;
}
size_t dev::stringDistance(string const& _str1, string const& _str2)
size_t solidity::util::stringDistance(string const& _str1, string const& _str2)
{
size_t n1 = _str1.size();
size_t n2 = _str2.size();
@ -86,7 +86,7 @@ size_t dev::stringDistance(string const& _str1, string const& _str2)
return dp[(n1 % 3) + n2 * 3];
}
string dev::quotedAlternativesList(vector<string> const& suggestions)
string solidity::util::quotedAlternativesList(vector<string> const& suggestions)
{
vector<string> quotedSuggestions;
@ -96,7 +96,7 @@ string dev::quotedAlternativesList(vector<string> const& suggestions)
return joinHumanReadable(quotedSuggestions, ", ", " or ");
}
string dev::suffixedVariableNameList(string const& _baseName, size_t _startSuffix, size_t _endSuffix)
string solidity::util::suffixedVariableNameList(string const& _baseName, size_t _startSuffix, size_t _endSuffix)
{
string result;
if (_startSuffix < _endSuffix)

View File

@ -28,7 +28,7 @@
#include <libdevcore/CommonData.h>
namespace dev
namespace solidity::util
{
// Calculates the DamerauLevenshtein distance between _str1 and _str2 and returns true if that distance is not greater than _maxDistance

View File

@ -22,7 +22,8 @@
#include <libdevcore/Keccak256.h>
using namespace std;
using namespace dev;
using namespace solidity;
using namespace solidity::util;
namespace
{
@ -102,13 +103,13 @@ h256 chunkHash(bytesConstRef const _data, bool _forceHigherLevel = false)
}
h256 dev::bzzr0Hash(string const& _input)
h256 solidity::util::bzzr0Hash(string const& _input)
{
return swarmHashIntermediate(_input, 0, _input.size());
}
h256 dev::bzzr1Hash(bytes const& _input)
h256 solidity::util::bzzr1Hash(bytes const& _input)
{
if (_input.empty())
return h256{};

View File

@ -23,7 +23,7 @@
#include <string>
namespace dev
namespace solidity::util
{
/// Compute the "swarm hash" of @a _input (OLD 0x1000-section version)

View File

@ -23,7 +23,7 @@
#include <libdevcore/UTF8.h>
namespace dev
namespace solidity::util
{
namespace
{

View File

@ -25,7 +25,7 @@
#include <string>
namespace dev
namespace solidity::util
{
/// Validate an input for UTF8 encoding

View File

@ -20,7 +20,7 @@
#pragma once
namespace dev
namespace solidity::util
{
/**

View File

@ -28,7 +28,7 @@
#include <regex>
using namespace std;
using namespace dev;
using namespace solidity::util;
Whiskers::Whiskers(string _template):
m_template(move(_template))

View File

@ -29,7 +29,7 @@
#include <map>
#include <vector>
namespace dev
namespace solidity::util
{
DEV_SIMPLE_EXCEPTION(WhiskersError);

View File

@ -10,7 +10,7 @@
#pragma warning(disable:597) // will not be called for implicit or explicit conversions
#endif
namespace dev
namespace solidity::util
{
/**

View File

@ -33,9 +33,10 @@
#include <json/json.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::langutil;
using namespace solidity::util;
void Assembly::append(Assembly const& _a)
{
@ -105,7 +106,7 @@ unsigned Assembly::bytesRequired(unsigned subTagSize) const
for (AssemblyItem const& i: m_items)
ret += i.bytesRequired(tagSize);
if (dev::bytesRequired(ret) <= tagSize)
if (util::bytesRequired(ret) <= tagSize)
return ret;
}
}
@ -290,15 +291,15 @@ Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const
createJsonValue("PUSH [ErrorTag]", i.location().start, i.location().end, ""));
else
collection.append(
createJsonValue("PUSH [tag]", i.location().start, i.location().end, dev::toString(i.data())));
createJsonValue("PUSH [tag]", i.location().start, i.location().end, toString(i.data())));
break;
case PushSub:
collection.append(
createJsonValue("PUSH [$]", i.location().start, i.location().end, dev::toString(h256(i.data()))));
createJsonValue("PUSH [$]", i.location().start, i.location().end, toString(h256(i.data()))));
break;
case PushSubSize:
collection.append(
createJsonValue("PUSH #[$]", i.location().start, i.location().end, dev::toString(h256(i.data()))));
createJsonValue("PUSH #[$]", i.location().start, i.location().end, toString(h256(i.data()))));
break;
case PushProgramSize:
collection.append(
@ -316,7 +317,7 @@ Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const
break;
case Tag:
collection.append(
createJsonValue("tag", i.location().start, i.location().end, dev::toString(i.data())));
createJsonValue("tag", i.location().start, i.location().end, toString(i.data())));
collection.append(
createJsonValue("JUMPDEST", i.location().start, i.location().end));
break;
@ -359,7 +360,7 @@ AssemblyItem Assembly::namedTag(string const& _name)
AssemblyItem Assembly::newPushLibraryAddress(string const& _identifier)
{
h256 h(dev::keccak256(_identifier));
h256 h(util::keccak256(_identifier));
m_libraries[h] = _identifier;
return AssemblyItem{PushLibraryAddress, h};
}
@ -543,14 +544,14 @@ LinkerObject const& Assembly::assemble() const
multimap<h256, unsigned> dataRef;
multimap<size_t, size_t> subRef;
vector<unsigned> sizeRef; ///< Pointers to code locations where the size of the program is inserted
unsigned bytesPerTag = dev::bytesRequired(bytesRequiredForCode);
unsigned bytesPerTag = util::bytesRequired(bytesRequiredForCode);
uint8_t tagPush = (uint8_t)Instruction::PUSH1 - 1 + bytesPerTag;
unsigned bytesRequiredIncludingData = bytesRequiredForCode + 1 + m_auxiliaryData.size();
for (auto const& sub: m_subs)
bytesRequiredIncludingData += sub->assemble().bytecode.size();
unsigned bytesPerDataRef = dev::bytesRequired(bytesRequiredIncludingData);
unsigned bytesPerDataRef = util::bytesRequired(bytesRequiredIncludingData);
uint8_t dataRefPush = (uint8_t)Instruction::PUSH1 - 1 + bytesPerDataRef;
ret.bytecode.reserve(bytesRequiredIncludingData);
@ -580,7 +581,7 @@ LinkerObject const& Assembly::assemble() const
}
case Push:
{
uint8_t b = max<unsigned>(1, dev::bytesRequired(i.data()));
uint8_t b = max<unsigned>(1, util::bytesRequired(i.data()));
ret.bytecode.push_back((uint8_t)Instruction::PUSH1 - 1 + b);
ret.bytecode.resize(ret.bytecode.size() + b);
bytesRef byr(&ret.bytecode.back() + 1 - b, b);
@ -610,7 +611,7 @@ LinkerObject const& Assembly::assemble() const
assertThrow(i.data() <= size_t(-1), AssemblyException, "");
auto s = m_subs.at(size_t(i.data()))->assemble().bytecode.size();
i.setPushedValue(u256(s));
uint8_t b = max<unsigned>(1, dev::bytesRequired(s));
uint8_t b = max<unsigned>(1, util::bytesRequired(s));
ret.bytecode.push_back((uint8_t)Instruction::PUSH1 - 1 + b);
ret.bytecode.resize(ret.bytecode.size() + b);
bytesRef byr(&ret.bytecode.back() + 1 - b, b);
@ -675,7 +676,7 @@ LinkerObject const& Assembly::assemble() const
assertThrow(tagId < tagPositions.size(), AssemblyException, "Reference to non-existing tag.");
size_t pos = tagPositions[tagId];
assertThrow(pos != size_t(-1), AssemblyException, "Reference to tag without position.");
assertThrow(dev::bytesRequired(pos) <= bytesPerTag, AssemblyException, "Tag too large for reserved space.");
assertThrow(util::bytesRequired(pos) <= bytesPerTag, AssemblyException, "Tag too large for reserved space.");
bytesRef r(ret.bytecode.data() + i.first, bytesPerTag);
toBigEndian(pos, r);
}

View File

@ -35,9 +35,7 @@
#include <sstream>
#include <memory>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
using AssemblyPointer = std::shared_ptr<Assembly>;
@ -49,8 +47,8 @@ public:
AssemblyItem newPushTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(PushTag, m_usedTags++); }
/// Returns a tag identified by the given name. Creates it if it does not yet exist.
AssemblyItem namedTag(std::string const& _name);
AssemblyItem newData(bytes const& _data) { h256 h(dev::keccak256(asString(_data))); m_data[h] = _data; return AssemblyItem(PushData, h); }
bytes const& data(h256 const& _i) const { return m_data.at(_i); }
AssemblyItem newData(bytes const& _data) { util::h256 h(util::keccak256(util::asString(_data))); m_data[h] = _data; return AssemblyItem(PushData, h); }
bytes const& data(util::h256 const& _i) const { return m_data.at(_i); }
AssemblyItem newSub(AssemblyPointer const& _sub) { m_subs.push_back(_sub); return AssemblyItem(PushSub, m_subs.size() - 1); }
Assembly const& sub(size_t _sub) const { return *m_subs.at(_sub); }
Assembly& sub(size_t _sub) { return *m_subs.at(_sub); }
@ -141,7 +139,7 @@ public:
public:
// These features are only used by LLL
AssemblyItem newPushString(std::string const& _data) { h256 h(dev::keccak256(_data)); m_strings[h] = _data; return AssemblyItem(PushString, h); }
AssemblyItem newPushString(std::string const& _data) { util::h256 h(util::keccak256(_data)); m_strings[h] = _data; return AssemblyItem(PushString, h); }
void append(Assembly const& _a);
void append(Assembly const& _a, int _deposit);
@ -149,7 +147,7 @@ public:
void injectStart(AssemblyItem const& _i);
AssemblyItem const& back() const { return m_items.back(); }
std::string backString() const { return m_items.size() && m_items.back().type() == PushString ? m_strings.at((h256)m_items.back().data()) : std::string(); }
std::string backString() const { return m_items.size() && m_items.back().type() == PushString ? m_strings.at((util::h256)m_items.back().data()) : std::string(); }
protected:
/// Does the same operations as @a optimise, but should only be applied to a sub and
@ -168,12 +166,12 @@ protected:
unsigned m_usedTags = 1;
std::map<std::string, size_t> m_namedTags;
AssemblyItems m_items;
std::map<h256, bytes> m_data;
std::map<util::h256, bytes> m_data;
/// Data that is appended to the very end of the contract.
bytes m_auxiliaryData;
std::vector<std::shared_ptr<Assembly>> m_subs;
std::map<h256, std::string> m_strings;
std::map<h256, std::string> m_libraries; ///< Identifiers of libraries to be linked.
std::map<util::h256, std::string> m_strings;
std::map<util::h256, std::string> m_libraries; ///< Identifiers of libraries to be linked.
mutable LinkerObject m_assembledObject;
mutable std::vector<size_t> m_tagPositionsInBytecode;
@ -192,4 +190,3 @@ inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a)
}
}
}

View File

@ -23,15 +23,15 @@
#include <fstream>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
static_assert(sizeof(size_t) <= 8, "size_t must be at most 64-bits wide");
AssemblyItem AssemblyItem::toSubAssemblyTag(size_t _subId) const
{
assertThrow(data() < (u256(1) << 64), Exception, "Tag already has subassembly set.");
assertThrow(m_type == PushTag || m_type == Tag, Exception, "");
assertThrow(data() < (u256(1) << 64), util::Exception, "Tag already has subassembly set.");
assertThrow(m_type == PushTag || m_type == Tag, util::Exception, "");
size_t tag = size_t(u256(data()) & 0xffffffffffffffffULL);
AssemblyItem r = *this;
r.m_type = PushTag;
@ -41,7 +41,7 @@ AssemblyItem AssemblyItem::toSubAssemblyTag(size_t _subId) const
pair<size_t, size_t> AssemblyItem::splitForeignPushTag() const
{
assertThrow(m_type == PushTag || m_type == Tag, Exception, "");
assertThrow(m_type == PushTag || m_type == Tag, util::Exception, "");
u256 combined = u256(data());
size_t subId = size_t((combined >> 64) - 1);
size_t tag = size_t(combined & 0xffffffffffffffffULL);
@ -50,7 +50,7 @@ pair<size_t, size_t> AssemblyItem::splitForeignPushTag() const
void AssemblyItem::setPushTagSubIdAndTag(size_t _subId, size_t _tag)
{
assertThrow(m_type == PushTag || m_type == Tag, Exception, "");
assertThrow(m_type == PushTag || m_type == Tag, util::Exception, "");
u256 data = _tag;
if (_subId != size_t(-1))
data |= (u256(_subId) + 1) << 64;
@ -67,7 +67,7 @@ unsigned AssemblyItem::bytesRequired(unsigned _addressLength) const
case PushString:
return 1 + 32;
case Push:
return 1 + max<unsigned>(1, dev::bytesRequired(data()));
return 1 + max<unsigned>(1, util::bytesRequired(data()));
case PushSubSize:
case PushProgramSize:
return 1 + 4; // worst case: a 16MB program
@ -170,10 +170,10 @@ string AssemblyItem::toAssemblyText() const
break;
}
case Push:
text = toHex(toCompactBigEndian(data(), 1), HexPrefix::Add);
text = toHex(util::toCompactBigEndian(data(), 1), util::HexPrefix::Add);
break;
case PushString:
text = string("data_") + toHex(data());
text = string("data_") + util::toHex(data());
break;
case PushTag:
{
@ -191,7 +191,7 @@ string AssemblyItem::toAssemblyText() const
text = string("tag_") + to_string(size_t(data())) + ":";
break;
case PushData:
text = string("data_") + toHex(data());
text = string("data_") + util::toHex(data());
break;
case PushSub:
text = string("dataOffset(sub_") + to_string(size_t(data())) + ")";
@ -203,7 +203,7 @@ string AssemblyItem::toAssemblyText() const
text = string("bytecodeSize");
break;
case PushLibraryAddress:
text = string("linkerSymbol(\"") + toHex(data()) + string("\")");
text = string("linkerSymbol(\"") + util::toHex(data()) + string("\")");
break;
case PushDeployTimeAddress:
text = string("deployTimeAddress()");
@ -225,7 +225,7 @@ string AssemblyItem::toAssemblyText() const
return text;
}
ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item)
ostream& solidity::evmasm::operator<<(ostream& _out, AssemblyItem const& _item)
{
switch (_item.type())
{
@ -266,7 +266,7 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item)
break;
case PushLibraryAddress:
{
string hash(h256((_item.data())).hex());
string hash(util::h256((_item.data())).hex());
_out << " PushLibraryAddress " << hash.substr(0, 8) + "..." + hash.substr(hash.length() - 8);
break;
}

View File

@ -29,9 +29,7 @@
#include <iostream>
#include <sstream>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
enum AssemblyItemType {
@ -77,8 +75,8 @@ public:
AssemblyItem& operator=(AssemblyItem const&) = default;
AssemblyItem& operator=(AssemblyItem&&) = default;
AssemblyItem tag() const { assertThrow(m_type == PushTag || m_type == Tag, Exception, ""); return AssemblyItem(Tag, data()); }
AssemblyItem pushTag() const { assertThrow(m_type == PushTag || m_type == Tag, Exception, ""); return AssemblyItem(PushTag, data()); }
AssemblyItem tag() const { assertThrow(m_type == PushTag || m_type == Tag, util::Exception, ""); return AssemblyItem(Tag, data()); }
AssemblyItem pushTag() const { assertThrow(m_type == PushTag || m_type == Tag, util::Exception, ""); return AssemblyItem(PushTag, data()); }
/// Converts the tag to a subassembly tag. This has to be called in order to move a tag across assemblies.
/// @param _subId the identifier of the subassembly the tag is taken from.
AssemblyItem toSubAssemblyTag(size_t _subId) const;
@ -89,11 +87,11 @@ public:
void setPushTagSubIdAndTag(size_t _subId, size_t _tag);
AssemblyItemType type() const { return m_type; }
u256 const& data() const { assertThrow(m_type != Operation, Exception, ""); return *m_data; }
void setData(u256 const& _data) { assertThrow(m_type != Operation, Exception, ""); m_data = std::make_shared<u256>(_data); }
u256 const& data() const { assertThrow(m_type != Operation, util::Exception, ""); return *m_data; }
void setData(u256 const& _data) { assertThrow(m_type != Operation, util::Exception, ""); m_data = std::make_shared<u256>(_data); }
/// @returns the instruction of this item (only valid if type() == Operation)
Instruction instruction() const { assertThrow(m_type == Operation, Exception, ""); return m_instruction; }
Instruction instruction() const { assertThrow(m_type == Operation, util::Exception, ""); return m_instruction; }
/// @returns true if the type and data of the items are equal.
bool operator==(AssemblyItem const& _other) const
@ -178,4 +176,3 @@ inline std::ostream& operator<<(std::ostream& _out, AssemblyItems const& _items)
}
}
}

View File

@ -30,8 +30,8 @@
#include <set>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
bool BlockDeduplicator::deduplicate()

View File

@ -30,9 +30,7 @@
#include <functional>
#include <map>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
@ -90,4 +88,3 @@ private:
};
}
}

View File

@ -28,9 +28,9 @@
#include <libevmasm/AssemblyItem.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::langutil;
vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
{

View File

@ -39,9 +39,7 @@ namespace langutil
struct SourceLocation;
}
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
@ -187,4 +185,3 @@ _AssemblyItemIterator CommonSubexpressionEliminator::feedItems(
}
}
}

View File

@ -22,9 +22,11 @@
#include <libevmasm/ConstantOptimiser.h>
#include <libevmasm/Assembly.h>
#include <libevmasm/GasMeter.h>
#include <libdevcore/CommonData.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
unsigned ConstantOptimisationMethod::optimiseConstants(
bool _isCreation,
@ -101,7 +103,7 @@ bigint ConstantOptimisationMethod::dataGas(bytes const& _data) const
size_t ConstantOptimisationMethod::bytesRequired(AssemblyItems const& _items)
{
return eth::bytesRequired(_items, 3); // assume 3 byte addresses
return evmasm::bytesRequired(_items, 3); // assume 3 byte addresses
}
void ConstantOptimisationMethod::replaceConstants(
@ -131,7 +133,7 @@ bigint LiteralMethod::gasNeeded() const
return combineGas(
simpleRunGas({Instruction::PUSH1}),
// PUSHX plus data
(m_params.isCreation ? GasCosts::txDataNonZeroGas(m_params.evmVersion) : GasCosts::createDataGas) + dataGas(toCompactBigEndian(m_value, 1)),
(m_params.isCreation ? GasCosts::txDataNonZeroGas(m_params.evmVersion) : GasCosts::createDataGas) + dataGas(util::toCompactBigEndian(m_value, 1)),
0
);
}
@ -144,13 +146,13 @@ bigint CodeCopyMethod::gasNeeded() const
// Data gas for copy routines: Some bytes are zero, but we ignore them.
bytesRequired(copyRoutine()) * (m_params.isCreation ? GasCosts::txDataNonZeroGas(m_params.evmVersion) : GasCosts::createDataGas),
// Data gas for data itself
dataGas(toBigEndian(m_value))
dataGas(util::toBigEndian(m_value))
);
}
AssemblyItems CodeCopyMethod::execute(Assembly& _assembly) const
{
bytes data = toBigEndian(m_value);
bytes data = util::toBigEndian(m_value);
assertThrow(data.size() == 32, OptimizerException, "Invalid number encoding.");
AssemblyItems actualCopyRoutine = copyRoutine();
actualCopyRoutine[4] = _assembly.newData(data);
@ -190,7 +192,7 @@ AssemblyItems ComputeMethod::findRepresentation(u256 const& _value)
if (_value < 0x10000)
// Very small value, not worth computing
return AssemblyItems{_value};
else if (dev::bytesRequired(~_value) < dev::bytesRequired(_value))
else if (util::bytesRequired(~_value) < util::bytesRequired(_value))
// Negated is shorter to represent
return findRepresentation(~_value) + AssemblyItems{Instruction::NOT};
else

View File

@ -31,9 +31,7 @@
#include <vector>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
@ -164,4 +162,3 @@ protected:
};
}
}

View File

@ -31,8 +31,8 @@
#include <libevmasm/KnownState.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
BlockId::BlockId(u256 const& _id):
m_id(unsigned(_id))

View File

@ -29,9 +29,7 @@
#include <libdevcore/Assertions.h>
#include <libevmasm/ExpressionClasses.h>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class KnownState;
@ -127,4 +125,3 @@ private:
}
}

View File

@ -23,12 +23,10 @@
#include <libdevcore/Exceptions.h>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
struct AssemblyException: virtual Exception {};
struct AssemblyException: virtual util::Exception {};
struct OptimizerException: virtual AssemblyException {};
struct StackTooDeepException: virtual OptimizerException {};
struct ItemNotAvailableException: virtual OptimizerException {};
@ -37,4 +35,3 @@ DEV_SIMPLE_EXCEPTION(InvalidDeposit);
DEV_SIMPLE_EXCEPTION(InvalidOpcode);
}
}

View File

@ -32,9 +32,9 @@
#include <libevmasm/SimplificationRules.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::langutil;
bool ExpressionClasses::Expression::operator<(ExpressionClasses::Expression const& _other) const
{

View File

@ -31,14 +31,12 @@
#include <memory>
#include <set>
namespace langutil
namespace solidity::langutil
{
struct SourceLocation;
}
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class Pattern;
@ -128,4 +126,3 @@ private:
};
}
}

View File

@ -22,8 +22,9 @@
#include <libdevcore/FixedHash.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::evmasm;
GasMeter::GasConsumption& GasMeter::GasConsumption::operator+=(GasConsumption const& _other)
{

View File

@ -29,9 +29,7 @@
#include <ostream>
#include <tuple>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class KnownState;
@ -180,4 +178,3 @@ inline std::ostream& operator<<(std::ostream& _str, GasMeter::GasConsumption con
}
}

View File

@ -27,10 +27,11 @@
#include <functional>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::evmasm;
std::map<std::string, Instruction> const dev::eth::c_instructions =
std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
{
{ "STOP", Instruction::STOP },
{ "ADD", Instruction::ADD },
@ -322,7 +323,7 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
{ Instruction::SELFDESTRUCT, { "SELFDESTRUCT", 0, 1, 0, true, Tier::Special } }
};
void dev::eth::eachInstruction(
void solidity::evmasm::eachInstruction(
bytes const& _mem,
function<void(Instruction,u256 const&)> const& _onInstruction
)
@ -351,7 +352,7 @@ void dev::eth::eachInstruction(
}
}
string dev::eth::disassemble(bytes const& _mem)
string solidity::evmasm::disassemble(bytes const& _mem)
{
stringstream ret;
eachInstruction(_mem, [&](Instruction _instr, u256 const& _data) {
@ -368,7 +369,7 @@ string dev::eth::disassemble(bytes const& _mem)
return ret.str();
}
InstructionInfo dev::eth::instructionInfo(Instruction _inst)
InstructionInfo solidity::evmasm::instructionInfo(Instruction _inst)
{
try
{
@ -380,7 +381,7 @@ InstructionInfo dev::eth::instructionInfo(Instruction _inst)
}
}
bool dev::eth::isValidInstruction(Instruction _inst)
bool solidity::evmasm::isValidInstruction(Instruction _inst)
{
return !!c_instructionInfo.count(_inst);
}

View File

@ -26,9 +26,7 @@
#include <libdevcore/Assertions.h>
#include <functional>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
/// Virtual machine bytecode instruction.
@ -318,4 +316,3 @@ void eachInstruction(bytes const& _mem, std::function<void(Instruction,u256 cons
std::string disassemble(bytes const& _mem);
}
}

View File

@ -24,9 +24,9 @@
#include <libevmasm/AssemblyItem.h>
using namespace std;
using namespace dev::eth;
using namespace dev;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::evmasm;
bool JumpdestRemover::optimise(set<size_t> const& _tagsReferencedFromOutside)
{

View File

@ -24,9 +24,7 @@
#include <cstddef>
#include <set>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
using AssemblyItems = std::vector<AssemblyItem>;
@ -47,4 +45,3 @@ private:
};
}
}

View File

@ -28,9 +28,9 @@
#include <functional>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::langutil;
ostream& KnownState::stream(ostream& _out) const
{
@ -383,9 +383,9 @@ KnownState::Id KnownState::applyKeccak256(
{
bytes data;
for (Id a: arguments)
data += toBigEndian(*m_expressionClasses->knownConstant(a));
data += util::toBigEndian(*m_expressionClasses->knownConstant(a));
data.resize(size_t(*l));
v = m_expressionClasses->find(AssemblyItem(u256(dev::keccak256(data)), _location));
v = m_expressionClasses->find(AssemblyItem(u256(util::keccak256(data)), _location));
}
else
v = m_expressionClasses->find(keccak256Item, {_start, _length}, true, m_sequenceNumber);

View File

@ -46,14 +46,12 @@
#include <libevmasm/ExpressionClasses.h>
#include <libevmasm/SemanticInformation.h>
namespace langutil
namespace solidity::langutil
{
struct SourceLocation;
}
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
@ -182,4 +180,3 @@ private:
};
}
}

View File

@ -23,9 +23,10 @@
#include <libdevcore/CommonData.h>
#include <libdevcore/Keccak256.h>
using namespace dev;
using namespace dev::eth;
using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::evmasm;
void LinkerObject::append(LinkerObject const& _other)
{
@ -47,7 +48,7 @@ void LinkerObject::link(map<string, h160> const& _libraryAddresses)
string LinkerObject::toHex() const
{
string hex = dev::toHex(bytecode);
string hex = solidity::util::toHex(bytecode);
for (auto const& ref: linkReferences)
{
size_t pos = ref.first * 2;

View File

@ -24,9 +24,7 @@
#include <libdevcore/Common.h>
#include <libdevcore/FixedHash.h>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
/**
@ -46,7 +44,7 @@ struct LinkerObject
void append(LinkerObject const& _other);
/// Links the given libraries by replacing their uses in the code and removes them from the references.
void link(std::map<std::string, h160> const& _libraryAddresses);
void link(std::map<std::string, util::h160> const& _libraryAddresses);
/// @returns a hex representation of the bytecode of the given object, replacing unlinked
/// addresses by placeholders. This output is lowercase.
@ -58,11 +56,10 @@ struct LinkerObject
static std::string libraryPlaceholder(std::string const& _libraryName);
private:
static h160 const* matchLibrary(
static util::h160 const* matchLibrary(
std::string const& _linkRefName,
std::map<std::string, h160> const& _libraryAddresses
std::map<std::string, util::h160> const& _libraryAddresses
);
};
}
}

View File

@ -24,8 +24,8 @@
#include <libevmasm/SemanticInformation.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
PathGasMeter::PathGasMeter(AssemblyItems const& _items, langutil::EVMVersion _evmVersion):
m_items(_items), m_evmVersion(_evmVersion)

View File

@ -29,9 +29,7 @@
#include <vector>
#include <memory>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class KnownState;
@ -85,4 +83,3 @@ private:
};
}
}

View File

@ -25,8 +25,8 @@
#include <libevmasm/SemanticInformation.h>
using namespace std;
using namespace dev::eth;
using namespace dev;
using namespace solidity;
using namespace solidity::evmasm;
// TODO: Extend this to use the tools from ExpressionClasses.cpp
@ -362,7 +362,7 @@ bool PeepholeOptimiser::optimise()
);
if (m_optimisedItems.size() < m_items.size() || (
m_optimisedItems.size() == m_items.size() && (
eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) ||
evmasm::bytesRequired(m_optimisedItems, 3) < evmasm::bytesRequired(m_items, 3) ||
numberOfPops(m_optimisedItems) > numberOfPops(m_items)
)
))

View File

@ -24,9 +24,7 @@
#include <cstddef>
#include <iterator>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
using AssemblyItems = std::vector<AssemblyItem>;
@ -53,4 +51,3 @@ private:
};
}
}

View File

@ -32,9 +32,7 @@
#include <vector>
#include <functional>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
template <class S> S divWorkaround(S const& _a, S const& _b)
@ -674,4 +672,3 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
}
}
}

View File

@ -25,8 +25,8 @@
#include <libevmasm/AssemblyItem.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
bool SemanticInformation::breaksCSEAnalysisBlock(AssemblyItem const& _item, bool _msizeImportant)
{
@ -96,14 +96,14 @@ bool SemanticInformation::isDupInstruction(AssemblyItem const& _item)
{
if (_item.type() != Operation)
return false;
return dev::eth::isDupInstruction(_item.instruction());
return evmasm::isDupInstruction(_item.instruction());
}
bool SemanticInformation::isSwapInstruction(AssemblyItem const& _item)
{
if (_item.type() != Operation)
return false;
return dev::eth::isSwapInstruction(_item.instruction());
return evmasm::isSwapInstruction(_item.instruction());
}
bool SemanticInformation::isJumpInstruction(AssemblyItem const& _item)

View File

@ -25,9 +25,7 @@
#include <libevmasm/Instruction.h>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class AssemblyItem;
@ -75,4 +73,3 @@ struct SemanticInformation
};
}
}

View File

@ -24,9 +24,7 @@
#include <libdevcore/CommonData.h>
#include <functional>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
/**
@ -158,4 +156,3 @@ struct EVMBuiltins
};
}
}

View File

@ -36,9 +36,9 @@
#include <functional>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::langutil;
SimplificationRule<Pattern> const* Rules::findFirstMatch(
Expression const& _expr,

View File

@ -33,14 +33,12 @@
#include <functional>
#include <vector>
namespace langutil
namespace solidity::langutil
{
struct SourceLocation;
}
namespace dev
{
namespace eth
namespace solidity::evmasm
{
class Pattern;
@ -89,7 +87,7 @@ public:
using Expression = ExpressionClasses::Expression;
using Id = ExpressionClasses::Id;
using Builtins = dev::eth::EVMBuiltins<Pattern>;
using Builtins = evmasm::EVMBuiltins<Pattern>;
static constexpr size_t WordSize = 256;
using Word = u256;
@ -159,4 +157,3 @@ struct ExpressionTemplate
};
}
}

View File

@ -54,7 +54,8 @@
#include <liblangutil/Exceptions.h>
using namespace std;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
char CharStream::advanceAndGet(size_t _chars)
{

View File

@ -56,7 +56,7 @@
#include <string>
#include <tuple>
namespace langutil
namespace solidity::langutil
{
/**

View File

@ -14,7 +14,7 @@
#pragma once
namespace langutil
namespace solidity::langutil
{
inline bool isDecimalDigit(char c)

View File

@ -20,8 +20,9 @@
#include <liblangutil/EVMVersion.h>
using namespace langutil;
using namespace dev::eth;
using namespace solidity;
using namespace solidity::evmasm;
using namespace solidity::langutil;
bool EVMVersion::hasOpcode(Instruction _opcode) const
{

View File

@ -28,7 +28,7 @@
#include <boost/operators.hpp>
namespace langutil
namespace solidity::langutil
{
/**
@ -87,7 +87,7 @@ public:
bool hasChainID() const { return *this >= istanbul(); }
bool hasSelfBalance() const { return *this >= istanbul(); }
bool hasOpcode(dev::eth::Instruction _opcode) const;
bool hasOpcode(evmasm::Instruction _opcode) const;
/// Whether we have to retain the costs for the call opcode itself (false),
/// or whether we can just forward easily all remaining gas (true).

View File

@ -25,8 +25,8 @@
#include <memory>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter)
{
@ -67,7 +67,7 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, st
auto err = make_shared<Error>(_type);
*err <<
errinfo_sourceLocation(_location) <<
errinfo_comment(_description);
util::errinfo_comment(_description);
m_errorList.push_back(err);
}
@ -81,7 +81,7 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, Se
*err <<
errinfo_sourceLocation(_location) <<
errinfo_secondarySourceLocation(_secondaryLocation) <<
errinfo_comment(_description);
util::errinfo_comment(_description);
m_errorList.push_back(err);
}
@ -100,7 +100,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
if (m_warningCount == c_maxWarningsAllowed)
{
auto err = make_shared<Error>(Error::Type::Warning);
*err << errinfo_comment("There are more than 256 warnings. Ignoring the rest.");
*err << util::errinfo_comment("There are more than 256 warnings. Ignoring the rest.");
m_errorList.push_back(err);
}
@ -114,7 +114,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
if (m_errorCount > c_maxErrorsAllowed)
{
auto err = make_shared<Error>(Error::Type::Warning);
*err << errinfo_comment("There are more than 256 errors. Aborting.");
*err << util::errinfo_comment("There are more than 256 errors. Aborting.");
m_errorList.push_back(err);
BOOST_THROW_EXCEPTION(FatalError());
}

View File

@ -30,7 +30,7 @@
#include <boost/range/adaptor/filtered.hpp>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter
@ -98,7 +98,7 @@ public:
auto filterEmpty = boost::adaptors::filtered([](std::string const& _s) { return !_s.empty(); });
std::string errorStr = dev::joinHumanReadable(descs | filterEmpty, " ");
std::string errorStr = util::joinHumanReadable(descs | filterEmpty, " ");
error(Error::Type::TypeError, _location, errorStr);
}

View File

@ -23,8 +23,8 @@
#include <liblangutil/Exceptions.h>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
Error::Error(Type _type, SourceLocation const& _location, string const& _description):
m_type(_type)
@ -54,7 +54,7 @@ Error::Error(Type _type, SourceLocation const& _location, string const& _descrip
if (!_location.isEmpty())
*this << errinfo_sourceLocation(_location);
if (!_description.empty())
*this << errinfo_comment(_description);
*this << util::errinfo_comment(_description);
}
Error::Error(Error::Type _type, std::string const& _description, SourceLocation const& _location):
@ -62,5 +62,5 @@ Error::Error(Error::Type _type, std::string const& _description, SourceLocation
{
if (!_location.isEmpty())
*this << errinfo_sourceLocation(_location);
*this << errinfo_comment(_description);
*this << util::errinfo_comment(_description);
}

View File

@ -31,27 +31,27 @@
#include <libdevcore/CommonData.h>
#include <liblangutil/SourceLocation.h>
namespace langutil
namespace solidity::langutil
{
class Error;
using ErrorList = std::vector<std::shared_ptr<Error const>>;
struct CompilerError: virtual dev::Exception {};
struct InternalCompilerError: virtual dev::Exception {};
struct FatalError: virtual dev::Exception {};
struct UnimplementedFeatureError: virtual dev::Exception {};
struct CompilerError: virtual util::Exception {};
struct InternalCompilerError: virtual util::Exception {};
struct FatalError: virtual util::Exception {};
struct UnimplementedFeatureError: virtual util::Exception {};
/// Assertion that throws an InternalCompilerError containing the given description if it is not met.
#define solAssert(CONDITION, DESCRIPTION) \
assertThrow(CONDITION, ::langutil::InternalCompilerError, DESCRIPTION)
assertThrow(CONDITION, ::solidity::langutil::InternalCompilerError, DESCRIPTION)
#define solUnimplementedAssert(CONDITION, DESCRIPTION) \
assertThrow(CONDITION, ::langutil::UnimplementedFeatureError, DESCRIPTION)
assertThrow(CONDITION, ::solidity::langutil::UnimplementedFeatureError, DESCRIPTION)
#define solUnimplemented(DESCRIPTION) \
solUnimplementedAssert(false, DESCRIPTION)
class Error: virtual public dev::Exception
class Error: virtual public util::Exception
{
public:
enum class Type

View File

@ -25,7 +25,8 @@
#include <liblangutil/ErrorReporter.h>
using namespace std;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
int ParserBase::position() const
{

View File

@ -27,7 +27,7 @@
#include <memory>
#include <string>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;

View File

@ -60,9 +60,10 @@
#include <tuple>
using namespace std;
using namespace langutil;
string langutil::to_string(ScannerError _errorCode)
namespace solidity::langutil {
string to_string(ScannerError _errorCode)
{
switch (_errorCode)
{
@ -84,14 +85,11 @@ string langutil::to_string(ScannerError _errorCode)
}
ostream& langutil::operator<<(ostream& os, ScannerError _errorCode)
ostream& operator<<(ostream& os, ScannerError _errorCode)
{
return os << to_string(_errorCode);
}
namespace langutil
{
/// Scoped helper for literal recording. Automatically drops the literal
/// if aborting the scanning before it's complete.
enum LiteralType
@ -132,8 +130,6 @@ private:
bool m_complete;
};
}
void Scanner::reset(CharStream _source)
{
m_source = make_shared<CharStream>(std::move(_source));
@ -933,3 +929,5 @@ tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
literal.complete();
return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal);
}
} // namespace solidity::langutil

View File

@ -61,7 +61,7 @@
#include <optional>
#include <iosfwd>
namespace langutil
namespace solidity::langutil
{
class AstRawString;

View File

@ -25,8 +25,8 @@
#include <functional>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
SemVerVersion::SemVerVersion(string const& _versionString)
{

View File

@ -26,10 +26,10 @@
#include <string>
#include <vector>
namespace langutil
namespace solidity::langutil
{
class SemVerError: dev::Exception
class SemVerError: util::Exception
{
};

View File

@ -31,9 +31,9 @@
#include <ostream>
#include <tuple>
namespace langutil
namespace solidity::langutil
{
struct SourceLocationError: virtual dev::Exception {};
struct SourceLocationError: virtual util::Exception {};
/**
* Representation of an interval of source positions.

View File

@ -22,14 +22,14 @@
#include <iomanip>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(Exception const& _exception, string _category)
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(util::Exception const& _exception, string _category)
{
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
string const* message = boost::get_error_info<errinfo_comment>(_exception);
string const* message = boost::get_error_info<util::errinfo_comment>(_exception);
SourceReference primary = extract(location, message ? *message : "");
std::vector<SourceReference> secondary;

View File

@ -21,12 +21,12 @@
#include <tuple>
#include <vector>
namespace dev
namespace solidity::util
{
struct Exception;
}
namespace langutil
namespace solidity::langutil
{
struct LineColumn
@ -68,7 +68,7 @@ namespace SourceReferenceExtractor
std::vector<SourceReference> secondary;
};
Message extract(dev::Exception const& _exception, std::string _category);
Message extract(util::Exception const& _exception, std::string _category);
SourceReference extract(SourceLocation const* _location, std::string message = "");
}

View File

@ -25,8 +25,9 @@
#include <liblangutil/Exceptions.h>
using namespace std;
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
void SourceReferenceFormatter::printSourceLocation(SourceLocation const* _location)
{
@ -70,7 +71,7 @@ void SourceReferenceFormatter::printSourceName(SourceReference const& _ref)
m_stream << _ref.sourceName << ":" << (_ref.position.line + 1) << ":" << (_ref.position.column + 1) << ": ";
}
void SourceReferenceFormatter::printExceptionInformation(dev::Exception const& _exception, std::string const& _category)
void SourceReferenceFormatter::printExceptionInformation(util::Exception const& _exception, std::string const& _category)
{
printExceptionInformation(SourceReferenceExtractor::extract(_exception, _category));
}

View File

@ -28,12 +28,12 @@
#include <liblangutil/Exceptions.h>
#include <liblangutil/SourceReferenceExtractor.h>
namespace dev
namespace solidity::util
{
struct Exception; // forward
}
namespace langutil
namespace solidity::langutil
{
struct SourceLocation;
class Scanner;
@ -52,7 +52,7 @@ public:
virtual void printExceptionInformation(SourceReferenceExtractor::Message const& _msg);
virtual void printSourceLocation(SourceLocation const* _location);
virtual void printExceptionInformation(dev::Exception const& _exception, std::string const& _category);
virtual void printExceptionInformation(util::Exception const& _exception, std::string const& _category);
virtual void printErrorInformation(Error const& _error);
static std::string formatErrorInformation(Error const& _error)
@ -64,7 +64,7 @@ public:
}
static std::string formatExceptionInformation(
dev::Exception const& _exception,
util::Exception const& _exception,
std::string const& _name
)
{

View File

@ -25,9 +25,10 @@
#include <iomanip>
using namespace std;
using namespace dev;
using namespace dev::formatting;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::util;
using namespace solidity::util::formatting;
AnsiColorized SourceReferenceFormatterHuman::normalColored() const
{

View File

@ -29,12 +29,12 @@
#include <sstream>
#include <functional>
namespace dev
namespace solidity::util
{
struct Exception; // forward
}
namespace langutil
namespace solidity::langutil
{
struct SourceLocation;
@ -52,7 +52,7 @@ public:
using SourceReferenceFormatter::printExceptionInformation;
static std::string formatExceptionInformation(
dev::Exception const& _exception,
util::Exception const& _exception,
std::string const& _name,
bool colored = false
)
@ -65,13 +65,13 @@ public:
}
private:
dev::AnsiColorized normalColored() const;
dev::AnsiColorized frameColored() const;
dev::AnsiColorized errorColored() const;
dev::AnsiColorized messageColored() const;
dev::AnsiColorized secondaryColored() const;
dev::AnsiColorized highlightColored() const;
dev::AnsiColorized diagColored() const;
util::AnsiColorized normalColored() const;
util::AnsiColorized frameColored() const;
util::AnsiColorized errorColored() const;
util::AnsiColorized messageColored() const;
util::AnsiColorized secondaryColored() const;
util::AnsiColorized highlightColored() const;
util::AnsiColorized diagColored() const;
private:
bool m_colored;

View File

@ -46,7 +46,7 @@
using namespace std;
namespace langutil
namespace solidity::langutil
{
void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second)
@ -82,7 +82,6 @@ void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _fi
namespace TokenTraits
{
char const* toString(Token tok)
{
switch (tok)

View File

@ -50,7 +50,7 @@
#include <string>
#include <tuple>
namespace langutil
namespace solidity::langutil
{
// TOKEN_LIST takes a list of 3 macros M, all of which satisfy the

View File

@ -608,7 +608,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
int targetDeposit = hasDefault ? code[code.size() - 1].m_asm.deposit() : 0;
// The conditions
eth::AssemblyItems jumpTags;
evmasm::AssemblyItems jumpTags;
for (unsigned i = 0; i < code.size() - 1; i += 2)
{
requireDeposit(i, 1);
@ -675,7 +675,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
requireMaxSize(3);
requireDeposit(1, 1);
auto subPush = m_asm.appendSubroutine(make_shared<eth::Assembly>(code[0].assembly(ns)));
auto subPush = m_asm.appendSubroutine(make_shared<evmasm::Assembly>(code[0].assembly(ns)));
m_asm.append(Instruction::DUP1);
if (code.size() == 3)
{

View File

@ -47,7 +47,7 @@ public:
static CodeFragment compile(std::string _src, CompilerState& _s, ReadCallback const& _readFile);
/// Consolidates data and compiles code.
eth::Assembly& assembly(CompilerState const& _cs) { finalise(_cs); return m_asm; }
evmasm::Assembly& assembly(CompilerState const& _cs) { finalise(_cs); return m_asm; }
private:
void finalise(CompilerState const& _cs);
@ -61,7 +61,7 @@ private:
void constructOperation(sp::utree const& _t, CompilerState& _s);
bool m_finalised = false;
eth::Assembly m_asm;
evmasm::Assembly m_asm;
ReadCallback m_readFile;
};

View File

@ -34,8 +34,11 @@
#include "license.h"
using namespace std;
using namespace dev;
using namespace solidity;
using namespace solidity::util;
using solidity::frontend::ReadCallback;
using solidity::frontend::StandardCompiler;
namespace
{
@ -122,7 +125,7 @@ extern char const* solidity_license() noexcept
extern char const* solidity_version() noexcept
{
return VersionString.c_str();
return frontend::VersionString.c_str();
}
extern char* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, void* _readContext) noexcept

View File

@ -27,8 +27,8 @@
#include <liblangutil/ErrorReporter.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::frontend;
void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
{

View File

@ -24,14 +24,12 @@
#include <libsolidity/ast/ASTVisitor.h>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class TypeChecker;
@ -72,4 +70,3 @@ private:
};
}
}

View File

@ -30,9 +30,9 @@
using namespace std;
using namespace dev;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
namespace
{
@ -361,10 +361,10 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contract)
{
set<FixedHash<4>> hashes;
set<util::FixedHash<4>> hashes;
for (auto const& it: _contract.interfaceFunctionList())
{
FixedHash<4> const& hash = it.first;
util::FixedHash<4> const& hash = it.first;
if (hashes.count(hash))
m_errorReporter.typeError(
_contract.location(),

View File

@ -28,14 +28,12 @@
#include <functional>
#include <set>
namespace langutil
namespace solidity::langutil
{
class ErrorReporter;
}
namespace dev
{
namespace solidity
namespace solidity::frontend
{
/**
@ -90,4 +88,3 @@ private:
};
}
}

View File

@ -22,8 +22,8 @@
#include <boost/range/algorithm/sort.hpp>
using namespace std;
using namespace langutil;
using namespace dev::solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
bool ControlFlowAnalyzer::analyze(ASTNode const& _astRoot)
{
@ -151,7 +151,7 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
void ControlFlowAnalyzer::checkUnreachable(CFGNode const* _entry, CFGNode const* _exit, CFGNode const* _revert) const
{
// collect all nodes reachable from the entry point
std::set<CFGNode const*> reachable = BreadthFirstSearch<CFGNode const*>{{_entry}}.run(
std::set<CFGNode const*> reachable = util::BreadthFirstSearch<CFGNode const*>{{_entry}}.run(
[](CFGNode const* _node, auto&& _addChild) {
for (CFGNode const* exit: _node->exits)
_addChild(exit);
@ -161,7 +161,7 @@ void ControlFlowAnalyzer::checkUnreachable(CFGNode const* _entry, CFGNode const*
// traverse all paths backwards from exit and revert
// and extract (valid) source locations of unreachable nodes into sorted set
std::set<SourceLocation> unreachable;
BreadthFirstSearch<CFGNode const*>{{_exit, _revert}}.run(
util::BreadthFirstSearch<CFGNode const*>{{_exit, _revert}}.run(
[&](CFGNode const* _node, auto&& _addChild) {
if (!reachable.count(_node) && !_node->location.isEmpty())
unreachable.insert(_node->location);

View File

@ -20,9 +20,7 @@
#include <libsolidity/analysis/ControlFlowGraph.h>
#include <set>
namespace dev
{
namespace solidity
namespace solidity::frontend
{
class ControlFlowAnalyzer: private ASTConstVisitor
@ -47,4 +45,3 @@ private:
};
}
}

View File

@ -17,9 +17,9 @@
#include <libsolidity/analysis/ControlFlowBuilder.h>
using namespace dev;
using namespace langutil;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
using namespace std;
ControlFlowBuilder::ControlFlowBuilder(CFG::NodeContainer& _nodeContainer, FunctionFlow const& _functionFlow):

View File

@ -24,8 +24,7 @@
#include <array>
#include <memory>
namespace dev {
namespace solidity {
namespace solidity::frontend {
/** Helper class that builds the control flow of a function or modifier.
* Modifiers are not yet applied to the functions. This is done in a second
@ -161,4 +160,3 @@ private:
};
}
}

Some files were not shown because too many files have changed in this diff Show More