in blingfirecompile.library/src/FATestCmpDfa.cpp [192:339]
const bool FATestCmpDfa::Process (const int /*MaxState*/, const int MaxIw)
{
DebugLogAssert (0 < MaxIw);
DebugLogAssert (m_pDfa1 && m_pDfa2);
Clear ();
if (false == CmpAlphabets ()) {
return false;
}
int State1 = m_pDfa1->GetInitial ();
int State2 = m_pDfa2->GetInitial ();
m_stack.push_back (State1);
m_stack.push_back (State2);
// mark the as "seen"
SetSeen (&m_visited1, State1);
SetSeen (&m_visited2, State2);
int StackSize = 2;
DebugLogAssert (m_stack.size () == (unsigned int) StackSize);
while (0 < StackSize) {
DebugLogAssert (m_stack.size () == (unsigned int) StackSize && \
0 == (StackSize & 1));
State2 = m_stack [StackSize - 1];
State1 = m_stack [StackSize - 2];
m_stack.resize (StackSize - 2);
StackSize -= 2;
/// // check whether they both final
/// const bool IsFinal1 = m_pDfa1->IsFinal (State1);
/// const bool IsFinal2 = m_pDfa2->IsFinal (State2);
/// if (IsFinal1 != IsFinal2) {
/// // both should be final or non-final
/// DebugLogAssert (0);
/// return false;
/// }
// check whether they both have same Ows associated
if (m_pState2Ow1 && m_pState2Ow2) {
const int Ow1 = m_pState2Ow1->GetOw (State1);
const int Ow2 = m_pState2Ow2->GetOw (State2);
if (Ow1 != Ow2) {
// Ows different
DebugLogAssert (0);
return false;
}
}
// check whether they both have same Ow-sets associated
if (m_pState2Ows1 && m_pState2Ows2) {
const int Count1 =
m_pState2Ows1->GetOws (State1, m_pOws1, m_MaxOws1Count);
const int Count2 =
m_pState2Ows2->GetOws (State2, m_pOws2, m_MaxOws2Count);
if (Count1 != Count2 || \
Count1 > m_MaxOws1Count || \
Count2 > m_MaxOws2Count) {
// problems with max values or different Ows
DebugLogAssert (0);
return false;
}
if (-1 != Count1 && \
0 != memcmp (m_pOws1, m_pOws2, Count1 * sizeof (int))) {
// different Ows
DebugLogAssert (0);
return false;
}
}
// process destination states
for (int iw = 0; iw <= MaxIw; ++iw) {
const int Dest1 = m_pDfa1->GetDest (State1, iw);
const int Dest2 = m_pDfa2->GetDest (State2, iw);
// transition does not exist
if (-1 == Dest1 && -1 == Dest2) {
continue;
}
if ((-1 == Dest1 || -1 == Dest2) && \
Dest2 != Dest1) {
// missing transition
DebugLogAssert (0);
return false;
}
if ((FAFsmConst::DFA_DEAD_STATE == Dest1 || \
FAFsmConst::DFA_DEAD_STATE == Dest2) && \
Dest2 != Dest1) {
// dead-state misrepresentation
DebugLogAssert (0);
return false;
}
const bool IsSeen1 = WasSeen (&m_visited1, Dest1);
const bool IsSeen2 = WasSeen (&m_visited2, Dest2);
if (IsSeen1 != IsSeen2) {
// transition graphs have different structure
DebugLogAssert (0);
return false;
}
if (m_pSigma1 && m_pSigma2) {
int Ow1 = -2;
const int D1 = m_pSigma1->GetDestOw (State1, iw, &Ow1);
int Ow2 = -3;
const int D2 = m_pSigma2->GetDestOw (State2, iw, &Ow2);
if (Ow1 != Ow2) {
// sigma difference in Ows
DebugLogAssert (0);
return false;
}
if (D1 != Dest1 || D2 != Dest2) {
// sigma difference in Dsts
return false;
}
}
if (!IsSeen1) {
m_stack.push_back (Dest1);
m_stack.push_back (Dest2);
StackSize += 2;
SetSeen (&m_visited1, Dest1);
SetSeen (&m_visited2, Dest2);
}
} // of for (int iw = 0; ...
} // of while (0 < StackSize) ...
return true;
}