Skip to content

Commit

Permalink
appease all -Wshadow warnings
Browse files Browse the repository at this point in the history
fix #217
  • Loading branch information
genivia-inc committed Nov 27, 2024
1 parent 3445a32 commit c8e367c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4853,7 +4853,7 @@ printf "%s\n" "#define uint64_t $ac_cv_c_uint64_t" >>confdefs.h


# if CXXFLAGS is undefined, set it to our preferred default flags
: ${CXXFLAGS="-Wall -Wextra -Wunused -O2"}
: ${CXXFLAGS="-Wall -Wextra -Wunused -Wshadow -O2"}

ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT64_T

# if CXXFLAGS is undefined, set it to our preferred default flags
: ${CXXFLAGS="-Wall -Wextra -Wunused -O2"}
: ${CXXFLAGS="-Wall -Wextra -Wunused -Wshadow -O2"}

AC_LANG([C++])
AC_PROG_CXX
Expand Down
2 changes: 1 addition & 1 deletion lib/Make
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CPP=c++
AR=ar
RANLIB=ranlib
COFLAGS=-O2
CWFLAGS=-Wall -Wunused -Wextra
CWFLAGS=-Wall -Wunused -Wextra -Wshadow
CIFLAGS=-I. -I../include
CMFLAGS=
# CMFLAGS=-DDEBUG
Expand Down
1 change: 0 additions & 1 deletion lib/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,6 @@ std::string convert(const char *pattern, const char *signature, convert_flag_typ
++pos;
loc = pos;
const std::string& subregex = expand(macros, pattern, len, pos);
int c;
if ((flags & convert_flag::lex) && pos + 5 < len && pattern[pos + 1] == '{' && ((c = pattern[pos + 2]) == '+' || c == '|' || c == '&' || c == '-') && pattern[pos + 3] == '}')
{
size_t subpos = 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3451,7 +3451,7 @@ bool Matcher::advance_string_bm(size_t loc)
}
else
{
size_t k = bms[static_cast<uint8_t>(*q)];
k = bms[static_cast<uint8_t>(*q)];
if (p + k > t + bmd)
s += k - (t - p);
else
Expand Down Expand Up @@ -3510,7 +3510,7 @@ bool Matcher::advance_string_bm_pma(size_t loc)
}
else
{
size_t k = bms[static_cast<uint8_t>(*q)];
k = bms[static_cast<uint8_t>(*q)];
if (p + k > t + bmd)
s += k - (t - p);
else
Expand Down Expand Up @@ -3570,7 +3570,7 @@ bool Matcher::advance_string_bm_pmh(size_t loc)
}
else
{
size_t k = bms[static_cast<uint8_t>(*q)];
k = bms[static_cast<uint8_t>(*q)];
if (p + k > t + bmd)
s += k - (t - p);
else
Expand Down
54 changes: 27 additions & 27 deletions lib/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,9 @@ void Pattern::parse(
bol_ = false;
bool quote = false;
#ifdef WITH_TREE_DFA
DFA::State *t = tfa_.start();
DFA::State *r = tfa_.start();
#else
Tree::Node *t = tfa_.root();
Tree::Node *r = tfa_.root();
#endif
while (loc < end)
{
Expand Down Expand Up @@ -830,29 +830,29 @@ void Pattern::parse(
c = lowercase(c);
}
#ifdef WITH_TREE_DFA
DFA::State::Edges::iterator i = t->edges.find(c);
if (i == t->edges.end())
DFA::State::Edges::iterator i = r->edges.find(c);
if (i == r->edges.end())
{
if (last_state == NULL)
last_state = t; // t points to the tree DFA start state
last_state = r; // r points to the tree DFA root (start state)
DFA::State *target_state = last_state = last_state->next = tfa_.state();
t->edges[c] = DFA::State::Edge(c, target_state);
t = target_state;
r->edges[c] = DFA::State::Edge(c, target_state);
r = target_state;
++eno_;
++vno_;
if (vno_ > DFA::MAX_STATES)
error(regex_error::exceeds_limits, loc);
}
else
{
t = i->second.second;
r = i->second.second;
}
#else
t = tfa_.edge(t, c);
r = tfa_.edge(r, c);
#endif
}
if (t->accept == 0)
t->accept = choice;
if (r->accept == 0)
r->accept = choice;
#ifdef WITH_TREE_DFA
acc_.resize(choice, false);
acc_[choice - 1] = true;
Expand Down Expand Up @@ -1165,12 +1165,12 @@ void Pattern::parse3(
}
else if (c == '{') // {n,m} repeat min n times to max m
{
size_t k = 0;
size_t d = 0;
for (Location i = 0; i < 7 && std::isdigit(c = at(++loc)); ++i)
k = 10 * k + (c - '0');
if (k > Position::MAXITER)
d = 10 * d + (c - '0');
if (d > Position::MAXITER)
error(regex_error::exceeds_limits, loc);
Iter n = static_cast<Iter>(k);
Iter n = static_cast<Iter>(d);
Iter m = n;
bool unlimited = false;
if (at(loc) == ',')
Expand Down Expand Up @@ -2378,9 +2378,9 @@ void Pattern::compile_transition(
error(regex_error::exceeds_limits, loc);
state->heads.insert(l);
}
Lookahead k = n;
Lookahead l = n;
n += static_cast<Lookahead>(i->second.size());
if (n < k)
if (n < l)
error(regex_error::exceeds_limits, loc);
}
}
Expand All @@ -2402,9 +2402,9 @@ void Pattern::compile_transition(
error(regex_error::exceeds_limits, loc);
state->tails.insert(l);
}
Lookahead k = n;
Lookahead l = n;
n += static_cast<Lookahead>(i->second.size());
if (n < k)
if (n < l)
error(regex_error::exceeds_limits, loc);
}
}
Expand Down Expand Up @@ -3049,9 +3049,9 @@ void Pattern::encode_dfa(DFA::State *start)
void Pattern::gencode_dfa(const DFA::State *start) const
{
#ifndef WITH_NO_CODEGEN
for (std::vector<std::string>::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i)
for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
{
const std::string& filename = *i;
const std::string& filename = *it;
size_t len = filename.length();
if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0)
|| (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0)
Expand Down Expand Up @@ -3521,9 +3521,9 @@ void Pattern::gencode_dfa_closure(FILE *file, const DFA::State *state, int nest,
void Pattern::graph_dfa(const DFA::State *start) const
{
#ifndef WITH_NO_CODEGEN
for (std::vector<std::string>::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i)
for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
{
const std::string& filename = *i;
const std::string& filename = *it;
size_t len = filename.length();
if ((len > 3 && filename.compare(len - 3, 3, ".gv") == 0)
|| (len > 4 && filename.compare(len - 4, 4, ".dot") == 0))
Expand Down Expand Up @@ -3694,9 +3694,9 @@ void Pattern::export_code() const
#ifndef WITH_NO_CODEGEN
if (nop_ == 0)
return;
for (std::vector<std::string>::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i)
for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
{
const std::string& filename = *i;
const std::string& filename = *it;
size_t len = filename.length();
if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0)
|| (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0)
Expand Down Expand Up @@ -4586,7 +4586,7 @@ void Pattern::gen_match_hfa(DFA::State *start)
{
HFA::HashRanges& set_ranges = hfa_.hashes[level][next->first->index];
HFA::HashRanges& get_ranges = next->second;
for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset <= level; ++offset)
for (size_t offset = std::max<size_t>(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset <= level; ++offset)
set_ranges[offset].swap(get_ranges[offset]);
}
}
Expand Down Expand Up @@ -4635,7 +4635,7 @@ bool Pattern::gen_match_hfa_transitions(size_t level, size_t& max_level, DFA::St
Char lo = edge.lo();
Char hi = edge.hi();
DBGLOG("%zu HFA %p: %u..%u -> %p", level, state, lo, hi, next_state);
for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset < level; ++offset)
for (size_t offset = std::max<size_t>(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset < level; ++offset)
{
DBGLOGN(" offset%3zu", offset);
HFA::HashRange& next_hashes = hashes[next_state][offset];
Expand Down
2 changes: 1 addition & 1 deletion src/Make
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CPP=c++
INCS=../include/reflex/convert.h ../include/reflex/debug.h ../include/reflex/error.h ../include/reflex/input.h ../include/reflex/pattern.h ../include/reflex/utf8.h
LIBS=../lib/libreflex.a
COFLAGS=-O2
CWFLAGS=-Wall -Wunused -Wextra
CWFLAGS=-Wall -Wunused -Wextra -Wshadow
CIFLAGS=-I. -I../include
CMFLAGS=
# CMFLAGS=-DDEBUG
Expand Down
8 changes: 4 additions & 4 deletions src/reflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ void Reflex::init(int argc, char **argv)
size_t pos;
while ((pos = name.find('-')) != std::string::npos)
name[pos] = '_';
StringMap::iterator i = options.find(name);
if (i == options.end())
StringMap::iterator it = options.find(name);
if (it == options.end())
help("unknown option --", arg);
if (val != NULL)
i->second = val + 1;
it->second = val + 1;
else
i->second = "true";
it->second = "true";
}
is_grouped = false;
break;
Expand Down

0 comments on commit c8e367c

Please sign in to comment.