<commit_before>
#include <libsolidity/InterfaceHandler.h>
#include <libsolidity/AST.h>
#include <libsolidity/CompilerStack.h>
using namespace std;

namespace dev
{
namespace solidity
{

/* -- public -- */

InterfaceHandler::InterfaceHandler()
{
	m_lastTag = DocTagType::NONE;
}

std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefinition const& _contractDef,
																DocumentationType _type)
{
	switch(_type)
	{
	case DocumentationType::NATSPEC_USER:
		return getUserDocumentation(_contractDef);
	case DocumentationType::NATSPEC_DEV:
		return getDevDocumentation(_contractDef);
	case DocumentationType::ABI_INTERFACE:
		return getABIInterface(_contractDef);
	case DocumentationType::ABI_SOLIDITY_INTERFACE:
		return getABISolidityInterface(_contractDef);
	}

	BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
	return nullptr;
}

std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
{
	Json::Value methods(Json::arrayValue);

	for (auto const& it: _contractDef.getInterfaceFunctions())
	{
		Json::Value method;
		Json::Value inputs(Json::arrayValue);
		Json::Value outputs(Json::arrayValue);

		auto populateParameters = [](vector<string> const& _paramNames,
									 vector<string> const& _paramTypes)
		{
			Json::Value params(Json::arrayValue);
			solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
			for (unsigned i = 0; i < _paramNames.size(); ++i)
			{
				Json::Value input;
				input["name"] = _paramNames[i];
				input["type"] = _paramTypes[i];
				params.append(input);
			}
			return params;
		};
		method["type"] = "function";
		method["name"] = it.second->getDeclaration().getName();
		method["constant"] = it.second->isConstant();
		method["inputs"] = populateParameters(it.second->getParameterNames(),
											  it.second->getParameterTypeNames());
		method["outputs"] = populateParameters(it.second->getReturnParameterNames(),
											   it.second->getReturnParameterTypeNames());
		methods.append(method);
	}
	return std::unique_ptr<std::string>(new std::string(m_writer.write(methods)));
}

unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
{
	string ret = "contract " + _contractDef.getName() + "{";<commit_msg>Code for outputing events as well as functions.<commit_after>
#include <libsolidity/InterfaceHandler.h>
#include <libsolidity/AST.h>
#include <libsolidity/CompilerStack.h>
using namespace std;

namespace dev
{
namespace solidity
{

/* -- public -- */

InterfaceHandler::InterfaceHandler()
{
	m_lastTag = DocTagType::NONE;
}

std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefinition const& _contractDef,
																DocumentationType _type)
{
	switch(_type)
	{
	case DocumentationType::NATSPEC_USER:
		return getUserDocumentation(_contractDef);
	case DocumentationType::NATSPEC_DEV:
		return getDevDocumentation(_contractDef);
	case DocumentationType::ABI_INTERFACE:
		return getABIInterface(_contractDef);
	case DocumentationType::ABI_SOLIDITY_INTERFACE:
		return getABISolidityInterface(_contractDef);
	}

	BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
	return nullptr;
}

std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
{
	Json::Value members(Json::arrayValue);
/*
	for (ASTPointer<EventDefinition> const& it: _contractDef.getEvents())
	{
		Json::Value event;5
		Json::Value inputs(Json::arrayValue);

		event["type"] = "event";
		Json::Value params(Json::arrayValue);
		for (ASTPointer<VariableDeclaration> const& p: it->getParameters())
		{
			Json::Value param;
			param["name"] = p->getName();
			param["type"] = p->getType()->toString();
			param["indexed"] = p->isIndexed();
			params.append(param);
		}
		event["inputs"] = params;
		members.append(event);
	}*/
	for (auto const& it: _contractDef.getInterfaceFunctions())
	{
		auto populateParameters = [](vector<string> const& _paramNames,
									 vector<string> const& _paramTypes)
		{
			Json::Value params(Json::arrayValue);
			solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
			for (unsigned i = 0; i < _paramNames.size(); ++i)
			{
				Json::Value input;
				input["name"] = _paramNames[i];
				input["type"] = _paramTypes[i];
				params.append(input);
			}
			return params;
		};

		Json::Value method;
		Json::Value inputs(Json::arrayValue);
		Json::Value outputs(Json::arrayValue);

		method["type"] = "function";
		method["name"] = it.second->getDeclaration().getName();
		method["constant"] = it.second->isConstant();
		method["inputs"] = populateParameters(it.second->getParameterNames(),
											  it.second->getParameterTypeNames());
		method["outputs"] = populateParameters(it.second->getReturnParameterNames(),
											   it.second->getReturnParameterTypeNames());
		members.append(method);
	}
	return std::unique_ptr<std::string>(new std::string(m_writer.write(members)));
}

unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
{
	string ret = "contract " + _contractDef.getName() + "{";
{'fraction_non_alphanumeric': 0.1422610015174507, 'fraction_numerical': 0.0005690440060698028, 'mean_word_length': 5.81266149870801, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3176591', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1582, 'n_words': 285}