Example #1
0
AutoPtr< List<String> > TokenWatcher::DumpInternal()
{
    AutoPtr< List<String> > a = new List<String>;
    {
        AutoLock lock(mLock);
        Set<AutoPtr<IBinder> > keys;
        HashMap<AutoPtr<IBinder>, AutoPtr<Death> >::Iterator iter = mTokens.Begin();
        for (; iter != mTokens.End(); ++iter) {
            keys.Insert(iter->mFirst);
        }
        StringBuilder sb("Token count: ");
        sb += mTokens.GetSize();
        a->PushBack(sb.ToString());
        Int32 i = 0;
        Set<AutoPtr<IBinder> >::Iterator iter2 = keys.Begin();
        AutoPtr<IBinder> b;
        for (; iter2 != keys.End(); ++iter) {
            StringBuilder sb2("[");
            sb2 += i;
            sb2 += "] ";
            sb2 += mTokens[b]->mTag;
            sb2 += " - ";
            String bstr;
            b->ToString(&bstr);
            sb2 += bstr;
            a->PushBack(sb2.ToString());
            i++;
        }
    }
    return a;
}
template <class T> void print(const Set<T>& l, const string& name)
{  // Print the contents of a Set. Notice the presence of a constant iterator.
	
	cout << endl << name << ", size of set is " << l.Size() << "\n[ ";

	set<T>::const_iterator i;

	for (i = l.Begin(); i != l.End(); ++i)
	{
			cout << *i << " ";

	}

	cout << "]\n";
}
Example #3
0
/*----------------------------------------------------------------------------------------------
	Generate the actual FSM table for the pass.
	Process:

 *	Initialize the table with the start state, corresponding to 0 slots matched.

 *	For each rule in the pass, add a state corresponding to 1 slot matched. Keep track of
	the relevant rule(s) and whether the new state is a terminating state for the rule(s).

 *	When we have created all the 1-slot-matched states, merge any equivalent states....

 *	For each 1-slot-matched, add 2-slots-matched states for any rules with at least 2 slots.
	Keep track of the relevant rule(s) and whether the new state is a terminating state for
	the rule(s).

 *	When we have created all the 2-slots-matched states, merge any equivalent states.

 *	Continue this process until we have created terminating states for every rule
	(ie, N-slots-matched state where the rule has N slots).
----------------------------------------------------------------------------------------------*/
void GdlPass::GenerateFsmTable(GrcManager * pcman)
{
	//	Hungarian: ifs = index of FsmState

	if (m_nGlobalID == -1)
	{
		m_nMaxRuleContext = 0;
		return;
	}

	m_pfsm = new FsmTable(m_nGlobalID, NumberOfFsmMachineClasses());
	Assert(m_pfsm->RawNumberOfStates() == 0);

	//	Create the start state, equivalent to no slots matched.
	m_pfsm->AddState(0);
	int ifsCurrent = 0;

	//	Index of the first state whose slot-count == the slot count of currState, ie, the
	//	beginning of the state range which may need to be fixed up as we merge.
	int ifsCurrSlotCntMin = 0;

	//	Index of first state whose slot-count == slot count of currState + 1, ie, the
	//	beginning of the state range in which to check for duplicates.
	int ifsNextSlotCntMin = 1;

	while (ifsCurrent < m_pfsm->RawNumberOfStates())
	{
		FsmState * pfstateCurr = m_pfsm->RawStateAt(ifsCurrent);
		int critSlotsMatched = pfstateCurr->SlotsMatched();
		if (!pfstateCurr->HasBeenMerged())
		{
			for (int iprule = 0; iprule < m_vprule.Size(); iprule++)
			{
				GdlRule * prule = m_vprule[iprule];

				if (ifsCurrent == 0	||	// for state #0, all rules are consider matched
					pfstateCurr->RuleMatched(iprule))
				{
					if (pfstateCurr->SlotsMatched() == prule->NumberOfInputItems())
					{
						pfstateCurr->AddRuleToSuccessList(iprule);
					}
					else
					{
						Set<FsmMachineClass *> setpfsmc;
						GetMachineClassesForRuleItem(prule, critSlotsMatched, setpfsmc);

						for (Set<FsmMachineClass *>::iterator it = setpfsmc.Begin();
							it != setpfsmc.End();
							++it)
						{
							FsmMachineClass * pfsmc = *it;
							int ifsmcColumn = pfsmc->Column();
							int ifsNextState = pfstateCurr->CellValue(ifsmcColumn);
							if (ifsNextState == 0)
							{
								//	Add a new state.
								ifsNextState = m_pfsm->RawNumberOfStates();
								m_pfsm->AddState(critSlotsMatched + 1);
								pfstateCurr->SetCellValue(ifsmcColumn, ifsNextState);
							}

							//	Store this rule as one matched for this state.
							m_pfsm->RawStateAt(ifsNextState)->AddRuleToMatchedList(iprule);
						}

					}
				}
			}
		}

		if (m_pfsm->RawNumberOfStates() > (ifsCurrent + 1) &&
			m_pfsm->RawStateAt(ifsCurrent + 1)->SlotsMatched() != critSlotsMatched)
		{
			//	We have just finished processing a group of states with critSlotsMatched,
			//	which had the effect of creating a group of states where slots-matched ==
			//	critSlotsMatched + 1. There could be duplicates in the latter group,
			//	which are pointed at by the former group. Mark the duplicates so that they
			//	point to the earlier identical state. (Note that since we are currently
			//	not actually deleting the duplicates, we don't need to fix up the earlier
			//	group.)

			MergeIdenticalStates(ifsCurrSlotCntMin, ifsNextSlotCntMin,
				m_pfsm->RawNumberOfStates());
			ifsCurrSlotCntMin = ifsNextSlotCntMin;
			ifsNextSlotCntMin = m_pfsm->RawNumberOfStates();
		}

		ifsCurrent++;	// go on to next state
	}

	m_nMaxRuleContext = m_pfsm->RawStateAt(ifsCurrent - 1)->m_critSlotsMatched;

	ReorderFsmStates();

	GenerateStartStates(pcman);
}