aboutsummaryrefslogtreecommitdiffstats
path: root/libyul
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-04 22:29:20 +0800
committerGitHub <noreply@github.com>2018-12-04 22:29:20 +0800
commit126ed2e990280b7200a7872d8d6f5b8db14e4b0a (patch)
tree89624148ff8018c19742a737c45ed4a7c3dff573 /libyul
parent8654f8f6d4cb8f609d5b43df217aff1406acbe6a (diff)
parent852297fa2f4c4ac0c3aa56011f70c667fafcb1fd (diff)
downloaddexon-solidity-126ed2e990280b7200a7872d8d6f5b8db14e4b0a.tar.gz
dexon-solidity-126ed2e990280b7200a7872d8d6f5b8db14e4b0a.tar.zst
dexon-solidity-126ed2e990280b7200a7872d8d6f5b8db14e4b0a.zip
Merge pull request #5583 from ethereum/builtins3
Analysis phase for builtin funtions.
Diffstat (limited to 'libyul')
-rw-r--r--libyul/AsmAnalysis.cpp8
-rw-r--r--libyul/AsmParser.cpp16
2 files changed, 19 insertions, 5 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/libyul/AsmParser.cpp b/libyul/AsmParser.cpp
index 5f393b29..33bb42f9 100644
--- a/libyul/AsmParser.cpp
+++ b/libyul/AsmParser.cpp
@@ -114,7 +114,9 @@ Statement Parser::parseStatement()
expectToken(Token::Colon);
assignment.variableName.location = location();
assignment.variableName.name = YulString(currentLiteral());
- if (instructions().count(assignment.variableName.name.str()))
+ if (m_dialect.builtins->query(assignment.variableName.name))
+ fatalParserError("Identifier expected, got builtin symbol.");
+ else if (instructions().count(assignment.variableName.name.str()))
fatalParserError("Identifier expected, got instruction name.");
assignment.location.end = endPosition();
expectToken(Token::Identifier);
@@ -174,7 +176,9 @@ Statement Parser::parseStatement()
if (currentToken() == Token::Assign && peekNextToken() != Token::Colon)
{
Assignment assignment = createWithLocation<Assignment>(identifier.location);
- if (m_dialect.flavour != AsmFlavour::Yul && instructions().count(identifier.name.str()))
+ if (m_dialect.builtins->query(identifier.name))
+ fatalParserError("Cannot assign to builtin function \"" + identifier.name.str() + "\".");
+ else if (m_dialect.flavour != AsmFlavour::Yul && instructions().count(identifier.name.str()))
fatalParserError("Cannot use instruction names for identifier names.");
advance();
assignment.variableNames.emplace_back(identifier);
@@ -357,8 +361,10 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
literal = YulString{"address"};
else
literal = YulString{currentLiteral()};
- // first search the set of instructions.
- if (m_dialect.flavour != AsmFlavour::Yul && instructions().count(literal.str()))
+ // first search the set of builtins, then the instructions.
+ if (m_dialect.builtins->query(literal))
+ ret = Identifier{location(), literal};
+ else if (m_dialect.flavour != AsmFlavour::Yul && instructions().count(literal.str()))
{
dev::solidity::Instruction const& instr = instructions().at(literal.str());
ret = Instruction{location(), instr};
@@ -592,6 +598,8 @@ YulString Parser::expectAsmIdentifier()
break;
}
}
+ else if (m_dialect.builtins->query(name))
+ fatalParserError("Cannot use builtin function name \"" + name.str() + "\" as identifier name.");
else if (instructions().count(name.str()))
fatalParserError("Cannot use instruction names for identifier names.");
expectToken(Token::Identifier);