2015-01-28 07:50:53 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2015-01-28 07:50:53 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2015-01-28 07:50:53 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2015-01-28 07:50:53 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2015-01-28 07:50:53 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
2018-09-27 00:53:34 +00:00
|
|
|
* Public compiler API.
|
2015-01-28 07:50:53 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-16 02:50:16 +00:00
|
|
|
#include <libsolc/libsolc.h>
|
2015-01-28 07:50:53 +00:00
|
|
|
#include <libdevcore/Common.h>
|
2016-11-15 17:33:28 +00:00
|
|
|
#include <libdevcore/JSON.h>
|
2017-03-16 23:48:51 +00:00
|
|
|
#include <libsolidity/interface/StandardCompiler.h>
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/interface/Version.h>
|
2015-01-28 07:50:53 +00:00
|
|
|
|
2017-08-28 23:34:39 +00:00
|
|
|
#include <string>
|
|
|
|
|
2017-06-13 20:47:33 +00:00
|
|
|
#include "license.h"
|
|
|
|
|
2015-01-28 07:50:53 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace dev;
|
|
|
|
using namespace solidity;
|
|
|
|
|
2017-08-09 11:44:53 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2017-07-13 19:06:04 +00:00
|
|
|
ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback = nullptr)
|
2017-03-16 23:48:51 +00:00
|
|
|
{
|
2017-07-13 19:06:04 +00:00
|
|
|
ReadCallback::Callback readCallback;
|
2017-03-16 23:48:51 +00:00
|
|
|
if (_readCallback)
|
|
|
|
{
|
|
|
|
readCallback = [=](string const& _path)
|
|
|
|
{
|
|
|
|
char* contents_c = nullptr;
|
|
|
|
char* error_c = nullptr;
|
|
|
|
_readCallback(_path.c_str(), &contents_c, &error_c);
|
2017-07-13 19:06:04 +00:00
|
|
|
ReadCallback::Result result;
|
2017-03-16 23:48:51 +00:00
|
|
|
result.success = true;
|
|
|
|
if (!contents_c && !error_c)
|
|
|
|
{
|
|
|
|
result.success = false;
|
2017-07-13 19:06:04 +00:00
|
|
|
result.responseOrErrorMessage = "File not found.";
|
2017-03-16 23:48:51 +00:00
|
|
|
}
|
|
|
|
if (contents_c)
|
|
|
|
{
|
|
|
|
result.success = true;
|
2017-07-13 19:06:04 +00:00
|
|
|
result.responseOrErrorMessage = string(contents_c);
|
2017-03-16 23:48:51 +00:00
|
|
|
free(contents_c);
|
|
|
|
}
|
|
|
|
if (error_c)
|
|
|
|
{
|
|
|
|
result.success = false;
|
2017-07-13 19:06:04 +00:00
|
|
|
result.responseOrErrorMessage = string(error_c);
|
2017-03-16 23:48:51 +00:00
|
|
|
free(error_c);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return readCallback;
|
|
|
|
}
|
|
|
|
|
2018-09-27 00:53:34 +00:00
|
|
|
string compile(string const& _input, CStyleReadFileCallback _readCallback = nullptr)
|
2017-03-16 23:48:51 +00:00
|
|
|
{
|
|
|
|
StandardCompiler compiler(wrapReadCallback(_readCallback));
|
|
|
|
return compiler.compile(_input);
|
|
|
|
}
|
|
|
|
|
2017-08-09 11:44:53 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 16:29:47 +00:00
|
|
|
static string s_outputBuffer;
|
2015-01-28 07:50:53 +00:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2018-09-27 00:53:34 +00:00
|
|
|
extern char const* solidity_license() noexcept
|
2017-06-13 20:47:33 +00:00
|
|
|
{
|
2017-06-30 14:59:53 +00:00
|
|
|
static string fullLicenseText = otherLicenses + licenseText;
|
|
|
|
return fullLicenseText.c_str();
|
2017-06-13 20:47:33 +00:00
|
|
|
}
|
2018-08-08 12:23:23 +00:00
|
|
|
extern char const* solidity_version() noexcept
|
2018-06-19 23:34:54 +00:00
|
|
|
{
|
2018-09-27 00:53:34 +00:00
|
|
|
return VersionString.c_str();
|
2018-06-19 23:34:54 +00:00
|
|
|
}
|
2018-08-08 12:23:23 +00:00
|
|
|
extern char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback) noexcept
|
2018-06-19 23:34:54 +00:00
|
|
|
{
|
2018-09-27 00:53:34 +00:00
|
|
|
s_outputBuffer = compile(_input, _readCallback);
|
|
|
|
return s_outputBuffer.c_str();
|
2018-06-19 23:34:54 +00:00
|
|
|
}
|
2019-01-22 11:41:21 +00:00
|
|
|
extern void solidity_free() noexcept
|
|
|
|
{
|
|
|
|
s_outputBuffer.clear();
|
|
|
|
}
|
2015-01-28 07:50:53 +00:00
|
|
|
}
|