aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorFederico Bond <federicobond@gmail.com>2017-12-19 23:45:04 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-02-13 06:53:33 +0800
commita320ffeafd62b349f6143ceb6b44547c746b08bc (patch)
tree81b5f8bb705d6f0671914e765ceedfee219905d7 /libsolidity
parent954903b50540456906fd7ba909d7d663e2bd7a7f (diff)
downloaddexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.tar
dexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.tar.gz
dexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.tar.bz2
dexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.tar.lz
dexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.tar.xz
dexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.tar.zst
dexon-solidity-a320ffeafd62b349f6143ceb6b44547c746b08bc.zip
Avoid output messages size blow-up using huge bignums literals
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp20
-rw-r--r--libsolidity/ast/Types.h4
2 files changed, 21 insertions, 3 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 21daac2c..716a1204 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -949,11 +949,25 @@ bool RationalNumberType::operator==(Type const& _other) const
return m_value == other.m_value;
}
-string RationalNumberType::toString(bool) const
+string RationalNumberType::bigintToString(dev::bigint const& _num, bool _short)
+{
+ string str = _num.str();
+ if (_short && str.size() > 32)
+ {
+ int omitted = str.size() - 8;
+ return str.substr(0, 4) + "...(" + to_string(omitted) + " digits omitted)..." + str.substr(str.size() - 4, 4);
+ }
+ return str;
+}
+
+string RationalNumberType::toString(bool _short) const
{
if (!isFractional())
- return "int_const " + m_value.numerator().str();
- return "rational_const " + m_value.numerator().str() + '/' + m_value.denominator().str();
+ return "int_const " + bigintToString(m_value.numerator(), _short);
+
+ string numerator = bigintToString(m_value.numerator(), _short);
+ string denominator = bigintToString(m_value.denominator(), _short);
+ return "rational_const " + numerator + '/' + denominator;
}
u256 RationalNumberType::literalValue(Literal const*) const
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index a54e4e09..05f23d04 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -437,6 +437,10 @@ private:
/// @returns true if the literal is a valid rational number.
static std::tuple<bool, rational> parseRational(std::string const& _value);
+
+ /// @returns a truncated readable representation of the bigint keeping only
+ /// up to 4 leading and 4 trailing digits.
+ static std::string bigintToString(dev::bigint const& num, bool _short);
};
/**