mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Program: Use unique_ptr rather than shared_ptr to hold a pointer to the AST root
- The class never shares the instance so unique_ptr makes more sense.
This commit is contained in:
parent
513d41c315
commit
14d726ff01
@ -25,7 +25,6 @@
|
||||
|
||||
#include <libyul/AsmAnalysis.h>
|
||||
#include <libyul/AsmAnalysisInfo.h>
|
||||
#include <libyul/AsmData.h>
|
||||
#include <libyul/AsmParser.h>
|
||||
#include <libyul/YulString.h>
|
||||
#include <libyul/backends/evm/EVMDialect.h>
|
||||
@ -56,7 +55,7 @@ set<YulString> const Program::s_externallyUsedIdentifiers = {};
|
||||
Program Program::load(string const& _sourcePath)
|
||||
{
|
||||
Dialect const& dialect = EVMDialect::strictAssemblyForEVMObjects(EVMVersion{});
|
||||
shared_ptr<Block> ast = parseSource(dialect, loadSource(_sourcePath));
|
||||
unique_ptr<Block> ast = parseSource(dialect, loadSource(_sourcePath));
|
||||
unique_ptr<AsmAnalysisInfo> analysisInfo = analyzeAST(dialect, *ast);
|
||||
|
||||
Program program(
|
||||
@ -85,14 +84,14 @@ CharStream Program::loadSource(string const& _sourcePath)
|
||||
return CharStream(sourceCode, _sourcePath);
|
||||
}
|
||||
|
||||
shared_ptr<Block> Program::parseSource(Dialect const& _dialect, CharStream _source)
|
||||
unique_ptr<Block> Program::parseSource(Dialect const& _dialect, CharStream _source)
|
||||
{
|
||||
ErrorList errors;
|
||||
ErrorReporter errorReporter(errors);
|
||||
auto scanner = make_shared<Scanner>(move(_source));
|
||||
Parser parser(errorReporter, _dialect);
|
||||
|
||||
shared_ptr<Block> ast = parser.parse(scanner, false);
|
||||
unique_ptr<Block> ast = parser.parse(scanner, false);
|
||||
assertThrow(ast != nullptr, InvalidProgram, "Error parsing source");
|
||||
assert(errorReporter.errors().empty());
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <libyul/optimiser/OptimiserStep.h>
|
||||
#include <libyul/optimiser/NameDispenser.h>
|
||||
#include <libyul/AsmData.h>
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
@ -36,7 +37,6 @@ namespace solidity::yul
|
||||
{
|
||||
|
||||
struct AsmAnalysisInfo;
|
||||
struct Block;
|
||||
struct Dialect;
|
||||
class YulString;
|
||||
|
||||
@ -66,15 +66,15 @@ public:
|
||||
private:
|
||||
Program(
|
||||
yul::Dialect const& _dialect,
|
||||
std::shared_ptr<yul::Block> _ast
|
||||
std::unique_ptr<yul::Block> _ast
|
||||
):
|
||||
m_ast(_ast),
|
||||
m_nameDispenser(_dialect, *_ast, s_externallyUsedIdentifiers),
|
||||
m_ast(std::move(_ast)),
|
||||
m_nameDispenser(_dialect, *m_ast, s_externallyUsedIdentifiers),
|
||||
m_optimiserStepContext{_dialect, m_nameDispenser, s_externallyUsedIdentifiers}
|
||||
{}
|
||||
|
||||
static langutil::CharStream loadSource(std::string const& _sourcePath);
|
||||
static std::shared_ptr<yul::Block> parseSource(
|
||||
static std::unique_ptr<yul::Block> parseSource(
|
||||
yul::Dialect const& _dialect,
|
||||
langutil::CharStream _source
|
||||
);
|
||||
@ -94,7 +94,7 @@ private:
|
||||
);
|
||||
static size_t computeCodeSize(yul::Block const& _ast);
|
||||
|
||||
std::shared_ptr<yul::Block> m_ast;
|
||||
std::unique_ptr<yul::Block> m_ast;
|
||||
yul::NameDispenser m_nameDispenser;
|
||||
yul::OptimiserStepContext m_optimiserStepContext;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user