diff --git a/libsolidity/ast/ASTJsonExporter.cpp b/libsolidity/ast/ASTJsonExporter.cpp index 8d5ed1a6c..939fc79c6 100644 --- a/libsolidity/ast/ASTJsonExporter.cpp +++ b/libsolidity/ast/ASTJsonExporter.cpp @@ -143,10 +143,10 @@ string ASTJsonExporter::namePathToString(std::vector const& _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); - 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; return typeDescriptions; diff --git a/libsolidity/ast/ASTJsonExporter.h b/libsolidity/ast/ASTJsonExporter.h index 566f13612..71d15ce0a 100644 --- a/libsolidity/ast/ASTJsonExporter.h +++ b/libsolidity/ast/ASTJsonExporter.h @@ -184,7 +184,7 @@ private: 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 const& _tps); void appendExpressionAttributes( std::vector> &_attributes, diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 5a315555b..f88d1afce 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -110,10 +110,10 @@ util::Result transformParametersToExternal(TypePointers const& _pa return transformed; } -string toStringInParentheses(TypePointers const& _types, bool _short) +string toStringInParentheses(TypePointers const& _types, bool _withoutDataLocation) { 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> ArrayType::makeStackItems() const solAssert(false, ""); } -string ArrayType::toString(bool _short) const +string ArrayType::toString(bool _withoutDataLocation) const { string ret; if (isString()) @@ -1798,12 +1798,12 @@ string ArrayType::toString(bool _short) const ret = "bytes"; else { - ret = baseType()->toString(_short) + "["; + ret = baseType()->toString(_withoutDataLocation) + "["; if (!isDynamicallySized()) ret += length().str(); ret += "]"; } - if (!_short) + if (!_withoutDataLocation) ret += " " + stringForReferencePart(); return ret; } @@ -2008,9 +2008,9 @@ bool ArraySliceType::operator==(Type const& _other) const 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 @@ -2279,10 +2279,10 @@ bool StructType::containsNestedMapping() const 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; - if (!_short) + if (!_withoutDataLocation) ret += " " + stringForReferencePart(); return ret; } @@ -2634,7 +2634,7 @@ bool UserDefinedValueType::operator==(Type const& _other) const return other.definition() == definition(); } -string UserDefinedValueType::toString(bool /* _short */) const +string UserDefinedValueType::toString(bool /* _withoutDataLocation */) const { return *definition().annotation().canonicalName; } @@ -2682,13 +2682,13 @@ bool TupleType::operator==(Type const& _other) const return false; } -string TupleType::toString(bool _short) const +string TupleType::toString(bool _withoutDataLocation) const { if (components().empty()) return "tuple()"; string str = "tuple("; for (auto const& t: components()) - str += (t ? t->toString(_short) : "") + ","; + str += (t ? t->toString(_withoutDataLocation) : "") + ","; str.pop_back(); return str + ")"; } @@ -3137,15 +3137,15 @@ string FunctionType::humanReadableName() const switch (m_kind) { 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: - return "event " + m_declaration->name() + toStringInParentheses(m_parameterTypes, /* _short */ true); + return "event " + m_declaration->name() + toStringInParentheses(m_parameterTypes, /* _withoutDataLocation */ true); default: - return toString(/* _short */ false); + return toString(/* _withoutDataLocation */ false); } } -string FunctionType::toString(bool _short) const +string FunctionType::toString(bool _withoutDataLocation) const { string name = "function "; if (m_kind == Kind::Declaration) @@ -3156,7 +3156,7 @@ string FunctionType::toString(bool _short) const name += *contract->annotation().canonicalName + "."; name += functionDefinition->name(); } - name += toStringInParentheses(m_parameterTypes, _short); + name += toStringInParentheses(m_parameterTypes, _withoutDataLocation); if (m_stateMutability != StateMutability::NonPayable) name += " " + stateMutabilityToString(m_stateMutability); if (m_kind == Kind::External) @@ -3164,7 +3164,7 @@ string FunctionType::toString(bool _short) const if (!m_returnParameterTypes.empty()) { name += " returns "; - name += toStringInParentheses(m_returnParameterTypes, _short); + name += toStringInParentheses(m_returnParameterTypes, _withoutDataLocation); } return name; } @@ -3756,9 +3756,9 @@ bool MappingType::operator==(Type const& _other) const 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 @@ -3983,11 +3983,11 @@ bool ModifierType::operator==(Type const& _other) const return true; } -string ModifierType::toString(bool _short) const +string ModifierType::toString(bool _withoutDataLocation) const { string name = "modifier ("; 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 + ")"; } @@ -4183,7 +4183,7 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const return {}; } -string MagicType::toString(bool _short) const +string MagicType::toString(bool _withoutDataLocation) const { switch (m_kind) { @@ -4197,7 +4197,7 @@ string MagicType::toString(bool _short) const return "abi"; case Kind::MetaType: solAssert(m_typeArgument, ""); - return "type(" + m_typeArgument->toString(_short) + ")"; + return "type(" + m_typeArgument->toString(_withoutDataLocation) + ")"; } solAssert(false, "Unknown kind of magic."); return {}; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 5eb10d814..553af6c7d 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -335,7 +335,7 @@ public: 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); } /// @returns the canonical name of this type for use in library function signatures. virtual std::string canonicalName() const { return toString(true); } @@ -428,7 +428,7 @@ public: 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; u256 literalValue(Literal const* _literal) const override; @@ -471,7 +471,7 @@ public: bool isValueType() 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; } TypeResult interfaceType(bool) const override { return this; } @@ -518,7 +518,7 @@ public: bool isValueType() 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; } TypeResult interfaceType(bool) const override { return this; } @@ -568,7 +568,7 @@ public: 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; Type const* mobileType() const override; @@ -832,7 +832,7 @@ public: bool containsNestedMapping() const override { return m_baseType->containsNestedMapping(); } 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 canonicalName() const override; std::string signatureInExternalFunction(bool _structsByName) const override; @@ -897,7 +897,7 @@ public: unsigned calldataEncodedTailSize() const override { return 32; } bool isDynamicallySized() 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; Type const* mobileType() const override; @@ -942,7 +942,7 @@ public: bool leftAligned() const override { solAssert(!isSuper(), ""); return false; } bool isValueType() 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; MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override; @@ -1004,7 +1004,7 @@ public: u256 storageSize() const override; bool containsNestedMapping() const override; 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; @@ -1066,7 +1066,7 @@ public: } unsigned storageBytes() const override; 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; bool isValueType() const override { return true; } bool nameable() const override { return true; } @@ -1153,7 +1153,7 @@ public: return false; } - std::string toString(bool _short) const override; + std::string toString(bool _withoutDataLocation) const override; std::string canonicalName() const override; std::string signatureInExternalFunction(bool) const override { solAssert(false, ""); } @@ -1179,7 +1179,7 @@ public: std::string richIdentifier() const override; bool operator==(Type const& _other) const override; 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; bool canBeStored() const override { return false; } u256 storageSize() const override; @@ -1383,7 +1383,7 @@ public: TypeResult binaryOperatorResult(Token, Type const*) const override; std::string canonicalName() 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; bool canBeStored() const override { return m_kind == Kind::Internal || m_kind == Kind::External; } u256 storageSize() const override; @@ -1517,7 +1517,7 @@ public: std::string richIdentifier() 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; bool containsNestedMapping() const override { return true; } TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; } @@ -1558,7 +1558,7 @@ public: bool canBeStored() const override { return false; } u256 storageSize() const override; 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; BoolResult isExplicitlyConvertibleTo(Type const& _convertTo) const override; @@ -1585,7 +1585,7 @@ public: bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } std::string richIdentifier() const override; bool operator==(Type const& _other) const override; - std::string toString(bool _short) const override; + std::string toString(bool _withoutDataLocation) const override; protected: std::vector> makeStackItems() const override { return {}; } private: @@ -1611,7 +1611,7 @@ public: bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } MemberList::MemberMap nativeMembers(ASTNode const*) const override; - std::string toString(bool _short) const override; + std::string toString(bool _withoutDataLocation) const override; protected: std::vector> makeStackItems() const override { return {}; } @@ -1650,7 +1650,7 @@ public: bool hasSimpleZeroValueInMemory() const override { solAssert(false, ""); } 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; }