mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Simplify AsmParser::parse(.) usage
This commit is contained in:
parent
ffc5cfd9a5
commit
6294aa871a
@ -441,7 +441,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
locationOverride = m_asm->currentSourceLocation();
|
||||
shared_ptr<yul::Block> parserResult =
|
||||
yul::Parser(errorReporter, dialect, std::move(locationOverride))
|
||||
.parse(make_shared<langutil::Scanner>(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<Scanner>(charStream), false);
|
||||
obj.code = yul::Parser(errorReporter, dialect).parse(charStream);
|
||||
*obj.analysisInfo = yul::AsmAnalyzer::analyzeStrictAssertCorrect(dialect, obj);
|
||||
}
|
||||
|
||||
|
@ -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> scanner = make_shared<Scanner>(charStream);
|
||||
yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion);
|
||||
shared_ptr<yul::Block> parserResult = yul::Parser{errorReporter, dialect}.parse(scanner, false);
|
||||
shared_ptr<yul::Block> parserResult = yul::Parser{errorReporter, dialect}.parse(charStream);
|
||||
solAssert(parserResult, "");
|
||||
sources[0]["ast"] = yul::AsmJsonConverter{sourceIndex}(*parserResult);
|
||||
sources[0]["name"] = sourceName;
|
||||
|
@ -1301,7 +1301,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
|
||||
}
|
||||
|
||||
yul::Parser asmParser(m_errorReporter, dialect);
|
||||
shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true);
|
||||
shared_ptr<yul::Block> block = asmParser.parseInline(m_scanner);
|
||||
if (block == nullptr)
|
||||
BOOST_THROW_EXCEPTION(FatalError());
|
||||
|
||||
|
@ -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&)
|
||||
{
|
||||
|
@ -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<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
||||
// TODO: pass CharStream here instead ^^^^^^
|
||||
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
|
||||
|
@ -168,7 +168,7 @@ optional<ObjectParser::SourceNameMap> ObjectParser::tryParseSourceNameMapping()
|
||||
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;
|
||||
}
|
||||
|
@ -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<Scanner>(charStream),
|
||||
false
|
||||
);
|
||||
m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(charStream);
|
||||
if (!errors.empty())
|
||||
{
|
||||
string message;
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <libyul/AsmAnalysis.h>
|
||||
#include <libyul/AsmAnalysisInfo.h>
|
||||
#include <libyul/Dialect.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
@ -56,7 +55,6 @@ shared_ptr<Block> parse(string const& _source, Dialect const& _dialect, ErrorRep
|
||||
try
|
||||
{
|
||||
auto stream = CharStream(_source, "");
|
||||
auto scanner = make_shared<Scanner>(stream);
|
||||
map<unsigned, shared_ptr<string const>> indicesToSourceNames;
|
||||
indicesToSourceNames[0] = make_shared<string const>("source0");
|
||||
indicesToSourceNames[1] = make_shared<string const>("source1");
|
||||
@ -65,7 +63,7 @@ shared_ptr<Block> parse(string const& _source, Dialect const& _dialect, ErrorRep
|
||||
errorReporter,
|
||||
_dialect,
|
||||
move(indicesToSourceNames)
|
||||
).parse(scanner, false);
|
||||
).parse(stream);
|
||||
if (parserResult)
|
||||
{
|
||||
yul::AsmAnalysisInfo analysisInfo;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <libsolutil/CommonIO.h>
|
||||
#include <libsolutil/Exceptions.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <libyul/AsmAnalysis.h>
|
||||
#include <libyul/AsmAnalysisInfo.h>
|
||||
#include <libsolidity/parsing/Parser.h>
|
||||
@ -45,7 +44,6 @@
|
||||
|
||||
#include <libsolidity/interface/OptimiserSettings.h>
|
||||
#include <liblangutil/CharStreamProvider.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
@ -92,8 +90,7 @@ public:
|
||||
{
|
||||
ErrorReporter errorReporter(m_errors);
|
||||
m_charStream = make_shared<CharStream>(_input, "");
|
||||
m_scanner = make_shared<Scanner>(*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<CharStream> m_charStream;
|
||||
shared_ptr<Scanner> m_scanner;
|
||||
shared_ptr<yul::Block> m_ast;
|
||||
Dialect const& m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})};
|
||||
shared_ptr<AsmAnalysisInfo> m_analysisInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user