Rename _short in toString to _withoutDataLocation

This commit is contained in:
Duc Thanh Nguyen 2022-07-05 13:45:01 -04:00
parent 0a14368315
commit e0ba7ef0d3
4 changed files with 45 additions and 45 deletions

View File

@ -143,10 +143,10 @@ string ASTJsonExporter::namePathToString(std::vector<ASTString> const& _namePath
return boost::algorithm::join(_namePath, "."); return boost::algorithm::join(_namePath, ".");
} }
Json::Value ASTJsonExporter::typePointerToJson(Type const* _tp, bool _short) Json::Value ASTJsonExporter::typePointerToJson(Type const* _tp, bool _withoutDataLocation)
{ {
Json::Value typeDescriptions(Json::objectValue); Json::Value typeDescriptions(Json::objectValue);
typeDescriptions["typeString"] = _tp ? Json::Value(_tp->toString(_short)) : Json::nullValue; typeDescriptions["typeString"] = _tp ? Json::Value(_tp->toString(_withoutDataLocation)) : Json::nullValue;
typeDescriptions["typeIdentifier"] = _tp ? Json::Value(_tp->identifier()) : Json::nullValue; typeDescriptions["typeIdentifier"] = _tp ? Json::Value(_tp->identifier()) : Json::nullValue;
return typeDescriptions; return typeDescriptions;

View File

@ -184,7 +184,7 @@ private:
return json; return json;
} }
static Json::Value typePointerToJson(Type const* _tp, bool _short = false); static Json::Value typePointerToJson(Type const* _tp, bool _withoutDataLocation = false);
static Json::Value typePointerToJson(std::optional<FuncCallArguments> const& _tps); static Json::Value typePointerToJson(std::optional<FuncCallArguments> const& _tps);
void appendExpressionAttributes( void appendExpressionAttributes(
std::vector<std::pair<std::string, Json::Value>> &_attributes, std::vector<std::pair<std::string, Json::Value>> &_attributes,

View File

@ -110,10 +110,10 @@ util::Result<TypePointers> transformParametersToExternal(TypePointers const& _pa
return transformed; return transformed;
} }
string toStringInParentheses(TypePointers const& _types, bool _short) string toStringInParentheses(TypePointers const& _types, bool _withoutDataLocation)
{ {
return '(' + util::joinHumanReadable( return '(' + util::joinHumanReadable(
_types | ranges::views::transform([&](auto const* _type) { return _type->toString(_short); }), _types | ranges::views::transform([&](auto const* _type) { return _type->toString(_withoutDataLocation); }),
"," ","
) + ')'; ) + ')';
} }
@ -1789,7 +1789,7 @@ vector<tuple<string, Type const*>> ArrayType::makeStackItems() const
solAssert(false, ""); solAssert(false, "");
} }
string ArrayType::toString(bool _short) const string ArrayType::toString(bool _withoutDataLocation) const
{ {
string ret; string ret;
if (isString()) if (isString())
@ -1798,12 +1798,12 @@ string ArrayType::toString(bool _short) const
ret = "bytes"; ret = "bytes";
else else
{ {
ret = baseType()->toString(_short) + "["; ret = baseType()->toString(_withoutDataLocation) + "[";
if (!isDynamicallySized()) if (!isDynamicallySized())
ret += length().str(); ret += length().str();
ret += "]"; ret += "]";
} }
if (!_short) if (!_withoutDataLocation)
ret += " " + stringForReferencePart(); ret += " " + stringForReferencePart();
return ret; return ret;
} }
@ -2008,9 +2008,9 @@ bool ArraySliceType::operator==(Type const& _other) const
return false; return false;
} }
string ArraySliceType::toString(bool _short) const string ArraySliceType::toString(bool _withoutDataLocation) const
{ {
return m_arrayType.toString(_short) + " slice"; return m_arrayType.toString(_withoutDataLocation) + " slice";
} }
string ArraySliceType::humanReadableName() const string ArraySliceType::humanReadableName() const
@ -2279,10 +2279,10 @@ bool StructType::containsNestedMapping() const
return m_struct.annotation().containsNestedMapping.value(); return m_struct.annotation().containsNestedMapping.value();
} }
string StructType::toString(bool _short) const string StructType::toString(bool _withoutDataLocation) const
{ {
string ret = "struct " + *m_struct.annotation().canonicalName; string ret = "struct " + *m_struct.annotation().canonicalName;
if (!_short) if (!_withoutDataLocation)
ret += " " + stringForReferencePart(); ret += " " + stringForReferencePart();
return ret; return ret;
} }
@ -2634,7 +2634,7 @@ bool UserDefinedValueType::operator==(Type const& _other) const
return other.definition() == definition(); return other.definition() == definition();
} }
string UserDefinedValueType::toString(bool /* _short */) const string UserDefinedValueType::toString(bool /* _withoutDataLocation */) const
{ {
return *definition().annotation().canonicalName; return *definition().annotation().canonicalName;
} }
@ -2682,13 +2682,13 @@ bool TupleType::operator==(Type const& _other) const
return false; return false;
} }
string TupleType::toString(bool _short) const string TupleType::toString(bool _withoutDataLocation) const
{ {
if (components().empty()) if (components().empty())
return "tuple()"; return "tuple()";
string str = "tuple("; string str = "tuple(";
for (auto const& t: components()) for (auto const& t: components())
str += (t ? t->toString(_short) : "") + ","; str += (t ? t->toString(_withoutDataLocation) : "") + ",";
str.pop_back(); str.pop_back();
return str + ")"; return str + ")";
} }
@ -3137,15 +3137,15 @@ string FunctionType::humanReadableName() const
switch (m_kind) switch (m_kind)
{ {
case Kind::Error: case Kind::Error:
return "error " + m_declaration->name() + toStringInParentheses(m_parameterTypes, /* _short */ true); return "error " + m_declaration->name() + toStringInParentheses(m_parameterTypes, /* _withoutDataLocation */ true);
case Kind::Event: case Kind::Event:
return "event " + m_declaration->name() + toStringInParentheses(m_parameterTypes, /* _short */ true); return "event " + m_declaration->name() + toStringInParentheses(m_parameterTypes, /* _withoutDataLocation */ true);
default: default:
return toString(/* _short */ false); return toString(/* _withoutDataLocation */ false);
} }
} }
string FunctionType::toString(bool _short) const string FunctionType::toString(bool _withoutDataLocation) const
{ {
string name = "function "; string name = "function ";
if (m_kind == Kind::Declaration) if (m_kind == Kind::Declaration)
@ -3156,7 +3156,7 @@ string FunctionType::toString(bool _short) const
name += *contract->annotation().canonicalName + "."; name += *contract->annotation().canonicalName + ".";
name += functionDefinition->name(); name += functionDefinition->name();
} }
name += toStringInParentheses(m_parameterTypes, _short); name += toStringInParentheses(m_parameterTypes, _withoutDataLocation);
if (m_stateMutability != StateMutability::NonPayable) if (m_stateMutability != StateMutability::NonPayable)
name += " " + stateMutabilityToString(m_stateMutability); name += " " + stateMutabilityToString(m_stateMutability);
if (m_kind == Kind::External) if (m_kind == Kind::External)
@ -3164,7 +3164,7 @@ string FunctionType::toString(bool _short) const
if (!m_returnParameterTypes.empty()) if (!m_returnParameterTypes.empty())
{ {
name += " returns "; name += " returns ";
name += toStringInParentheses(m_returnParameterTypes, _short); name += toStringInParentheses(m_returnParameterTypes, _withoutDataLocation);
} }
return name; return name;
} }
@ -3756,9 +3756,9 @@ bool MappingType::operator==(Type const& _other) const
return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType; return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType;
} }
string MappingType::toString(bool _short) const string MappingType::toString(bool _withoutDataLocation) const
{ {
return "mapping(" + keyType()->toString(_short) + " => " + valueType()->toString(_short) + ")"; return "mapping(" + keyType()->toString(_withoutDataLocation) + " => " + valueType()->toString(_withoutDataLocation) + ")";
} }
string MappingType::canonicalName() const string MappingType::canonicalName() const
@ -3983,11 +3983,11 @@ bool ModifierType::operator==(Type const& _other) const
return true; return true;
} }
string ModifierType::toString(bool _short) const string ModifierType::toString(bool _withoutDataLocation) const
{ {
string name = "modifier ("; string name = "modifier (";
for (auto it = m_parameterTypes.begin(); it != m_parameterTypes.end(); ++it) for (auto it = m_parameterTypes.begin(); it != m_parameterTypes.end(); ++it)
name += (*it)->toString(_short) + (it + 1 == m_parameterTypes.end() ? "" : ","); name += (*it)->toString(_withoutDataLocation) + (it + 1 == m_parameterTypes.end() ? "" : ",");
return name + ")"; return name + ")";
} }
@ -4183,7 +4183,7 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const
return {}; return {};
} }
string MagicType::toString(bool _short) const string MagicType::toString(bool _withoutDataLocation) const
{ {
switch (m_kind) switch (m_kind)
{ {
@ -4197,7 +4197,7 @@ string MagicType::toString(bool _short) const
return "abi"; return "abi";
case Kind::MetaType: case Kind::MetaType:
solAssert(m_typeArgument, ""); solAssert(m_typeArgument, "");
return "type(" + m_typeArgument->toString(_short) + ")"; return "type(" + m_typeArgument->toString(_withoutDataLocation) + ")";
} }
solAssert(false, "Unknown kind of magic."); solAssert(false, "Unknown kind of magic.");
return {}; return {};

View File

@ -335,7 +335,7 @@ public:
return members(_currentScope).memberType(_name); return members(_currentScope).memberType(_name);
} }
virtual std::string toString(bool _short) const = 0; virtual std::string toString(bool _withoutDataLocation) const = 0;
std::string toString() const { return toString(false); } std::string toString() const { return toString(false); }
/// @returns the canonical name of this type for use in library function signatures. /// @returns the canonical name of this type for use in library function signatures.
virtual std::string canonicalName() const { return toString(true); } virtual std::string canonicalName() const { return toString(true); }
@ -428,7 +428,7 @@ public:
MemberList::MemberMap nativeMembers(ASTNode const*) const override; MemberList::MemberMap nativeMembers(ASTNode const*) const override;
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string canonicalName() const override; std::string canonicalName() const override;
u256 literalValue(Literal const* _literal) const override; u256 literalValue(Literal const* _literal) const override;
@ -471,7 +471,7 @@ public:
bool isValueType() const override { return true; } bool isValueType() const override { return true; }
bool nameable() const override { return true; } bool nameable() const override { return true; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
Type const* encodingType() const override { return this; } Type const* encodingType() const override { return this; }
TypeResult interfaceType(bool) const override { return this; } TypeResult interfaceType(bool) const override { return this; }
@ -518,7 +518,7 @@ public:
bool isValueType() const override { return true; } bool isValueType() const override { return true; }
bool nameable() const override { return true; } bool nameable() const override { return true; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
Type const* encodingType() const override { return this; } Type const* encodingType() const override { return this; }
TypeResult interfaceType(bool) const override { return this; } TypeResult interfaceType(bool) const override { return this; }
@ -568,7 +568,7 @@ public:
bool canBeStored() const override { return false; } bool canBeStored() const override { return false; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
u256 literalValue(Literal const* _literal) const override; u256 literalValue(Literal const* _literal) const override;
Type const* mobileType() const override; Type const* mobileType() const override;
@ -832,7 +832,7 @@ public:
bool containsNestedMapping() const override { return m_baseType->containsNestedMapping(); } bool containsNestedMapping() const override { return m_baseType->containsNestedMapping(); }
bool nameable() const override { return true; } bool nameable() const override { return true; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string humanReadableName() const override; std::string humanReadableName() const override;
std::string canonicalName() const override; std::string canonicalName() const override;
std::string signatureInExternalFunction(bool _structsByName) const override; std::string signatureInExternalFunction(bool _structsByName) const override;
@ -897,7 +897,7 @@ public:
unsigned calldataEncodedTailSize() const override { return 32; } unsigned calldataEncodedTailSize() const override { return 32; }
bool isDynamicallySized() const override { return true; } bool isDynamicallySized() const override { return true; }
bool isDynamicallyEncoded() const override { return true; } bool isDynamicallyEncoded() const override { return true; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string humanReadableName() const override; std::string humanReadableName() const override;
Type const* mobileType() const override; Type const* mobileType() const override;
@ -942,7 +942,7 @@ public:
bool leftAligned() const override { solAssert(!isSuper(), ""); return false; } bool leftAligned() const override { solAssert(!isSuper(), ""); return false; }
bool isValueType() const override { return !isSuper(); } bool isValueType() const override { return !isSuper(); }
bool nameable() const override { return !isSuper(); } bool nameable() const override { return !isSuper(); }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string canonicalName() const override; std::string canonicalName() const override;
MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override; MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override;
@ -1004,7 +1004,7 @@ public:
u256 storageSize() const override; u256 storageSize() const override;
bool containsNestedMapping() const override; bool containsNestedMapping() const override;
bool nameable() const override { return true; } bool nameable() const override { return true; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override; MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override;
@ -1066,7 +1066,7 @@ public:
} }
unsigned storageBytes() const override; unsigned storageBytes() const override;
bool leftAligned() const override { return false; } bool leftAligned() const override { return false; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string canonicalName() const override; std::string canonicalName() const override;
bool isValueType() const override { return true; } bool isValueType() const override { return true; }
bool nameable() const override { return true; } bool nameable() const override { return true; }
@ -1153,7 +1153,7 @@ public:
return false; return false;
} }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string canonicalName() const override; std::string canonicalName() const override;
std::string signatureInExternalFunction(bool) const override { solAssert(false, ""); } std::string signatureInExternalFunction(bool) const override { solAssert(false, ""); }
@ -1179,7 +1179,7 @@ public:
std::string richIdentifier() const override; std::string richIdentifier() const override;
bool operator==(Type const& _other) const override; bool operator==(Type const& _other) const override;
TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; } TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; }
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string humanReadableName() const override; std::string humanReadableName() const override;
bool canBeStored() const override { return false; } bool canBeStored() const override { return false; }
u256 storageSize() const override; u256 storageSize() const override;
@ -1383,7 +1383,7 @@ public:
TypeResult binaryOperatorResult(Token, Type const*) const override; TypeResult binaryOperatorResult(Token, Type const*) const override;
std::string canonicalName() const override; std::string canonicalName() const override;
std::string humanReadableName() const override; std::string humanReadableName() const override;
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
unsigned calldataEncodedSize(bool _padded) const override; unsigned calldataEncodedSize(bool _padded) const override;
bool canBeStored() const override { return m_kind == Kind::Internal || m_kind == Kind::External; } bool canBeStored() const override { return m_kind == Kind::Internal || m_kind == Kind::External; }
u256 storageSize() const override; u256 storageSize() const override;
@ -1517,7 +1517,7 @@ public:
std::string richIdentifier() const override; std::string richIdentifier() const override;
bool operator==(Type const& _other) const override; bool operator==(Type const& _other) const override;
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
std::string canonicalName() const override; std::string canonicalName() const override;
bool containsNestedMapping() const override { return true; } bool containsNestedMapping() const override { return true; }
TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; } TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; }
@ -1558,7 +1558,7 @@ public:
bool canBeStored() const override { return false; } bool canBeStored() const override { return false; }
u256 storageSize() const override; u256 storageSize() const override;
bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); }
std::string toString(bool _short) const override { return "type(" + m_actualType->toString(_short) + ")"; } std::string toString(bool _withoutDataLocation) const override { return "type(" + m_actualType->toString(_withoutDataLocation) + ")"; }
MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override; MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override;
BoolResult isExplicitlyConvertibleTo(Type const& _convertTo) const override; BoolResult isExplicitlyConvertibleTo(Type const& _convertTo) const override;
@ -1585,7 +1585,7 @@ public:
bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); }
std::string richIdentifier() const override; std::string richIdentifier() const override;
bool operator==(Type const& _other) const override; bool operator==(Type const& _other) const override;
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
protected: protected:
std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override { return {}; } std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override { return {}; }
private: private:
@ -1611,7 +1611,7 @@ public:
bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); }
MemberList::MemberMap nativeMembers(ASTNode const*) const override; MemberList::MemberMap nativeMembers(ASTNode const*) const override;
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
protected: protected:
std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override { return {}; } std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override { return {}; }
@ -1650,7 +1650,7 @@ public:
bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); }
MemberList::MemberMap nativeMembers(ASTNode const*) const override; MemberList::MemberMap nativeMembers(ASTNode const*) const override;
std::string toString(bool _short) const override; std::string toString(bool _withoutDataLocation) const override;
Kind kind() const { return m_kind; } Kind kind() const { return m_kind; }