diff options
author | chriseth <chris@ethereum.org> | 2018-12-04 18:23:28 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-12-04 21:50:00 +0800 |
commit | 852297fa2f4c4ac0c3aa56011f70c667fafcb1fd (patch) | |
tree | 89624148ff8018c19742a737c45ed4a7c3dff573 | |
parent | c3fc2da7637eb7f7d0c8930845b373fc0ea5be78 (diff) | |
download | dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.tar dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.tar.gz dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.tar.bz2 dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.tar.lz dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.tar.xz dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.tar.zst dexon-solidity-852297fa2f4c4ac0c3aa56011f70c667fafcb1fd.zip |
Builtin functions for yul analysis.
-rw-r--r-- | libyul/AsmAnalysis.cpp | 8 | ||||
-rw-r--r-- | test/libyul/Parser.cpp | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 5215e5c2..3cbed9c7 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -299,7 +299,13 @@ bool AsmAnalyzer::operator()(FunctionCall const& _funCall) bool success = true; size_t parameters = 0; size_t returns = 0; - if (!m_currentScope->lookup(_funCall.functionName.name, Scope::Visitor( + if (BuiltinFunction const* f = m_dialect.builtins->query(_funCall.functionName.name)) + { + // TODO: compare types, too + parameters = f->parameters.size(); + returns = f->returns.size(); + } + else if (!m_currentScope->lookup(_funCall.functionName.name, Scope::Visitor( [&](Scope::Variable const&) { m_errorReporter.typeError( diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index fe66847f..eb2e735a 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -22,10 +22,12 @@ #include <test/Options.h> #include <test/libsolidity/ErrorCheck.h> +#include <test/libyul/Common.h> #include <libyul/AsmParser.h> #include <libyul/AsmAnalysis.h> #include <libyul/AsmAnalysisInfo.h> +#include <libyul/Dialect.h> #include <liblangutil/Scanner.h> #include <liblangutil/ErrorReporter.h> @@ -319,6 +321,23 @@ BOOST_AUTO_TEST_CASE(builtins_parser) CHECK_ERROR_DIALECT("{ builtin := 6 }", ParserError, "Cannot assign to builtin function \"builtin\".", dialect); } +BOOST_AUTO_TEST_CASE(builtins_analysis) +{ + struct SimpleBuiltinsAnalysis: public Builtins + { + yul::BuiltinFunction const* query(YulString _name) const override + { + return _name == YulString("builtin") ? &m_builtin : nullptr; + } + BuiltinFunction m_builtin{YulString{"builtin"}, vector<Type>(2), vector<Type>(3), false}; + }; + + Dialect dialect(AsmFlavour::Strict, make_shared<SimpleBuiltinsAnalysis>()); + BOOST_CHECK(successParse("{ let a, b, c := builtin(1, 2) }", dialect)); + CHECK_ERROR_DIALECT("{ let a, b, c := builtin(1) }", TypeError, "Function expects 2 arguments but got 1", dialect); + CHECK_ERROR_DIALECT("{ let a, b := builtin(1, 2) }", DeclarationError, "Variable count mismatch: 2 variables and 3 values.", dialect); +} + BOOST_AUTO_TEST_SUITE_END() } |