aboutsummaryrefslogtreecommitdiffstats
path: root/solc
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-03-17 07:48:51 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-21 02:38:00 +0800
commit4f3c76364c5f76c42f28fcaeb28f57946545a61a (patch)
tree0677cde5e755cd4d804708c101cec2c29c695093 /solc
parent985db17e1eb74badb02d2ea6ba23b0d1e7dbc969 (diff)
downloaddexon-solidity-4f3c76364c5f76c42f28fcaeb28f57946545a61a.tar.gz
dexon-solidity-4f3c76364c5f76c42f28fcaeb28f57946545a61a.tar.zst
dexon-solidity-4f3c76364c5f76c42f28fcaeb28f57946545a61a.zip
Export StandardCompiler as compileStandard in soljson
Diffstat (limited to 'solc')
-rw-r--r--solc/jsonCompiler.cpp80
1 files changed, 49 insertions, 31 deletions
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp
index fd375ce3..42c25de0 100644
--- a/solc/jsonCompiler.cpp
+++ b/solc/jsonCompiler.cpp
@@ -36,6 +36,7 @@
#include <libsolidity/analysis/NameAndTypeResolver.h>
#include <libsolidity/interface/Exceptions.h>
#include <libsolidity/interface/CompilerStack.h>
+#include <libsolidity/interface/StandardCompiler.h>
#include <libsolidity/interface/SourceReferenceFormatter.h>
#include <libsolidity/ast/ASTJsonConverter.h>
#include <libsolidity/interface/Version.h>
@@ -50,6 +51,41 @@ extern "C" {
typedef void (*CStyleReadFileCallback)(char const* _path, char** o_contents, char** o_error);
}
+ReadFile::Callback wrapReadCallback(CStyleReadFileCallback _readCallback = nullptr)
+{
+ ReadFile::Callback readCallback;
+ if (_readCallback)
+ {
+ readCallback = [=](string const& _path)
+ {
+ char* contents_c = nullptr;
+ char* error_c = nullptr;
+ _readCallback(_path.c_str(), &contents_c, &error_c);
+ ReadFile::Result result;
+ result.success = true;
+ if (!contents_c && !error_c)
+ {
+ result.success = false;
+ result.contentsOrErrorMessage = "File not found.";
+ }
+ if (contents_c)
+ {
+ result.success = true;
+ result.contentsOrErrorMessage = string(contents_c);
+ free(contents_c);
+ }
+ if (error_c)
+ {
+ result.success = false;
+ result.contentsOrErrorMessage = string(error_c);
+ free(error_c);
+ }
+ return result;
+ };
+ }
+ return readCallback;
+}
+
Json::Value functionHashes(ContractDefinition const& _contract)
{
Json::Value functionHashes(Json::objectValue);
@@ -103,37 +139,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
{
Json::Value output(Json::objectValue);
Json::Value errors(Json::arrayValue);
- ReadFile::Callback readCallback;
- if (_readCallback)
- {
- readCallback = [=](string const& _path)
- {
- char* contents_c = nullptr;
- char* error_c = nullptr;
- _readCallback(_path.c_str(), &contents_c, &error_c);
- ReadFile::Result result;
- result.success = true;
- if (!contents_c && !error_c)
- {
- result.success = false;
- result.contentsOrErrorMessage = "File not found.";
- }
- if (contents_c)
- {
- result.success = true;
- result.contentsOrErrorMessage = string(contents_c);
- free(contents_c);
- }
- if (error_c)
- {
- result.success = false;
- result.contentsOrErrorMessage = string(error_c);
- free(error_c);
- }
- return result;
- };
- }
- CompilerStack compiler(readCallback);
+ CompilerStack compiler(wrapReadCallback(_readCallback));
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return compiler.scanner(_sourceName); };
bool success = false;
try
@@ -287,6 +293,13 @@ string compileSingle(string const& _input, bool _optimize)
return compile(sources, _optimize, nullptr);
}
+
+string compileStandardInternal(string const& _input, CStyleReadFileCallback _readCallback = nullptr)
+{
+ StandardCompiler compiler(wrapReadCallback(_readCallback));
+ return compiler.compile(_input);
+}
+
static string s_outputBuffer;
extern "C"
@@ -310,4 +323,9 @@ extern char const* compileJSONCallback(char const* _input, bool _optimize, CStyl
s_outputBuffer = compileMulti(_input, _optimize, _readCallback);
return s_outputBuffer.c_str();
}
+extern char const* compileStandard(char const* _input, CStyleReadFileCallback _readCallback)
+{
+ s_outputBuffer = compileStandardInternal(_input, _readCallback);
+ return s_outputBuffer.c_str();
+}
}