Doxygen
Loading...
Searching...
No Matches
dotcallgraph.cpp
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright (C) 1997-2020 by Dimitri van Heesch.
4*
5* Permission to use, copy, modify, and distribute this software and its
6* documentation under the terms of the GNU General Public License is hereby
7* granted. No representations are made about the suitability of this software
8* for any purpose. It is provided "as is" without express or implied warranty.
9* See the GNU General Public License for more details.
10*
11* Documents produced by Doxygen are derivative works derived from the
12* input used in their production; they are not affected by this license.
13*
14*/
15
16#include "dotcallgraph.h"
17
18#include "dotnode.h"
19#include "memberlist.h"
20#include "config.h"
21#include "util.h"
22
24{
25 const MemberDef *def = md->memberDefinition();
26 if (def==nullptr) def = md;
27 QCString result = def->getReference()+"$"+
28 def->getOutputFileBase()+"#"+
29 def->anchor();
30 return result;
31}
32
33void DotCallGraph::buildGraph(DotNode *n,const MemberDef *md,int distance)
34{
35 auto refs = m_inverse ? md->getReferencedByMembers() : md->getReferencesMembers();
36 for (const auto &rmd : refs)
37 {
38 if (rmd->isCallable())
39 {
40 QCString uniqueId = getUniqueId(rmd);
41 auto it = m_usedNodes.find(uniqueId.str());
42 if (it!=m_usedNodes.end()) // file is already a node in the graph
43 {
44 DotNode *bn = it->second;
46 bn->addParent(n);
47 bn->setDistance(distance);
48 }
49 else
50 {
51 QCString name;
52 if (Config_getBool(HIDE_SCOPE_NAMES))
53 {
54 name = rmd->getOuterScope()==m_scope ?
55 rmd->name() : rmd->qualifiedName();
56 }
57 else
58 {
59 name = rmd->qualifiedName();
60 }
61 QCString tooltip = rmd->briefDescriptionAsTooltip();
62 DotNode *bn = new DotNode(
63 this,
64 linkToText(rmd->getLanguage(),name,FALSE),
65 tooltip,
66 uniqueId,
67 0 //distance
68 );
70 bn->addParent(n);
71 bn->setDistance(distance);
72 m_usedNodes.emplace(uniqueId.str(),bn);
73
74 buildGraph(bn,rmd,distance+1);
75 }
76 }
77 }
78}
79
81{
82 while (!queue.empty() && maxNodes>0)
83 {
84 DotNode *n = queue.front();
85 queue.pop_front();
86 if (!n->isVisible() && n->distance()<=Config_getInt(MAX_DOT_GRAPH_DEPTH)) // not yet processed
87 {
88 n->markAsVisible();
89 maxNodes--;
90 // add direct children
91 for (const auto &dn : n->children())
92 {
93 queue.push_back(dn);
94 }
95 }
96 }
97}
98
100{
101 while (!queue.empty())
102 {
103 DotNode *n = queue.front();
104 queue.pop_front();
105 if (n->isVisible() && n->isTruncated()==DotNode::Unknown)
106 {
107 bool truncated = FALSE;
108 for (const auto &dn : n->children())
109 {
110 if (!dn->isVisible())
111 truncated = TRUE;
112 else
113 queue.push_back(dn);
114 }
115 n->markAsTruncated(truncated);
116 }
117 }
118}
119
121{
122 m_inverse = inverse;
123 m_diskName = md->getOutputFileBase()+"_"+md->anchor();
124 m_scope = md->getOuterScope();
125 QCString uniqueId = getUniqueId(md);
126 QCString name;
127 if (Config_getBool(HIDE_SCOPE_NAMES))
128 {
129 name = md->name();
130 }
131 else
132 {
133 name = md->qualifiedName();
134 }
135 QCString tooltip = md->briefDescriptionAsTooltip();
136 m_startNode = new DotNode(this,
137 linkToText(md->getLanguage(),name,FALSE),
138 tooltip,
139 uniqueId,
140 TRUE // root node
141 );
142 m_startNode->setDistance(0);
143 m_usedNodes.emplace(uniqueId.str(),m_startNode);
145
146 int maxNodes = Config_getInt(DOT_GRAPH_MAX_NODES);
147 DotNodeDeque openNodeQueue;
148 openNodeQueue.push_back(m_startNode);
149 determineVisibleNodes(openNodeQueue,maxNodes);
150 openNodeQueue.clear();
151 openNodeQueue.push_back(m_startNode);
152 determineTruncatedNodes(openNodeQueue);
153}
154
159
161{
162 return m_diskName + (m_inverse ? "_icgraph" : "_cgraph");
163}
164
166{
171 m_inverse ? "RL" : "LR",
172 FALSE,
173 m_inverse,
174 m_startNode->label(),
175 m_theGraph);
176}
177
179{
180 return m_baseName;
181}
182
184 TextStream &out,
185 GraphOutputFormat graphFormat,
186 EmbeddedOutputFormat textFormat,
187 const QCString &path,
188 const QCString &fileName,
189 const QCString &relPath,bool generateImageMap,
190 int graphId)
191{
193
194 return DotGraph::writeGraph(out, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
195}
196
198{
199 return m_startNode->children().empty();
200}
201
203{
204 return numNodes()>=Config_getInt(DOT_GRAPH_MAX_NODES);
205}
206
208{
209 return static_cast<int>(m_startNode->children().size());
210}
211
212bool DotCallGraph::isTrivial(const MemberDef *md,bool inverse)
213{
214 auto refs = inverse ? md->getReferencedByMembers() : md->getReferencesMembers();
215 for (const auto &rmd : refs)
216 {
217 if (rmd->isCallable())
218 {
219 return FALSE;
220 }
221 }
222 return TRUE;
223}
224
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual QCString anchor() const =0
virtual QCString briefDescriptionAsTooltip() const =0
virtual QCString getReference() const =0
virtual QCString qualifiedName() const =0
virtual QCString getOutputFileBase() const =0
virtual Definition * getOuterScope() const =0
virtual const MemberVector & getReferencedByMembers() const =0
virtual const MemberVector & getReferencesMembers() const =0
virtual const QCString & name() const =0
DotCallGraph(const MemberDef *md, bool inverse)
void computeTheGraph() override
void buildGraph(DotNode *n, const MemberDef *md, int distance)
int numNodes() const
QCString getBaseName() const override
bool isTooBig() const
DotNode * m_startNode
const Definition * m_scope
~DotCallGraph() override
DotNodeMap m_usedNodes
QCString getMapLabel() const override
QCString m_diskName
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
bool isTrivial() const
void determineTruncatedNodes(DotNodeDeque &queue)
void determineVisibleNodes(DotNodeDeque &queue, int &maxNodes)
static void computeGraph(DotNode *root, GraphType gt, GraphOutputFormat format, const QCString &rank, bool renderParents, bool backArrows, const QCString &title, QCString &graphStr)
Definition dotgraph.cpp:306
GraphOutputFormat m_graphFormat
Definition dotgraph.h:85
bool m_doNotAddImageToIndex
Definition dotgraph.h:97
QCString m_theGraph
Definition dotgraph.h:95
QCString m_baseName
Definition dotgraph.h:94
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
Definition dotgraph.cpp:115
friend class DotNode
Definition dotgraph.h:36
int distance() const
Definition dotnode.h:106
void setDistance(int distance)
Definition dotnode.cpp:366
void markAsVisible(bool b=TRUE)
Definition dotnode.h:120
DotNode & markAsTruncated(bool b=TRUE)
Definition dotnode.h:121
static void deleteNodes(DotNode *node)
Definition dotnode.cpp:380
void addParent(DotNode *n)
Definition dotnode.cpp:331
bool isVisible() const
Definition dotnode.h:104
@ Unknown
Definition dotnode.h:76
void addChild(DotNode *n, EdgeInfo::Colors edgeColor=EdgeInfo::Purple, EdgeInfo::Styles edgeStyle=EdgeInfo::Solid, const QCString &edgeLab=QCString(), const QCString &edgeURL=QCString(), int edgeLabCol=-1)
Definition dotnode.cpp:314
const DotNodeRefVector & children() const
Definition dotnode.h:122
TruncState isTruncated() const
Definition dotnode.h:105
@ Solid
Definition dotnode.h:36
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
virtual MemberDef * memberDefinition() const =0
This is an alternative implementation of QCString.
Definition qcstring.h:101
const std::string & str() const
Definition qcstring.h:526
Text streaming class that buffers data.
Definition textstream.h:36
#define Config_getInt(name)
Definition config.h:34
#define Config_getBool(name)
Definition config.h:33
static QCString getUniqueId(const MemberDef *md)
@ CallGraph
Definition dotgraph.h:31
EmbeddedOutputFormat
Definition dotgraph.h:30
GraphOutputFormat
Definition dotgraph.h:29
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
QCString linkToText(SrcLangExt lang, const QCString &link, bool isFileName)
Definition util.cpp:3100
A bunch of utility functions.