Skip to content

Commit c8e367c

Browse files
committed
appease all -Wshadow warnings
fix #217
1 parent 3445a32 commit c8e367c

File tree

8 files changed

+38
-39
lines changed

8 files changed

+38
-39
lines changed

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4853,7 +4853,7 @@ printf "%s\n" "#define uint64_t $ac_cv_c_uint64_t" >>confdefs.h
48534853

48544854

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

48584858
ac_ext=cpp
48594859
ac_cpp='$CXXCPP $CPPFLAGS'

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ AC_TYPE_UINT32_T
1111
AC_TYPE_UINT64_T
1212

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

1616
AC_LANG([C++])
1717
AC_PROG_CXX

lib/Make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CPP=c++
1010
AR=ar
1111
RANLIB=ranlib
1212
COFLAGS=-O2
13-
CWFLAGS=-Wall -Wunused -Wextra
13+
CWFLAGS=-Wall -Wunused -Wextra -Wshadow
1414
CIFLAGS=-I. -I../include
1515
CMFLAGS=
1616
# CMFLAGS=-DDEBUG

lib/convert.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,6 @@ std::string convert(const char *pattern, const char *signature, convert_flag_typ
20172017
++pos;
20182018
loc = pos;
20192019
const std::string& subregex = expand(macros, pattern, len, pos);
2020-
int c;
20212020
if ((flags & convert_flag::lex) && pos + 5 < len && pattern[pos + 1] == '{' && ((c = pattern[pos + 2]) == '+' || c == '|' || c == '&' || c == '-') && pattern[pos + 3] == '}')
20222021
{
20232022
size_t subpos = 0;

lib/matcher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,7 @@ bool Matcher::advance_string_bm(size_t loc)
34513451
}
34523452
else
34533453
{
3454-
size_t k = bms[static_cast<uint8_t>(*q)];
3454+
k = bms[static_cast<uint8_t>(*q)];
34553455
if (p + k > t + bmd)
34563456
s += k - (t - p);
34573457
else
@@ -3510,7 +3510,7 @@ bool Matcher::advance_string_bm_pma(size_t loc)
35103510
}
35113511
else
35123512
{
3513-
size_t k = bms[static_cast<uint8_t>(*q)];
3513+
k = bms[static_cast<uint8_t>(*q)];
35143514
if (p + k > t + bmd)
35153515
s += k - (t - p);
35163516
else
@@ -3570,7 +3570,7 @@ bool Matcher::advance_string_bm_pmh(size_t loc)
35703570
}
35713571
else
35723572
{
3573-
size_t k = bms[static_cast<uint8_t>(*q)];
3573+
k = bms[static_cast<uint8_t>(*q)];
35743574
if (p + k > t + bmd)
35753575
s += k - (t - p);
35763576
else

lib/pattern.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,9 @@ void Pattern::parse(
795795
bol_ = false;
796796
bool quote = false;
797797
#ifdef WITH_TREE_DFA
798-
DFA::State *t = tfa_.start();
798+
DFA::State *r = tfa_.start();
799799
#else
800-
Tree::Node *t = tfa_.root();
800+
Tree::Node *r = tfa_.root();
801801
#endif
802802
while (loc < end)
803803
{
@@ -830,29 +830,29 @@ void Pattern::parse(
830830
c = lowercase(c);
831831
}
832832
#ifdef WITH_TREE_DFA
833-
DFA::State::Edges::iterator i = t->edges.find(c);
834-
if (i == t->edges.end())
833+
DFA::State::Edges::iterator i = r->edges.find(c);
834+
if (i == r->edges.end())
835835
{
836836
if (last_state == NULL)
837-
last_state = t; // t points to the tree DFA start state
837+
last_state = r; // r points to the tree DFA root (start state)
838838
DFA::State *target_state = last_state = last_state->next = tfa_.state();
839-
t->edges[c] = DFA::State::Edge(c, target_state);
840-
t = target_state;
839+
r->edges[c] = DFA::State::Edge(c, target_state);
840+
r = target_state;
841841
++eno_;
842842
++vno_;
843843
if (vno_ > DFA::MAX_STATES)
844844
error(regex_error::exceeds_limits, loc);
845845
}
846846
else
847847
{
848-
t = i->second.second;
848+
r = i->second.second;
849849
}
850850
#else
851-
t = tfa_.edge(t, c);
851+
r = tfa_.edge(r, c);
852852
#endif
853853
}
854-
if (t->accept == 0)
855-
t->accept = choice;
854+
if (r->accept == 0)
855+
r->accept = choice;
856856
#ifdef WITH_TREE_DFA
857857
acc_.resize(choice, false);
858858
acc_[choice - 1] = true;
@@ -1165,12 +1165,12 @@ void Pattern::parse3(
11651165
}
11661166
else if (c == '{') // {n,m} repeat min n times to max m
11671167
{
1168-
size_t k = 0;
1168+
size_t d = 0;
11691169
for (Location i = 0; i < 7 && std::isdigit(c = at(++loc)); ++i)
1170-
k = 10 * k + (c - '0');
1171-
if (k > Position::MAXITER)
1170+
d = 10 * d + (c - '0');
1171+
if (d > Position::MAXITER)
11721172
error(regex_error::exceeds_limits, loc);
1173-
Iter n = static_cast<Iter>(k);
1173+
Iter n = static_cast<Iter>(d);
11741174
Iter m = n;
11751175
bool unlimited = false;
11761176
if (at(loc) == ',')
@@ -2378,9 +2378,9 @@ void Pattern::compile_transition(
23782378
error(regex_error::exceeds_limits, loc);
23792379
state->heads.insert(l);
23802380
}
2381-
Lookahead k = n;
2381+
Lookahead l = n;
23822382
n += static_cast<Lookahead>(i->second.size());
2383-
if (n < k)
2383+
if (n < l)
23842384
error(regex_error::exceeds_limits, loc);
23852385
}
23862386
}
@@ -2402,9 +2402,9 @@ void Pattern::compile_transition(
24022402
error(regex_error::exceeds_limits, loc);
24032403
state->tails.insert(l);
24042404
}
2405-
Lookahead k = n;
2405+
Lookahead l = n;
24062406
n += static_cast<Lookahead>(i->second.size());
2407-
if (n < k)
2407+
if (n < l)
24082408
error(regex_error::exceeds_limits, loc);
24092409
}
24102410
}
@@ -3049,9 +3049,9 @@ void Pattern::encode_dfa(DFA::State *start)
30493049
void Pattern::gencode_dfa(const DFA::State *start) const
30503050
{
30513051
#ifndef WITH_NO_CODEGEN
3052-
for (std::vector<std::string>::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i)
3052+
for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
30533053
{
3054-
const std::string& filename = *i;
3054+
const std::string& filename = *it;
30553055
size_t len = filename.length();
30563056
if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0)
30573057
|| (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0)
@@ -3521,9 +3521,9 @@ void Pattern::gencode_dfa_closure(FILE *file, const DFA::State *state, int nest,
35213521
void Pattern::graph_dfa(const DFA::State *start) const
35223522
{
35233523
#ifndef WITH_NO_CODEGEN
3524-
for (std::vector<std::string>::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i)
3524+
for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
35253525
{
3526-
const std::string& filename = *i;
3526+
const std::string& filename = *it;
35273527
size_t len = filename.length();
35283528
if ((len > 3 && filename.compare(len - 3, 3, ".gv") == 0)
35293529
|| (len > 4 && filename.compare(len - 4, 4, ".dot") == 0))
@@ -3694,9 +3694,9 @@ void Pattern::export_code() const
36943694
#ifndef WITH_NO_CODEGEN
36953695
if (nop_ == 0)
36963696
return;
3697-
for (std::vector<std::string>::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i)
3697+
for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
36983698
{
3699-
const std::string& filename = *i;
3699+
const std::string& filename = *it;
37003700
size_t len = filename.length();
37013701
if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0)
37023702
|| (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0)
@@ -4586,7 +4586,7 @@ void Pattern::gen_match_hfa(DFA::State *start)
45864586
{
45874587
HFA::HashRanges& set_ranges = hfa_.hashes[level][next->first->index];
45884588
HFA::HashRanges& get_ranges = next->second;
4589-
for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset <= level; ++offset)
4589+
for (size_t offset = std::max<size_t>(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset <= level; ++offset)
45904590
set_ranges[offset].swap(get_ranges[offset]);
45914591
}
45924592
}
@@ -4635,7 +4635,7 @@ bool Pattern::gen_match_hfa_transitions(size_t level, size_t& max_level, DFA::St
46354635
Char lo = edge.lo();
46364636
Char hi = edge.hi();
46374637
DBGLOG("%zu HFA %p: %u..%u -> %p", level, state, lo, hi, next_state);
4638-
for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset < level; ++offset)
4638+
for (size_t offset = std::max<size_t>(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset < level; ++offset)
46394639
{
46404640
DBGLOGN(" offset%3zu", offset);
46414641
HFA::HashRange& next_hashes = hashes[next_state][offset];

src/Make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CPP=c++
99
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
1010
LIBS=../lib/libreflex.a
1111
COFLAGS=-O2
12-
CWFLAGS=-Wall -Wunused -Wextra
12+
CWFLAGS=-Wall -Wunused -Wextra -Wshadow
1313
CIFLAGS=-I. -I../include
1414
CMFLAGS=
1515
# CMFLAGS=-DDEBUG

src/reflex.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,13 @@ void Reflex::init(int argc, char **argv)
381381
size_t pos;
382382
while ((pos = name.find('-')) != std::string::npos)
383383
name[pos] = '_';
384-
StringMap::iterator i = options.find(name);
385-
if (i == options.end())
384+
StringMap::iterator it = options.find(name);
385+
if (it == options.end())
386386
help("unknown option --", arg);
387387
if (val != NULL)
388-
i->second = val + 1;
388+
it->second = val + 1;
389389
else
390-
i->second = "true";
390+
it->second = "true";
391391
}
392392
is_grouped = false;
393393
break;

0 commit comments

Comments
 (0)