diff options
Diffstat (limited to 'solc/jsonCompiler.cpp')
-rw-r--r-- | solc/jsonCompiler.cpp | 80 |
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(); +} } |