From 642653ea04109724cc8a698734dce9f47a8b656e Mon Sep 17 00:00:00 2001 From: cameel Date: Wed, 22 Jan 2020 17:12:04 +0100 Subject: [PATCH] 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. --- libsolidity/codegen/CompilerContext.cpp | 2 +- libyul/AsmParser.cpp | 4 ++-- libyul/AsmParser.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index ef5534a3c..9f233cfc0 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -385,7 +385,7 @@ void CompilerContext::appendInlineAssembly( ErrorReporter errorReporter(errors); auto scanner = make_shared(langutil::CharStream(_assembly, "--CODEGEN--")); yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion); - auto parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false); + shared_ptr parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false); #ifdef SOL_OUTPUT_ASM cout << yul::AsmPrinter()(*parserResult) << endl; #endif diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 3b955b96f..7ba122775 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -37,7 +37,7 @@ using namespace solidity::util; using namespace solidity::langutil; using namespace solidity::yul; -shared_ptr Parser::parse(std::shared_ptr const& _scanner, bool _reuseScanner) +unique_ptr Parser::parse(std::shared_ptr const& _scanner, bool _reuseScanner) { m_recursionDepth = 0; @@ -47,7 +47,7 @@ shared_ptr Parser::parse(std::shared_ptr const& _scanner, bool _ try { m_scanner = _scanner; - auto block = make_shared(parseBlock()); + auto block = make_unique(parseBlock()); if (!_reuseScanner) expectToken(Token::EOS); return block; diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h index 8583550e7..8abdcc91a 100644 --- a/libyul/AsmParser.h +++ b/libyul/AsmParser.h @@ -52,7 +52,7 @@ 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::shared_ptr parse(std::shared_ptr const& _scanner, bool _reuseScanner); + std::unique_ptr parse(std::shared_ptr const& _scanner, bool _reuseScanner); /// @returns a map of all EVM instructions available to assembly. static std::map const& instructions();