mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rename traverseObjectTree to visitPath and make it a member function
This commit is contained in:
parent
3b2805b760
commit
4d8d6fe447
@ -144,28 +144,29 @@ std::set<YulString> Object::qualifiedDataNames() const
|
|||||||
return qualifiedNames;
|
return qualifiedNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::traverseObjectTree(Object const* _object, YulString _qualifiedName, std::function<bool(Object const*)> _visitor)
|
void Object::visitPath(YulString _qualifiedName, std::function<bool(Object const*)> _visitor) const
|
||||||
{
|
{
|
||||||
yulAssert(!_qualifiedName.empty(), "");
|
yulAssert(!_qualifiedName.empty(), "");
|
||||||
|
|
||||||
std::vector<std::string> subObjectPathComponents;
|
std::vector<std::string> subObjectPathComponents;
|
||||||
boost::algorithm::split(subObjectPathComponents, _qualifiedName.str(), boost::is_any_of("."));
|
boost::algorithm::split(subObjectPathComponents, _qualifiedName.str(), boost::is_any_of("."));
|
||||||
|
|
||||||
|
Object const* object = this;
|
||||||
for (std::string const& currentSubObjectName: subObjectPathComponents)
|
for (std::string const& currentSubObjectName: subObjectPathComponents)
|
||||||
{
|
{
|
||||||
yulAssert(!currentSubObjectName.empty(), "");
|
yulAssert(!currentSubObjectName.empty(), "");
|
||||||
|
|
||||||
auto subObjectIt = ranges::find_if(
|
auto subObjectIt = ranges::find_if(
|
||||||
_object->subObjects,
|
object->subObjects,
|
||||||
[¤tSubObjectName](auto const& _subObject) { return _subObject->name.str() == currentSubObjectName; }
|
[¤tSubObjectName](auto const& _subObject) { return _subObject->name.str() == currentSubObjectName; }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (subObjectIt != _object->subObjects.end())
|
if (subObjectIt != object->subObjects.end())
|
||||||
{
|
{
|
||||||
_object = dynamic_cast<Object const*>(subObjectIt->get());
|
object = dynamic_cast<Object const*>(subObjectIt->get());
|
||||||
yulAssert(_object, "Assembly object <" + _object->name.str() + "> not found or does not contain code.");
|
yulAssert(object, "Assembly object <" + object->name.str() + "> not found or does not contain code.");
|
||||||
yulAssert(_object->subId != std::numeric_limits<size_t>::max(), "");
|
yulAssert(object->subId != std::numeric_limits<size_t>::max(), "");
|
||||||
if (_visitor(_object))
|
if (_visitor(object))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,7 +182,7 @@ std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
|
|||||||
_qualifiedName = YulString{_qualifiedName.str().substr(name.str().length() + 1)};
|
_qualifiedName = YulString{_qualifiedName.str().substr(name.str().length() + 1)};
|
||||||
yulAssert(!_qualifiedName.empty(), "");
|
yulAssert(!_qualifiedName.empty(), "");
|
||||||
|
|
||||||
traverseObjectTree(this, _qualifiedName, [&](Object const* _object) -> bool {
|
this->visitPath(_qualifiedName, [&](Object const* _object) -> bool {
|
||||||
path.push_back({_object->subId});
|
path.push_back({_object->subId});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -190,15 +191,15 @@ std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
|
|||||||
|
|
||||||
std::shared_ptr<Object> Object::objectAt(std::shared_ptr<Object> const& _object, std::string const& _qualifiedName)
|
std::shared_ptr<Object> Object::objectAt(std::shared_ptr<Object> const& _object, std::string const& _qualifiedName)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Object> object = nullptr;
|
std::shared_ptr<Object> foundObject = nullptr;
|
||||||
traverseObjectTree(_object.get(), YulString(_qualifiedName), [&](Object const* _obj) -> bool {
|
_object->visitPath(YulString(_qualifiedName), [&](Object const* _subObject) -> bool {
|
||||||
if (_qualifiedName.empty() || _qualifiedName == _obj->name.str())
|
if (_qualifiedName.empty() || _qualifiedName == _subObject->name.str())
|
||||||
{
|
{
|
||||||
object = std::make_shared<Object>(*_obj);
|
foundObject = std::make_shared<Object>(*_subObject);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return object;
|
return foundObject;
|
||||||
}
|
}
|
||||||
|
@ -117,13 +117,14 @@ public:
|
|||||||
/// The path must not lead to a @a Data object (will throw in that case).
|
/// The path must not lead to a @a Data object (will throw in that case).
|
||||||
std::vector<size_t> pathToSubObject(YulString _qualifiedName) const;
|
std::vector<size_t> pathToSubObject(YulString _qualifiedName) const;
|
||||||
|
|
||||||
/// Traverses the @a _object tree applying the function @a _visitor at every subobject
|
/// Visits all subobjects in the path given by the @a _qualifiedName
|
||||||
/// in the path given by the @a _qualifiedName.
|
/// of the current object applying the function @a _visitor.
|
||||||
static void traverseObjectTree(
|
/// If @a _visitor returns `true` the visiting stops, otherwise,
|
||||||
Object const* _object,
|
/// it continues until the last subobject in the path is reached.
|
||||||
|
void visitPath(
|
||||||
YulString _qualifiedName,
|
YulString _qualifiedName,
|
||||||
std::function<bool(Object const*)> _visitor
|
std::function<bool(Object const*)> _visitor
|
||||||
);
|
) const;
|
||||||
|
|
||||||
/// sub id for object if it is subobject of another object, max value if it is not subobject
|
/// sub id for object if it is subobject of another object, max value if it is not subobject
|
||||||
size_t subId = std::numeric_limits<size_t>::max();
|
size_t subId = std::numeric_limits<size_t>::max();
|
||||||
|
Loading…
Reference in New Issue
Block a user