diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-07-09 18:30:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-09 18:30:11 +0800 |
commit | c42583d27e7d93b982bdd44dc536994ac0be874f (patch) | |
tree | e467c4710a7920a30f0a7277adc7d018acabff95 | |
parent | f3e0bf1dd85fef29bf80f2235b5c0c19a6d30f31 (diff) | |
parent | 328554a4f91bbd77fc9a901e0bde66eb16d988ea (diff) | |
download | dexon-solidity-c42583d27e7d93b982bdd44dc536994ac0be874f.tar.gz dexon-solidity-c42583d27e7d93b982bdd44dc536994ac0be874f.tar.zst dexon-solidity-c42583d27e7d93b982bdd44dc536994ac0be874f.zip |
Merge pull request #4366 from ethereum/libsolc-cleanup
Implement new libsolc API
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libsolc/libsolc.cpp | 15 | ||||
-rw-r--r-- | libsolc/libsolc.h | 4 | ||||
-rw-r--r-- | test/libsolidity/LibSolc.cpp (renamed from test/libsolidity/JSONCompiler.cpp) | 24 |
5 files changed, 43 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 34343a8b..8cd0b4b7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -43,6 +43,7 @@ Language Features: * General: Scoping rules now follow the C99-style. Compiler Features: + * C API (``libsolc``): Export the ``solidity_license``, ``solidity_version`` and ``solidity_compile`` methods. * Type Checker: Show named argument in case of error. * Tests: Determine transaction status during IPC calls. diff --git a/libsolc/CMakeLists.txt b/libsolc/CMakeLists.txt index e67583dd..63fc1a83 100644 --- a/libsolc/CMakeLists.txt +++ b/libsolc/CMakeLists.txt @@ -1,5 +1,5 @@ if (EMSCRIPTEN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='[\"_compileJSON\",\"_license\",\"_version\",\"_compileJSONMulti\",\"_compileJSONCallback\",\"_compileStandard\"]' -s RESERVED_FUNCTION_POINTERS=20") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='[\"_solidity_license\",\"_solidity_version\",\"_solidity_compile\",\"_license\",\"_version\",\"_compileJSON\",\"_compileJSONMulti\",\"_compileJSONCallback\",\"_compileStandard\"]' -s RESERVED_FUNCTION_POINTERS=20") add_executable(soljson libsolc.cpp) target_link_libraries(soljson PRIVATE solidity) else() diff --git a/libsolc/libsolc.cpp b/libsolc/libsolc.cpp index 6c587e23..26ce98ce 100644 --- a/libsolc/libsolc.cpp +++ b/libsolc/libsolc.cpp @@ -299,4 +299,19 @@ extern char const* compileStandard(char const* _input, CStyleReadFileCallback _r s_outputBuffer = compileStandardInternal(_input, _readCallback); return s_outputBuffer.c_str(); } +extern char const* solidity_license() +{ + /// todo: make this the default or an alias + return license(); +} +extern char const* solidity_version() +{ + /// todo: make this the default or an alias + return version(); +} +extern char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback) +{ + /// todo: make this the default or an alias + return compileStandard(_input, _readCallback); +} } diff --git a/libsolc/libsolc.h b/libsolc/libsolc.h index c392ce93..2cc004d4 100644 --- a/libsolc/libsolc.h +++ b/libsolc/libsolc.h @@ -37,6 +37,10 @@ char const* compileJSONMulti(char const* _input, bool _optimize); char const* compileJSONCallback(char const* _input, bool _optimize, CStyleReadFileCallback _readCallback); char const* compileStandard(char const* _input, CStyleReadFileCallback _readCallback); +char const* solidity_license(); +char const* solidity_version(); +char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback); + #ifdef __cplusplus } #endif diff --git a/test/libsolidity/JSONCompiler.cpp b/test/libsolidity/LibSolc.cpp index 2b3df3a7..9d5ffa27 100644 --- a/test/libsolidity/JSONCompiler.cpp +++ b/test/libsolidity/LibSolc.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for solc/jsonCompiler.cpp. + * Unit tests for libsolc/libsolc.cpp. */ #include <string> @@ -70,7 +70,7 @@ Json::Value compile(string const& _input) } // end anonymous namespace -BOOST_AUTO_TEST_SUITE(JSONCompiler) +BOOST_AUTO_TEST_SUITE(LibSolc) BOOST_AUTO_TEST_CASE(read_version) { @@ -201,6 +201,26 @@ BOOST_AUTO_TEST_CASE(standard_compilation) BOOST_CHECK(result.isMember("contracts")); } +BOOST_AUTO_TEST_CASE(new_api) +{ + char const* input = R"( + { + "language": "Solidity", + "sources": { + "fileA": { + "content": "contract A { }" + } + } + } + )"; + BOOST_CHECK_EQUAL(string(version()), string(solidity_version())); + BOOST_CHECK_EQUAL(string(license()), string(solidity_license())); + BOOST_CHECK_EQUAL( + string(compileStandard(input, nullptr)), + string(solidity_compile(input, nullptr)) + ); +} + BOOST_AUTO_TEST_SUITE_END() } |