From 631bd9ab38f9fc232f851fcb82121e258d729d11 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 5 Jan 2015 16:37:43 +0100 Subject: [PATCH 1/4] Fix for sol scanner where empty multiline comment became Natspec comment --- libsolidity/Scanner.cpp | 23 ++++++++++++++++------- libsolidity/Scanner.h | 1 + test/SolidityScanner.cpp | 7 +++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libsolidity/Scanner.cpp b/libsolidity/Scanner.cpp index f22e69bc8..1f700d8b1 100644 --- a/libsolidity/Scanner.cpp +++ b/libsolidity/Scanner.cpp @@ -285,8 +285,6 @@ Token::Value Scanner::scanMultiLineDocComment() bool endFound = false; bool charsAdded = false; - advance(); //consume the last '*' at /** - skipWhitespaceExceptLF(); while (!isSourcePastEndOfInput()) { //handle newlines in multline comments @@ -354,11 +352,22 @@ Token::Value Scanner::scanSlash() return Token::WHITESPACE; else if (m_char == '*') { - Token::Value comment; - m_nextSkippedComment.location.start = firstSlashPosition; - comment = scanMultiLineDocComment(); - m_nextSkippedComment.location.end = getSourcePos(); - m_nextSkippedComment.token = comment; + advance(); //consume the last '*' at /** + skipWhitespaceExceptLF(); + + // special case of a closed normal multiline comment + if (!m_source.isPastEndOfInput() && m_source.get(0) == '/') + { + advance(); //skip the closing slash + } + else // we actually have a multiline documentation comment + { + Token::Value comment; + m_nextSkippedComment.location.start = firstSlashPosition; + comment = scanMultiLineDocComment(); + m_nextSkippedComment.location.end = getSourcePos(); + m_nextSkippedComment.token = comment; + } return Token::WHITESPACE; } else diff --git a/libsolidity/Scanner.h b/libsolidity/Scanner.h index 5b90a94eb..d93b79df0 100644 --- a/libsolidity/Scanner.h +++ b/libsolidity/Scanner.h @@ -119,6 +119,7 @@ public: { return m_currentToken.token; } + Location getCurrentLocation() const { return m_currentToken.location; } std::string const& getCurrentLiteral() const { return m_currentToken.literal; } ///@} diff --git a/test/SolidityScanner.cpp b/test/SolidityScanner.cpp index 355ea9e22..b7942d293 100644 --- a/test/SolidityScanner.cpp +++ b/test/SolidityScanner.cpp @@ -227,6 +227,13 @@ BOOST_AUTO_TEST_CASE(documentation_comment_before_eos) BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); } +BOOST_AUTO_TEST_CASE(empty_multiline_comment) +{ + Scanner scanner(CharStream("/**/")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); +} + BOOST_AUTO_TEST_CASE(empty_multiline_documentation_comment_before_eos) { Scanner scanner(CharStream("/***/")); From bec29881b07b673c33b4e0d26eabee6b62ae6ef8 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 5 Jan 2015 16:40:57 +0100 Subject: [PATCH 2/4] use of client() without if --- libweb3jsonrpc/WebThreeStubServer.cpp | 53 ++++----------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index d88aa0a5f..e441ce6f3 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -272,15 +272,11 @@ std::string WebThreeStubServer::eth_balanceAt(string const& _address) Json::Value WebThreeStubServer::eth_blockByHash(std::string const& _hash) { - if (!client()) - return ""; return toJson(client()->blockInfo(jsToFixed<32>(_hash))); } Json::Value WebThreeStubServer::eth_blockByNumber(int const& _number) { - if (!client()) - return ""; return toJson(client()->blockInfo(client()->hashFromNumber(_number))); } @@ -332,8 +328,6 @@ static TransactionSkeleton toTransaction(Json::Value const& _json) std::string WebThreeStubServer::eth_call(Json::Value const& _json) { std::string ret; - if (!client()) - return ret; TransactionSkeleton t = toTransaction(_json); if (!t.from && m_accounts.size()) { @@ -355,31 +349,29 @@ std::string WebThreeStubServer::eth_call(Json::Value const& _json) bool WebThreeStubServer::eth_changed(int const& _id) { - if (!client()) - return false; return client()->checkWatch(_id); } std::string WebThreeStubServer::eth_codeAt(string const& _address) { int block = 0; - return client() ? jsFromBinary(client()->codeAt(jsToAddress(_address), block)) : ""; + return jsFromBinary(client()->codeAt(jsToAddress(_address), block)); } std::string WebThreeStubServer::eth_coinbase() { - return client() ? toJS(client()->address()) : ""; + return toJS(client()->address()); } double WebThreeStubServer::eth_countAt(string const& _address) { int block = 0; - return client() ? (double)(uint64_t)client()->countAt(jsToAddress(_address), block) : 0; + return (double)(uint64_t)client()->countAt(jsToAddress(_address), block); } int WebThreeStubServer::eth_defaultBlock() { - return client() ? client()->getDefault() : 0; + return client()->getDefault(); } std::string WebThreeStubServer::eth_gasPrice() @@ -397,15 +389,11 @@ std::string WebThreeStubServer::db_get(std::string const& _name, std::string con Json::Value WebThreeStubServer::eth_filterLogs(int const& _id) { - if (!client()) - return Json::Value(Json::arrayValue); return toJson(client()->logs(_id)); } Json::Value WebThreeStubServer::eth_logs(Json::Value const& _json) { - if (!client()) - return Json::Value(Json::arrayValue); return toJson(client()->logs(toLogFilter(_json))); } @@ -429,15 +417,12 @@ bool WebThreeStubServer::eth_listening() bool WebThreeStubServer::eth_mining() { - return client() ? client()->isMining() : false; + return client()->isMining(); } int WebThreeStubServer::eth_newFilter(Json::Value const& _json) { unsigned ret = -1; - if (!client()) - return ret; -// ret = client()->installWatch(toMessageFilter(_json)); ret = client()->installWatch(toLogFilter(_json)); return ret; } @@ -445,8 +430,6 @@ int WebThreeStubServer::eth_newFilter(Json::Value const& _json) int WebThreeStubServer::eth_newFilterString(std::string const& _filter) { unsigned ret = -1; - if (!client()) - return ret; if (_filter.compare("chain") == 0) ret = client()->installWatch(dev::eth::ChainChangedFilter); else if (_filter.compare("pending") == 0) @@ -528,7 +511,7 @@ std::string WebThreeStubServer::eth_solidity(std::string const& _code) int WebThreeStubServer::eth_number() { - return client() ? client()->number() + 1 : 0; + return client()->number() + 1; } int WebThreeStubServer::eth_peerCount() @@ -538,7 +521,6 @@ int WebThreeStubServer::eth_peerCount() bool WebThreeStubServer::shh_post(Json::Value const& _json) { -// cnote << this << m_ids; shh::Message m = toMessage(_json); Secret from; @@ -571,16 +553,12 @@ bool WebThreeStubServer::db_putString(std::string const& _name, std::string cons bool WebThreeStubServer::eth_setCoinbase(std::string const& _address) { - if (!client()) - return false; client()->setAddress(jsToAddress(_address)); return true; } bool WebThreeStubServer::eth_setDefaultBlock(int const& _block) { - if (!client()) - return false; client()->setDefault(_block); return true; } @@ -596,9 +574,6 @@ bool WebThreeStubServer::eth_setListening(bool const& _listening) bool WebThreeStubServer::eth_setMining(bool const& _mining) { - if (!client()) - return false; - if (_mining) client()->startMining(); else @@ -647,21 +622,17 @@ bool WebThreeStubServer::shh_uninstallFilter(int const& _id) std::string WebThreeStubServer::eth_stateAt(string const& _address, string const& _storage) { int block = 0; - return client() ? toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), block)) : ""; + return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), block)); } Json::Value WebThreeStubServer::eth_storageAt(string const& _address) { - if (!client()) - return Json::Value(Json::objectValue); return toJson(client()->storageAt(jsToAddress(_address))); } std::string WebThreeStubServer::eth_transact(Json::Value const& _json) { std::string ret; - if (!client()) - return ret; TransactionSkeleton t = toTransaction(_json); if (!t.from && m_accounts.size()) { @@ -689,36 +660,26 @@ std::string WebThreeStubServer::eth_transact(Json::Value const& _json) Json::Value WebThreeStubServer::eth_transactionByHash(std::string const& _hash, int const& _i) { - if (!client()) - return ""; return toJson(client()->transaction(jsToFixed<32>(_hash), _i)); } Json::Value WebThreeStubServer::eth_transactionByNumber(int const& _number, int const& _i) { - if (!client()) - return ""; return toJson(client()->transaction(client()->hashFromNumber(_number), _i)); } Json::Value WebThreeStubServer::eth_uncleByHash(std::string const& _hash, int const& _i) { - if (!client()) - return ""; return toJson(client()->uncle(jsToFixed<32>(_hash), _i)); } Json::Value WebThreeStubServer::eth_uncleByNumber(int const& _number, int const& _i) { - if (!client()) - return ""; return toJson(client()->uncle(client()->hashFromNumber(_number), _i)); } bool WebThreeStubServer::eth_uninstallFilter(int const& _id) { - if (!client()) - return false; client()->uninstallWatch(_id); return true; } From 58eb79733200ee12a73f799aab1056f00d8082ff Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 5 Jan 2015 16:46:44 +0100 Subject: [PATCH 3/4] applying changes from #715 --- libweb3jsonrpc/WebThreeStubServer.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index e441ce6f3..6cba16f84 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -266,8 +266,7 @@ std::string WebThreeStubServer::shh_addToGroup(std::string const& _group, std::s std::string WebThreeStubServer::eth_balanceAt(string const& _address) { - int block = 0; - return toJS(client()->balanceAt(jsToAddress(_address), block)); + return toJS(client()->balanceAt(jsToAddress(_address), client()->getDefault())); } Json::Value WebThreeStubServer::eth_blockByHash(std::string const& _hash) @@ -354,8 +353,7 @@ bool WebThreeStubServer::eth_changed(int const& _id) std::string WebThreeStubServer::eth_codeAt(string const& _address) { - int block = 0; - return jsFromBinary(client()->codeAt(jsToAddress(_address), block)); + return jsFromBinary(client()->codeAt(jsToAddress(_address), client()->getDefault())); } std::string WebThreeStubServer::eth_coinbase() @@ -365,8 +363,7 @@ std::string WebThreeStubServer::eth_coinbase() double WebThreeStubServer::eth_countAt(string const& _address) { - int block = 0; - return (double)(uint64_t)client()->countAt(jsToAddress(_address), block); + return (double)(uint64_t)client()->countAt(jsToAddress(_address), client()->getDefault()); } int WebThreeStubServer::eth_defaultBlock() @@ -621,8 +618,7 @@ bool WebThreeStubServer::shh_uninstallFilter(int const& _id) std::string WebThreeStubServer::eth_stateAt(string const& _address, string const& _storage) { - int block = 0; - return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), block)); + return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), client()->getDefault())); } Json::Value WebThreeStubServer::eth_storageAt(string const& _address) From 6d098faab069b11db3427900c2476f3e0335e4f6 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 5 Jan 2015 16:55:17 +0100 Subject: [PATCH 4/4] style: curlies --- libsolidity/Scanner.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsolidity/Scanner.cpp b/libsolidity/Scanner.cpp index 1f700d8b1..6433b5262 100644 --- a/libsolidity/Scanner.cpp +++ b/libsolidity/Scanner.cpp @@ -357,9 +357,7 @@ Token::Value Scanner::scanSlash() // special case of a closed normal multiline comment if (!m_source.isPastEndOfInput() && m_source.get(0) == '/') - { advance(); //skip the closing slash - } else // we actually have a multiline documentation comment { Token::Value comment;