1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the utils of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "dotgraph.h"
30
31#include "lalr.h"
32
33#include <QtCore/qtextstream.h>
34
35DotGraph::DotGraph(QTextStream &o):
36 out (o)
37{
38}
39
40void DotGraph::operator () (Automaton *aut)
41{
42 Grammar *g = aut->_M_grammar;
43
44 out << "digraph {" << Qt::endl << Qt::endl;
45
46 out << "subgraph Includes {" << Qt::endl;
47 for (Automaton::IncludesGraph::iterator incl = Automaton::IncludesGraph::begin_nodes ();
48 incl != Automaton::IncludesGraph::end_nodes (); ++incl)
49 {
50 for (Automaton::IncludesGraph::edge_iterator edge = incl->begin (); edge != incl->end (); ++edge)
51 {
52 out << "\t\"(" << aut->id (state: incl->data.state) << ", " << incl->data.nt << ")\"";
53 out << "\t->\t";
54 out << "\"(" << aut->id (state: (*edge)->data.state) << ", " << (*edge)->data.nt << ")\"\t";
55 out << "[label=\"" << incl->data.state->follows [incl->data.nt] << "\"]";
56 out << Qt::endl;
57 }
58 }
59 out << "}" << Qt::endl << Qt::endl;
60
61
62 out << "subgraph LRA {" << Qt::endl;
63 //out << "node [shape=record];" << Qt::endl << Qt::endl;
64
65 for (StatePointer q = aut->states.begin (); q != aut->states.end (); ++q)
66 {
67 int state = aut->id (state: q);
68
69 out << "\t" << state << "\t[shape=record,label=\"{";
70
71 out << "<0> State " << state;
72
73 int index = 1;
74 for (ItemPointer item = q->kernel.begin (); item != q->kernel.end (); ++item)
75 out << "| <" << index++ << "> " << *item;
76
77 out << "}\"]" << Qt::endl;
78
79 for (Bundle::iterator a = q->bundle.begin (); a != q->bundle.end (); ++a)
80 {
81 const char *clr = g->isTerminal (name: a.key ()) ? "blue" : "red";
82 out << "\t" << state << "\t->\t" << aut->id (state: *a) << "\t[color=\"" << clr << "\",label=\"" << a.key () << "\"]" << Qt::endl;
83 }
84 out << Qt::endl;
85 }
86
87 out << "}" << Qt::endl;
88 out << Qt::endl << Qt::endl << "}" << Qt::endl;
89}
90

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