aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-16 05:47:26 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-17 00:23:08 +0800
commit93be0dd92309c711e7a29dac5257067b837eb7f8 (patch)
treed5ed6dbbbfd8a81bcaa464806d3e4f5c4a3eea30
parent4449820be3b23cb074c8db77915a799b3ff31c49 (diff)
downloaddexon-solidity-93be0dd92309c711e7a29dac5257067b837eb7f8.tar.gz
dexon-solidity-93be0dd92309c711e7a29dac5257067b837eb7f8.tar.zst
dexon-solidity-93be0dd92309c711e7a29dac5257067b837eb7f8.zip
FunctionType comparison/identifer to support all statemutability levels
-rw-r--r--libsolidity/ast/Types.cpp14
-rw-r--r--test/libsolidity/ASTJSON.cpp2
-rw-r--r--test/libsolidity/SolidityTypes.cpp4
3 files changed, 7 insertions, 13 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 302f1022..e6664895 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -2215,10 +2215,7 @@ string FunctionType::identifier() const
case Kind::Require: id += "require";break;
default: solAssert(false, "Unknown function location."); break;
}
- if (isConstant())
- id += "_constant";
- if (isPayable())
- id += "_payable";
+ id += "_" + stateMutabilityToString(m_stateMutability);
id += identifierList(m_parameterTypes) + "returns" + identifierList(m_returnParameterTypes);
if (m_gasSet)
id += "gas";
@@ -2237,8 +2234,7 @@ bool FunctionType::operator==(Type const& _other) const
FunctionType const& other = dynamic_cast<FunctionType const&>(_other);
if (
m_kind != other.m_kind ||
- isConstant() != other.isConstant() ||
- isPayable() != other.isPayable() ||
+ m_stateMutability != other.stateMutability() ||
m_parameterTypes.size() != other.m_parameterTypes.size() ||
m_returnParameterTypes.size() != other.m_returnParameterTypes.size()
)
@@ -2300,10 +2296,8 @@ string FunctionType::toString(bool _short) const
for (auto it = m_parameterTypes.begin(); it != m_parameterTypes.end(); ++it)
name += (*it)->toString(_short) + (it + 1 == m_parameterTypes.end() ? "" : ",");
name += ")";
- if (isConstant())
- name += " constant";
- if (isPayable())
- name += " payable";
+ if (m_stateMutability != StateMutability::NonPayable)
+ name += " " + stateMutabilityToString(m_stateMutability);
if (m_kind == Kind::External)
name += " external";
if (!m_returnParameterTypes.empty())
diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp
index 4fb4f20c..31165922 100644
--- a/test/libsolidity/ASTJSON.cpp
+++ b/test/libsolidity/ASTJSON.cpp
@@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(function_type)
Json::Value retval = fun["children"][1]["children"][0];
BOOST_CHECK_EQUAL(retval["name"], "VariableDeclaration");
BOOST_CHECK_EQUAL(retval["attributes"]["name"], "");
- BOOST_CHECK_EQUAL(retval["attributes"]["type"], "function () constant external returns (uint256)");
+ BOOST_CHECK_EQUAL(retval["attributes"]["type"], "function () view external returns (uint256)");
funType = retval["children"][0];
BOOST_CHECK_EQUAL(funType["attributes"]["constant"], true);
BOOST_CHECK_EQUAL(funType["attributes"]["payable"], false);
diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp
index 0b5ab516..9f385a04 100644
--- a/test/libsolidity/SolidityTypes.cpp
+++ b/test/libsolidity/SolidityTypes.cpp
@@ -129,10 +129,10 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
BOOST_CHECK_EQUAL(t.identifier(), "t_tuple$_t_type$_t_enum$_Enum_$4_$_$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$_t_array$_t_string_storage_$20_storage_ptr_$__$");
TypePointer sha3fun = make_shared<FunctionType>(strings{}, strings{}, FunctionType::Kind::SHA3);
- BOOST_CHECK_EQUAL(sha3fun->identifier(), "t_function_sha3$__$returns$__$");
+ BOOST_CHECK_EQUAL(sha3fun->identifier(), "t_function_sha3_nonpayable$__$returns$__$");
FunctionType metaFun(TypePointers{sha3fun}, TypePointers{s.type()});
- BOOST_CHECK_EQUAL(metaFun.identifier(), "t_function_internal$_t_function_sha3$__$returns$__$_$returns$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$");
+ BOOST_CHECK_EQUAL(metaFun.identifier(), "t_function_internal_nonpayable$_t_function_sha3_nonpayable$__$returns$__$_$returns$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$");
TypePointer m = make_shared<MappingType>(Type::fromElementaryTypeName("bytes32"), s.type());
MappingType m2(Type::fromElementaryTypeName("uint64"), m);