From ffce12b7ee412cbd29dd0873a3e894dd7133ca4e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 9 Jan 2015 00:22:06 +0100 Subject: Basic logging in Solidity (though no tests yet). --- InterfaceHandler.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'InterfaceHandler.cpp') diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp index 224234cb..06b9824c 100644 --- a/InterfaceHandler.cpp +++ b/InterfaceHandler.cpp @@ -2,6 +2,7 @@ #include #include #include +using namespace std; namespace dev { @@ -26,6 +27,8 @@ std::unique_ptr InterfaceHandler::getDocumentation(ContractDefiniti return getDevDocumentation(_contractDef); case DocumentationType::ABI_INTERFACE: return getABIInterface(_contractDef); + case DocumentationType::ABI_SOLIDITY_INTERFACE: + return getABISolidityInterface(_contractDef); } BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type")); @@ -64,6 +67,28 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio return std::unique_ptr(new std::string(m_writer.write(methods))); } +unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef) +{ + string ret = "contract " + _contractDef.getName() + "{"; + for (FunctionDefinition const* f: _contractDef.getInterfaceFunctions()) + { + auto populateParameters = [](vector> const& _vars) + { + string r = ""; + for (ASTPointer const& var: _vars) + r += (r.size() ? "," : "(") + var->getType()->toString() + " " + var->getName(); + return r.size() ? r + ")" : "()"; + }; + ret += "function " + f->getName() + populateParameters(f->getParameters()) + (f->isDeclaredConst() ? "constant " : ""); + if (f->getReturnParameters().size()) + ret += "returns" + populateParameters(f->getReturnParameters()); + else if (ret.back() == ' ') + ret.pop_back(); + ret += "{}"; + } + return unique_ptr(new string(ret + "}")); +} + std::unique_ptr InterfaceHandler::getUserDocumentation(ContractDefinition const& _contractDef) { Json::Value doc; -- cgit v1.2.3