diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 083dc570c..291bbc255 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -441,7 +441,7 @@ void CompilerContext::appendInlineAssembly( locationOverride = m_asm->currentSourceLocation(); shared_ptr parserResult = yul::Parser(errorReporter, dialect, std::move(locationOverride)) - .parse(make_shared(charStream), false); + .parse(charStream); #ifdef SOL_OUTPUT_ASM cout << yul::AsmPrinter(&dialect)(*parserResult) << endl; #endif @@ -492,7 +492,7 @@ void CompilerContext::appendInlineAssembly( m_generatedYulUtilityCode = yul::AsmPrinter(dialect)(*obj.code); string code = yul::AsmPrinter{dialect}(*obj.code); langutil::CharStream charStream(m_generatedYulUtilityCode, _sourceName); - obj.code = yul::Parser(errorReporter, dialect).parse(make_shared(charStream), false); + obj.code = yul::Parser(errorReporter, dialect).parse(charStream); *obj.analysisInfo = yul::AsmAnalyzer::analyzeStrictAssertCorrect(dialect, obj); } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 757fdebc3..cbdfff454 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -755,9 +755,8 @@ Json::Value CompilerStack::generatedSources(string const& _contractName, bool _r ErrorList errors; ErrorReporter errorReporter(errors); CharStream charStream(source, sourceName); - shared_ptr scanner = make_shared(charStream); yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion); - shared_ptr parserResult = yul::Parser{errorReporter, dialect}.parse(scanner, false); + shared_ptr parserResult = yul::Parser{errorReporter, dialect}.parse(charStream); solAssert(parserResult, ""); sources[0]["ast"] = yul::AsmJsonConverter{sourceIndex}(*parserResult); sources[0]["name"] = sourceName; diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index c5a62c76e..efb31545a 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1301,7 +1301,7 @@ ASTPointer Parser::parseInlineAssembly(ASTPointer con } yul::Parser asmParser(m_errorReporter, dialect); - shared_ptr block = asmParser.parse(m_scanner, true); + shared_ptr block = asmParser.parseInline(m_scanner); if (block == nullptr) BOOST_THROW_EXCEPTION(FatalError()); diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index b5e542926..d1465c737 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -85,7 +85,15 @@ std::shared_ptr Parser::createDebugData() const solAssert(false, ""); } -unique_ptr Parser::parse(std::shared_ptr const& _scanner, bool _reuseScanner) +unique_ptr Parser::parse(CharStream& _charStream) +{ + m_scanner = make_shared(_charStream); + unique_ptr block = parseInline(m_scanner); + expectToken(Token::EOS); + return block; +} + +unique_ptr Parser::parseInline(std::shared_ptr const& _scanner) { m_recursionDepth = 0; @@ -97,10 +105,7 @@ unique_ptr Parser::parse(std::shared_ptr const& _scanner, bool _ m_scanner = _scanner; if (m_sourceNames) fetchSourceLocationFromComment(); - auto block = make_unique(parseBlock()); - if (!_reuseScanner) - expectToken(Token::EOS); - return block; + return make_unique(parseBlock()); } catch (FatalError const&) { diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h index c386bbe6f..da6eb7226 100644 --- a/libyul/AsmParser.h +++ b/libyul/AsmParser.h @@ -87,10 +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 parse(std::shared_ptr const& _scanner, bool _reuseScanner); - // TODO: pass CharStream here instead ^^^^^^ + std::unique_ptr parseInline(std::shared_ptr 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 parse(langutil::CharStream& _charStream); protected: langutil::SourceLocation currentLocation() const override diff --git a/libyul/ObjectParser.cpp b/libyul/ObjectParser.cpp index 347096a3b..d100351b2 100644 --- a/libyul/ObjectParser.cpp +++ b/libyul/ObjectParser.cpp @@ -168,7 +168,7 @@ optional ObjectParser::tryParseSourceNameMapping() shared_ptr ObjectParser::parseBlock() { Parser parser(m_errorReporter, m_dialect, m_sourceNameMapping); - shared_ptr block = parser.parse(m_scanner, true); + shared_ptr block = parser.parseInline(m_scanner); yulAssert(block || m_errorReporter.hasErrors(), "Invalid block but no error!"); return block; } diff --git a/libyul/backends/wasm/EVMToEwasmTranslator.cpp b/libyul/backends/wasm/EVMToEwasmTranslator.cpp index 418d0dbcb..a5d355ede 100644 --- a/libyul/backends/wasm/EVMToEwasmTranslator.cpp +++ b/libyul/backends/wasm/EVMToEwasmTranslator.cpp @@ -136,10 +136,7 @@ void EVMToEwasmTranslator::parsePolyfill() string(solidity::yul::wasm::polyfill::Logical) + string(solidity::yul::wasm::polyfill::Memory) + "}", ""); - m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse( - make_shared(charStream), - false - ); + m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(charStream); if (!errors.empty()) { string message; diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 3cea20dde..4a95f625e 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -56,7 +55,6 @@ shared_ptr parse(string const& _source, Dialect const& _dialect, ErrorRep try { auto stream = CharStream(_source, ""); - auto scanner = make_shared(stream); map> indicesToSourceNames; indicesToSourceNames[0] = make_shared("source0"); indicesToSourceNames[1] = make_shared("source1"); @@ -65,7 +63,7 @@ shared_ptr parse(string const& _source, Dialect const& _dialect, ErrorRep errorReporter, _dialect, move(indicesToSourceNames) - ).parse(scanner, false); + ).parse(stream); if (parserResult) { yul::AsmAnalysisInfo analysisInfo; diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index 284561473..357311595 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +44,6 @@ #include #include -#include #include #include @@ -92,8 +90,7 @@ public: { ErrorReporter errorReporter(m_errors); m_charStream = make_shared(_input, ""); - m_scanner = make_shared(*m_charStream); - m_ast = yul::Parser(errorReporter, m_dialect).parse(m_scanner, false); + m_ast = yul::Parser(errorReporter, m_dialect).parse(*m_charStream); if (!m_ast || !errorReporter.errors().empty()) { cerr << "Error parsing source." << endl; @@ -236,7 +233,6 @@ public: private: ErrorList m_errors; shared_ptr m_charStream; - shared_ptr m_scanner; shared_ptr m_ast; Dialect const& m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})}; shared_ptr m_analysisInfo;