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();
|
locationOverride = m_asm->currentSourceLocation();
|
||||||
shared_ptr<yul::Block> parserResult =
|
shared_ptr<yul::Block> parserResult =
|
||||||
yul::Parser(errorReporter, dialect, std::move(locationOverride))
|
yul::Parser(errorReporter, dialect, std::move(locationOverride))
|
||||||
.parse(make_shared<langutil::Scanner>(charStream), false);
|
.parse(charStream);
|
||||||
#ifdef SOL_OUTPUT_ASM
|
#ifdef SOL_OUTPUT_ASM
|
||||||
cout << yul::AsmPrinter(&dialect)(*parserResult) << endl;
|
cout << yul::AsmPrinter(&dialect)(*parserResult) << endl;
|
||||||
#endif
|
#endif
|
||||||
@ -492,7 +492,7 @@ void CompilerContext::appendInlineAssembly(
|
|||||||
m_generatedYulUtilityCode = yul::AsmPrinter(dialect)(*obj.code);
|
m_generatedYulUtilityCode = yul::AsmPrinter(dialect)(*obj.code);
|
||||||
string code = yul::AsmPrinter{dialect}(*obj.code);
|
string code = yul::AsmPrinter{dialect}(*obj.code);
|
||||||
langutil::CharStream charStream(m_generatedYulUtilityCode, _sourceName);
|
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);
|
*obj.analysisInfo = yul::AsmAnalyzer::analyzeStrictAssertCorrect(dialect, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,9 +755,8 @@ Json::Value CompilerStack::generatedSources(string const& _contractName, bool _r
|
|||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
ErrorReporter errorReporter(errors);
|
ErrorReporter errorReporter(errors);
|
||||||
CharStream charStream(source, sourceName);
|
CharStream charStream(source, sourceName);
|
||||||
shared_ptr<Scanner> scanner = make_shared<Scanner>(charStream);
|
|
||||||
yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion);
|
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, "");
|
solAssert(parserResult, "");
|
||||||
sources[0]["ast"] = yul::AsmJsonConverter{sourceIndex}(*parserResult);
|
sources[0]["ast"] = yul::AsmJsonConverter{sourceIndex}(*parserResult);
|
||||||
sources[0]["name"] = sourceName;
|
sources[0]["name"] = sourceName;
|
||||||
|
@ -1301,7 +1301,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
|
|||||||
}
|
}
|
||||||
|
|
||||||
yul::Parser asmParser(m_errorReporter, dialect);
|
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)
|
if (block == nullptr)
|
||||||
BOOST_THROW_EXCEPTION(FatalError());
|
BOOST_THROW_EXCEPTION(FatalError());
|
||||||
|
|
||||||
|
@ -85,7 +85,15 @@ std::shared_ptr<DebugData const> Parser::createDebugData() const
|
|||||||
solAssert(false, "");
|
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;
|
m_recursionDepth = 0;
|
||||||
|
|
||||||
@ -97,10 +105,7 @@ unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _
|
|||||||
m_scanner = _scanner;
|
m_scanner = _scanner;
|
||||||
if (m_sourceNames)
|
if (m_sourceNames)
|
||||||
fetchSourceLocationFromComment();
|
fetchSourceLocationFromComment();
|
||||||
auto block = make_unique<Block>(parseBlock());
|
return make_unique<Block>(parseBlock());
|
||||||
if (!_reuseScanner)
|
|
||||||
expectToken(Token::EOS);
|
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
catch (FatalError const&)
|
catch (FatalError const&)
|
||||||
{
|
{
|
||||||
|
@ -87,10 +87,13 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
/// Parses an inline assembly block starting with `{` and ending with `}`.
|
/// 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.
|
/// @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);
|
||||||
// TODO: pass CharStream here instead ^^^^^^
|
|
||||||
|
/// 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:
|
protected:
|
||||||
langutil::SourceLocation currentLocation() const override
|
langutil::SourceLocation currentLocation() const override
|
||||||
|
@ -168,7 +168,7 @@ optional<ObjectParser::SourceNameMap> ObjectParser::tryParseSourceNameMapping()
|
|||||||
shared_ptr<Block> ObjectParser::parseBlock()
|
shared_ptr<Block> ObjectParser::parseBlock()
|
||||||
{
|
{
|
||||||
Parser parser(m_errorReporter, m_dialect, m_sourceNameMapping);
|
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!");
|
yulAssert(block || m_errorReporter.hasErrors(), "Invalid block but no error!");
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
@ -136,10 +136,7 @@ void EVMToEwasmTranslator::parsePolyfill()
|
|||||||
string(solidity::yul::wasm::polyfill::Logical) +
|
string(solidity::yul::wasm::polyfill::Logical) +
|
||||||
string(solidity::yul::wasm::polyfill::Memory) +
|
string(solidity::yul::wasm::polyfill::Memory) +
|
||||||
"}", "");
|
"}", "");
|
||||||
m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(
|
m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(charStream);
|
||||||
make_shared<Scanner>(charStream),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
if (!errors.empty())
|
if (!errors.empty())
|
||||||
{
|
{
|
||||||
string message;
|
string message;
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <libyul/AsmAnalysis.h>
|
#include <libyul/AsmAnalysis.h>
|
||||||
#include <libyul/AsmAnalysisInfo.h>
|
#include <libyul/AsmAnalysisInfo.h>
|
||||||
#include <libyul/Dialect.h>
|
#include <libyul/Dialect.h>
|
||||||
#include <liblangutil/Scanner.h>
|
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
@ -56,7 +55,6 @@ shared_ptr<Block> parse(string const& _source, Dialect const& _dialect, ErrorRep
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto stream = CharStream(_source, "");
|
auto stream = CharStream(_source, "");
|
||||||
auto scanner = make_shared<Scanner>(stream);
|
|
||||||
map<unsigned, shared_ptr<string const>> indicesToSourceNames;
|
map<unsigned, shared_ptr<string const>> indicesToSourceNames;
|
||||||
indicesToSourceNames[0] = make_shared<string const>("source0");
|
indicesToSourceNames[0] = make_shared<string const>("source0");
|
||||||
indicesToSourceNames[1] = make_shared<string const>("source1");
|
indicesToSourceNames[1] = make_shared<string const>("source1");
|
||||||
@ -65,7 +63,7 @@ shared_ptr<Block> parse(string const& _source, Dialect const& _dialect, ErrorRep
|
|||||||
errorReporter,
|
errorReporter,
|
||||||
_dialect,
|
_dialect,
|
||||||
move(indicesToSourceNames)
|
move(indicesToSourceNames)
|
||||||
).parse(scanner, false);
|
).parse(stream);
|
||||||
if (parserResult)
|
if (parserResult)
|
||||||
{
|
{
|
||||||
yul::AsmAnalysisInfo analysisInfo;
|
yul::AsmAnalysisInfo analysisInfo;
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
#include <libsolutil/Exceptions.h>
|
#include <libsolutil/Exceptions.h>
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
#include <liblangutil/Scanner.h>
|
|
||||||
#include <libyul/AsmAnalysis.h>
|
#include <libyul/AsmAnalysis.h>
|
||||||
#include <libyul/AsmAnalysisInfo.h>
|
#include <libyul/AsmAnalysisInfo.h>
|
||||||
#include <libsolidity/parsing/Parser.h>
|
#include <libsolidity/parsing/Parser.h>
|
||||||
@ -45,7 +44,6 @@
|
|||||||
|
|
||||||
#include <libsolidity/interface/OptimiserSettings.h>
|
#include <libsolidity/interface/OptimiserSettings.h>
|
||||||
#include <liblangutil/CharStreamProvider.h>
|
#include <liblangutil/CharStreamProvider.h>
|
||||||
#include <liblangutil/Scanner.h>
|
|
||||||
|
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
@ -92,8 +90,7 @@ public:
|
|||||||
{
|
{
|
||||||
ErrorReporter errorReporter(m_errors);
|
ErrorReporter errorReporter(m_errors);
|
||||||
m_charStream = make_shared<CharStream>(_input, "");
|
m_charStream = make_shared<CharStream>(_input, "");
|
||||||
m_scanner = make_shared<Scanner>(*m_charStream);
|
m_ast = yul::Parser(errorReporter, m_dialect).parse(*m_charStream);
|
||||||
m_ast = yul::Parser(errorReporter, m_dialect).parse(m_scanner, false);
|
|
||||||
if (!m_ast || !errorReporter.errors().empty())
|
if (!m_ast || !errorReporter.errors().empty())
|
||||||
{
|
{
|
||||||
cerr << "Error parsing source." << endl;
|
cerr << "Error parsing source." << endl;
|
||||||
@ -236,7 +233,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
ErrorList m_errors;
|
ErrorList m_errors;
|
||||||
shared_ptr<CharStream> m_charStream;
|
shared_ptr<CharStream> m_charStream;
|
||||||
shared_ptr<Scanner> m_scanner;
|
|
||||||
shared_ptr<yul::Block> m_ast;
|
shared_ptr<yul::Block> m_ast;
|
||||||
Dialect const& m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})};
|
Dialect const& m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})};
|
||||||
shared_ptr<AsmAnalysisInfo> m_analysisInfo;
|
shared_ptr<AsmAnalysisInfo> m_analysisInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user