Make yul::Parser::parse() return unique_ptr rather than shared_ptr

- unique_ptr is more flexible and generally recommended for factory methods. It gets automatically converted to shared_ptr if necessary. Returning shared_ptr, on the other hand, forces the caller to use shared_ptr because a conversion to unique_ptr is not possible.
This commit is contained in:
cameel 2020-01-22 17:12:04 +01:00
parent e41155cf48
commit 642653ea04
3 changed files with 4 additions and 4 deletions

View File

@ -385,7 +385,7 @@ void CompilerContext::appendInlineAssembly(
ErrorReporter errorReporter(errors); ErrorReporter errorReporter(errors);
auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly, "--CODEGEN--")); auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly, "--CODEGEN--"));
yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion); yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion);
auto parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false); shared_ptr<yul::Block> parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false);
#ifdef SOL_OUTPUT_ASM #ifdef SOL_OUTPUT_ASM
cout << yul::AsmPrinter()(*parserResult) << endl; cout << yul::AsmPrinter()(*parserResult) << endl;
#endif #endif

View File

@ -37,7 +37,7 @@ using namespace solidity::util;
using namespace solidity::langutil; using namespace solidity::langutil;
using namespace solidity::yul; using namespace solidity::yul;
shared_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner) unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
{ {
m_recursionDepth = 0; m_recursionDepth = 0;
@ -47,7 +47,7 @@ shared_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _
try try
{ {
m_scanner = _scanner; m_scanner = _scanner;
auto block = make_shared<Block>(parseBlock()); auto block = make_unique<Block>(parseBlock());
if (!_reuseScanner) if (!_reuseScanner)
expectToken(Token::EOS); expectToken(Token::EOS);
return block; return block;

View File

@ -52,7 +52,7 @@ 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 `}`. /// @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::shared_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner); std::unique_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
/// @returns a map of all EVM instructions available to assembly. /// @returns a map of all EVM instructions available to assembly.
static std::map<std::string, evmasm::Instruction> const& instructions(); static std::map<std::string, evmasm::Instruction> const& instructions();