aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsolidity/InterfaceHandler.cpp35
-rw-r--r--test/libsolidity/SolidityInterface.cpp3
2 files changed, 31 insertions, 7 deletions
diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp
index 533634c2..d23d8264 100644
--- a/libsolidity/InterfaceHandler.cpp
+++ b/libsolidity/InterfaceHandler.cpp
@@ -1,5 +1,8 @@
#include <libsolidity/InterfaceHandler.h>
+#include <boost/range/adaptor/transformed.hpp>
+#include <boost/range/irange.hpp>
+#include <boost/algorithm/string/join.hpp>
#include <libsolidity/AST.h>
#include <libsolidity/CompilerStack.h>
using namespace std;
@@ -108,16 +111,36 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef)
string InterfaceHandler::ABISolidityInterface(ContractDefinition const& _contractDef)
{
- string ret = "contract " + _contractDef.name() + "{";
+ using namespace boost::adaptors;
+ using namespace boost::algorithm;
+ string ret = (_contractDef.isLibrary() ? "library " : "contract ") + _contractDef.name() + "{";
auto populateParameters = [](vector<string> const& _paramNames, vector<string> const& _paramTypes)
{
- string r = "";
- solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
- for (unsigned i = 0; i < _paramNames.size(); ++i)
- r += (r.size() ? "," : "(") + _paramTypes[i] + " " + _paramNames[i];
- return r.size() ? r + ")" : "()";
+ return "(" + join(boost::irange<size_t>(0, _paramNames.size()) | transformed([&](size_t _i) {
+ return _paramTypes[_i] + " " + _paramNames[_i];
+ }), ",") + ")";
};
+ // If this is a library, include all its enum and struct types. Should be more intelligent
+ // in the future and check what is actually used (it might even use types from other libraries
+ // or contracts or in the global scope).
+ if (_contractDef.isLibrary())
+ {
+ for (auto const& stru: _contractDef.definedStructs())
+ {
+ ret += "struct " + stru->name() + "{";
+ for (ASTPointer<VariableDeclaration> const& _member: stru->members())
+ ret += _member->type(nullptr)->canonicalName(false) + " " + _member->name() + ";";
+ ret += "}";
+ }
+ for (auto const& enu: _contractDef.definedEnums())
+ {
+ ret += "enum " + enu->name() + "{" +
+ join(enu->members() | transformed([](ASTPointer<EnumValue> const& _value) {
+ return _value->name();
+ }), ",") + "}";
+ }
+ }
if (_contractDef.constructor())
{
auto externalFunction = FunctionType(*_contractDef.constructor()).interfaceFunctionType();
diff --git a/test/libsolidity/SolidityInterface.cpp b/test/libsolidity/SolidityInterface.cpp
index 4006968a..f0d2be20 100644
--- a/test/libsolidity/SolidityInterface.cpp
+++ b/test/libsolidity/SolidityInterface.cpp
@@ -152,7 +152,8 @@ BOOST_AUTO_TEST_CASE(libraries)
}
)";
ContractDefinition const& contract = checkInterface(sourceCode);
- set<string> expectedFunctions({"function f(uint256[] x,Lib.Str y,Lib.E z);"});
+ BOOST_CHECK(contract.isLibrary());
+ set<string> expectedFunctions({"function f(uint256[] x,Lib.Str storage y,Lib.E z);"});
BOOST_REQUIRE_EQUAL(1, contract.definedFunctions().size());
BOOST_CHECK(expectedFunctions == set<string>({sourcePart(*contract.definedFunctions().at(0))}));
}