mirror of
https://github.com/YosysHQ/yosys
synced 2025-08-03 18:00:24 +00:00
log_help: Fix mem leaks
`_content` vector owns elements so that when the `ContentListing` is deleted so is the content. Remove `get_content()` method in favour of `begin()` and `end()` const iterators. More `const` in general, and iterations over `ContentListing` use `&content` to avoid copying data.
This commit is contained in:
parent
c4f685c057
commit
3e8746e78b
3 changed files with 31 additions and 36 deletions
|
@ -21,7 +21,7 @@
|
|||
|
||||
USING_YOSYS_NAMESPACE
|
||||
|
||||
Json ContentListing::to_json() {
|
||||
Json ContentListing::to_json() const {
|
||||
Json::object object;
|
||||
object["type"] = type;
|
||||
if (body.length()) object["body"] = body;
|
||||
|
@ -29,7 +29,7 @@ Json ContentListing::to_json() {
|
|||
if (source_line != 0) object["source_line"] = source_line;
|
||||
object["options"] = Json(options);
|
||||
Json::array content_array;
|
||||
for (auto child : _content) content_array.push_back(child->to_json());
|
||||
for (auto child : _content) content_array.push_back(child.to_json());
|
||||
object["content"] = content_array;
|
||||
return object;
|
||||
}
|
||||
|
@ -73,9 +73,8 @@ ContentListing* ContentListing::open_option(const string &text,
|
|||
const source_location location)
|
||||
{
|
||||
log_assert(type.compare("root") == 0 || type.compare("usage") == 0);
|
||||
auto option = new ContentListing("option", text, location);
|
||||
add_content(option);
|
||||
return option;
|
||||
add_content("option", text, location);
|
||||
return back();
|
||||
}
|
||||
|
||||
#define MAX_LINE_LEN 80
|
||||
|
@ -131,20 +130,20 @@ PrettyHelp *PrettyHelp::get_current()
|
|||
return current_help;
|
||||
}
|
||||
|
||||
void PrettyHelp::log_help()
|
||||
void PrettyHelp::log_help() const
|
||||
{
|
||||
for (auto content : _root_listing.get_content()) {
|
||||
if (content->type.compare("usage") == 0) {
|
||||
log_pass_str(content->body, 1, true);
|
||||
for (auto &content : _root_listing) {
|
||||
if (content.type.compare("usage") == 0) {
|
||||
log_pass_str(content.body, 1, true);
|
||||
log("\n");
|
||||
} else if (content->type.compare("option") == 0) {
|
||||
log_pass_str(content->body, 1);
|
||||
for (auto text : content->get_content()) {
|
||||
log_pass_str(text->body, 2);
|
||||
} else if (content.type.compare("option") == 0) {
|
||||
log_pass_str(content.body, 1);
|
||||
for (auto text : content) {
|
||||
log_pass_str(text.body, 2);
|
||||
log("\n");
|
||||
}
|
||||
} else {
|
||||
log_pass_str(content->body, 0);
|
||||
log_pass_str(content.body, 0);
|
||||
log("\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue