@@ -110,10 +110,10 @@ util::Result<TypePointers> transformParametersToExternal(TypePointers const& _pa
110
110
return transformed;
111
111
}
112
112
113
- string toStringInParentheses (TypePointers const & _types, bool _short )
113
+ string toStringInParentheses (TypePointers const & _types, bool _withoutDataLocation )
114
114
{
115
115
return ' (' + util::joinHumanReadable (
116
- _types | ranges::views::transform ([&](auto const * _type) { return _type->toString (_short ); }),
116
+ _types | ranges::views::transform ([&](auto const * _type) { return _type->toString (_withoutDataLocation ); }),
117
117
" ,"
118
118
) + ' )' ;
119
119
}
@@ -1789,7 +1789,7 @@ vector<tuple<string, Type const*>> ArrayType::makeStackItems() const
1789
1789
solAssert (false , " " );
1790
1790
}
1791
1791
1792
- string ArrayType::toString (bool _short ) const
1792
+ string ArrayType::toString (bool _withoutDataLocation ) const
1793
1793
{
1794
1794
string ret;
1795
1795
if (isString ())
@@ -1798,16 +1798,34 @@ string ArrayType::toString(bool _short) const
1798
1798
ret = " bytes" ;
1799
1799
else
1800
1800
{
1801
- ret = baseType ()->toString (_short ) + " [" ;
1801
+ ret = baseType ()->toString (_withoutDataLocation ) + " [" ;
1802
1802
if (!isDynamicallySized ())
1803
1803
ret += length ().str ();
1804
1804
ret += " ]" ;
1805
1805
}
1806
- if (!_short )
1806
+ if (!_withoutDataLocation )
1807
1807
ret += " " + stringForReferencePart ();
1808
1808
return ret;
1809
1809
}
1810
1810
1811
+ string ArrayType::humanReadableName () const
1812
+ {
1813
+ string ret;
1814
+ if (isString ())
1815
+ ret = " string" ;
1816
+ else if (isByteArrayOrString ())
1817
+ ret = " bytes" ;
1818
+ else
1819
+ {
1820
+ ret = baseType ()->toString (true ) + " [" ;
1821
+ if (!isDynamicallySized ())
1822
+ ret += length ().str ();
1823
+ ret += " ]" ;
1824
+ }
1825
+ ret += " " + stringForReferencePart ();
1826
+ return ret;
1827
+ }
1828
+
1811
1829
string ArrayType::canonicalName () const
1812
1830
{
1813
1831
string ret;
@@ -1990,9 +2008,14 @@ bool ArraySliceType::operator==(Type const& _other) const
1990
2008
return false ;
1991
2009
}
1992
2010
1993
- string ArraySliceType::toString (bool _short) const
2011
+ string ArraySliceType::toString (bool _withoutDataLocation) const
2012
+ {
2013
+ return m_arrayType.toString (_withoutDataLocation) + " slice" ;
2014
+ }
2015
+
2016
+ string ArraySliceType::humanReadableName () const
1994
2017
{
1995
- return m_arrayType.toString (_short ) + " slice" ;
2018
+ return m_arrayType.humanReadableName ( ) + " slice" ;
1996
2019
}
1997
2020
1998
2021
Type const * ArraySliceType::mobileType () const
@@ -2256,10 +2279,10 @@ bool StructType::containsNestedMapping() const
2256
2279
return m_struct.annotation ().containsNestedMapping .value ();
2257
2280
}
2258
2281
2259
- string StructType::toString (bool _short ) const
2282
+ string StructType::toString (bool _withoutDataLocation ) const
2260
2283
{
2261
2284
string ret = " struct " + *m_struct.annotation ().canonicalName ;
2262
- if (!_short )
2285
+ if (!_withoutDataLocation )
2263
2286
ret += " " + stringForReferencePart ();
2264
2287
return ret;
2265
2288
}
@@ -2611,7 +2634,7 @@ bool UserDefinedValueType::operator==(Type const& _other) const
2611
2634
return other.definition () == definition ();
2612
2635
}
2613
2636
2614
- string UserDefinedValueType::toString (bool /* _short */ ) const
2637
+ string UserDefinedValueType::toString (bool /* _withoutDataLocation */ ) const
2615
2638
{
2616
2639
return *definition ().annotation ().canonicalName ;
2617
2640
}
@@ -2659,13 +2682,24 @@ bool TupleType::operator==(Type const& _other) const
2659
2682
return false ;
2660
2683
}
2661
2684
2662
- string TupleType::toString (bool _short) const
2685
+ string TupleType::toString (bool _withoutDataLocation) const
2686
+ {
2687
+ if (components ().empty ())
2688
+ return " tuple()" ;
2689
+ string str = " tuple(" ;
2690
+ for (auto const & t: components ())
2691
+ str += (t ? t->toString (_withoutDataLocation) : " " ) + " ," ;
2692
+ str.pop_back ();
2693
+ return str + " )" ;
2694
+ }
2695
+
2696
+ string TupleType::humanReadableName () const
2663
2697
{
2664
2698
if (components ().empty ())
2665
2699
return " tuple()" ;
2666
2700
string str = " tuple(" ;
2667
2701
for (auto const & t: components ())
2668
- str += (t ? t->toString (_short ) : " " ) + " ," ;
2702
+ str += (t ? t->humanReadableName ( ) : " " ) + " ," ;
2669
2703
str.pop_back ();
2670
2704
return str + " )" ;
2671
2705
}
@@ -3103,15 +3137,15 @@ string FunctionType::humanReadableName() const
3103
3137
switch (m_kind)
3104
3138
{
3105
3139
case Kind::Error:
3106
- return " error " + m_declaration->name () + toStringInParentheses (m_parameterTypes, /* _short */ true );
3140
+ return " error " + m_declaration->name () + toStringInParentheses (m_parameterTypes, /* _withoutDataLocation */ true );
3107
3141
case Kind::Event:
3108
- return " event " + m_declaration->name () + toStringInParentheses (m_parameterTypes, /* _short */ true );
3142
+ return " event " + m_declaration->name () + toStringInParentheses (m_parameterTypes, /* _withoutDataLocation */ true );
3109
3143
default :
3110
- return toString (/* _short */ false );
3144
+ return toString (/* _withoutDataLocation */ false );
3111
3145
}
3112
3146
}
3113
3147
3114
- string FunctionType::toString (bool _short ) const
3148
+ string FunctionType::toString (bool _withoutDataLocation ) const
3115
3149
{
3116
3150
string name = " function " ;
3117
3151
if (m_kind == Kind::Declaration)
@@ -3122,15 +3156,15 @@ string FunctionType::toString(bool _short) const
3122
3156
name += *contract->annotation ().canonicalName + " ." ;
3123
3157
name += functionDefinition->name ();
3124
3158
}
3125
- name += toStringInParentheses (m_parameterTypes, _short );
3159
+ name += toStringInParentheses (m_parameterTypes, _withoutDataLocation );
3126
3160
if (m_stateMutability != StateMutability::NonPayable)
3127
3161
name += " " + stateMutabilityToString (m_stateMutability);
3128
3162
if (m_kind == Kind::External)
3129
3163
name += " external" ;
3130
3164
if (!m_returnParameterTypes.empty ())
3131
3165
{
3132
3166
name += " returns " ;
3133
- name += toStringInParentheses (m_returnParameterTypes, _short );
3167
+ name += toStringInParentheses (m_returnParameterTypes, _withoutDataLocation );
3134
3168
}
3135
3169
return name;
3136
3170
}
@@ -3722,9 +3756,9 @@ bool MappingType::operator==(Type const& _other) const
3722
3756
return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType;
3723
3757
}
3724
3758
3725
- string MappingType::toString (bool _short ) const
3759
+ string MappingType::toString (bool _withoutDataLocation ) const
3726
3760
{
3727
- return " mapping(" + keyType ()->toString (_short ) + " => " + valueType ()->toString (_short ) + " )" ;
3761
+ return " mapping(" + keyType ()->toString (_withoutDataLocation ) + " => " + valueType ()->toString (_withoutDataLocation ) + " )" ;
3728
3762
}
3729
3763
3730
3764
string MappingType::canonicalName () const
@@ -3949,11 +3983,11 @@ bool ModifierType::operator==(Type const& _other) const
3949
3983
return true ;
3950
3984
}
3951
3985
3952
- string ModifierType::toString (bool _short ) const
3986
+ string ModifierType::toString (bool _withoutDataLocation ) const
3953
3987
{
3954
3988
string name = " modifier (" ;
3955
3989
for (auto it = m_parameterTypes.begin (); it != m_parameterTypes.end (); ++it)
3956
- name += (*it)->toString (_short ) + (it + 1 == m_parameterTypes.end () ? " " : " ," );
3990
+ name += (*it)->toString (_withoutDataLocation ) + (it + 1 == m_parameterTypes.end () ? " " : " ," );
3957
3991
return name + " )" ;
3958
3992
}
3959
3993
@@ -4149,7 +4183,7 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const
4149
4183
return {};
4150
4184
}
4151
4185
4152
- string MagicType::toString (bool _short ) const
4186
+ string MagicType::toString (bool _withoutDataLocation ) const
4153
4187
{
4154
4188
switch (m_kind)
4155
4189
{
@@ -4163,7 +4197,7 @@ string MagicType::toString(bool _short) const
4163
4197
return " abi" ;
4164
4198
case Kind::MetaType:
4165
4199
solAssert (m_typeArgument, " " );
4166
- return " type(" + m_typeArgument->toString (_short ) + " )" ;
4200
+ return " type(" + m_typeArgument->toString (_withoutDataLocation ) + " )" ;
4167
4201
}
4168
4202
solAssert (false , " Unknown kind of magic." );
4169
4203
return {};
0 commit comments