From b5e6d9c4cae1a9057a02b416b07c35d306d71768 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 12 Sep 2020 15:04:22 +0200 Subject: [PATCH] glr2.cc: address warnings with G++ 4.8 input.cc: In constructor 'glr_stack_item::glr_stack_item(bool)': input.cc:1423:5: error: declaration of 'isState' shadows a member of 'this' [-Werror=shadow] : isState_(isState) { ^ test.cc:1165:45: error: declaration of 'begin' shadows a member of 'this' [-Werror=shadow] test.cc:1167:45: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow] * data/skeletons/glr2.cc (isState): Rename as... (is_state): this. Formatting changes. (reduceToOneStack): Rename variables to avoid name clashes. --- data/skeletons/glr2.cc | 73 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index 8e29bf0b..a7f2d129 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -818,8 +818,9 @@ static inline int yyrhsLength (rule_num yyrule); -class glr_state { - public: +class glr_state +{ +public: glr_state() : yyresolved(false) , yylrState(0) @@ -1195,58 +1196,60 @@ class semantic_option { YYLTYPE yyloc;]])[ }; -/** Type of the items in the GLR stack. The isState_ field +/** Type of the items in the GLR stack. The is_state_ field * indicates which item of the union is valid. */ -class glr_stack_item { - public: - glr_stack_item(bool isState = true) - : isState_(isState) { - if (isState) { - new (&raw_) glr_state; - } else { - new (&raw_) semantic_option; - } +class glr_stack_item +{ +public: + glr_stack_item(bool is_state = true) + : is_state_(is_state) + { + if (is_state) + new (&raw_) glr_state; + else + new (&raw_) semantic_option; } glr_stack_item(const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW - : isState_(other.isState_) { + : is_state_(other.is_state_) + { std::memcpy(raw_, other.raw_, union_size); } glr_stack_item& operator=(glr_stack_item other) { - std::swap(isState_, other.isState_); + std::swap(is_state_, other.is_state_); std::swap(raw_, other.raw_); return *this; } - ~glr_stack_item() { - if (isState()) { + ~glr_stack_item() + { + if (is_state()) getState().~glr_state(); - } else { + else getOption().~semantic_option(); - } } glr_state& getState() { - YYDASSERT(isState()); + YYDASSERT(is_state()); return *reinterpret_cast(&raw_); } const glr_state& getState() const { - YYDASSERT(isState()); + YYDASSERT(is_state()); return *reinterpret_cast(&raw_); } semantic_option& getOption() { - YYDASSERT(!isState()); + YYDASSERT(!is_state()); return *reinterpret_cast(&raw_); } const semantic_option& getOption() const { - YYDASSERT(!isState()); + YYDASSERT(!is_state()); return *reinterpret_cast(&raw_); } - bool isState() const { - return isState_; + bool is_state() const { + return is_state_; } private: /// The possible contents of raw_. Since they have constructors, they cannot @@ -1265,7 +1268,7 @@ class glr_stack_item { char raw_[union_size]; }; /** Type tag for the union. */ - bool isState_; + bool is_state_; }; glr_state* glr_state::pred() { @@ -1409,15 +1412,13 @@ class state_stack { bool reduceToOneStack() { - const std::vector::iterator begin = - yytops.begin(); - const std::vector::iterator end = - yytops.end(); + const std::vector::iterator yybegin = yytops.begin(); + const std::vector::iterator yyend = yytops.end(); std::vector::iterator yyit = - std::find_if(begin, end, yyGLRStateNotNull); - if (yyit == end) + std::find_if(yybegin, yyend, yyGLRStateNotNull); + if (yyit == yyend) return false; - for (state_set_index yyk = create_state_set_index(yyit + 1 - begin); + for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin); yyk.uget() != numTops(); ++yyk) yytops.yymarkStackDeleted (yyk); yytops.yyremoveDeletes (); @@ -1642,7 +1643,7 @@ class state_stack { { glr_stack_item& item = yyitems[yyi]; std::cerr << std::setw(3) << yyi << ". "; - if (item.isState()) + if (item.is_state()) { std::cerr << "Res: " << item.getState().yyresolved << ", LR State: " << item.getState().yylrState @@ -1709,14 +1710,14 @@ class state_stack { } /** Return a fresh GLRStackItem in this. The item is an LR state - * if YYISSTATE, and otherwise a semantic option. Callers should call + * if YYIS_STATE, and otherwise a semantic option. Callers should call * yyreserveStack afterwards to make sure there is sufficient * headroom. */ inline size_t - yynewGLRStackItem (bool yyisState) + yynewGLRStackItem (bool yyis_state) { YYDASSERT(yyitems.size() < yyitems.capacity()); - yyitems.push_back(glr_stack_item(yyisState)); + yyitems.push_back(glr_stack_item(yyis_state)); return yyitems.size() - 1; }