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:
Mathias Baumann
2019-08-19 17:42:03 +02:00
parent 5e2a31f43b
commit 0e3ff25b4e
6 changed files with 549 additions and 6 deletions
+4 -1
View File
@@ -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()))
});
+15 -5
View File
@@ -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);