511 {
512 std::string result;
513 result += "digraph {\n";
514 std::set<StateIndex> terminalStates;
515
518 for(
Uptr charIndex = 0;charIndex < 256;++charIndex)
519 {
520 const Uptr classIndex = charToOffsetMap[charIndex] / numStates;
521 classCharSets[classIndex].add((
U8)charIndex);
522 }
523
524 {
525 std::map<StateIndex,CharSet> transitions;
526 for(
Uptr classIndex = 0;classIndex < numClasses;++classIndex)
527 {
528 const InternalStateIndex nextState = stateAndOffsetToNextStateMap[0 + classIndex * numStates];
529 CharSet& transitionPredicate = transitions[nextState];
530 transitionPredicate = classCharSets[classIndex] | transitionPredicate;
531 }
532
534 for(auto transitionPair : transitions)
535 {
537 {
538 result += "start" + std::to_string(startIndex) + "[shape=triangle label=\"\"];\n";
539
541 std::string nextStateName = transitionPair.first < 0
543 :
"state" +
std::to_string(transitionPair.first);
544 result += "start" + std::to_string(startIndex)
545 + " -> "
546 + nextStateName + "[label=\""
549
550 if(transitionPair.first < 0)
551 {
553 }
554
555 ++startIndex;
556 }
557 }
558 }
559
560 for(
Uptr stateIndex = 1;stateIndex < numStates;++stateIndex)
561 {
562 result += "state" + std::to_string(stateIndex) + "[shape=square label=\"" + std::to_string(stateIndex) + "\"];\n";
563
564 std::map<StateIndex,CharSet> transitions;
565 for(
Uptr classIndex = 0;classIndex < numClasses;++classIndex)
566 {
567 const InternalStateIndex nextState = stateAndOffsetToNextStateMap[stateIndex + classIndex * numStates];
568 CharSet& transitionPredicate = transitions[nextState];
569 transitionPredicate = classCharSets[classIndex] | transitionPredicate;
570 }
571
572 for(auto transitionPair : transitions)
573 {
575 {
577 std::string nextStateName = transitionPair.first < 0
579 :
"state" +
std::to_string(transitionPair.first);
580 result += "state" + std::to_string(stateIndex)
581 + " -> "
582 + nextStateName + "[label=\""
585
586 if(transitionPair.first < 0)
587 {
588 terminalStates.emplace(transitionPair.first);
589 }
590 }
591 }
592 }
593 for(auto terminalState : terminalStates)
594 {
597 }
598 result += "}\n";
599 return result;
600 }
std::string getGraphEdgeLabel(const CharSet &charSet)
DenseStaticIntSet< U8, 256 > CharSet
std::string escapeString(const std::string &string)
@ maximumTerminalStateIndex
@ edgeDoesntConsumeInputFlag
@ unmatchedCharacterTerminal
memset(pInfo->slotDescription, ' ', 64)