From a574a6c3ee46cb4ac48e18ef1337011242a0992b Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Sun, 16 May 2021 17:18:11 +0200 Subject: [PATCH] Pass -Wshadow (#97) Requested from: https://github.com/robinlinden/hastur/pull/12 --- CMakeLists.txt | 1 + include/ftxui/dom/node.hpp | 2 +- src/ftxui/component/radiobox.cpp | 4 ++-- src/ftxui/component/terminal_input_parser.hpp | 2 +- src/ftxui/dom/border.cpp | 18 +++++++++--------- src/ftxui/dom/dbox.cpp | 10 +++++----- src/ftxui/dom/flex.cpp | 10 +++++----- src/ftxui/dom/frame.cpp | 10 +++++----- src/ftxui/dom/hbox.cpp | 10 +++++----- src/ftxui/dom/hflow.cpp | 4 ++-- src/ftxui/dom/node.cpp | 6 +++--- src/ftxui/dom/node_decorator.cpp | 4 ++-- src/ftxui/dom/reflect.cpp | 12 ++++++------ src/ftxui/dom/separator.cpp | 8 +++++--- src/ftxui/dom/size.cpp | 4 ++-- src/ftxui/dom/vbox.cpp | 10 +++++----- 16 files changed, 59 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6d1e33..69f9de3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,7 @@ foreach(lib screen dom component) target_compile_options(${lib} PRIVATE "-Werror") target_compile_options(${lib} PRIVATE "-Wmissing-declarations") target_compile_options(${lib} PRIVATE "-Wdeprecated") + target_compile_options(${lib} PRIVATE "-Wshadow-all") endif() endforeach() diff --git a/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp index 3ca5139..e47121e 100644 --- a/include/ftxui/dom/node.hpp +++ b/include/ftxui/dom/node.hpp @@ -35,9 +35,9 @@ class Node { // Step 3: Draw this element. virtual void Render(Screen& screen); - std::vector children; protected: + std::vector children_; Requirement requirement_; Box box_; }; diff --git a/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp index b56b0d1..83730c5 100644 --- a/src/ftxui/component/radiobox.cpp +++ b/src/ftxui/component/radiobox.cpp @@ -49,8 +49,8 @@ RadioboxBase* RadioboxBase::From(Component component) { } RadioboxBase::RadioboxBase(const std::vector* entries, - int* selected_) - : entries_(entries), selected_(selected_) {} + int* selected) + : entries_(entries), selected_(selected) {} Element RadioboxBase::Render() { std::vector elements; diff --git a/src/ftxui/component/terminal_input_parser.hpp b/src/ftxui/component/terminal_input_parser.hpp index 244e843..899fcd5 100644 --- a/src/ftxui/component/terminal_input_parser.hpp +++ b/src/ftxui/component/terminal_input_parser.hpp @@ -44,7 +44,7 @@ class TerminalInputParser { CursorReporting cursor; }; - Output(Type type) : type(type) {} + Output(Type t) : type(t) {} }; void Send(Output type); diff --git a/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp index feacaaf..9b71cff 100644 --- a/src/ftxui/dom/border.cpp +++ b/src/ftxui/dom/border.cpp @@ -29,12 +29,12 @@ class Border : public Node { void ComputeRequirement() override { Node::ComputeRequirement(); - requirement_ = children[0]->requirement(); + requirement_ = children_[0]->requirement(); requirement_.min_x += 2; requirement_.min_y += 2; - if (children.size() == 2) { + if (children_.size() == 2) { requirement_.min_x = - std::max(requirement_.min_x, children[1]->requirement().min_x + 2); + std::max(requirement_.min_x, children_[1]->requirement().min_x + 2); } requirement_.selected_box.x_min++; requirement_.selected_box.x_max++; @@ -44,24 +44,24 @@ class Border : public Node { void SetBox(Box box) override { Node::SetBox(box); - if (children.size() == 2) { + if (children_.size() == 2) { Box title_box; title_box.x_min = box.x_min + 1; title_box.x_max = box.x_max - 1; title_box.y_min = box.y_min; title_box.y_max = box.y_min; - children[1]->SetBox(title_box); + children_[1]->SetBox(title_box); } box.x_min++; box.x_max--; box.y_min++; box.y_max--; - children[0]->SetBox(box); + children_[0]->SetBox(box); } void Render(Screen& screen) override { // Draw content. - children[0]->Render(screen); + children_[0]->Render(screen); // Draw the border. if (box_.x_min >= box_.x_max || box_.y_min >= box_.y_max) @@ -88,8 +88,8 @@ class Border : public Node { } // Draw title. - if (children.size() == 2) - children[1]->Render(screen); + if (children_.size() == 2) + children_[1]->Render(screen); } void RenderChar(Screen& screen) { diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index e39283b..7881941 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -22,7 +22,7 @@ class DBox : public Node { requirement_.flex_grow_y = 0; requirement_.flex_shrink_x = 0; requirement_.flex_shrink_y = 0; - for (auto& child : children) { + for (auto& child : children_) { child->ComputeRequirement(); requirement_.min_x = std::max(requirement_.min_x, child->requirement().min_x); @@ -39,17 +39,17 @@ class DBox : public Node { void SetBox(Box box) override { Node::SetBox(box); - for (auto& child : children) + for (auto& child : children_) child->SetBox(box); } }; /// @brief Stack several element on top of each other. -/// @param children The input element. +/// @param children_ The input element. /// @return The right aligned element. /// @ingroup dom -Element dbox(Elements children) { - return std::make_shared(std::move(children)); +Element dbox(Elements children_) { + return std::make_shared(std::move(children_)); } } // namespace ftxui diff --git a/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp index 3ad4a51..2837707 100644 --- a/src/ftxui/dom/flex.cpp +++ b/src/ftxui/dom/flex.cpp @@ -73,17 +73,17 @@ class Flex : public Node { void ComputeRequirement() override { requirement_.min_x = 0; requirement_.min_y = 0; - if (!children.empty()) { - children[0]->ComputeRequirement(); - requirement_ = children[0]->requirement(); + if (!children_.empty()) { + children_[0]->ComputeRequirement(); + requirement_ = children_[0]->requirement(); } f_(requirement_); } void SetBox(Box box) override { - if (children.empty()) + if (children_.empty()) return; - children[0]->SetBox(box); + children_[0]->SetBox(box); } FlexFunction f_; diff --git a/src/ftxui/dom/frame.cpp b/src/ftxui/dom/frame.cpp index 6ee8c44..ba815f9 100644 --- a/src/ftxui/dom/frame.cpp +++ b/src/ftxui/dom/frame.cpp @@ -21,7 +21,7 @@ class Select : public Node { void ComputeRequirement() override { Node::ComputeRequirement(); - requirement_ = children[0]->requirement(); + requirement_ = children_[0]->requirement(); auto& selected_box = requirement_.selected_box; selected_box.x_min = 0; selected_box.y_min = 0; @@ -32,7 +32,7 @@ class Select : public Node { void SetBox(Box box) override { box_ = box; - children[0]->SetBox(box); + children_[0]->SetBox(box); } }; @@ -70,7 +70,7 @@ class Frame : public Node { void ComputeRequirement() override { Node::ComputeRequirement(); - requirement_ = children[0]->requirement(); + requirement_ = children_[0]->requirement(); } void SetBox(Box box) override { @@ -98,13 +98,13 @@ class Frame : public Node { children_box.y_max = box.y_min + internal_dimy - dy; } - children[0]->SetBox(children_box); + children_[0]->SetBox(children_box); } void Render(Screen& screen) override { AutoReset stencil(&screen.stencil, Box::Intersection(box_, screen.stencil)); - children[0]->Render(screen); + children_[0]->Render(screen); } private: diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index 43757e6..b48e5ec 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -22,7 +22,7 @@ class HBox : public Node { requirement_.flex_grow_y = 0; requirement_.flex_shrink_x = 0; requirement_.flex_shrink_y = 0; - for (auto& child : children) { + for (auto& child : children_) { child->ComputeRequirement(); if (requirement_.selection < child->requirement().selection) { requirement_.selection = child->requirement().selection; @@ -46,7 +46,7 @@ class HBox : public Node { int flex_grow_sum = 0; int flex_shrink_sum = 0; int flex_shrink_size = 0; - for (auto& child : children) { + for (auto& child : children_) { const Requirement& r = child->requirement(); flex_grow_sum += r.flex_grow_x; flex_shrink_sum += r.min_x * r.flex_shrink_x; @@ -67,7 +67,7 @@ class HBox : public Node { void SetBoxGrow(Box box, int extra_space, int flex_grow_sum) { int x = box.x_min; - for (auto& child : children) { + for (auto& child : children_) { Box child_box = box; const Requirement& r = child->requirement(); @@ -86,7 +86,7 @@ class HBox : public Node { void SetBoxShrinkEasy(Box box, int extra_space, int flex_shrink_sum) { int x = box.x_min; - for (auto& child : children) { + for (auto& child : children_) { Box child_box = box; const Requirement& r = child->requirement(); @@ -105,7 +105,7 @@ class HBox : public Node { void SetBoxShrinkHard(Box box, int extra_space, int size) { int x = box.x_min; - for (auto& child : children) { + for (auto& child : children_) { Box child_box = box; const Requirement& r = child->requirement(); diff --git a/src/ftxui/dom/hflow.cpp b/src/ftxui/dom/hflow.cpp index eb20233..b5976f9 100644 --- a/src/ftxui/dom/hflow.cpp +++ b/src/ftxui/dom/hflow.cpp @@ -22,7 +22,7 @@ class HFlow : public Node { requirement_.flex_grow_y = 1; requirement_.flex_shrink_x = 0; requirement_.flex_shrink_y = 0; - for (auto& child : children) + for (auto& child : children_) child->ComputeRequirement(); } @@ -34,7 +34,7 @@ class HFlow : public Node { int y = box.y_min; int y_next = y; // The position of next row of elements. - for (auto& child : children) { + for (auto& child : children_) { Requirement requirement = child->requirement(); // Does it fit the end of the row? diff --git a/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp index 9ed078b..3e07d9e 100644 --- a/src/ftxui/dom/node.cpp +++ b/src/ftxui/dom/node.cpp @@ -8,13 +8,13 @@ namespace ftxui { using ftxui::Screen; Node::Node() {} -Node::Node(Elements children) : children(std::move(children)) {} +Node::Node(Elements children) : children_(std::move(children)) {} Node::~Node() {} /// @brief Compute how much space an elements needs. /// @ingroup dom void Node::ComputeRequirement() { - for (auto& child : children) + for (auto& child : children_) child->ComputeRequirement(); } @@ -27,7 +27,7 @@ void Node::SetBox(Box box) { /// @brief Display an element on a ftxui::Screen. /// @ingroup dom void Node::Render(Screen& screen) { - for (auto& child : children) + for (auto& child : children_) child->Render(screen); } diff --git a/src/ftxui/dom/node_decorator.cpp b/src/ftxui/dom/node_decorator.cpp index ec01d1c..2134348 100644 --- a/src/ftxui/dom/node_decorator.cpp +++ b/src/ftxui/dom/node_decorator.cpp @@ -9,12 +9,12 @@ namespace ftxui { void NodeDecorator::ComputeRequirement() { Node::ComputeRequirement(); - requirement_ = children[0]->requirement(); + requirement_ = children_[0]->requirement(); } void NodeDecorator::SetBox(Box box) { Node::SetBox(box); - children[0]->SetBox(box); + children_[0]->SetBox(box); } } // namespace ftxui diff --git a/src/ftxui/dom/reflect.cpp b/src/ftxui/dom/reflect.cpp index 3c7c9ee..a263063 100644 --- a/src/ftxui/dom/reflect.cpp +++ b/src/ftxui/dom/reflect.cpp @@ -13,22 +13,22 @@ namespace ftxui { class Reflect : public Node { public: Reflect(Element child, Box& box) - : Node(unpack(std::move(child))), box_(box) {} + : Node(unpack(std::move(child))), reflected_box_(box) {} ~Reflect() override {} void ComputeRequirement() final { Node::ComputeRequirement(); - requirement_ = children[0]->requirement(); + requirement_ = children_[0]->requirement(); } void SetBox(Box box) final { - box_ = box; - Node::SetBox(box_); - children[0]->SetBox(box_); + reflected_box_ = box; + Node::SetBox(reflected_box_); + children_[0]->SetBox(reflected_box_); } private: - Box& box_; + Box& reflected_box_; }; Decorator reflect(Box& box) { diff --git a/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp index 0646f80..2751d62 100644 --- a/src/ftxui/dom/separator.cpp +++ b/src/ftxui/dom/separator.cpp @@ -45,10 +45,12 @@ class Separator : public Node { class SeparatorWithPixel : public Separator { public: - SeparatorWithPixel(Pixel p) : p(p) {} + SeparatorWithPixel(Pixel pixel) : pixel_(pixel) {} ~SeparatorWithPixel() override {} - void Render(Screen& screen) override { RenderWithPixel(screen, p); } - Pixel p; + void Render(Screen& screen) override { RenderWithPixel(screen, pixel_); } + + private: + Pixel pixel_; }; Element separator() { diff --git a/src/ftxui/dom/size.cpp b/src/ftxui/dom/size.cpp index ca564ea..93a3c5a 100644 --- a/src/ftxui/dom/size.cpp +++ b/src/ftxui/dom/size.cpp @@ -23,7 +23,7 @@ class Size : public Node { void ComputeRequirement() override { Node::ComputeRequirement(); - requirement_ = children[0]->requirement(); + requirement_ = children_[0]->requirement(); auto& value = direction_ == WIDTH ? requirement_.min_x : requirement_.min_y; @@ -70,7 +70,7 @@ class Size : public Node { break; } } - children[0]->SetBox(box); + children_[0]->SetBox(box); } private: diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index 0686498..ef2a1d8 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -22,7 +22,7 @@ class VBox : public Node { requirement_.flex_grow_y = 0; requirement_.flex_shrink_x = 0; requirement_.flex_shrink_y = 0; - for (auto& child : children) { + for (auto& child : children_) { child->ComputeRequirement(); if (requirement_.selection < child->requirement().selection) { requirement_.selection = child->requirement().selection; @@ -46,7 +46,7 @@ class VBox : public Node { int flex_grow_sum = 0; int flex_shrink_sum = 0; int flex_shrink_size = 0; - for (auto& child : children) { + for (auto& child : children_) { const Requirement& r = child->requirement(); flex_grow_sum += r.flex_grow_y; flex_shrink_sum += r.min_y * r.flex_shrink_y; @@ -67,7 +67,7 @@ class VBox : public Node { void SetBoxGrow(Box box, int extra_space, int flex_grow_sum) { int y = box.y_min; - for (auto& child : children) { + for (auto& child : children_) { Box child_box = box; const Requirement& r = child->requirement(); @@ -86,7 +86,7 @@ class VBox : public Node { void SetBoxShrinkEasy(Box box, int extra_space, int flex_shrink_sum) { int y = box.y_min; - for (auto& child : children) { + for (auto& child : children_) { Box child_box = box; const Requirement& r = child->requirement(); @@ -105,7 +105,7 @@ class VBox : public Node { void SetBoxShrinkHard(Box box, int extra_space, int size) { int y = box.y_min; - for (auto& child : children) { + for (auto& child : children_) { Box child_box = box; const Requirement& r = child->requirement();