From 43d6726dd78e35bf79fa2da3824c2916c5e6b0a8 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 1 Dec 2014 17:03:04 +0100 Subject: Exporting Natspec documentation to a JSON interface - Adding a getDocumentation() function to solidity compiler stack so that we can obtain the natspec interface for a contract - Adding libjsoncpp as a dependency of libsolidity. This is done in a dirty way, using libjsonrpc-cpp s an intermediate dependency for the moment. Will fix soon. - Start of a test file for Natspec exporting to JSON --- CompilerStack.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'CompilerStack.h') 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 m_contractASTNode; bool m_parseSuccessful; std::string m_interface; + std::string m_documentation; std::shared_ptr m_compiler; bytes m_bytecode; }; -- cgit From be81981ec4a3a9e7704b230096d9a580175d759e Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 3 Dec 2014 13:50:04 +0100 Subject: Separate user and dev natspec documentation - plus other small changes according to the spec --- CompilerStack.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'CompilerStack.h') diff --git a/CompilerStack.h b/CompilerStack.h index 74784c5e..4e0d2251 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -62,9 +62,12 @@ 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. + /// Returns a string representing the contract's user documentation in JSON. /// Prerequisite: Successful call to parse or compile. - std::string const& getDocumentation(); + std::string const& getUserDocumentation(); + /// Returns a string representing the contract's developer documentation in JSON. + /// Prerequisite: Successful call to parse or compile. + std::string const& getDevDocumentation(); /// Returns the previously used scanner, useful for counting lines during error reporting. Scanner const& getScanner() const { return *m_scanner; } @@ -80,7 +83,8 @@ private: std::shared_ptr m_contractASTNode; bool m_parseSuccessful; std::string m_interface; - std::string m_documentation; + std::string m_userDocumentation; + std::string m_devDocumentation; std::shared_ptr m_compiler; bytes m_bytecode; }; -- cgit From d25581de7cc89470a060625c043dba8cf9ae293f Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 3 Dec 2014 16:40:37 +0100 Subject: Moving all Interface and Documentation functionality to own class - Creating the Interface Handler class which will take care of the parsing of Natspec comments and of interfacing with and outputing to JSON files. - Will also handle the ABI interface creation --- CompilerStack.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'CompilerStack.h') diff --git a/CompilerStack.h b/CompilerStack.h index 4e0d2251..7dc86e2b 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -35,6 +35,14 @@ class Scanner; class ContractDefinition; class Compiler; class GlobalContext; +class InterfaceHandler; + +enum documentation_type : unsigned short +{ + NATSPEC_USER = 1, + NATSPEC_DEV, + ABI_INTERFACE +}; /** * Easy to use and self-contained Solidity compiler with as few header dependencies as possible. @@ -44,7 +52,7 @@ class GlobalContext; class CompilerStack { public: - CompilerStack() {} + CompilerStack(); void reset() { *this = CompilerStack(); } void setSource(std::string const& _sourceCode); void parse(); @@ -62,12 +70,11 @@ 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's user documentation in JSON. - /// Prerequisite: Successful call to parse or compile. - std::string const& getUserDocumentation(); - /// Returns a string representing the contract's developer documentation in JSON. + /// Returns a string representing the contract's documentation in JSON. /// Prerequisite: Successful call to parse or compile. - std::string const& getDevDocumentation(); + /// @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 documentation_type type); /// Returns the previously used scanner, useful for counting lines during error reporting. Scanner const& getScanner() const { return *m_scanner; } @@ -82,10 +89,11 @@ private: std::shared_ptr m_globalContext; std::shared_ptr m_contractASTNode; bool m_parseSuccessful; - std::string m_interface; - std::string m_userDocumentation; - std::string m_devDocumentation; + std::unique_ptr m_interface; + std::unique_ptr m_userDocumentation; + std::unique_ptr m_devDocumentation; std::shared_ptr m_compiler; + std::shared_ptr m_interfaceHandler; bytes m_bytecode; }; -- cgit From ba27dc74214d70a4ce8dcfcbb0b15a829f2b050d Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 4 Dec 2014 01:27:38 +0100 Subject: Styling in libsolidity's InterfaceHandler --- CompilerStack.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'CompilerStack.h') diff --git a/CompilerStack.h b/CompilerStack.h index 7dc86e2b..51195129 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -37,7 +37,7 @@ class Compiler; class GlobalContext; class InterfaceHandler; -enum documentation_type : 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 documentation_type 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; } -- cgit From dedd1a312ba51c4ed8f9f801628dc23f1b09216d Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 4 Dec 2014 23:55:47 +0100 Subject: Addressing styling and miscellaneous issue with Natspec --- CompilerStack.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'CompilerStack.h') 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; } -- cgit From c8f96589c58c1a0ab290a192e4aa1dfb263d01df Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 5 Dec 2014 12:41:32 +0100 Subject: Stack compiler now correctly returns a string and not a pointer --- CompilerStack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'CompilerStack.h') diff --git a/CompilerStack.h b/CompilerStack.h index de356b1a..8dc546fb 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -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; } -- cgit