diff options
-rw-r--r-- | CompilerStack.cpp | 20 | ||||
-rw-r--r-- | CompilerStack.h | 4 | ||||
-rw-r--r-- | InterfaceHandler.cpp | 49 | ||||
-rw-r--r-- | InterfaceHandler.h | 18 |
4 files changed, 43 insertions, 48 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp index 3e9791bd..3281442f 100644 --- a/CompilerStack.cpp +++ b/CompilerStack.cpp @@ -36,7 +36,7 @@ namespace dev namespace solidity { -CompilerStack::CompilerStack():m_interfaceHandler(make_shared<InterfaceHandler>()){} +CompilerStack::CompilerStack(): m_interfaceHandler(make_shared<InterfaceHandler>()) {} void CompilerStack::setSource(string const& _sourceCode) { @@ -84,33 +84,31 @@ void CompilerStack::streamAssembly(ostream& _outStream) m_compiler->streamAssembly(_outStream); } -std::string const* CompilerStack::getJsonDocumentation(enum documentationType _type) +std::string const* CompilerStack::getJsonDocumentation(enum DocumentationType _type) { if (!m_parseSuccessful) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful.")); - auto createOrReturnDoc = [this, _type](std::unique_ptr<string>& _doc) + auto createDocIfNotThere = [this, _type](std::unique_ptr<string>& _doc) { - if(!_doc) - { + if (!_doc) _doc = m_interfaceHandler->getDocumentation(m_contractASTNode, _type); - } }; switch (_type) { case NATSPEC_USER: - createOrReturnDoc(m_userDocumentation); + createDocIfNotThere(m_userDocumentation); return m_userDocumentation.get(); case NATSPEC_DEV: - createOrReturnDoc(m_devDocumentation); + createDocIfNotThere(m_devDocumentation); return m_devDocumentation.get(); case ABI_INTERFACE: - createOrReturnDoc(m_interface); + createDocIfNotThere(m_interface); return m_interface.get(); } - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal error")); - return nullptr; + + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type.")); } bytes CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimize) diff --git a/CompilerStack.h b/CompilerStack.h index 51195129..de356b1a 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -37,7 +37,7 @@ class Compiler; class GlobalContext; class InterfaceHandler; -enum documentationType: unsigned short +enum DocumentationType: unsigned short { NATSPEC_USER = 1, NATSPEC_DEV, @@ -74,7 +74,7 @@ public: /// Prerequisite: Successful call to parse or compile. /// @param type The type of the documentation to get. /// Can be one of 3 types defined at @c documentation_type - std::string const* getJsonDocumentation(enum documentationType type); + std::string const* getJsonDocumentation(enum DocumentationType type); /// Returns the previously used scanner, useful for counting lines during error reporting. Scanner const& getScanner() const { return *m_scanner; } diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp index 2a6de2c3..53632bc6 100644 --- a/InterfaceHandler.cpp +++ b/InterfaceHandler.cpp @@ -3,8 +3,10 @@ #include <libsolidity/AST.h> #include <libsolidity/CompilerStack.h> -namespace dev { -namespace solidity { +namespace dev +{ +namespace solidity +{ /* -- public -- */ @@ -14,7 +16,7 @@ InterfaceHandler::InterfaceHandler() } std::unique_ptr<std::string> InterfaceHandler::getDocumentation(std::shared_ptr<ContractDefinition> _contractDef, - enum documentationType _type) + enum DocumentationType _type) { switch(_type) { @@ -34,8 +36,7 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(std::shared_ptr<C { Json::Value methods(Json::arrayValue); - std::vector<FunctionDefinition const*> exportedFunctions = _contractDef->getInterfaceFunctions(); - for (FunctionDefinition const* f: exportedFunctions) + for (FunctionDefinition const* f: _contractDef->getInterfaceFunctions()) { Json::Value method; Json::Value inputs(Json::arrayValue); @@ -107,9 +108,8 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(std::shared_p method["details"] = Json::Value(m_dev); Json::Value params(Json::objectValue); for (auto const& pair: m_params) - { params[pair.first] = pair.second; - } + if (!m_params.empty()) method["params"] = params; if (!m_return.empty()) @@ -145,12 +145,12 @@ size_t skipLineOrEOS(std::string const& _string, size_t _nlPos) size_t InterfaceHandler::parseDocTagLine(std::string const& _string, std::string& _tagString, size_t _pos, - enum docTagType _tagType) + enum DocTagType _tagType) { - size_t nlPos = _string.find("\n", _pos); + size_t nlPos = _string.find('\n', _pos); _tagString += _string.substr(_pos, nlPos == std::string::npos ? - _string.length() : + _string.length() - _pos: nlPos - _pos); m_lastTag = _tagType; return skipLineOrEOS(_string, nlPos); @@ -159,20 +159,18 @@ size_t InterfaceHandler::parseDocTagLine(std::string const& _string, size_t InterfaceHandler::parseDocTagParam(std::string const& _string, size_t _startPos) { // find param name - size_t currPos = _string.find(" ", _startPos); + size_t currPos = _string.find(' ', _startPos); if (currPos == std::string::npos) - { BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of param name not found")); - return currPos; //no end of tag found - } + auto paramName = _string.substr(_startPos, currPos - _startPos); currPos += 1; - size_t nlPos = _string.find("\n", currPos); + size_t nlPos = _string.find('\n', currPos); auto paramDesc = _string.substr(currPos, nlPos == std::string::npos ? - _string.length() : + _string.length() - currPos : nlPos - currPos); m_params.push_back(std::make_pair(paramName, paramDesc)); @@ -184,13 +182,13 @@ size_t InterfaceHandler::parseDocTagParam(std::string const& _string, size_t _st size_t InterfaceHandler::appendDocTagParam(std::string const& _string, size_t _startPos) { // Should never be called with an empty vector - assert(!m_params.empty()); - + if (asserts(!m_params.empty())) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal: Tried to append to empty parameter")); auto pair = m_params.back(); - size_t nlPos = _string.find("\n", _startPos); + size_t nlPos = _string.find('\n', _startPos); pair.second += _string.substr(_startPos, nlPos == std::string::npos ? - _string.length() : + _string.length() - _startPos : nlPos - _startPos); m_params.at(m_params.size() - 1) = pair; @@ -227,7 +225,7 @@ size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string con size_t InterfaceHandler::appendDocTag(std::string const& _string, size_t _startPos) { size_t newPos = _startPos; - switch(m_lastTag) + switch (m_lastTag) { case DOCTAG_DEV: m_dev += " "; @@ -254,18 +252,15 @@ void InterfaceHandler::parseDocString(std::string const& _string, size_t _startP { size_t pos2; size_t newPos = _startPos; - size_t tagPos = _string.find("@", _startPos); - size_t nlPos = _string.find("\n", _startPos); + size_t tagPos = _string.find('@', _startPos); + size_t nlPos = _string.find('\n', _startPos); if (tagPos != std::string::npos && tagPos < nlPos) { // we found a tag - pos2 = _string.find(" ", tagPos); + pos2 = _string.find(' ', tagPos); if (pos2 == std::string::npos) - { BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of tag not found")); - return; //no end of tag found - } newPos = parseDocTag(_string, _string.substr(tagPos + 1, pos2 - tagPos - 1), pos2 + 1); } diff --git a/InterfaceHandler.h b/InterfaceHandler.h index eeaed033..e9e3a83c 100644 --- a/InterfaceHandler.h +++ b/InterfaceHandler.h @@ -30,14 +30,16 @@ #include <memory> #include <jsonrpc/json/json.h> -namespace dev { -namespace solidity { +namespace dev +{ +namespace solidity +{ // Forward declarations class ContractDefinition; -enum documentationType: unsigned short; +enum DocumentationType: unsigned short; -enum docTagType +enum DocTagType { DOCTAG_NONE = 0, DOCTAG_DEV, @@ -54,11 +56,11 @@ public: /// Get the given type of documentation /// @param _contractDef The contract definition /// @param _type The type of the documentation. Can be one of the - /// types provided by @c documentation_type + /// types provided by @c DocumentationType /// @return A unique pointer contained string with the json /// representation of provided type std::unique_ptr<std::string> getDocumentation(std::shared_ptr<ContractDefinition> _contractDef, - enum documentationType _type); + enum DocumentationType _type); /// Get the ABI Interface of the contract /// @param _contractDef The contract definition /// @return A unique pointer contained string with the json @@ -79,7 +81,7 @@ private: void resetUser(); void resetDev(); - size_t parseDocTagLine(std::string const& _string, std::string& _tagString, size_t _pos, enum docTagType _tagType); + size_t parseDocTagLine(std::string const& _string, std::string& _tagString, size_t _pos, enum DocTagType _tagType); size_t parseDocTagParam(std::string const& _string, size_t _startPos); size_t appendDocTagParam(std::string const& _string, size_t _startPos); void parseDocString(std::string const& _string, size_t _startPos = 0); @@ -89,7 +91,7 @@ private: Json::StyledWriter m_writer; // internal state - enum docTagType m_lastTag; + enum DocTagType m_lastTag; std::string m_notice; std::string m_dev; std::string m_return; |