Skip to content

Commit

Permalink
remove debug printf
Browse files Browse the repository at this point in the history
  • Loading branch information
qinwf committed Mar 13, 2020
1 parent 535f01e commit 7feece2
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ GTAGS
^inst/img/number\.png$
^number\.png$

^test-unicode\.R$
test-unicode.R
76 changes: 38 additions & 38 deletions src/dfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ DFA::DFA(Prog* prog, Prog::MatchKind kind, int64_t max_mem)
q0_(NULL),
q1_(NULL),
mem_budget_(max_mem) {
if (ExtraDebug)
fprintf(stderr, "\nkind %d\n%s\n", kind_, prog_->DumpUnanchored().c_str());
// if (ExtraDebug)
// fprintf(stderr, "\nkind %d\n%s\n", kind_, prog_->DumpUnanchored().c_str());
int nmark = 0;
if (kind_ == Prog::kLongestMatch)
nmark = prog_->size();
Expand Down Expand Up @@ -619,8 +619,8 @@ DFA::State* DFA::WorkqToCachedState(Workq* q, Workq* mq, uint32_t flag) {
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 (ExtraDebug)
fprintf(stderr, "WorkqToCachedState %s [%#x]", DumpWorkq(q).c_str(), flag);
// 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;
if (sawmatch && (kind_ == Prog::kFirstMatch || q->is_mark(id)))
Expand All @@ -645,8 +645,8 @@ DFA::State* DFA::WorkqToCachedState(Workq* q, Workq* mq, uint32_t flag) {
(kind_ != Prog::kLongestMatch || !sawmark) &&
(flag & kFlagMatch)) {
delete[] inst;
if (ExtraDebug)
fprintf(stderr, " -> FullMatchState\n");
// if (ExtraDebug)
// fprintf(stderr, " -> FullMatchState\n");
return FullMatchState;
}
FALLTHROUGH_INTENDED;
Expand Down Expand Up @@ -692,8 +692,8 @@ DFA::State* DFA::WorkqToCachedState(Workq* q, Workq* mq, uint32_t flag) {
// if the state is *not* a matching state.
if (n == 0 && flag == 0) {
delete[] inst;
if (ExtraDebug)
fprintf(stderr, " -> DeadState\n");
// if (ExtraDebug)
// fprintf(stderr, " -> DeadState\n");
return DeadState;
}

Expand Down Expand Up @@ -757,8 +757,8 @@ DFA::State* DFA::CachedState(int* inst, int ninst, uint32_t flag) {
state.flag_ = flag;
StateSet::iterator it = state_cache_.find(&state);
if (it != state_cache_.end()) {
if (ExtraDebug)
fprintf(stderr, " -cached-> %s\n", DumpState(*it).c_str());
// if (ExtraDebug)
// fprintf(stderr, " -cached-> %s\n", DumpState(*it).c_str());
return *it;
}

Expand Down Expand Up @@ -788,8 +788,8 @@ DFA::State* DFA::CachedState(int* inst, int ninst, uint32_t flag) {
memmove(s->inst_, inst, ninst*sizeof s->inst_[0]);
s->ninst_ = ninst;
s->flag_ = flag;
if (ExtraDebug)
fprintf(stderr, " -> %s\n", DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, " -> %s\n", DumpState(s).c_str());

// Put state in cache and return it.
state_cache_.insert(s);
Expand Down Expand Up @@ -1002,9 +1002,9 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
}
}

if (ExtraDebug)
fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n",
DumpWorkq(oldq).c_str(), c, flag, DumpWorkq(newq).c_str(), *ismatch);
// if (ExtraDebug)
// fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n",
// DumpWorkq(oldq).c_str(), c, flag, DumpWorkq(newq).c_str(), *ismatch);
}

// Processes input byte c in state, returning new state.
Expand Down Expand Up @@ -1362,14 +1362,14 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
bool matched = false;

State* s = start;
if (ExtraDebug)
fprintf(stderr, "@stx: %s\n", DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, "@stx: %s\n", DumpState(s).c_str());

if (s->IsMatch()) {
matched = true;
lastmatch = p;
if (ExtraDebug)
fprintf(stderr, "match @stx! [%s]\n", DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, "match @stx! [%s]\n", DumpState(s).c_str());
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
Expand All @@ -1385,8 +1385,8 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
}

while (p != ep) {
if (ExtraDebug)
fprintf(stderr, "@%td: %s\n", p - bp, DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, "@%td: %s\n", p - bp, DumpState(s).c_str());

if (have_first_byte && s == start) {
// In start state, only way out is to find first_byte,
Expand Down Expand Up @@ -1493,8 +1493,8 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
lastmatch = p - 1;
else
lastmatch = p + 1;
if (ExtraDebug)
fprintf(stderr, "match @%td! [%s]\n", lastmatch - bp, DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, "match @%td! [%s]\n", lastmatch - bp, DumpState(s).c_str());
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
Expand All @@ -1512,8 +1512,8 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,

// Process one more byte to see if it triggers a match.
// (Remember, matches are delayed one byte.)
if (ExtraDebug)
fprintf(stderr, "@etx: %s\n", DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, "@etx: %s\n", DumpState(s).c_str());

int lastbyte;
if (run_forward) {
Expand Down Expand Up @@ -1560,8 +1560,8 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
if (s->IsMatch()) {
matched = true;
lastmatch = p;
if (ExtraDebug)
fprintf(stderr, "match @etx! [%s]\n", DumpState(s).c_str());
// if (ExtraDebug)
// fprintf(stderr, "match @etx! [%s]\n", DumpState(s).c_str());
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
Expand Down Expand Up @@ -1719,10 +1719,10 @@ bool DFA::AnalyzeSearch(SearchParams* params) {
}
}

if (ExtraDebug)
fprintf(stderr, "anchored=%d fwd=%d flags=%#x state=%s first_byte=%d\n",
params->anchored, params->run_forward, flags,
DumpState(info->start).c_str(), info->first_byte.load());
// if (ExtraDebug)
// fprintf(stderr, "anchored=%d fwd=%d flags=%#x state=%s first_byte=%d\n",
// params->anchored, params->run_forward, flags,
// DumpState(info->start).c_str(), info->first_byte.load());

params->start = info->start;
params->first_byte = info->first_byte.load(std::memory_order_acquire);
Expand Down Expand Up @@ -1794,11 +1794,11 @@ bool DFA::Search(const StringPiece& text,
}
*failed = false;

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",
std::string(text).c_str(), anchored, want_earliest_match, run_forward, kind_);
}
// 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",
// std::string(text).c_str(), anchored, want_earliest_match, run_forward, kind_);
// }

RWLocker l(&cache_mutex_);
SearchParams params(text, context, &l);
Expand All @@ -1820,8 +1820,8 @@ bool DFA::Search(const StringPiece& text,
*epp = text.data() + text.size();
return true;
}
if (ExtraDebug)
fprintf(stderr, "start %s\n", DumpState(params.start).c_str());
// if (ExtraDebug)
// fprintf(stderr, "start %s\n", DumpState(params.start).c_str());
bool ret = FastSearchLoop(&params);
if (params.failed) {
*failed = true;
Expand Down
70 changes: 35 additions & 35 deletions src/nfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
if (id == 0)
continue;
if (q->has_index(id)) {
if (ExtraDebug)
fprintf(stderr, " [%d%s]\n", id, FormatCapture(t0->capture).c_str());
// if (ExtraDebug)
// fprintf(stderr, " [%d%s]\n", id, FormatCapture(t0->capture).c_str());
continue;
}

Expand Down Expand Up @@ -292,8 +292,8 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
// Save state; will pick up at next byte.
t = Incref(t0);
*tp = t;
if (ExtraDebug)
fprintf(stderr, " + %d%s\n", id, FormatCapture(t0->capture).c_str());
// if (ExtraDebug)
// fprintf(stderr, " + %d%s\n", id, FormatCapture(t0->capture).c_str());

if (ip->hint() == 0)
break;
Expand All @@ -304,8 +304,8 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
// Save state; will pick up at next byte.
t = Incref(t0);
*tp = t;
if (ExtraDebug)
fprintf(stderr, " ! %d%s\n", id, FormatCapture(t0->capture).c_str());
// if (ExtraDebug)
// fprintf(stderr, " ! %d%s\n", id, FormatCapture(t0->capture).c_str());

Next:
if (ip->last())
Expand Down Expand Up @@ -496,9 +496,9 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
// For convenience.
etext_ = text.data() + text.size();

if (ExtraDebug)
fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
std::string(text).c_str(), std::string(context).c_str(), anchored, longest);
// if (ExtraDebug)
// fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
// std::string(text).c_str(), std::string(context).c_str(), anchored, longest);

// Set up search.
Threadq* runq = &q0_;
Expand All @@ -509,24 +509,24 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,

// Loop over the text, stepping the machine.
for (const char* p = text.data();; p++) {
if (ExtraDebug) {
int c = 0;
if (p == btext_)
c = '^';
else if (p > etext_)
c = '$';
else if (p < etext_)
c = p[0] & 0xFF;

fprintf(stderr, "%c:", c);
for (Threadq::iterator i = runq->begin(); i != runq->end(); ++i) {
Thread* t = i->value();
if (t == NULL)
continue;
fprintf(stderr, " %d%s", i->index(), FormatCapture(t->capture).c_str());
}
fprintf(stderr, "\n");
}
// if (ExtraDebug) {
// int c = 0;
// if (p == btext_)
// c = '^';
// else if (p > etext_)
// c = '$';
// else if (p < etext_)
// c = p[0] & 0xFF;

// fprintf(stderr, "%c:", c);
// for (Threadq::iterator i = runq->begin(); i != runq->end(); ++i) {
// Thread* t = i->value();
// if (t == NULL)
// continue;
// fprintf(stderr, " %d%s", i->index(), FormatCapture(t->capture).c_str());
// }
// fprintf(stderr, "\n");
// }

// This is a no-op the first time around the loop because runq is empty.
int id = Step(runq, nextq, p < etext_ ? p[0] & 0xFF : -1, context, p);
Expand Down Expand Up @@ -594,8 +594,8 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,

// If all the threads have died, stop early.
if (runq->size() == 0) {
if (ExtraDebug)
fprintf(stderr, "dead\n");
// if (ExtraDebug)
// fprintf(stderr, "dead\n");
break;
}

Expand All @@ -620,10 +620,10 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
submatch[i] =
StringPiece(match_[2 * i],
static_cast<size_t>(match_[2 * i + 1] - match_[2 * i]));
if (ExtraDebug)
fprintf(stderr, "match (%td,%td)\n",
match_[0] - btext_,
match_[1] - btext_);
// if (ExtraDebug)
// fprintf(stderr, "match (%td,%td)\n",
// match_[0] - btext_,
// match_[1] - btext_);
return true;
}
return false;
Expand Down Expand Up @@ -694,8 +694,8 @@ bool
Prog::SearchNFA(const StringPiece& text, const StringPiece& context,
Anchor anchor, MatchKind kind,
StringPiece* match, int nmatch) {
if (ExtraDebug)
Dump();
// if (ExtraDebug)
// Dump();

NFA nfa(this);
StringPiece sp;
Expand Down
Loading

0 comments on commit 7feece2

Please sign in to comment.