From 4d9184ef04a3163a4740b2d179398682c9f5140e Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 25 Sep 2018 16:29:46 +0200 Subject: Expression breaker. --- libdevcore/CommonData.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libdevcore/CommonData.h') diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index e410af5c..98136b44 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -25,11 +25,14 @@ #include +#include + #include #include #include #include #include +#include namespace dev { @@ -229,6 +232,36 @@ bool contains(T const& _t, V const& _v) return std::end(_t) != std::find(std::begin(_t), std::end(_t), _v); } + +/// Function that iterates over a vector, calling a function on each of its +/// elements. If that function returns a vector, the element is replaced by +/// the returned vector. During the iteration, the original vector is only valid +/// on the current element and after that. The actual replacement takes +/// place at the end, but already visited elements might be invalidated. +/// If nothing is replaced, no copy is performed. +template +void iterateReplacing(std::vector& _vector, std::function>(T&)> _f) +{ + bool useModified = false; + std::vector modifiedVector; + for (size_t i = 0; i < _vector.size(); ++i) + { + if (boost::optional> r = _f(_vector[i])) + { + if (!useModified) + { + std::move(_vector.begin(), _vector.begin() + i, back_inserter(modifiedVector)); + useModified = true; + } + modifiedVector += std::move(*r); + } + else if (useModified) + modifiedVector.emplace_back(std::move(_vector[i])); + } + if (useModified) + _vector = std::move(modifiedVector); +} + /// @returns true iff @a _str passess the hex address checksum test. /// @param _strict if false, hex strings with only uppercase or only lowercase letters /// are considered valid. -- cgit v1.2.3 From 04612936c2ceb41e1c63bfa637eb65f000319c23 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 15 Oct 2018 15:17:20 +0200 Subject: Yul: Introduces a block flattening pass + tests --- libdevcore/CommonData.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libdevcore/CommonData.h') diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 98136b44..f208c425 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -239,9 +239,10 @@ bool contains(T const& _t, V const& _v) /// on the current element and after that. The actual replacement takes /// place at the end, but already visited elements might be invalidated. /// If nothing is replaced, no copy is performed. -template -void iterateReplacing(std::vector& _vector, std::function>(T&)> _f) +template +void iterateReplacing(std::vector& _vector, const F& _f) { + // Concept: _f must be Callable, must accept param T&, must return optional> bool useModified = false; std::vector modifiedVector; for (size_t i = 0; i < _vector.size(); ++i) -- cgit v1.2.3 From 19be6cd818e4bb1a49325d8bfea7f7727d85c933 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 16 Oct 2018 17:58:17 +0200 Subject: Some well-formedness checks for the Yul AST. --- libdevcore/CommonData.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libdevcore/CommonData.h') diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index f208c425..0782fabc 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -272,4 +272,7 @@ bool passesAddressChecksum(std::string const& _str, bool _strict); /// @param hex strings that look like an address std::string getChecksummedAddress(std::string const& _addr); +bool isValidHex(std::string const& _string); +bool isValidDecimal(std::string const& _string); + } -- cgit v1.2.3 From ab0de38f16a9eff13ee5a32a3408b890d87941f6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 7 Nov 2018 12:04:46 +0100 Subject: Eliminate `byte`-typedef and use `uint8_t` in all their places instead. This change is made to (easily) be forward compatible with future C++ standards, in order to allow compiling the code with newer standards at some point in the future. * Removed the `using byte = uint8_t;` line from Common.h * Mechanically change all uses of `byte` to `uint8_t`. Tested with GCC 7.3 in C++11/14/17 modes :-) --- libdevcore/CommonData.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdevcore/CommonData.h') diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 0782fabc..fedd3af2 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -88,7 +88,7 @@ inline std::string asString(bytesConstRef _b) /// Converts a string to a byte array containing the string's (byte) data. inline bytes asBytes(std::string const& _b) { - return bytes((byte const*)_b.data(), (byte const*)(_b.data() + _b.size())); + return bytes((uint8_t const*)_b.data(), (uint8_t const*)(_b.data() + _b.size())); } // Big-endian to/from host endian conversion functions. @@ -117,7 +117,7 @@ inline T fromBigEndian(_In const& _bytes) { T ret = (T)0; for (auto i: _bytes) - ret = (T)((ret << 8) | (byte)(typename std::make_unsigned::type)i); + ret = (T)((ret << 8) | (uint8_t)(typename std::make_unsigned::type)i); return ret; } inline bytes toBigEndian(u256 _val) { bytes ret(32); toBigEndian(_val, ret); return ret; } @@ -135,7 +135,7 @@ inline bytes toCompactBigEndian(T _val, unsigned _min = 0) toBigEndian(_val, ret); return ret; } -inline bytes toCompactBigEndian(byte _val, unsigned _min = 0) +inline bytes toCompactBigEndian(uint8_t _val, unsigned _min = 0) { return (_min || _val) ? bytes{ _val } : bytes{}; } -- cgit v1.2.3