mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11658 from ethereum/removeScannerFromCompilerStack
Remove scanner from compiler stack
This commit is contained in:
@@ -166,7 +166,8 @@ Literal AsmJsonImporter::createLiteral(Json::Value const& _node)
|
||||
|
||||
if (kind == "number")
|
||||
{
|
||||
langutil::Scanner scanner{langutil::CharStream(lit.value.str(), "")};
|
||||
langutil::CharStream charStream(lit.value.str(), "");
|
||||
langutil::Scanner scanner{charStream};
|
||||
lit.kind = LiteralKind::Number;
|
||||
yulAssert(
|
||||
scanner.currentToken() == Token::Number,
|
||||
@@ -175,7 +176,8 @@ Literal AsmJsonImporter::createLiteral(Json::Value const& _node)
|
||||
}
|
||||
else if (kind == "bool")
|
||||
{
|
||||
langutil::Scanner scanner{langutil::CharStream(lit.value.str(), "")};
|
||||
langutil::CharStream charStream(lit.value.str(), "");
|
||||
langutil::Scanner scanner{charStream};
|
||||
lit.kind = LiteralKind::Boolean;
|
||||
yulAssert(
|
||||
scanner.currentToken() == Token::TrueLiteral ||
|
||||
|
||||
+10
-5
@@ -85,7 +85,15 @@ std::shared_ptr<DebugData const> Parser::createDebugData() const
|
||||
solAssert(false, "");
|
||||
}
|
||||
|
||||
unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
|
||||
unique_ptr<Block> Parser::parse(CharStream& _charStream)
|
||||
{
|
||||
m_scanner = make_shared<Scanner>(_charStream);
|
||||
unique_ptr<Block> block = parseInline(m_scanner);
|
||||
expectToken(Token::EOS);
|
||||
return block;
|
||||
}
|
||||
|
||||
unique_ptr<Block> Parser::parseInline(std::shared_ptr<Scanner> const& _scanner)
|
||||
{
|
||||
m_recursionDepth = 0;
|
||||
|
||||
@@ -97,10 +105,7 @@ unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _
|
||||
m_scanner = _scanner;
|
||||
if (m_sourceNames)
|
||||
fetchSourceLocationFromComment();
|
||||
auto block = make_unique<Block>(parseBlock());
|
||||
if (!_reuseScanner)
|
||||
expectToken(Token::EOS);
|
||||
return block;
|
||||
return make_unique<Block>(parseBlock());
|
||||
}
|
||||
catch (FatalError const&)
|
||||
{
|
||||
|
||||
+6
-2
@@ -87,9 +87,13 @@ public:
|
||||
{}
|
||||
|
||||
/// Parses an inline assembly block starting with `{` and ending with `}`.
|
||||
/// @param _reuseScanner if true, do check for end of input after the `}`.
|
||||
/// @returns an empty shared pointer on error.
|
||||
std::unique_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
||||
std::unique_ptr<Block> parseInline(std::shared_ptr<langutil::Scanner> const& _scanner);
|
||||
|
||||
/// Parses an assembly block starting with `{` and ending with `}`
|
||||
/// and expects end of input after the '}'.
|
||||
/// @returns an empty shared pointer on error.
|
||||
std::unique_ptr<Block> parse(langutil::CharStream& _charStream);
|
||||
|
||||
protected:
|
||||
langutil::SourceLocation currentLocation() const override
|
||||
|
||||
@@ -131,7 +131,8 @@ optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
|
||||
|
||||
solAssert(sm.size() == 2, "");
|
||||
auto text = m_scanner->currentCommentLiteral().substr(static_cast<size_t>(sm.position() + sm.length()));
|
||||
Scanner scanner(make_shared<CharStream>(text, ""));
|
||||
CharStream charStream(text, "");
|
||||
Scanner scanner(charStream);
|
||||
if (scanner.currentToken() == Token::EOS)
|
||||
return SourceNameMap{};
|
||||
SourceNameMap sourceNames;
|
||||
@@ -168,7 +169,7 @@ optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
|
||||
shared_ptr<Block> ObjectParser::parseBlock()
|
||||
{
|
||||
Parser parser(m_errorReporter, m_dialect, m_sourceNameMapping);
|
||||
shared_ptr<Block> block = parser.parse(m_scanner, true);
|
||||
shared_ptr<Block> block = parser.parseInline(m_scanner);
|
||||
yulAssert(block || m_errorReporter.hasErrors(), "Invalid block but no error!");
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ void EVMToEwasmTranslator::parsePolyfill()
|
||||
{
|
||||
ErrorList errors;
|
||||
ErrorReporter errorReporter(errors);
|
||||
shared_ptr<Scanner> scanner{make_shared<Scanner>(CharStream(
|
||||
CharStream charStream(
|
||||
"{" +
|
||||
string(solidity::yul::wasm::polyfill::Arithmetic) +
|
||||
string(solidity::yul::wasm::polyfill::Bitwise) +
|
||||
@@ -135,15 +135,15 @@ void EVMToEwasmTranslator::parsePolyfill()
|
||||
string(solidity::yul::wasm::polyfill::Keccak) +
|
||||
string(solidity::yul::wasm::polyfill::Logical) +
|
||||
string(solidity::yul::wasm::polyfill::Memory) +
|
||||
"}", ""))};
|
||||
m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(scanner, false);
|
||||
"}", "");
|
||||
m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(charStream);
|
||||
if (!errors.empty())
|
||||
{
|
||||
string message;
|
||||
for (auto const& err: errors)
|
||||
message += langutil::SourceReferenceFormatter::formatErrorInformation(
|
||||
*err,
|
||||
SingletonCharStreamProvider(*scanner->charStream())
|
||||
SingletonCharStreamProvider(charStream)
|
||||
);
|
||||
yulAssert(false, message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user