2016-02-22 01:13:41 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2016-02-22 01:13:41 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2016-02-22 01:13:41 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2016-02-22 01:13:41 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-22 01:13:41 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2016
|
|
|
|
* Solidity inline assembly parser.
|
|
|
|
*/
|
|
|
|
|
2018-11-23 10:18:57 +00:00
|
|
|
#include <libyul/AsmParser.h>
|
2019-11-26 21:52:09 +00:00
|
|
|
#include <libyul/Exceptions.h>
|
2018-11-14 13:59:30 +00:00
|
|
|
#include <liblangutil/Scanner.h>
|
|
|
|
#include <liblangutil/ErrorReporter.h>
|
2019-03-04 14:38:05 +00:00
|
|
|
#include <libdevcore/Common.h>
|
2017-08-21 10:08:29 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2018-10-09 18:06:22 +00:00
|
|
|
#include <cctype>
|
2016-02-22 01:13:41 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace dev;
|
2018-11-14 16:11:55 +00:00
|
|
|
using namespace langutil;
|
2018-11-21 11:42:34 +00:00
|
|
|
using namespace yul;
|
2016-02-22 01:13:41 +00:00
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
shared_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
m_recursionDepth = 0;
|
2019-04-24 11:16:43 +00:00
|
|
|
|
|
|
|
_scanner->supportPeriodInIdentifier(true);
|
|
|
|
ScopeGuard resetScanner([&]{ _scanner->supportPeriodInIdentifier(false); });
|
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_scanner = _scanner;
|
2018-02-20 17:39:00 +00:00
|
|
|
auto block = make_shared<Block>(parseBlock());
|
|
|
|
if (!_reuseScanner)
|
|
|
|
expectToken(Token::EOS);
|
|
|
|
return block;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
catch (FatalError const&)
|
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
2019-04-24 11:16:43 +00:00
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-24 11:38:35 +00:00
|
|
|
std::map<string, dev::eth::Instruction> const& Parser::instructions()
|
|
|
|
{
|
|
|
|
// Allowed instructions, lowercase names.
|
|
|
|
static map<string, dev::eth::Instruction> s_instructions;
|
|
|
|
if (s_instructions.empty())
|
|
|
|
{
|
|
|
|
for (auto const& instruction: dev::eth::c_instructions)
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
instruction.second == dev::eth::Instruction::JUMPDEST ||
|
|
|
|
dev::eth::isPushInstruction(instruction.second)
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
string name = instruction.first;
|
|
|
|
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
|
|
|
|
s_instructions[name] = instruction.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s_instructions;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
Block Parser::parseBlock()
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2018-11-21 11:42:34 +00:00
|
|
|
Block block = createWithLocation<Block>();
|
2016-02-22 01:13:41 +00:00
|
|
|
expectToken(Token::LBrace);
|
2017-05-24 23:13:51 +00:00
|
|
|
while (currentToken() != Token::RBrace)
|
2016-02-22 01:13:41 +00:00
|
|
|
block.statements.emplace_back(parseStatement());
|
2016-04-18 11:47:40 +00:00
|
|
|
block.location.end = endPosition();
|
2017-05-24 23:13:51 +00:00
|
|
|
advance();
|
2016-02-22 01:13:41 +00:00
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
Statement Parser::parseStatement()
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2017-05-24 23:13:51 +00:00
|
|
|
switch (currentToken())
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
|
|
|
case Token::Let:
|
|
|
|
return parseVariableDeclaration();
|
2017-01-31 22:59:41 +00:00
|
|
|
case Token::Function:
|
|
|
|
return parseFunctionDefinition();
|
2016-02-22 01:13:41 +00:00
|
|
|
case Token::LBrace:
|
|
|
|
return parseBlock();
|
2017-11-21 12:36:41 +00:00
|
|
|
case Token::If:
|
|
|
|
{
|
2018-11-21 11:42:34 +00:00
|
|
|
If _if = createWithLocation<If>();
|
2019-02-21 19:19:39 +00:00
|
|
|
advance();
|
2019-01-09 13:05:03 +00:00
|
|
|
_if.condition = make_unique<Expression>(parseExpression());
|
2017-11-21 12:36:41 +00:00
|
|
|
_if.body = parseBlock();
|
2019-01-09 13:05:03 +00:00
|
|
|
return Statement{move(_if)};
|
2017-11-21 12:36:41 +00:00
|
|
|
}
|
2017-04-28 13:27:56 +00:00
|
|
|
case Token::Switch:
|
|
|
|
{
|
2018-11-21 11:42:34 +00:00
|
|
|
Switch _switch = createWithLocation<Switch>();
|
2019-02-21 19:19:39 +00:00
|
|
|
advance();
|
2019-01-09 13:05:03 +00:00
|
|
|
_switch.expression = make_unique<Expression>(parseExpression());
|
2019-02-21 19:19:39 +00:00
|
|
|
while (currentToken() == Token::Case)
|
2017-04-28 13:27:56 +00:00
|
|
|
_switch.cases.emplace_back(parseCase());
|
2019-02-21 19:19:39 +00:00
|
|
|
if (currentToken() == Token::Default)
|
2017-05-19 17:04:40 +00:00
|
|
|
_switch.cases.emplace_back(parseCase());
|
2019-02-21 19:19:39 +00:00
|
|
|
if (currentToken() == Token::Default)
|
2017-05-26 00:49:32 +00:00
|
|
|
fatalParserError("Only one default case allowed.");
|
2019-02-21 19:19:39 +00:00
|
|
|
else if (currentToken() == Token::Case)
|
2017-05-26 00:49:32 +00:00
|
|
|
fatalParserError("Case not allowed after default case.");
|
2018-10-09 03:29:37 +00:00
|
|
|
if (_switch.cases.empty())
|
2017-04-28 13:27:56 +00:00
|
|
|
fatalParserError("Switch statement without any cases.");
|
|
|
|
_switch.location.end = _switch.cases.back().body.location.end;
|
2019-01-09 13:05:03 +00:00
|
|
|
return Statement{move(_switch)};
|
2017-04-28 13:27:56 +00:00
|
|
|
}
|
2017-04-28 13:33:52 +00:00
|
|
|
case Token::For:
|
|
|
|
return parseForLoop();
|
2019-03-04 14:38:05 +00:00
|
|
|
case Token::Break:
|
2019-04-18 10:51:28 +00:00
|
|
|
{
|
|
|
|
Statement stmt{createWithLocation<Break>()};
|
|
|
|
checkBreakContinuePosition("break");
|
|
|
|
m_scanner->next();
|
|
|
|
return stmt;
|
|
|
|
}
|
2019-03-04 14:38:05 +00:00
|
|
|
case Token::Continue:
|
2019-04-18 10:51:28 +00:00
|
|
|
{
|
|
|
|
Statement stmt{createWithLocation<Continue>()};
|
|
|
|
checkBreakContinuePosition("continue");
|
|
|
|
m_scanner->next();
|
|
|
|
return stmt;
|
|
|
|
}
|
2016-02-22 01:13:41 +00:00
|
|
|
case Token::Assign:
|
|
|
|
{
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour != AsmFlavour::Loose)
|
2017-04-27 18:20:53 +00:00
|
|
|
break;
|
2018-11-21 11:42:34 +00:00
|
|
|
StackAssignment assignment = createWithLocation<StackAssignment>();
|
2017-05-24 23:13:51 +00:00
|
|
|
advance();
|
2016-02-22 01:13:41 +00:00
|
|
|
expectToken(Token::Colon);
|
2016-04-18 11:47:40 +00:00
|
|
|
assignment.variableName.location = location();
|
2018-10-29 14:12:02 +00:00
|
|
|
assignment.variableName.name = YulString(currentLiteral());
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.builtin(assignment.variableName.name))
|
2018-12-03 16:47:29 +00:00
|
|
|
fatalParserError("Identifier expected, got builtin symbol.");
|
|
|
|
else if (instructions().count(assignment.variableName.name.str()))
|
2017-01-26 12:52:02 +00:00
|
|
|
fatalParserError("Identifier expected, got instruction name.");
|
2016-04-18 11:47:40 +00:00
|
|
|
assignment.location.end = endPosition();
|
2016-02-22 01:13:41 +00:00
|
|
|
expectToken(Token::Identifier);
|
2019-01-09 13:05:03 +00:00
|
|
|
return Statement{move(assignment)};
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Options left:
|
|
|
|
// Simple instruction (might turn into functional),
|
|
|
|
// literal,
|
|
|
|
// identifier (might turn into label or functional assignment)
|
2018-01-06 00:09:08 +00:00
|
|
|
ElementaryOperation elementary(parseElementaryOperation());
|
2019-05-16 19:19:50 +00:00
|
|
|
|
2017-05-24 23:13:51 +00:00
|
|
|
switch (currentToken())
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
|
|
|
case Token::LParen:
|
2017-12-08 13:01:22 +00:00
|
|
|
{
|
|
|
|
Expression expr = parseCall(std::move(elementary));
|
|
|
|
return ExpressionStatement{locationOf(expr), expr};
|
|
|
|
}
|
2017-05-19 16:06:26 +00:00
|
|
|
case Token::Comma:
|
2019-02-18 14:07:15 +00:00
|
|
|
case Token::AssemblyAssign:
|
2017-05-19 16:06:26 +00:00
|
|
|
{
|
2019-02-18 14:07:15 +00:00
|
|
|
std::vector<Identifier> variableNames;
|
2017-05-19 16:06:26 +00:00
|
|
|
|
2019-02-18 14:07:15 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!holds_alternative<Identifier>(elementary))
|
2019-02-18 14:07:15 +00:00
|
|
|
{
|
|
|
|
auto const token = currentToken() == Token::Comma ? "," : ":=";
|
2017-05-19 16:06:26 +00:00
|
|
|
|
2019-02-18 14:07:15 +00:00
|
|
|
fatalParserError(
|
|
|
|
std::string("Variable name must precede \"") +
|
|
|
|
token +
|
|
|
|
"\"" +
|
|
|
|
(currentToken() == Token::Comma ? " in multiple assignment." : " in assignment.")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:42:49 +00:00
|
|
|
auto const& identifier = std::get<Identifier>(elementary);
|
2019-02-18 14:07:15 +00:00
|
|
|
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.builtin(identifier.name))
|
2019-02-18 14:07:15 +00:00
|
|
|
fatalParserError("Cannot assign to builtin function \"" + identifier.name.str() + "\".");
|
|
|
|
|
|
|
|
variableNames.emplace_back(identifier);
|
|
|
|
|
|
|
|
if (currentToken() != Token::Comma)
|
|
|
|
break;
|
2017-05-19 16:06:26 +00:00
|
|
|
|
|
|
|
expectToken(Token::Comma);
|
2019-02-18 14:07:15 +00:00
|
|
|
|
2018-01-06 00:09:08 +00:00
|
|
|
elementary = parseElementaryOperation();
|
2017-05-19 16:06:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 14:07:15 +00:00
|
|
|
Assignment assignment =
|
2019-11-19 15:42:49 +00:00
|
|
|
createWithLocation<Assignment>(std::get<Identifier>(elementary).location);
|
2019-02-18 14:07:15 +00:00
|
|
|
assignment.variableNames = std::move(variableNames);
|
|
|
|
|
|
|
|
expectToken(Token::AssemblyAssign);
|
2017-05-19 16:06:26 +00:00
|
|
|
|
2019-11-27 16:24:21 +00:00
|
|
|
assignment.value = make_unique<Expression>(parseExpression());
|
2017-05-19 16:06:26 +00:00
|
|
|
assignment.location.end = locationOf(*assignment.value).end;
|
2019-02-18 14:07:15 +00:00
|
|
|
|
2019-01-09 13:05:03 +00:00
|
|
|
return Statement{std::move(assignment)};
|
2017-05-19 16:06:26 +00:00
|
|
|
}
|
2016-02-22 01:13:41 +00:00
|
|
|
case Token::Colon:
|
|
|
|
{
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!holds_alternative<Identifier>(elementary))
|
2019-02-18 14:07:15 +00:00
|
|
|
fatalParserError("Label name must precede \":\".");
|
|
|
|
|
2019-11-19 15:42:49 +00:00
|
|
|
Identifier const& identifier = std::get<Identifier>(elementary);
|
2019-02-18 14:07:15 +00:00
|
|
|
|
2017-05-24 23:13:51 +00:00
|
|
|
advance();
|
2019-02-18 14:07:15 +00:00
|
|
|
|
|
|
|
// label
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour != AsmFlavour::Loose)
|
2019-02-18 14:07:15 +00:00
|
|
|
fatalParserError("Labels are not supported.");
|
|
|
|
|
|
|
|
Label label = createWithLocation<Label>(identifier.location);
|
|
|
|
label.name = identifier.name;
|
|
|
|
return label;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
default:
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour != AsmFlavour::Loose)
|
2017-05-02 08:24:35 +00:00
|
|
|
fatalParserError("Call or assignment expected.");
|
2016-02-22 01:13:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-05-16 19:19:50 +00:00
|
|
|
|
2019-11-19 15:42:49 +00:00
|
|
|
if (holds_alternative<Identifier>(elementary))
|
2017-12-08 13:01:22 +00:00
|
|
|
{
|
2019-11-19 15:42:49 +00:00
|
|
|
Identifier& identifier = std::get<Identifier>(elementary);
|
2019-05-22 14:46:04 +00:00
|
|
|
return ExpressionStatement{identifier.location, { move(identifier) }};
|
2017-12-08 13:01:22 +00:00
|
|
|
}
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (holds_alternative<Literal>(elementary))
|
2017-12-08 13:01:22 +00:00
|
|
|
{
|
2019-11-19 15:42:49 +00:00
|
|
|
Expression expr = std::get<Literal>(elementary);
|
2017-12-08 13:01:22 +00:00
|
|
|
return ExpressionStatement{locationOf(expr), expr};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(holds_alternative<Instruction>(elementary), "Invalid elementary operation.");
|
2019-11-19 15:42:49 +00:00
|
|
|
return std::get<Instruction>(elementary);
|
2017-12-08 13:01:22 +00:00
|
|
|
}
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
Case Parser::parseCase()
|
2017-04-28 13:27:56 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2018-11-21 11:42:34 +00:00
|
|
|
Case _case = createWithLocation<Case>();
|
2019-02-21 19:19:39 +00:00
|
|
|
if (currentToken() == Token::Default)
|
|
|
|
advance();
|
|
|
|
else if (currentToken() == Token::Case)
|
2017-04-28 13:27:56 +00:00
|
|
|
{
|
2019-02-21 19:19:39 +00:00
|
|
|
advance();
|
2017-12-08 13:01:22 +00:00
|
|
|
ElementaryOperation literal = parseElementaryOperation();
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!holds_alternative<Literal>(literal))
|
2017-05-17 10:21:37 +00:00
|
|
|
fatalParserError("Literal expected.");
|
2019-11-19 15:42:49 +00:00
|
|
|
_case.value = make_unique<Literal>(std::get<Literal>(std::move(literal)));
|
2017-04-28 13:27:56 +00:00
|
|
|
}
|
2017-05-19 17:04:40 +00:00
|
|
|
else
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(false, "Case or default case expected.");
|
2017-04-28 13:27:56 +00:00
|
|
|
_case.body = parseBlock();
|
|
|
|
_case.location.end = _case.body.location.end;
|
|
|
|
return _case;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
ForLoop Parser::parseForLoop()
|
2017-04-28 13:33:52 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2019-04-18 10:51:28 +00:00
|
|
|
|
|
|
|
ForLoopComponent outerForLoopComponent = m_currentForLoopComponent;
|
|
|
|
|
2017-04-28 13:33:52 +00:00
|
|
|
ForLoop forLoop = createWithLocation<ForLoop>();
|
|
|
|
expectToken(Token::For);
|
2019-04-18 10:51:28 +00:00
|
|
|
m_currentForLoopComponent = ForLoopComponent::ForLoopPre;
|
2017-04-28 13:33:52 +00:00
|
|
|
forLoop.pre = parseBlock();
|
2019-04-18 10:51:28 +00:00
|
|
|
m_currentForLoopComponent = ForLoopComponent::None;
|
2019-01-09 13:05:03 +00:00
|
|
|
forLoop.condition = make_unique<Expression>(parseExpression());
|
2019-04-18 10:51:28 +00:00
|
|
|
m_currentForLoopComponent = ForLoopComponent::ForLoopPost;
|
2017-04-28 13:33:52 +00:00
|
|
|
forLoop.post = parseBlock();
|
2019-04-18 10:51:28 +00:00
|
|
|
m_currentForLoopComponent = ForLoopComponent::ForLoopBody;
|
2017-04-28 13:33:52 +00:00
|
|
|
forLoop.body = parseBlock();
|
|
|
|
forLoop.location.end = forLoop.body.location.end;
|
2019-04-18 10:51:28 +00:00
|
|
|
|
|
|
|
m_currentForLoopComponent = outerForLoopComponent;
|
|
|
|
|
2017-04-28 13:33:52 +00:00
|
|
|
return forLoop;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
Expression Parser::parseExpression()
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2019-05-16 19:19:50 +00:00
|
|
|
|
2018-01-06 00:09:08 +00:00
|
|
|
ElementaryOperation operation = parseElementaryOperation();
|
2019-11-19 15:42:49 +00:00
|
|
|
if (holds_alternative<FunctionCall>(operation))
|
2019-05-16 19:19:50 +00:00
|
|
|
return parseCall(std::move(operation));
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (holds_alternative<Instruction>(operation))
|
2017-06-13 16:38:55 +00:00
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(m_dialect.flavour == AsmFlavour::Loose, "");
|
2019-11-19 15:42:49 +00:00
|
|
|
Instruction const& instr = std::get<Instruction>(operation);
|
2018-01-06 00:09:08 +00:00
|
|
|
// Disallow instructions returning multiple values (and DUP/SWAP) as expression.
|
|
|
|
if (
|
|
|
|
instructionInfo(instr.instruction).ret != 1 ||
|
|
|
|
isDupInstruction(instr.instruction) ||
|
|
|
|
isSwapInstruction(instr.instruction)
|
|
|
|
)
|
|
|
|
fatalParserError(
|
|
|
|
"Instruction \"" +
|
|
|
|
instructionNames().at(instr.instruction) +
|
|
|
|
"\" not allowed in this context."
|
|
|
|
);
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour != AsmFlavour::Loose && currentToken() != Token::LParen)
|
2018-01-09 17:30:14 +00:00
|
|
|
fatalParserError(
|
|
|
|
"Non-functional instructions are not allowed in this context."
|
|
|
|
);
|
2018-01-08 00:39:22 +00:00
|
|
|
// Enforce functional notation for instructions requiring multiple arguments.
|
|
|
|
int args = instructionInfo(instr.instruction).args;
|
2018-01-09 17:30:14 +00:00
|
|
|
if (args > 0 && currentToken() != Token::LParen)
|
2018-01-08 00:39:22 +00:00
|
|
|
fatalParserError(string(
|
2018-05-02 18:59:05 +00:00
|
|
|
"Expected '(' (instruction \"" +
|
2018-01-08 00:39:22 +00:00
|
|
|
instructionNames().at(instr.instruction) +
|
|
|
|
"\" expects " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(args) +
|
2018-01-08 00:39:22 +00:00
|
|
|
" arguments)"
|
|
|
|
));
|
2017-06-13 16:38:55 +00:00
|
|
|
}
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::LParen)
|
2017-05-24 00:26:17 +00:00
|
|
|
return parseCall(std::move(operation));
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (holds_alternative<Instruction>(operation))
|
2017-12-08 13:01:22 +00:00
|
|
|
{
|
2018-01-06 00:09:08 +00:00
|
|
|
// Instructions not taking arguments are allowed as expressions.
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(m_dialect.flavour == AsmFlavour::Loose, "");
|
2019-11-19 15:42:49 +00:00
|
|
|
Instruction& instr = std::get<Instruction>(operation);
|
2017-12-08 13:01:22 +00:00
|
|
|
return FunctionalInstruction{std::move(instr.location), instr.instruction, {}};
|
|
|
|
}
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (holds_alternative<Identifier>(operation))
|
|
|
|
return std::get<Identifier>(operation);
|
2016-02-22 01:13:41 +00:00
|
|
|
else
|
2017-12-08 13:01:22 +00:00
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(holds_alternative<Literal>(operation), "");
|
2019-11-19 15:42:49 +00:00
|
|
|
return std::get<Literal>(operation);
|
2017-12-08 13:01:22 +00:00
|
|
|
}
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 11:47:21 +00:00
|
|
|
std::map<dev::eth::Instruction, string> const& Parser::instructionNames()
|
2017-06-09 12:44:38 +00:00
|
|
|
{
|
2019-03-28 11:47:21 +00:00
|
|
|
static map<dev::eth::Instruction, string> s_instructionNames;
|
2017-06-09 12:44:38 +00:00
|
|
|
if (s_instructionNames.empty())
|
|
|
|
{
|
|
|
|
for (auto const& instr: instructions())
|
|
|
|
s_instructionNames[instr.second] = instr.first;
|
|
|
|
// set the ambiguous instructions to a clear default
|
2019-03-28 11:47:21 +00:00
|
|
|
s_instructionNames[dev::eth::Instruction::SELFDESTRUCT] = "selfdestruct";
|
|
|
|
s_instructionNames[dev::eth::Instruction::KECCAK256] = "keccak256";
|
2017-06-09 12:44:38 +00:00
|
|
|
}
|
|
|
|
return s_instructionNames;
|
|
|
|
}
|
|
|
|
|
2018-01-06 00:09:08 +00:00
|
|
|
Parser::ElementaryOperation Parser::parseElementaryOperation()
|
2017-01-25 10:33:09 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2017-12-08 13:01:22 +00:00
|
|
|
ElementaryOperation ret;
|
2017-05-24 23:13:51 +00:00
|
|
|
switch (currentToken())
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
|
|
|
case Token::Identifier:
|
2016-03-01 21:56:39 +00:00
|
|
|
case Token::Return:
|
2016-04-05 12:57:40 +00:00
|
|
|
case Token::Byte:
|
2019-06-18 16:12:30 +00:00
|
|
|
case Token::Bool:
|
2016-10-05 10:47:56 +00:00
|
|
|
case Token::Address:
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2019-06-18 16:12:30 +00:00
|
|
|
YulString literal{currentLiteral()};
|
2018-12-03 16:47:29 +00:00
|
|
|
// first search the set of builtins, then the instructions.
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.builtin(literal))
|
2019-05-16 19:19:50 +00:00
|
|
|
{
|
2019-05-22 14:46:04 +00:00
|
|
|
Identifier identifier{location(), literal};
|
2019-05-16 19:19:50 +00:00
|
|
|
advance();
|
2019-05-22 14:46:04 +00:00
|
|
|
// If the builtin is not followed by `(` and we are in loose mode,
|
|
|
|
// fall back to instruction.
|
|
|
|
if (
|
|
|
|
m_dialect.flavour == AsmFlavour::Loose &&
|
|
|
|
instructions().count(identifier.name.str()) &&
|
|
|
|
m_scanner->currentToken() != Token::LParen
|
|
|
|
)
|
|
|
|
return Instruction{identifier.location, instructions().at(identifier.name.str())};
|
|
|
|
else
|
|
|
|
return FunctionCall{identifier.location, identifier, {}};
|
2019-05-16 19:19:50 +00:00
|
|
|
}
|
|
|
|
else if (m_dialect.flavour == AsmFlavour::Loose && instructions().count(literal.str()))
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2019-03-28 11:47:21 +00:00
|
|
|
dev::eth::Instruction const& instr = instructions().at(literal.str());
|
2016-04-18 11:47:40 +00:00
|
|
|
ret = Instruction{location(), instr};
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
else
|
2018-12-03 16:47:15 +00:00
|
|
|
ret = Identifier{location(), literal};
|
2017-05-24 23:13:51 +00:00
|
|
|
advance();
|
2016-02-22 01:13:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::StringLiteral:
|
|
|
|
case Token::Number:
|
2017-05-02 17:26:33 +00:00
|
|
|
case Token::TrueLiteral:
|
|
|
|
case Token::FalseLiteral:
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-05-02 17:26:33 +00:00
|
|
|
LiteralKind kind = LiteralKind::Number;
|
2017-05-24 23:13:51 +00:00
|
|
|
switch (currentToken())
|
2017-05-02 17:26:33 +00:00
|
|
|
{
|
|
|
|
case Token::StringLiteral:
|
|
|
|
kind = LiteralKind::String;
|
|
|
|
break;
|
|
|
|
case Token::Number:
|
2017-08-21 10:08:29 +00:00
|
|
|
if (!isValidNumberLiteral(currentLiteral()))
|
|
|
|
fatalParserError("Invalid number literal.");
|
2017-05-02 17:26:33 +00:00
|
|
|
kind = LiteralKind::Number;
|
|
|
|
break;
|
|
|
|
case Token::TrueLiteral:
|
|
|
|
case Token::FalseLiteral:
|
|
|
|
kind = LiteralKind::Boolean;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-26 22:58:34 +00:00
|
|
|
Literal literal{
|
2016-04-18 11:47:40 +00:00
|
|
|
location(),
|
2017-05-02 17:26:33 +00:00
|
|
|
kind,
|
2018-10-29 14:12:02 +00:00
|
|
|
YulString{currentLiteral()},
|
|
|
|
{}
|
2016-02-22 01:13:41 +00:00
|
|
|
};
|
2017-05-24 23:13:51 +00:00
|
|
|
advance();
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour == AsmFlavour::Yul)
|
2017-04-26 22:58:34 +00:00
|
|
|
{
|
|
|
|
expectToken(Token::Colon);
|
|
|
|
literal.location.end = endPosition();
|
2018-12-03 16:47:15 +00:00
|
|
|
literal.type = expectAsmIdentifier();
|
2017-04-26 22:58:34 +00:00
|
|
|
}
|
2017-05-02 17:26:33 +00:00
|
|
|
else if (kind == LiteralKind::Boolean)
|
|
|
|
fatalParserError("True and false are not valid literals.");
|
2017-04-26 22:58:34 +00:00
|
|
|
ret = std::move(literal);
|
2016-04-18 11:47:40 +00:00
|
|
|
break;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
default:
|
2017-05-02 08:25:12 +00:00
|
|
|
fatalParserError(
|
2019-05-16 08:56:56 +00:00
|
|
|
m_dialect.flavour == AsmFlavour::Yul ?
|
2017-05-02 08:25:12 +00:00
|
|
|
"Literal or identifier expected." :
|
2017-05-26 08:41:53 +00:00
|
|
|
"Literal, identifier or instruction expected."
|
2017-05-02 08:25:12 +00:00
|
|
|
);
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
2016-04-18 11:47:40 +00:00
|
|
|
return ret;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
VariableDeclaration Parser::parseVariableDeclaration()
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2016-04-18 11:47:40 +00:00
|
|
|
VariableDeclaration varDecl = createWithLocation<VariableDeclaration>();
|
2016-02-22 01:13:41 +00:00
|
|
|
expectToken(Token::Let);
|
2017-05-05 17:35:40 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2017-05-26 08:41:53 +00:00
|
|
|
varDecl.variables.emplace_back(parseTypedName());
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::Comma)
|
2017-05-05 17:35:40 +00:00
|
|
|
expectToken(Token::Comma);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2019-02-18 14:07:15 +00:00
|
|
|
if (currentToken() == Token::AssemblyAssign)
|
2017-05-05 15:46:26 +00:00
|
|
|
{
|
2019-02-18 14:07:15 +00:00
|
|
|
expectToken(Token::AssemblyAssign);
|
2019-01-09 13:05:03 +00:00
|
|
|
varDecl.value = make_unique<Expression>(parseExpression());
|
2017-05-05 15:46:26 +00:00
|
|
|
varDecl.location.end = locationOf(*varDecl.value).end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
varDecl.location.end = varDecl.variables.back().location.end;
|
2016-04-18 11:47:40 +00:00
|
|
|
return varDecl;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
FunctionDefinition Parser::parseFunctionDefinition()
|
2017-01-31 22:59:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2019-04-18 16:10:45 +00:00
|
|
|
|
|
|
|
if (m_currentForLoopComponent == ForLoopComponent::ForLoopPre)
|
|
|
|
m_errorReporter.syntaxError(
|
|
|
|
location(),
|
|
|
|
"Functions cannot be defined inside a for-loop init block."
|
|
|
|
);
|
|
|
|
|
2019-04-18 10:51:28 +00:00
|
|
|
ForLoopComponent outerForLoopComponent = m_currentForLoopComponent;
|
|
|
|
m_currentForLoopComponent = ForLoopComponent::None;
|
|
|
|
|
2017-01-31 22:59:41 +00:00
|
|
|
FunctionDefinition funDef = createWithLocation<FunctionDefinition>();
|
|
|
|
expectToken(Token::Function);
|
2018-12-03 16:47:15 +00:00
|
|
|
funDef.name = expectAsmIdentifier();
|
2017-01-31 22:59:41 +00:00
|
|
|
expectToken(Token::LParen);
|
2017-05-24 23:13:51 +00:00
|
|
|
while (currentToken() != Token::RParen)
|
2017-01-31 22:59:41 +00:00
|
|
|
{
|
2017-12-01 13:10:49 +00:00
|
|
|
funDef.parameters.emplace_back(parseTypedName());
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::RParen)
|
2017-01-31 22:59:41 +00:00
|
|
|
break;
|
|
|
|
expectToken(Token::Comma);
|
|
|
|
}
|
|
|
|
expectToken(Token::RParen);
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::Sub)
|
2017-01-31 22:59:41 +00:00
|
|
|
{
|
|
|
|
expectToken(Token::Sub);
|
|
|
|
expectToken(Token::GreaterThan);
|
|
|
|
while (true)
|
|
|
|
{
|
2017-12-01 13:10:49 +00:00
|
|
|
funDef.returnVariables.emplace_back(parseTypedName());
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::LBrace)
|
2017-01-31 22:59:41 +00:00
|
|
|
break;
|
|
|
|
expectToken(Token::Comma);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
funDef.body = parseBlock();
|
|
|
|
funDef.location.end = funDef.body.location.end;
|
2019-04-18 10:51:28 +00:00
|
|
|
|
|
|
|
m_currentForLoopComponent = outerForLoopComponent;
|
2017-01-31 22:59:41 +00:00
|
|
|
return funDef;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2019-11-19 15:42:49 +00:00
|
|
|
if (holds_alternative<Instruction>(_initialOp))
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(m_dialect.flavour != AsmFlavour::Yul, "Instructions are invalid in Yul");
|
2019-11-19 15:42:49 +00:00
|
|
|
Instruction& instruction = std::get<Instruction>(_initialOp);
|
2017-02-01 20:20:21 +00:00
|
|
|
FunctionalInstruction ret;
|
2017-12-05 13:44:20 +00:00
|
|
|
ret.instruction = instruction.instruction;
|
|
|
|
ret.location = std::move(instruction.location);
|
2019-03-28 11:47:21 +00:00
|
|
|
dev::eth::Instruction instr = ret.instruction;
|
|
|
|
dev::eth::InstructionInfo instrInfo = instructionInfo(instr);
|
|
|
|
if (dev::eth::isDupInstruction(instr))
|
2017-02-01 20:20:21 +00:00
|
|
|
fatalParserError("DUPi instructions not allowed for functional notation");
|
2019-03-28 11:47:21 +00:00
|
|
|
if (dev::eth::isSwapInstruction(instr))
|
2017-02-01 20:20:21 +00:00
|
|
|
fatalParserError("SWAPi instructions not allowed for functional notation");
|
|
|
|
expectToken(Token::LParen);
|
|
|
|
unsigned args = unsigned(instrInfo.args);
|
|
|
|
for (unsigned i = 0; i < args; ++i)
|
2016-04-18 11:47:40 +00:00
|
|
|
{
|
2017-05-24 12:13:05 +00:00
|
|
|
/// check for premature closing parentheses
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::RParen)
|
2017-05-24 12:13:05 +00:00
|
|
|
fatalParserError(string(
|
2018-05-02 18:59:05 +00:00
|
|
|
"Expected expression (instruction \"" +
|
2017-06-09 12:44:38 +00:00
|
|
|
instructionNames().at(instr) +
|
|
|
|
"\" expects " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(args) +
|
2017-05-24 12:27:58 +00:00
|
|
|
" arguments)"
|
2017-05-24 12:13:05 +00:00
|
|
|
));
|
|
|
|
|
2017-02-01 20:20:21 +00:00
|
|
|
ret.arguments.emplace_back(parseExpression());
|
|
|
|
if (i != args - 1)
|
|
|
|
{
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() != Token::Comma)
|
2017-02-01 20:20:21 +00:00
|
|
|
fatalParserError(string(
|
2018-05-02 18:59:05 +00:00
|
|
|
"Expected ',' (instruction \"" +
|
2017-06-09 12:44:38 +00:00
|
|
|
instructionNames().at(instr) +
|
|
|
|
"\" expects " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(args) +
|
2017-02-01 20:20:21 +00:00
|
|
|
" arguments)"
|
|
|
|
));
|
|
|
|
else
|
2017-05-24 23:13:51 +00:00
|
|
|
advance();
|
2017-02-01 20:20:21 +00:00
|
|
|
}
|
2016-04-18 11:47:40 +00:00
|
|
|
}
|
2017-02-01 20:20:21 +00:00
|
|
|
ret.location.end = endPosition();
|
2017-05-24 23:13:51 +00:00
|
|
|
if (currentToken() == Token::Comma)
|
2017-06-09 12:44:38 +00:00
|
|
|
fatalParserError(string(
|
2018-05-02 18:59:05 +00:00
|
|
|
"Expected ')' (instruction \"" +
|
2017-06-09 12:44:38 +00:00
|
|
|
instructionNames().at(instr) +
|
|
|
|
"\" expects " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(args) +
|
2017-06-09 12:44:38 +00:00
|
|
|
" arguments)"
|
|
|
|
));
|
2017-02-01 20:20:21 +00:00
|
|
|
expectToken(Token::RParen);
|
|
|
|
return ret;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (holds_alternative<Identifier>(_initialOp) || holds_alternative<FunctionCall>(_initialOp))
|
2017-02-01 20:20:21 +00:00
|
|
|
{
|
|
|
|
FunctionCall ret;
|
2019-11-19 15:42:49 +00:00
|
|
|
if (holds_alternative<Identifier>(_initialOp))
|
2019-05-16 19:19:50 +00:00
|
|
|
{
|
2019-11-19 15:42:49 +00:00
|
|
|
ret.functionName = std::move(std::get<Identifier>(_initialOp));
|
2019-05-16 19:19:50 +00:00
|
|
|
ret.location = ret.functionName.location;
|
|
|
|
}
|
|
|
|
else
|
2019-11-19 15:42:49 +00:00
|
|
|
ret = std::move(std::get<FunctionCall>(_initialOp));
|
2017-02-01 20:20:21 +00:00
|
|
|
expectToken(Token::LParen);
|
2019-06-06 11:16:27 +00:00
|
|
|
if (currentToken() != Token::RParen)
|
2017-02-01 20:20:21 +00:00
|
|
|
{
|
|
|
|
ret.arguments.emplace_back(parseExpression());
|
2019-06-06 11:16:27 +00:00
|
|
|
while (currentToken() != Token::RParen)
|
|
|
|
{
|
|
|
|
expectToken(Token::Comma);
|
|
|
|
ret.arguments.emplace_back(parseExpression());
|
|
|
|
}
|
2017-02-01 20:20:21 +00:00
|
|
|
}
|
|
|
|
ret.location.end = endPosition();
|
|
|
|
expectToken(Token::RParen);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
2017-05-02 08:25:12 +00:00
|
|
|
fatalParserError(
|
2019-05-16 08:56:56 +00:00
|
|
|
m_dialect.flavour == AsmFlavour::Yul ?
|
2017-05-02 08:25:12 +00:00
|
|
|
"Function name expected." :
|
|
|
|
"Assembly instruction or function name required in front of \"(\")"
|
|
|
|
);
|
2017-02-01 20:20:21 +00:00
|
|
|
|
|
|
|
return {};
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
2017-01-31 22:59:41 +00:00
|
|
|
|
2017-04-26 22:58:34 +00:00
|
|
|
TypedName Parser::parseTypedName()
|
|
|
|
{
|
2017-08-21 10:33:29 +00:00
|
|
|
RecursionGuard recursionGuard(*this);
|
2017-04-26 22:58:34 +00:00
|
|
|
TypedName typedName = createWithLocation<TypedName>();
|
2018-12-03 16:47:15 +00:00
|
|
|
typedName.name = expectAsmIdentifier();
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour == AsmFlavour::Yul)
|
2017-04-26 22:58:34 +00:00
|
|
|
{
|
|
|
|
expectToken(Token::Colon);
|
|
|
|
typedName.location.end = endPosition();
|
2018-12-03 16:47:15 +00:00
|
|
|
typedName.type = expectAsmIdentifier();
|
2017-04-26 22:58:34 +00:00
|
|
|
}
|
|
|
|
return typedName;
|
|
|
|
}
|
|
|
|
|
2018-12-03 16:47:15 +00:00
|
|
|
YulString Parser::expectAsmIdentifier()
|
2017-01-31 22:59:41 +00:00
|
|
|
{
|
2019-06-18 16:12:30 +00:00
|
|
|
YulString name{currentLiteral()};
|
|
|
|
switch (currentToken())
|
2017-05-17 12:33:05 +00:00
|
|
|
{
|
2019-06-18 16:12:30 +00:00
|
|
|
case Token::Return:
|
|
|
|
case Token::Byte:
|
|
|
|
case Token::Address:
|
|
|
|
case Token::Bool:
|
|
|
|
case Token::Identifier:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
expectToken(Token::Identifier);
|
|
|
|
break;
|
2017-05-17 12:33:05 +00:00
|
|
|
}
|
2019-06-18 16:12:30 +00:00
|
|
|
|
|
|
|
if (m_dialect.builtin(name))
|
2018-12-03 16:47:29 +00:00
|
|
|
fatalParserError("Cannot use builtin function name \"" + name.str() + "\" as identifier name.");
|
2019-06-18 16:12:30 +00:00
|
|
|
else if (m_dialect.flavour == AsmFlavour::Loose && instructions().count(name.str()))
|
|
|
|
fatalParserError("Cannot use instruction name \"" + name.str() + "\" as identifier name.");
|
|
|
|
advance();
|
2017-01-31 22:59:41 +00:00
|
|
|
return name;
|
|
|
|
}
|
2017-08-21 10:08:29 +00:00
|
|
|
|
2019-04-18 10:51:28 +00:00
|
|
|
void Parser::checkBreakContinuePosition(string const& _which)
|
|
|
|
{
|
|
|
|
switch (m_currentForLoopComponent)
|
|
|
|
{
|
|
|
|
case ForLoopComponent::None:
|
|
|
|
m_errorReporter.syntaxError(location(), "Keyword \"" + _which + "\" needs to be inside a for-loop body.");
|
|
|
|
break;
|
|
|
|
case ForLoopComponent::ForLoopPre:
|
|
|
|
m_errorReporter.syntaxError(location(), "Keyword \"" + _which + "\" in for-loop init block is not allowed.");
|
|
|
|
break;
|
|
|
|
case ForLoopComponent::ForLoopPost:
|
|
|
|
m_errorReporter.syntaxError(location(), "Keyword \"" + _which + "\" in for-loop post block is not allowed.");
|
|
|
|
break;
|
|
|
|
case ForLoopComponent::ForLoopBody:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 10:08:29 +00:00
|
|
|
bool Parser::isValidNumberLiteral(string const& _literal)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-05-17 10:19:29 +00:00
|
|
|
// Try to convert _literal to u256.
|
|
|
|
auto tmp = u256(_literal);
|
|
|
|
(void) tmp;
|
2017-08-21 10:08:29 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (boost::starts_with(_literal, "0x"))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return _literal.find_first_not_of("0123456789") == string::npos;
|
|
|
|
}
|