diff options
author | chriseth <chris@ethereum.org> | 2017-07-03 19:23:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-03 19:23:28 +0800 |
commit | 2b233e73889d047a036227a22e60a4d32e837d43 (patch) | |
tree | 984ecac8318de86b484cec34a79289b0e915a44d /libsolidity/interface | |
parent | aa262d5c8febadd067539c1e05232b1b8c91b4f5 (diff) | |
parent | 75c193e9595c290967d14a5e203f0a6192c10aa2 (diff) | |
download | dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.tar dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.tar.gz dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.tar.bz2 dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.tar.lz dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.tar.xz dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.tar.zst dexon-solidity-2b233e73889d047a036227a22e60a4d32e837d43.zip |
Merge pull request #2507 from ethereum/jsonio-safe
Handle parsing errors in StandardCompiler
Diffstat (limited to 'libsolidity/interface')
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 18 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 13 |
2 files changed, 17 insertions, 14 deletions
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index c51ae9c9..03a1b806 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -77,6 +77,14 @@ enum class DocumentationType: uint8_t class CompilerStack: boost::noncopyable { public: + enum State { + Empty, + SourcesSet, + ParsingSuccessful, + AnalysisSuccessful, + CompilationSuccessful + }; + /// Creates a new compiler stack. /// @param _readFile callback to used to read files for import statements. Must return /// and must not emit exceptions. @@ -194,6 +202,8 @@ public: /// @returns the list of errors that occured during parsing and type checking. ErrorList const& errors() { return m_errorReporter.errors(); } + State state() const { return m_stackState; } + private: /** * Information pertaining to one source unit, filled gradually during parsing and compilation. @@ -220,14 +230,6 @@ private: mutable std::unique_ptr<std::string const> sourceMapping; mutable std::unique_ptr<std::string const> runtimeSourceMapping; }; - enum State { - Empty, - SourcesSet, - ParsingSuccessful, - AnalysisSuccessful, - CompilationSuccessful - }; - /// Loads the missing sources from @a _ast (named @a _path) using the callback /// @a m_readFile and stores the absolute paths of all imports in the AST annotations. /// @returns the newly loaded sources. diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 2e5005b8..e677afc8 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -265,11 +265,9 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compilerStack.scanner(_sourceName); }; - bool success = false; - try { - success = m_compilerStack.compile(optimize, optimizeRuns, libraries); + m_compilerStack.compile(optimize, optimizeRuns, libraries); for (auto const& error: m_compilerStack.errors()) { @@ -359,13 +357,16 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) if (errors.size() > 0) output["errors"] = errors; + bool parsingSuccess = m_compilerStack.state() >= CompilerStack::State::ParsingSuccessful; + bool compilationSuccess = m_compilerStack.state() == CompilerStack::State::CompilationSuccessful; + /// Inconsistent state - stop here to receive error reports from users - if (!success && (errors.size() == 0)) + if (!compilationSuccess && (errors.size() == 0)) return formatFatalError("InternalCompilerError", "No error reported, but compilation failed."); output["sources"] = Json::objectValue; unsigned sourceIndex = 0; - for (auto const& source: m_compilerStack.sourceNames()) + for (auto const& source: parsingSuccess ? m_compilerStack.sourceNames() : vector<string>()) { Json::Value sourceResult = Json::objectValue; sourceResult["id"] = sourceIndex++; @@ -375,7 +376,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) } Json::Value contractsOutput = Json::objectValue; - for (string const& contractName: success ? m_compilerStack.contractNames() : vector<string>()) + for (string const& contractName: compilationSuccess ? m_compilerStack.contractNames() : vector<string>()) { size_t colon = contractName.find(':'); solAssert(colon != string::npos, ""); |