mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Prevent externally used functions from being removed.
This commit is contained in:
@@ -33,12 +33,14 @@ using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::yul;
|
||||
|
||||
UnusedPruner::UnusedPruner(Block& _ast)
|
||||
UnusedPruner::UnusedPruner(Block& _ast, set<string> const& _externallyUsedFunctions)
|
||||
{
|
||||
ReferencesCounter counter;
|
||||
counter(_ast);
|
||||
|
||||
m_references = counter.references();
|
||||
for (auto const& f: _externallyUsedFunctions)
|
||||
++m_references[f];
|
||||
}
|
||||
|
||||
void UnusedPruner::operator()(Block& _block)
|
||||
@@ -89,11 +91,11 @@ void UnusedPruner::operator()(Block& _block)
|
||||
ASTModifier::operator()(_block);
|
||||
}
|
||||
|
||||
void UnusedPruner::runUntilStabilised(Block& _ast)
|
||||
void UnusedPruner::runUntilStabilised(Block& _ast, set<string> const& _externallyUsedFunctions)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
UnusedPruner pruner(_ast);
|
||||
UnusedPruner pruner(_ast, _externallyUsedFunctions);
|
||||
pruner(_ast);
|
||||
if (!pruner.shouldRunAgain())
|
||||
return;
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace yul
|
||||
class UnusedPruner: public ASTModifier
|
||||
{
|
||||
public:
|
||||
explicit UnusedPruner(Block& _ast);
|
||||
explicit UnusedPruner(Block& _ast, std::set<std::string> const& _externallyUsedFunctions = std::set<std::string>());
|
||||
|
||||
using ASTModifier::operator();
|
||||
virtual void operator()(Block& _block) override;
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
bool shouldRunAgain() const { return m_shouldRunAgain; }
|
||||
|
||||
// Run the pruner until the code does not change anymore.
|
||||
static void runUntilStabilised(Block& _ast);
|
||||
static void runUntilStabilised(Block& _ast, std::set<std::string> const& _externallyUsedFunctions = std::set<std::string>());
|
||||
|
||||
private:
|
||||
bool used(std::string const& _name) const;
|
||||
|
||||
Reference in New Issue
Block a user