diff options
author | chriseth <c@ethdev.com> | 2015-10-15 23:12:22 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-10-16 00:29:56 +0800 |
commit | 52ef07695ab665f22a6ae1a85d88197a35bcf086 (patch) | |
tree | 193ad918ad9f4e7dbd02e1a01829f1ba796f54aa /solc/jsonCompiler.cpp | |
parent | 7ba42f470753f9af25531017f319cf94eb26d3f2 (diff) | |
download | dexon-solidity-52ef07695ab665f22a6ae1a85d88197a35bcf086.tar.gz dexon-solidity-52ef07695ab665f22a6ae1a85d88197a35bcf086.tar.zst dexon-solidity-52ef07695ab665f22a6ae1a85d88197a35bcf086.zip |
Multiple sources for json compiler.
Diffstat (limited to 'solc/jsonCompiler.cpp')
-rw-r--r-- | solc/jsonCompiler.cpp | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index 0746fc88..b117325d 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -114,18 +114,16 @@ Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract) return gasEstimates; } -string compile(string _input, bool _optimize) +string compile(StringMap const& _sources, bool _optimize) { - StringMap sources; - sources[""] = _input; - Json::Value output(Json::objectValue); Json::Value errors(Json::arrayValue); CompilerStack compiler; bool success = false; try { - bool succ = compiler.compile(_input, _optimize); + compiler.addSources(_sources); + bool succ = compiler.compile(_optimize); for (auto const& error: compiler.errors()) { auto err = dynamic_pointer_cast<Error const>(error); @@ -175,18 +173,51 @@ string compile(string _input, bool _optimize) contractData["functionHashes"] = functionHashes(compiler.contractDefinition(contractName)); contractData["gasEstimates"] = estimateGas(compiler, contractName); ostringstream unused; - contractData["assembly"] = compiler.streamAssembly(unused, contractName, sources, true); + contractData["assembly"] = compiler.streamAssembly(unused, contractName, _sources, true); output["contracts"][contractName] = contractData; } output["sources"] = Json::Value(Json::objectValue); - output["sources"][""] = Json::Value(Json::objectValue); - output["sources"][""]["AST"] = ASTJsonConverter(compiler.ast("")).json(); + for (auto const& source: _sources) + { + output["sources"][source.first] = Json::Value(Json::objectValue); + output["sources"][source.first]["AST"] = ASTJsonConverter(compiler.ast(source.first)).json(); + } } return Json::FastWriter().write(output); } +string compileMulti(string const& _input, bool _optimize) +{ + Json::Reader reader; + Json::Value input; + if (!reader.parse(_input, input, false)) + { + Json::Value errors(Json::arrayValue); + errors.append("Error parsing input JSON: " + reader.getFormattedErrorMessages()); + Json::Value output(Json::objectValue); + output["errors"] = errors; + return Json::FastWriter().write(output); + } + else + { + StringMap sources; + Json::Value jsonSources = input["sources"]; + if (jsonSources.isObject()) + for (auto const& sourceName: jsonSources.getMemberNames()) + sources[sourceName] = jsonSources[sourceName].asString(); + return compile(sources, _optimize); + } +} + +string compileSingle(string const& _input, bool _optimize) +{ + StringMap sources; + sources[""] = _input; + return compile(sources, _optimize); +} + static string outputBuffer; extern "C" @@ -197,7 +228,12 @@ extern char const* version() } extern char const* compileJSON(char const* _input, bool _optimize) { - outputBuffer = compile(_input, _optimize); + outputBuffer = compileSingle(_input, _optimize); + return outputBuffer.c_str(); +} +extern char const* compileJSONMulti(char const* _input, bool _optimize) +{ + outputBuffer = compileMulti(_input, _optimize); return outputBuffer.c_str(); } } |