1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include "dotgraph.h"
5
6#include "lalr.h"
7
8#include <QtCore/qtextstream.h>
9
10DotGraph::DotGraph(QTextStream &o):
11 out (o)
12{
13}
14
15void DotGraph::operator () (Automaton *aut)
16{
17 Grammar *g = aut->_M_grammar;
18
19 out << "digraph {" << Qt::endl << Qt::endl;
20
21 out << "subgraph Includes {" << Qt::endl;
22 for (Automaton::IncludesGraph::iterator incl = Automaton::IncludesGraph::begin_nodes ();
23 incl != Automaton::IncludesGraph::end_nodes (); ++incl)
24 {
25 for (Automaton::IncludesGraph::edge_iterator edge = incl->begin (); edge != incl->end (); ++edge)
26 {
27 out << "\t\"(" << aut->id (state: incl->data.state) << ", " << incl->data.nt << ")\"";
28 out << "\t->\t";
29 out << "\"(" << aut->id (state: (*edge)->data.state) << ", " << (*edge)->data.nt << ")\"\t";
30 out << "[label=\"" << incl->data.state->follows [incl->data.nt] << "\"]";
31 out << Qt::endl;
32 }
33 }
34 out << "}" << Qt::endl << Qt::endl;
35
36
37 out << "subgraph LRA {" << Qt::endl;
38 //out << "node [shape=record];" << Qt::endl << Qt::endl;
39
40 for (StatePointer q = aut->states.begin (); q != aut->states.end (); ++q)
41 {
42 int state = aut->id (state: q);
43
44 out << "\t" << state << "\t[shape=record,label=\"{";
45
46 out << "<0> State " << state;
47
48 int index = 1;
49 for (ItemPointer item = q->kernel.begin (); item != q->kernel.end (); ++item)
50 out << "| <" << index++ << "> " << *item;
51
52 out << "}\"]" << Qt::endl;
53
54 for (Bundle::iterator a = q->bundle.begin (); a != q->bundle.end (); ++a)
55 {
56 const char *clr = g->isTerminal (name: a.key ()) ? "blue" : "red";
57 out << "\t" << state << "\t->\t" << aut->id (state: *a) << "\t[color=\"" << clr << "\",label=\"" << a.key () << "\"]" << Qt::endl;
58 }
59 out << Qt::endl;
60 }
61
62 out << "}" << Qt::endl;
63 out << Qt::endl << Qt::endl << "}" << Qt::endl;
64}
65

source code of qtbase/src/tools/qlalr/dotgraph.cpp