diff --git a/libyul/ObjectParser.cpp b/libyul/ObjectParser.cpp index a511e33f3..1993f6b77 100644 --- a/libyul/ObjectParser.cpp +++ b/libyul/ObjectParser.cpp @@ -100,7 +100,6 @@ std::shared_ptr ObjectParser::parseObject(Object* _containingObject) } if (_containingObject) { - ret->subId = _containingObject->subObjects.size(); addNamedSubObject(*_containingObject, ret->name, ret); } diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index b17cd1f5d..74851d333 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -87,18 +87,38 @@ public: }.printErrorInformation(_errors); } - shared_ptr getSubObject(shared_ptr const& _rootObject, string const& _path) + shared_ptr getSubObject(shared_ptr const& _object, string const& _path) { - if (_path.empty()) - return _rootObject; + if (_path.empty() || _path == _object->name.str()) + return _object; - auto pathToSubObject = _rootObject->pathToSubObject(YulString(_path)); - auto subObject = _rootObject; + yulAssert( + boost::algorithm::starts_with(_path, _object->name.str() + "."), + "Assembly object not found." + ); - for (auto const& i: pathToSubObject) - subObject = dynamic_pointer_cast(subObject->subObjects[i]); + const auto subObjectPath = _path.substr(_object->name.str().length() + 1); + const auto subObjectName = subObjectPath.substr(0, subObjectPath.find_first_of('.')); - return subObject; + auto subObjectIt = find_if( + _object->subObjects.begin(), + _object->subObjects.end(), + [subObjectName](auto const& subObject) { return subObject->name.str() == subObjectName; } + ); + + yulAssert( + subObjectIt != _object->subObjects.end(), + "Assembly object not found." + ); + + auto subObject = dynamic_pointer_cast(*subObjectIt); + + yulAssert( + subObject != nullptr, + "Assembly object may not contain code." + ); + + return getSubObject(subObject, subObjectPath); } void parse(string const& _input, string const& _objectPath)