Pragma stdlib.

This commit is contained in:
chriseth 2022-07-14 16:25:11 +02:00 committed by Nikola Matic
parent 8af62d66af
commit 2d490a0213
5 changed files with 27 additions and 3 deletions

View File

@ -72,6 +72,8 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit)
} }
if (!m_sourceUnit->annotation().useABICoderV2.set()) if (!m_sourceUnit->annotation().useABICoderV2.set())
m_sourceUnit->annotation().useABICoderV2 = true; m_sourceUnit->annotation().useABICoderV2 = true;
if (!m_sourceUnit->annotation().useStdlib.set())
m_sourceUnit->annotation().useStdlib = false;
m_sourceUnit = nullptr; m_sourceUnit = nullptr;
} }
@ -176,6 +178,19 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
solAssert(false); solAssert(false);
} }
} }
else if (_pragma.literals()[0] == "stdlib")
{
solAssert(m_sourceUnit, "");
if (m_evmVersion < EVMVersion::constantinople())
m_errorReporter.syntaxError(
6634_error,
_pragma.location(),
"\"pragma stdlib\" requires Constantinople EVM version at the minimum (selected EVM version is " +
m_evmVersion.name() +
")."
);
m_sourceUnit->annotation().useStdlib = true;
}
else else
m_errorReporter.syntaxError(4936_error, _pragma.location(), "Unknown pragma \"" + _pragma.literals()[0] + "\""); m_errorReporter.syntaxError(4936_error, _pragma.location(), "Unknown pragma \"" + _pragma.literals()[0] + "\"");

View File

@ -45,9 +45,10 @@ class SyntaxChecker: private ASTConstVisitor
{ {
public: public:
/// @param _errorReporter provides the error logging functionality. /// @param _errorReporter provides the error logging functionality.
SyntaxChecker(langutil::ErrorReporter& _errorReporter, bool _useYulOptimizer): SyntaxChecker(langutil::ErrorReporter& _errorReporter, bool _useYulOptimizer, langutil::EVMVersion _evmVersion):
m_errorReporter(_errorReporter), m_errorReporter(_errorReporter),
m_useYulOptimizer(_useYulOptimizer) m_useYulOptimizer(_useYulOptimizer),
m_evmVersion(_evmVersion)
{} {}
bool checkSyntax(ASTNode const& _astRoot); bool checkSyntax(ASTNode const& _astRoot);
@ -101,6 +102,8 @@ private:
bool m_useYulOptimizer = false; bool m_useYulOptimizer = false;
langutil::EVMVersion m_evmVersion;
/// Flag that indicates whether a function modifier actually contains '_'. /// Flag that indicates whether a function modifier actually contains '_'.
bool m_placeholderFound = false; bool m_placeholderFound = false;

View File

@ -97,6 +97,8 @@ struct SourceUnitAnnotation: ASTAnnotation
std::set<ExperimentalFeature> experimentalFeatures; std::set<ExperimentalFeature> experimentalFeatures;
/// Using the new ABI coder. Set to `false` if using ABI coder v1. /// Using the new ABI coder. Set to `false` if using ABI coder v1.
util::SetOnce<bool> useABICoderV2; util::SetOnce<bool> useABICoderV2;
/// Using the new standard library mechanism.
util::SetOnce<bool> useStdlib;
}; };
struct ScopableAnnotation struct ScopableAnnotation

View File

@ -444,7 +444,7 @@ bool CompilerStack::analyze()
try try
{ {
SyntaxChecker syntaxChecker(m_errorReporter, m_optimiserSettings.runYulOptimiser); SyntaxChecker syntaxChecker(m_errorReporter, m_optimiserSettings.runYulOptimiser, m_evmVersion);
for (Source const* source: m_sourceOrder) for (Source const* source: m_sourceOrder)
if (source->ast && !syntaxChecker.checkSyntax(*source->ast)) if (source->ast && !syntaxChecker.checkSyntax(*source->ast))
noErrors = false; noErrors = false;

View File

@ -0,0 +1,4 @@
pragma stdlib;
// ====
// EVMVersion: <constantinople
// ----