diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-09-08 09:18:17 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-23 01:24:22 +0800 |
commit | efe4d68a7bdc55fd79b9e01b863064b27528428a (patch) | |
tree | 66fed23805dcf2dffdb2bc8509ddf077ac99e45d | |
parent | 210b4870a805620329793c8ba2177a3ff6e7b477 (diff) | |
download | dexon-solidity-efe4d68a7bdc55fd79b9e01b863064b27528428a.tar.gz dexon-solidity-efe4d68a7bdc55fd79b9e01b863064b27528428a.tar.zst dexon-solidity-efe4d68a7bdc55fd79b9e01b863064b27528428a.zip |
Introduce view (and keep constant as an alias)
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | docs/types.rst | 2 | ||||
-rw-r--r-- | libsolidity/ast/ASTJsonConverter.cpp | 2 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 1 | ||||
-rw-r--r-- | libsolidity/interface/ABI.cpp | 3 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 3 | ||||
-rw-r--r-- | libsolidity/parsing/Token.h | 4 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 6 |
8 files changed, 13 insertions, 9 deletions
diff --git a/Changelog.md b/Changelog.md index 39cbd44b..efcea03f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ Features: * ABI JSON: Include new field ``statemutability`` with values ``view``, ``nonpayable`` and ``payable``. * Parser: Display previous visibility specifier in error if multiple are found. + * Parser: Introduce ``view`` keyword on functions (``constant`` remains an alias for ``view``). * Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features. * Static Analyzer: Warn about large storage structures. * Metadata: Store experimental flag in metadata CBOR. diff --git a/docs/types.rst b/docs/types.rst index 13c848c2..9c1c73c6 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -337,7 +337,7 @@ be passed via and returned from external function calls. Function types are notated as follows:: - function (<parameter types>) {internal|external} [constant|payable] [returns (<return types>)] + function (<parameter types>) {internal|external} [constant|view|payable] [returns (<return types>)] In contrast to the parameter types, the return types cannot be empty - if the function type should not return anything, the whole ``returns (<return types>)`` diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index f7661357..cb74ea39 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -323,6 +323,7 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node) { std::vector<pair<string, Json::Value>> attributes = { make_pair("name", _node.name()), + // FIXME: remove with next breaking release make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() == StateMutability::View), make_pair("payable", _node.isPayable()), make_pair("statemutability", stateMutabilityToString(_node.stateMutability())), @@ -415,6 +416,7 @@ bool ASTJsonConverter::visit(FunctionTypeName const& _node) make_pair("payable", _node.isPayable()), make_pair("visibility", Declaration::visibilityToString(_node.visibility())), make_pair("statemutability", stateMutabilityToString(_node.stateMutability())), + // FIXME: remove with next breaking release make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() == StateMutability::View), make_pair("parameterTypes", toJson(*_node.parameterTypeList())), make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())), diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 56546a82..ce2d3bf8 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -993,7 +993,6 @@ public: return *m_declaration; } bool hasDeclaration() const { return !!m_declaration; } - bool isConstant() const { return m_stateMutability == StateMutability::View; } /// @returns true if the the result of this function only depends on its arguments /// and it does not modify the state. /// Currently, this will only return true for internal functions like keccak and ecrecover. diff --git a/libsolidity/interface/ABI.cpp b/libsolidity/interface/ABI.cpp index a7224e86..6e8563f7 100644 --- a/libsolidity/interface/ABI.cpp +++ b/libsolidity/interface/ABI.cpp @@ -35,7 +35,8 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef) Json::Value method; method["type"] = "function"; method["name"] = it.second->declaration().name(); - method["constant"] = it.second->isConstant(); + // TODO: deprecate constant in a future release + method["constant"] = it.second->stateMutability() == StateMutability::View; method["payable"] = it.second->isPayable(); method["statemutability"] = stateMutabilityToString(it.second->stateMutability()); method["inputs"] = formatTypeList( diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 7455cbca..92a614e0 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -337,7 +337,8 @@ StateMutability Parser::parseStateMutability(Token::Value _token) StateMutability stateMutability(StateMutability::NonPayable); if (_token == Token::Payable) stateMutability = StateMutability::Payable; - else if (_token == Token::Constant) + // FIXME: constant should be removed at the next breaking release + else if (_token == Token::View || _token == Token::Constant) stateMutability = StateMutability::View; else solAssert(false, "Invalid state mutability specifier."); diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index efbe5e9e..3bc52f1d 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -176,6 +176,7 @@ namespace solidity K(Throw, "throw", 0) \ K(Using, "using", 0) \ K(Var, "var", 0) \ + K(View, "view", 0) \ K(While, "while", 0) \ \ /* Ether subdenominations */ \ @@ -236,7 +237,6 @@ namespace solidity K(Try, "try", 0) \ K(Type, "type", 0) \ K(TypeOf, "typeof", 0) \ - K(View, "view", 0) \ /* Illegal token - not able to scan. */ \ T(Illegal, "ILLEGAL", 0) \ \ @@ -290,7 +290,7 @@ public: static bool isVisibilitySpecifier(Value op) { return isVariableVisibilitySpecifier(op) || op == External; } static bool isVariableVisibilitySpecifier(Value op) { return op == Public || op == Private || op == Internal; } static bool isLocationSpecifier(Value op) { return op == Memory || op == Storage; } - static bool isStateMutabilitySpecifier(Value op) { return op == Constant || op == Payable; } + static bool isStateMutabilitySpecifier(Value op) { return op == Constant || op == View || op == Payable; } static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; } static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; } static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= TypeOf); } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f5f607ca..380978e8 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1172,7 +1172,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_REQUIRE(function && function->hasDeclaration()); auto returnParams = function->returnParameterTypes(); BOOST_CHECK_EQUAL(returnParams.at(0)->canonicalName(false), "uint256"); - BOOST_CHECK(function->isConstant()); + BOOST_CHECK(function->stateMutability() == StateMutability::View); function = retrieveFunctionBySignature(*contract, "map(uint256)"); BOOST_REQUIRE(function && function->hasDeclaration()); @@ -1180,7 +1180,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_CHECK_EQUAL(params.at(0)->canonicalName(false), "uint256"); returnParams = function->returnParameterTypes(); BOOST_CHECK_EQUAL(returnParams.at(0)->canonicalName(false), "bytes4"); - BOOST_CHECK(function->isConstant()); + BOOST_CHECK(function->stateMutability() == StateMutability::View); function = retrieveFunctionBySignature(*contract, "multiple_map(uint256,uint256)"); BOOST_REQUIRE(function && function->hasDeclaration()); @@ -1189,7 +1189,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_CHECK_EQUAL(params.at(1)->canonicalName(false), "uint256"); returnParams = function->returnParameterTypes(); BOOST_CHECK_EQUAL(returnParams.at(0)->canonicalName(false), "bytes4"); - BOOST_CHECK(function->isConstant()); + BOOST_CHECK(function->stateMutability() == StateMutability::View); } BOOST_AUTO_TEST_CASE(function_clash_with_state_variable_accessor) |