mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make sure json output array order is consistent
The source of the "contractDependencies" value was an std::map, thus order was more or less random.
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
#include <libdevcore/UTF8.h>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
@@ -259,7 +262,7 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
|
||||
make_pair("fullyImplemented", _node.annotation().unimplementedFunctions.empty()),
|
||||
make_pair("linearizedBaseContracts", getContainerIds(_node.annotation().linearizedBaseContracts)),
|
||||
make_pair("baseContracts", toJson(_node.baseContracts())),
|
||||
make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies)),
|
||||
make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies, true)),
|
||||
make_pair("nodes", toJson(_node.subNodes())),
|
||||
make_pair("scope", idOrNull(_node.scope()))
|
||||
});
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <json/json.h>
|
||||
#include <ostream>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
@@ -148,15 +150,23 @@ private:
|
||||
return _node.id();
|
||||
}
|
||||
template<class Container>
|
||||
static Json::Value getContainerIds(Container const& container)
|
||||
static Json::Value getContainerIds(Container const& _container, bool _order = false)
|
||||
{
|
||||
Json::Value tmp(Json::arrayValue);
|
||||
for (auto const& element: container)
|
||||
std::vector<int> tmp;
|
||||
|
||||
for (auto const& element: _container)
|
||||
{
|
||||
solAssert(element, "");
|
||||
tmp.append(nodeId(*element));
|
||||
tmp.push_back(nodeId(*element));
|
||||
}
|
||||
return tmp;
|
||||
if (_order)
|
||||
std::sort(tmp.begin(), tmp.end());
|
||||
Json::Value json(Json::arrayValue);
|
||||
|
||||
for (int val: tmp)
|
||||
json.append(val);
|
||||
|
||||
return json;
|
||||
}
|
||||
static Json::Value typePointerToJson(TypePointer _tp, bool _short = false);
|
||||
static Json::Value typePointerToJson(boost::optional<FuncCallArguments> const& _tps);
|
||||
|
||||
Reference in New Issue
Block a user