diff options
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 5 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 10 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 3 | ||||
-rw-r--r-- | solc/CommandLineInterface.cpp | 4 | ||||
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.h | 3 |
5 files changed, 17 insertions, 8 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index e5bb58d2..89e024b3 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -87,6 +87,7 @@ void CompilerStack::reset(bool _keepSources) m_stackState = Empty; m_sources.clear(); } + m_libraries.clear(); m_optimize = false; m_optimizeRuns = 200; m_globalContext.reset(); @@ -261,8 +262,7 @@ vector<string> CompilerStack::contractNames() const return contractNames; } - -bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> const& _libraries) +bool CompilerStack::compile(bool _optimize, unsigned _runs) { if (m_stackState < AnalysisSuccessful) if (!parseAndAnalyze()) @@ -270,7 +270,6 @@ bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> co m_optimize = _optimize; m_optimizeRuns = _runs; - m_libraries = _libraries; map<ContractDefinition const*, eth::Assembly const*> compiledContracts; for (Source const* source: m_sourceOrder) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 1bfb193d..39875c32 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -96,6 +96,13 @@ public: /// Sets path remappings in the format "context:prefix=target" void setRemappings(std::vector<std::string> const& _remappings); + /// Sets library addresses. Addresses are cleared iff @a _libraries is missing. + /// Will not take effect before running compile. + void setLibraries(std::map<std::string, h160> const& _libraries = std::map<std::string, h160>{}) + { + m_libraries = _libraries; + } + /// Resets the compiler to a state where the sources are not parsed or even removed. /// Sets the state to SourcesSet if @a _keepSources is true, otherwise to Empty. /// All settings, with the exception of remappings, are reset. @@ -121,8 +128,7 @@ public: /// @returns false on error. bool compile( bool _optimize = false, - unsigned _runs = 200, - std::map<std::string, h160> const& _libraries = std::map<std::string, h160>{} + unsigned _runs = 200 ); /// @returns the assembled object for a contract. diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 82eeac3d..1690f3cc 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -259,6 +259,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) // @TODO use libraries only for the given source libraries[library] = h160(jsonSourceName[library].asString()); } + m_compilerStack.setLibraries(libraries); Json::Value metadataSettings = settings.get("metadata", Json::Value()); m_compilerStack.useMetadataLiteralSources(metadataSettings.get("useLiteralContent", Json::Value(false)).asBool()); @@ -267,7 +268,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) try { - m_compilerStack.compile(optimize, optimizeRuns, libraries); + m_compilerStack.compile(optimize, optimizeRuns); for (auto const& error: m_compilerStack.errors()) { diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index db497d84..38f72713 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -774,10 +774,12 @@ bool CommandLineInterface::processInput() m_compiler->setRemappings(m_args[g_argInputFile].as<vector<string>>()); for (auto const& sourceCode: m_sourceCodes) m_compiler->addSource(sourceCode.first, sourceCode.second); + if (m_args.count(g_argLibraries)) + m_compiler->setLibraries(m_libraries); // TODO: Perhaps we should not compile unless requested bool optimize = m_args.count(g_argOptimize) > 0; unsigned runs = m_args[g_argOptimizeRuns].as<unsigned>(); - bool successful = m_compiler->compile(optimize, runs, m_libraries); + bool successful = m_compiler->compile(optimize, runs); for (auto const& error: m_compiler->errors()) SourceReferenceFormatter::printExceptionInformation( diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index 03e3a881..6a13423b 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -56,7 +56,8 @@ public: std::string sourceCode = "pragma solidity >=0.0;\n" + _sourceCode; m_compiler.reset(false); m_compiler.addSource("", sourceCode); - if (!m_compiler.compile(m_optimize, m_optimizeRuns, _libraryAddresses)) + m_compiler.setLibraries(_libraryAddresses); + if (!m_compiler.compile(m_optimize, m_optimizeRuns)) { for (auto const& error: m_compiler.errors()) SourceReferenceFormatter::printExceptionInformation( |