aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AST.h2
-rw-r--r--CMakeLists.txt4
-rw-r--r--CompilerStack.cpp26
-rw-r--r--CompilerStack.h4
4 files changed, 35 insertions, 1 deletions
diff --git a/AST.h b/AST.h
index 81a12ad1..4ed8489f 100644
--- a/AST.h
+++ b/AST.h
@@ -199,7 +199,7 @@ public:
Block& getBody() { return *m_body; }
/// @return A shared pointer of an ASTString.
/// Can contain a nullptr in which case indicates absence of documentation
- ASTPointer<ASTString> const& getDocumentation() { return m_documentation; }
+ ASTPointer<ASTString> const& getDocumentation() const { return m_documentation; }
void addLocalVariable(VariableDeclaration const& _localVariable) { m_localVariables.push_back(&_localVariable); }
std::vector<VariableDeclaration const*> const& getLocalVariables() const { return m_localVariables; }
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea2ef4b7..b5147ced 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,10 @@ endif()
include_directories(..)
target_link_libraries(${EXECUTABLE} evmcore devcore)
+# TODO: Temporary until PR 532 https://github.com/ethereum/cpp-ethereum/pull/532
+# gets accepted. Then we can simply add jsoncpp as a dependency and not the
+# whole of JSONRPC as we are doing right here
+target_link_libraries(${EXECUTABLE} ${JSONRPC_LS})
install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )
diff --git a/CompilerStack.cpp b/CompilerStack.cpp
index 6535e00d..45d3e0b8 100644
--- a/CompilerStack.cpp
+++ b/CompilerStack.cpp
@@ -28,6 +28,8 @@
#include <libsolidity/Compiler.h>
#include <libsolidity/CompilerStack.h>
+#include <jsonrpc/json/json.h>
+
using namespace std;
namespace dev
@@ -125,6 +127,30 @@ string const& CompilerStack::getInterface()
return m_interface;
}
+string const& CompilerStack::getDocumentation()
+{
+
+ Json::StyledWriter writer;
+ if (!m_parseSuccessful)
+ BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
+ if (m_documentation.empty())
+ {
+ Json::Value doc;
+ Json::Value methods;
+
+ vector<FunctionDefinition const*> exportedFunctions = m_contractASTNode->getInterfaceFunctions();
+ for (FunctionDefinition const* f: exportedFunctions)
+ {
+ Json::Value user;
+ user["user"] = Json::Value(*f->getDocumentation());
+ methods[f->getName()] = user;
+ }
+ doc["methods"] = methods;
+ m_documentation = writer.write(doc);
+ }
+ return m_documentation;
+}
+
bytes CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimize)
{
CompilerStack stack;
diff --git a/CompilerStack.h b/CompilerStack.h
index 6cae8660..74784c5e 100644
--- a/CompilerStack.h
+++ b/CompilerStack.h
@@ -62,6 +62,9 @@ public:
/// Returns a string representing the contract interface in JSON.
/// Prerequisite: Successful call to parse or compile.
std::string const& getInterface();
+ /// Returns a string representing the contract documentation in JSON.
+ /// Prerequisite: Successful call to parse or compile.
+ std::string const& getDocumentation();
/// Returns the previously used scanner, useful for counting lines during error reporting.
Scanner const& getScanner() const { return *m_scanner; }
@@ -77,6 +80,7 @@ private:
std::shared_ptr<ContractDefinition> m_contractASTNode;
bool m_parseSuccessful;
std::string m_interface;
+ std::string m_documentation;
std::shared_ptr<Compiler> m_compiler;
bytes m_bytecode;
};