Computer Laboratory

tesla::internal::DFABuilder Class Reference

Detailed Description

Definition at line 706 of file Automaton.cpp.

Public Member Functions

DFAConstructDFA (const NFA *N)
 Public interface to this class. Constructs a DFA from the provided NFA. More...
 

Member Function Documentation

DFA* tesla::internal::DFABuilder::ConstructDFA ( const NFA N)
inline

Public interface to this class. Constructs a DFA from the provided NFA.

Definition at line 770 of file Automaton.cpp.

References tesla::State::begin(), tesla::Transition::Copy(), tesla::debugs(), tesla::Transition::Destination(), tesla::State::end(), tesla::Automaton::getAssertion(), tesla::Transition::getKind(), tesla::Transition::GroupClasses(), tesla::State::ID(), tesla::Automaton::ID(), tesla::Transition::IsRealisable(), tesla::Automaton::Name(), tesla::Transition::Null, tesla::Automaton::States, tesla::Automaton::String(), and tesla::Automaton::Use().

Referenced by tesla::DFA::Convert().

770  {
771  assert(N != NULL);
772  // We can't reuse these currently.
773  assert(States.empty());
774  // The set of DFA states that correspond to the current location
775  NFAState CurrentState;
776  stateForNFAState(N->States.front());
777  while (!UnfinishedStates.empty()) {
778  CurrentState = UnfinishedStates.back().first;
779  auto StartFinal = UnfinishedStates.back().second;
780  bool Start = StartFinal.first;
781  bool Final = StartFinal.second;
782  UnfinishedStates.pop_back();
783  // Find the NFA states that correspond to the current state.
784  State *DS = stateForNFAStates(CurrentState, Start, Final);
785  if (FinishedStates.find(DS->ID()) != FinishedStates.end())
786  continue;
787  FinishedStates.insert(DS->ID());
788  // Now we have a state, we need to handle its transitions.
789  // If there is only one state in the current state set, then we can just
790  // copy all of the transitions from it.
791  unordered_set<Transition*> FinishedTransitions;
792  // Loop over all of the NFA states and find their outgoing transitions
793  for (auto SI=CurrentState.begin(), SE=CurrentState.end() ; SI!=SE ; ++SI) {
794  unsigned I = *SI;
795  State *NState = N->States[I];
796  Start = false;
797  Final = false;
798  for (auto TI=NState->begin(), TE=NState->end() ; TI!=TE ; ++TI) {
799  Transition *T = *TI;
800  if (T->getKind() == Transition::Null) continue;
801  assert(T->IsRealisable());
802  if (FinishedTransitions.count(T) != 0) continue;
803  NFAState Destinations;
804  collectFrontier(Destinations, &T->Destination(), Start, Final);
805  FinishedTransitions.insert(T);
806  // Find the other transitions from this state that are equivalent to this one.
807  auto DTI = TI;
808  for (++DTI ; DTI!=TE ; ++DTI) {
809  if ((*DTI)->EquivalentTo(*T)) {
810  assert(FinishedTransitions.count(*DTI) == 0);
811  FinishedTransitions.insert(*DTI);
812  collectFrontier(Destinations, &(*DTI)->Destination(), Start, Final);
813  }
814  }
815  auto DSI = SI;
816  for (++DSI ; DSI!=SE ; ++DSI)
817  for (Transition *DT : *N->States[*DSI]) {
818  if (DT->EquivalentTo(*T)) {
819  assert(FinishedTransitions.count(DT) == 0);
820  FinishedTransitions.insert(DT);
821  collectFrontier(Destinations, &DT->Destination(), Start, Final);
822  }
823  }
824 
825  State *Dest = stateForNFAStates(Destinations, Start, Final);
826  Transition::Copy(*DS, *Dest, T, Transitions);
827  }
828  }
829  }
830  TransitionSets TEquivClasses;
831  Transition::GroupClasses(Transitions, TEquivClasses);
832 
833  DFA *D = new DFA(N->ID(),
834  const_cast<AutomatonDescription&>(N->getAssertion()),
835  N->Use(), N->Name(), States, TEquivClasses);
836 
837  debugs("tesla.automata.dfa")
838  << "DFA conversion results:\n"
839  << "> NFA: " << N->String() << "\n"
840  << "> DFA: " << D->String() << "\n"
841  << ">> DFA state map:\n"
842  << DFAStates
843  << ">> DFA transition equivalence classes:\n"
844  ;
845 
846  return D;
847  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: