Tidy up the "extra debugging" knobs and their uses.
Change-Id: I6325501283e1a8d7af65ebbc8ba9e9562f78e526
Reviewed-on: https://code-review.googlesource.com/7403
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/dfa.cc b/re2/dfa.cc
index ef83ccf..319af74 100644
--- a/re2/dfa.cc
+++ b/re2/dfa.cc
@@ -66,7 +66,7 @@
// Changing this to true compiles in prints that trace execution of the DFA.
// Generates a lot of output -- only useful for debugging.
-static const bool DebugDFA = false;
+static const bool ExtraDebug = false;
// A DFA implementation of a regular expression program.
// Since this is entirely a forward declaration mandated by C++,
@@ -430,7 +430,7 @@
q1_(NULL),
astack_(NULL),
mem_budget_(max_mem) {
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "\nkind %d\n%s\n", (int)kind_, prog_->DumpUnanchored().c_str());
int nmark = 0;
if (kind_ == Prog::kLongestMatch)
@@ -603,7 +603,7 @@
uint32_t needflags = 0; // flags needed by kInstEmptyWidth instructions
bool sawmatch = false; // whether queue contains guaranteed kInstMatch
bool sawmark = false; // whether queue contains a Mark
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "WorkqToCachedState %s [%#x]", DumpWorkq(q).c_str(), flag);
for (Workq::iterator it = q->begin(); it != q->end(); ++it) {
int id = *it;
@@ -629,7 +629,7 @@
(kind_ != Prog::kLongestMatch || !sawmark) &&
(flag & kFlagMatch)) {
delete[] inst;
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, " -> FullMatchState\n");
return FullMatchState;
}
@@ -676,7 +676,7 @@
// if the state is *not* a matching state.
if (n == 0 && flag == 0) {
delete[] inst;
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, " -> DeadState\n");
return DeadState;
}
@@ -721,7 +721,7 @@
state.flag_ = flag;
StateSet::iterator it = state_cache_.find(&state);
if (it != state_cache_.end()) {
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, " -cached-> %s\n", DumpState(*it).c_str());
return *it;
}
@@ -752,7 +752,7 @@
memmove(s->inst_, inst, ninst*sizeof s->inst_[0]);
s->ninst_ = ninst;
s->flag_ = flag;
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, " -> %s\n", DumpState(s).c_str());
// Put state in cache and return it.
@@ -944,7 +944,7 @@
}
}
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n", DumpWorkq(oldq).c_str(),
c, flag, DumpWorkq(newq).c_str(), *ismatch);
}
@@ -1316,7 +1316,7 @@
}
while (p != ep) {
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "@%td: %s\n",
p - bp, DumpState(s).c_str());
if (have_firstbyte && s == start) {
@@ -1422,7 +1422,7 @@
lastmatch = p - 1;
else
lastmatch = p + 1;
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "match @%td! [%s]\n",
lastmatch - bp, DumpState(s).c_str());
@@ -1467,7 +1467,7 @@
}
}
s = ns;
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "@_: %s\n", DumpState(s).c_str());
if (s == FullMatchState) {
params->ep = reinterpret_cast<const char*>(ep);
@@ -1490,7 +1490,7 @@
}
}
}
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "match @%td! [%s]\n",
lastmatch - bp, DumpState(s).c_str());
}
@@ -1641,7 +1641,7 @@
}
}
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "anchored=%d fwd=%d flags=%#x state=%s firstbyte=%d\n",
params->anchored, params->run_forward, flags,
DumpState(info->start).c_str(), info->firstbyte.load());
@@ -1728,7 +1728,7 @@
}
*failed = false;
- if (DebugDFA) {
+ if (ExtraDebug) {
fprintf(stderr, "\nprogram:\n%s\n", prog_->DumpUnanchored().c_str());
fprintf(stderr, "text %s anchored=%d earliest=%d fwd=%d kind %d\n",
text.ToString().c_str(), anchored, want_earliest_match,
@@ -1755,7 +1755,7 @@
*epp = text.end();
return true;
}
- if (DebugDFA)
+ if (ExtraDebug)
fprintf(stderr, "start %s\n", DumpState(params.start).c_str());
bool ret = FastSearchLoop(¶ms);
if (params.failed) {
diff --git a/re2/nfa.cc b/re2/nfa.cc
index ab93692..31481da 100644
--- a/re2/nfa.cc
+++ b/re2/nfa.cc
@@ -40,6 +40,8 @@
namespace re2 {
+static const bool ExtraDebug = false;
+
class NFA {
public:
NFA(Prog* prog);
@@ -60,8 +62,6 @@
bool anchored, bool longest,
StringPiece* submatch, int nsubmatch);
- static const int Debug = 0;
-
private:
struct Thread {
union {
@@ -238,7 +238,7 @@
if (id == 0)
continue;
if (q->has_index(id)) {
- if (Debug)
+ if (ExtraDebug)
fprintf(stderr, " [%d%s]\n", id, FormatCapture(t0->capture).c_str());
continue;
}
@@ -304,7 +304,7 @@
// Save state; will pick up at next byte.
t = Incref(t0);
*tp = t;
- if (Debug)
+ if (ExtraDebug)
fprintf(stderr, " + %d%s\n", id, FormatCapture(t0->capture).c_str());
Next:
@@ -484,11 +484,10 @@
// For debugging prints.
btext_ = context.begin();
- if (Debug) {
+ if (ExtraDebug)
fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
text.ToString().c_str(), context.ToString().c_str(), anchored,
longest);
- }
// Set up search.
Threadq* runq = &q0_;
@@ -528,7 +527,7 @@
else
flag |= kEmptyNonWordBoundary;
- if (Debug) {
+ if (ExtraDebug) {
int c = 0;
if (p == context.begin())
c = '^';
@@ -620,7 +619,7 @@
// If all the threads have died, stop early.
if (runq->size() == 0) {
- if (Debug)
+ if (ExtraDebug)
fprintf(stderr, "dead\n");
break;
}
@@ -636,7 +635,7 @@
submatch[i] =
StringPiece(match_[2 * i],
static_cast<size_t>(match_[2 * i + 1] - match_[2 * i]));
- if (Debug)
+ if (ExtraDebug)
fprintf(stderr, "match (%td,%td)\n",
match_[0] - btext_, match_[1] - btext_);
return true;
@@ -709,7 +708,7 @@
Prog::SearchNFA(const StringPiece& text, const StringPiece& context,
Anchor anchor, MatchKind kind,
StringPiece* match, int nmatch) {
- if (NFA::Debug)
+ if (ExtraDebug)
Dump();
NFA nfa(this);
diff --git a/re2/onepass.cc b/re2/onepass.cc
index 65eb937..10dc642 100644
--- a/re2/onepass.cc
+++ b/re2/onepass.cc
@@ -72,7 +72,7 @@
namespace re2 {
-static const int Debug = 0;
+static const bool ExtraDebug = false;
// The key insight behind this implementation is that the
// non-determinism in an NFA for a one-pass regular expression
@@ -460,7 +460,7 @@
int nextindex = nodebyid[ip->out()];
if (nextindex == -1) {
if (nalloc >= maxnodes) {
- if (Debug)
+ if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: hit node limit %d >= %d", nalloc, maxnodes);
goto fail;
@@ -485,10 +485,9 @@
if ((act & kImpossible) == kImpossible) {
node->action[b] = newact;
} else if (act != newact) {
- if (Debug) {
+ if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: conflict on byte %#x at state %d", c, *it);
- }
goto fail;
}
}
@@ -507,10 +506,9 @@
if ((act & kImpossible) == kImpossible) {
node->action[b] = newact;
} else if (act != newact) {
- if (Debug) {
+ if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: conflict on byte %#x at state %d", c, *it);
- }
goto fail;
}
}
@@ -549,10 +547,9 @@
// If already on work queue, (1) is violated: bail out.
if (!AddQ(&workq, ip->out())) {
- if (Debug) {
+ if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: multiple paths %d -> %d\n", *it, ip->out());
- }
goto fail;
}
id = ip->out();
@@ -561,10 +558,9 @@
case kInstMatch:
if (matched) {
// (3) is violated
- if (Debug) {
+ if (ExtraDebug)
LOG(ERROR) << StringPrintf(
"Not OnePass: multiple matches from %d\n", *it);
- }
goto fail;
}
matched = true;
@@ -584,7 +580,7 @@
}
}
- if (Debug) { // For debugging, dump one-pass NFA to LOG(ERROR).
+ if (ExtraDebug) { // For debugging, dump one-pass NFA to LOG(ERROR).
LOG(ERROR) << "bytemap:\n" << DumpByteMap();
LOG(ERROR) << "prog:\n" << Dump();
diff --git a/re2/prefilter.cc b/re2/prefilter.cc
index 9cc79d6..f644e73 100644
--- a/re2/prefilter.cc
+++ b/re2/prefilter.cc
@@ -19,7 +19,7 @@
namespace re2 {
-static const bool Trace = false;
+static const bool ExtraDebug = false;
typedef std::set<string>::iterator SSIter;
typedef std::set<string>::const_iterator ConstSSIter;
@@ -453,7 +453,7 @@
typedef CharClass::iterator CCIter;
Prefilter::Info* Prefilter::Info::CClass(CharClass *cc,
bool latin1) {
- if (Trace) {
+ if (ExtraDebug) {
LOG(INFO) << "CharClassInfo:";
for (CCIter i = cc->begin(); i != cc->end(); ++i)
LOG(INFO) << " " << i->lo << "-" << i->hi;
@@ -476,9 +476,8 @@
a->is_exact_ = true;
- if (Trace) {
+ if (ExtraDebug)
LOG(INFO) << " = " << a->ToString();
- }
return a;
}
@@ -505,9 +504,8 @@
};
Prefilter::Info* Prefilter::BuildInfo(Regexp* re) {
- if (Trace) {
+ if (ExtraDebug)
LOG(INFO) << "BuildPrefilter::Info: " << re->ToString();
- }
bool latin1 = (re->parse_flags() & Regexp::Latin1) != 0;
Prefilter::Info::Walker w(latin1);
@@ -638,10 +636,9 @@
break;
}
- if (Trace) {
+ if (ExtraDebug)
LOG(INFO) << "BuildInfo " << re->ToString()
<< ": " << (info ? info->ToString() : "");
- }
return info;
}
diff --git a/re2/prefilter_tree.cc b/re2/prefilter_tree.cc
index dbcbb90..556561f 100644
--- a/re2/prefilter_tree.cc
+++ b/re2/prefilter_tree.cc
@@ -20,6 +20,8 @@
namespace re2 {
+static const bool ExtraDebug = false;
+
PrefilterTree::PrefilterTree()
: compiled_(false),
min_atom_len_(3) {
@@ -97,7 +99,8 @@
}
}
- PrintDebugInfo();
+ if (ExtraDebug)
+ PrintDebugInfo();
}
Prefilter* PrefilterTree::CanonicalNode(Prefilter* node) {