Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
dotgraph.cpp
Go to the documentation of this file.
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// Qt-Security score:insignificant reason:build-tool
4
5#include "dotgraph.h"
6
7#include "lalr.h"
8
9#include <QtCore/qtextstream.h>
10
11DotGraph::DotGraph(QTextStream &o):
12 out (o)
13{
14}
15
17{
18 Grammar *g = aut->_M_grammar;
19
20 out << "digraph {" << Qt::endl << Qt::endl;
21
22 out << "subgraph Includes {" << Qt::endl;
23 for (Automaton::IncludesGraph::iterator incl = Automaton::IncludesGraph::begin_nodes ();
24 incl != Automaton::IncludesGraph::end_nodes (); ++incl)
25 {
26 for (Automaton::IncludesGraph::edge_iterator edge = incl->begin (); edge != incl->end (); ++edge)
27 {
28 out << "\t\"(" << aut->id (incl->data.state) << ", " << incl->data.nt << ")\"";
29 out << "\t->\t";
30 out << "\"(" << aut->id ((*edge)->data.state) << ", " << (*edge)->data.nt << ")\"\t";
31 out << "[label=\"" << incl->data.state->follows [incl->data.nt] << "\"]";
32 out << Qt::endl;
33 }
34 }
35 out << "}" << Qt::endl << Qt::endl;
36
37
38 out << "subgraph LRA {" << Qt::endl;
39 //out << "node [shape=record];" << Qt::endl << Qt::endl;
40
41 for (StatePointer q = aut->states.begin (); q != aut->states.end (); ++q)
42 {
43 int state = aut->id (q);
44
45 out << "\t" << state << "\t[shape=record,label=\"{";
46
47 out << "<0> State " << state;
48
49 int index = 1;
50 for (ItemPointer item = q->kernel.begin (); item != q->kernel.end (); ++item)
51 out << "| <" << index++ << "> " << *item;
52
53 out << "}\"]" << Qt::endl;
54
55 for (Bundle::iterator a = q->bundle.begin (); a != q->bundle.end (); ++a)
56 {
57 const char *clr = g->isTerminal (a.key ()) ? "blue" : "red";
58 out << "\t" << state << "\t->\t" << aut->id (*a) << "\t[color=\"" << clr << "\",label=\"" << a.key () << "\"]" << Qt::endl;
59 }
60 out << Qt::endl;
61 }
62
63 out << "}" << Qt::endl;
64 out << Qt::endl << Qt::endl << "}" << Qt::endl;
65}
int id(RulePointer rule)
Definition lalr.cpp:243
Grammar * _M_grammar
Definition lalr.h:351
StateList states
Definition lalr.h:352
void operator()(Automaton *a)
Definition dotgraph.cpp:16
bool isTerminal(Name name) const
Definition lalr.h:222
StateList::iterator StatePointer
Definition lalr.h:43