From 2a07c6dfdc53ab417261a0bf08284903f33a9dab Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 27 Jun 2022 00:18:33 +0200 Subject: [PATCH] Add CompilerStack.setStdlib --- libsolidity/interface/CompilerStack.cpp | 13 ++++++++++++- libsolidity/interface/CompilerStack.h | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index a3d05bd23..3b55a8ae9 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -218,6 +218,13 @@ void CompilerStack::setViaIR(bool _viaIR) m_viaIR = _viaIR; } +void CompilerStack::setStdlib(bool _stdlib) +{ + if (m_stackState >= ParsedAndImported) + solThrow(CompilerError, "Must set stdlib before parsing."); + m_stdlib = _stdlib; +} + void CompilerStack::setEVMVersion(langutil::EVMVersion _version) { if (m_stackState >= ParsedAndImported) @@ -340,6 +347,10 @@ bool CompilerStack::parse() Parser parser{m_errorReporter, m_evmVersion, m_parserErrorRecovery}; + if (m_stdlib) { + // TODO: fill out m_sources + } + vector sourcesToParse; for (auto const& s: m_sources) sourcesToParse.push_back(s.first); @@ -433,7 +444,7 @@ bool CompilerStack::analyze() if (source->ast && !syntaxChecker.checkSyntax(*source->ast)) noErrors = false; - m_globalContext = make_shared(false); + m_globalContext = make_shared(m_stdlib); // We need to keep the same resolver during the whole process. NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_errorReporter); for (Source const* source: m_sourceOrder) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index e5bc9b345..b45f30e01 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -169,6 +169,10 @@ public: /// Must be set before parsing. void setViaIR(bool _viaIR); + /// Sets the pipeline to use the stdlib or not. + /// Must be set before parsing. + void setStdlib(bool _stdlib); + /// Set the EVM version used before running compile. /// When called without an argument it will revert to the default version. /// Must be set before parsing. @@ -487,6 +491,7 @@ private: RevertStrings m_revertStrings = RevertStrings::Default; State m_stopAfter = State::CompilationSuccessful; bool m_viaIR = false; + bool m_stdlib = false; langutil::EVMVersion m_evmVersion; ModelCheckerSettings m_modelCheckerSettings; std::map> m_requestedContractNames;