mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds SourceUnit::replaceNode(_old, _new)
This commit is contained in:
parent
e1fcd53216
commit
2130c446e2
@ -27,6 +27,8 @@
|
||||
#include <libsolidity/ast/TypeProvider.h>
|
||||
#include <libsolutil/Keccak256.h>
|
||||
|
||||
#include <boost/range/algorithm/find_if.hpp>
|
||||
#include <boost/range/algorithm/replace_if.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
@ -72,6 +74,22 @@ set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse, set<Sour
|
||||
return sourceUnits;
|
||||
}
|
||||
|
||||
void SourceUnit::replaceNode(ASTPointer<ASTNode> _oldNode, ASTPointer<ASTNode> _newNode)
|
||||
{
|
||||
solAssert(
|
||||
boost::range::find_if(
|
||||
m_nodes,
|
||||
[&](auto const& node) { return node->id() == _oldNode->id(); }
|
||||
) != m_nodes.end(),
|
||||
""
|
||||
);
|
||||
boost::range::replace_if(
|
||||
m_nodes,
|
||||
[&](auto const& node) { return node->id() == _oldNode->id(); },
|
||||
_newNode
|
||||
);
|
||||
}
|
||||
|
||||
ImportAnnotation& ImportDirective::annotation() const
|
||||
{
|
||||
return initAnnotation<ImportAnnotation>();
|
||||
|
@ -173,6 +173,9 @@ public:
|
||||
std::optional<std::string> const& licenseString() const { return m_licenseString; }
|
||||
std::vector<ASTPointer<ASTNode>> nodes() const { return m_nodes; }
|
||||
|
||||
/// Replaces given top-level AST node with a new AST node.
|
||||
void replaceNode(ASTPointer<ASTNode> _oldNode, ASTPointer<ASTNode> _newNode);
|
||||
|
||||
/// @returns a set of referenced SourceUnits. Recursively if @a _recurse is true.
|
||||
std::set<SourceUnit const*> referencedSourceUnits(bool _recurse = false, std::set<SourceUnit const*> _skipList = std::set<SourceUnit const*>()) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user