aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-02-13 20:36:05 +0800
committerGitHub <noreply@github.com>2018-02-13 20:36:05 +0800
commit8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a (patch)
tree159d2bb15029f85c91092add1feae87745dd21ee /libsolidity
parent1d21f30f828ee9b50ae71e877218b11c75b37526 (diff)
parent560fbd0df1f9f9ba1c9a95f1319914df8fd79278 (diff)
downloaddexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.tar
dexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.tar.gz
dexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.tar.bz2
dexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.tar.lz
dexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.tar.xz
dexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.tar.zst
dexon-solidity-8f8ad3840eecd7b22565e0c36eb55ceca5d5b57a.zip
Merge pull request #3349 from federicobond/number-improv
Avoid output messages size blow-up using huge bignums literals
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp18
-rw-r--r--libsolidity/ast/Types.h4
2 files changed, 20 insertions, 2 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 21daac2c..e4b7e4fd 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::bigintToReadableString(dev::bigint const& _num)
+{
+ string str = _num.str();
+ if (str.size() > 32)
+ {
+ int omitted = str.size() - 8;
+ str = str.substr(0, 4) + "...(" + to_string(omitted) + " digits omitted)..." + str.substr(str.size() - 4, 4);
+ }
+ return str;
+}
+
string RationalNumberType::toString(bool) const
{
if (!isFractional())
- return "int_const " + m_value.numerator().str();
- return "rational_const " + m_value.numerator().str() + '/' + m_value.denominator().str();
+ return "int_const " + bigintToReadableString(m_value.numerator());
+
+ string numerator = bigintToReadableString(m_value.numerator());
+ string denominator = bigintToReadableString(m_value.denominator());
+ 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..2e7d05ba 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 bigintToReadableString(dev::bigint const& num);
};
/**