yul::reindent() to reindent with spaces instead of tabs (width: 4)

This commit is contained in:
Christian Parpart 2019-07-08 11:08:41 +02:00
parent 019ec63f63
commit 7ba9537ae1
No known key found for this signature in database
GPG Key ID: 19BC8DD20312C929
2 changed files with 84 additions and 79 deletions

View File

@ -42,6 +42,8 @@ using boost::is_any_of;
string yul::reindent(string const& _code) string yul::reindent(string const& _code)
{ {
int constexpr indentationWidth = 4;
auto const static countBraces = [](string const& _s) noexcept -> int auto const static countBraces = [](string const& _s) noexcept -> int
{ {
auto const i = _s.find("//"); auto const i = _s.find("//");
@ -65,10 +67,13 @@ string yul::reindent(string const& _code)
if (diff < 0) if (diff < 0)
depth += diff; depth += diff;
for (int i = 0; i < depth; ++i) if (!line.empty())
out << '\t'; {
for (int i = 0; i < depth * indentationWidth; ++i)
out << line << '\n'; out << ' ';
out << line;
}
out << '\n';
if (diff > 0) if (diff > 0)
depth += diff; depth += diff;

View File

@ -7,81 +7,81 @@
object \"C_6\" { object \"C_6\" {
\tcode { code {
\t\tmstore(64, 128) mstore(64, 128)
\t\t
\t\t
\t\tcodecopy(0, dataoffset(\"C_6_deployed\"), datasize(\"C_6_deployed\")) codecopy(0, dataoffset(\"C_6_deployed\"), datasize(\"C_6_deployed\"))
\t\treturn(0, datasize(\"C_6_deployed\")) return(0, datasize(\"C_6_deployed\"))
\t\t
\t\t
\t\tfunction fun_f_5() { function fun_f_5() {
\t\t\tfor { let return_flag := 1 } return_flag {} { for { let return_flag := 1 } return_flag {} {
\t\t\t\t
\t\t\t\tbreak break
\t\t\t} }
\t\t} }
\t\t
\t} }
\tobject \"C_6_deployed\" { object \"C_6_deployed\" {
\t\tcode { code {
\t\t\tmstore(64, 128) mstore(64, 128)
\t\t\t
\t\t\tif iszero(lt(calldatasize(), 4)) if iszero(lt(calldatasize(), 4))
\t\t\t{ {
\t\t\t\tlet selector := shift_right_224_unsigned(calldataload(0)) let selector := shift_right_224_unsigned(calldataload(0))
\t\t\t\tswitch selector switch selector
\t\t\t\t
\t\t\t\tcase 0x26121ff0 case 0x26121ff0
\t\t\t\t{ {
\t\t\t\t\t// f() // f()
\t\t\t\t\tif callvalue() { revert(0, 0) } if callvalue() { revert(0, 0) }
\t\t\t\t\tabi_decode_tuple_(4, calldatasize()) abi_decode_tuple_(4, calldatasize())
\t\t\t\t\tfun_f_5() fun_f_5()
\t\t\t\t\tlet memPos := allocateMemory(0) let memPos := allocateMemory(0)
\t\t\t\t\tlet memEnd := abi_encode_tuple__to__fromStack(memPos ) let memEnd := abi_encode_tuple__to__fromStack(memPos )
\t\t\t\t\treturn(memPos, sub(memEnd, memPos)) return(memPos, sub(memEnd, memPos))
\t\t\t\t} }
\t\t\t\t
\t\t\t\tdefault {} default {}
\t\t\t} }
\t\t\trevert(0, 0) revert(0, 0)
\t\t\t
\t\t\t
\t\t\tfunction abi_decode_tuple_(headStart, dataEnd) { function abi_decode_tuple_(headStart, dataEnd) {
\t\t\t\tif slt(sub(dataEnd, headStart), 0) { revert(0, 0) } if slt(sub(dataEnd, headStart), 0) { revert(0, 0) }
\t\t\t\t
\t\t\t} }
\t\t\t
\t\t\tfunction abi_encode_tuple__to__fromStack(headStart ) -> tail { function abi_encode_tuple__to__fromStack(headStart ) -> tail {
\t\t\t\ttail := add(headStart, 0) tail := add(headStart, 0)
\t\t\t\t
\t\t\t} }
\t\t\t
\t\t\tfunction allocateMemory(size) -> memPtr { function allocateMemory(size) -> memPtr {
\t\t\t\tmemPtr := mload(64) memPtr := mload(64)
\t\t\t\tlet newFreePtr := add(memPtr, size) let newFreePtr := add(memPtr, size)
\t\t\t\t// protect against overflow // protect against overflow
\t\t\t\tif or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { revert(0, 0) } if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { revert(0, 0) }
\t\t\t\tmstore(64, newFreePtr) mstore(64, newFreePtr)
\t\t\t} }
\t\t\t
\t\t\tfunction fun_f_5() { function fun_f_5() {
\t\t\t\tfor { let return_flag := 1 } return_flag {} { for { let return_flag := 1 } return_flag {} {
\t\t\t\t\t
\t\t\t\t\tbreak break
\t\t\t\t} }
\t\t\t} }
\t\t\t
\t\t\tfunction shift_right_224_unsigned(value) -> newValue { function shift_right_224_unsigned(value) -> newValue {
\t\t\t\tnewValue := newValue :=
\t\t\t\t
\t\t\t\tshr(224, value) shr(224, value)
\t\t\t\t
\t\t\t} }
\t\t\t
\t\t} }
\t} }
} }
"}}},"sources":{"A":{"id":0}}} "}}},"sources":{"A":{"id":0}}}