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// own header
17#include "dotcallgraph.h"
18
19// other includes
20#include "config.h"
21#include "dotnode.h"
22#include "memberlist.h"
23#include "util.h"
24
25static DString getUniqueId(const MemberDef *md)
26{
27 const MemberDef *def = md->memberDefinition();
28 if (def==nullptr) def = md;
29 DString result = def->getReference()+"$"+
30 def->getOutputFileBase()+"#"+
31 def->anchor();
32 return result;
33}
34
35void DotCallGraph::buildGraph(DotNode *n,const MemberDef *md,int distance)
36{
37 auto refs = m_inverse ? md->getReferencedByMembers() : md->getReferencesMembers();
38 for (const auto &rmd : refs)
39 {
40 if (rmd->isCallable())
41 {
42 DString uniqueId = getUniqueId(rmd);
43 auto it = m_usedNodes.find(uniqueId.str());
44 if (it!=m_usedNodes.end()) // file is already a node in the graph
45 {
46 DotNode *bn = it->second;
48 bn->addParent(n);
49 bn->setDistance(distance);
50 }
51 else
52 {
53 DString name;
54 if (Config_getBool(HIDE_SCOPE_NAMES))
55 {
56 name = rmd->getOuterScope()==m_scope ?
57 rmd->name() : rmd->qualifiedName();
58 }
59 else
60 {
61 name = rmd->qualifiedName();
62 }
63 DString tooltip = rmd->briefDescriptionAsTooltip();
64 DotNode *bn = new DotNode(
65 this,
66 linkToText(rmd->getLanguage(),name,false),
67 tooltip,
68 uniqueId,
69 0 //distance
70 );
72 bn->addParent(n);
73 bn->setDistance(distance);
74 m_usedNodes.emplace(uniqueId.str(),bn);
75
76 buildGraph(bn,rmd,distance+1);
77 }
78 }
79 }
80}
81
83{
84 while (!queue.empty() && maxNodes>0)
85 {
86 DotNode *n = queue.front();
87 queue.pop_front();
88 if (!n->isVisible() && n->distance()<=Config_getInt(MAX_DOT_GRAPH_DEPTH)) // not yet processed
89 {
90 n->markAsVisible();
91 maxNodes--;
92 // add direct children
93 for (const auto &dn : n->children())
94 {
95 queue.push_back(dn);
96 }
97 }
98 }
99}
100
102{
103 while (!queue.empty())
104 {
105 DotNode *n = queue.front();
106 queue.pop_front();
107 if (n->isVisible() && n->isTruncated()==DotNode::Unknown)
108 {
109 bool truncated = false;
110 for (const auto &dn : n->children())
111 {
112 if (!dn->isVisible())
113 truncated = true;
114 else
115 queue.push_back(dn);
116 }
117 n->markAsTruncated(truncated);
118 }
119 }
120}
121
123{
124 m_inverse = inverse;
125 m_diskName = md->getOutputFileBase()+"_"+md->anchor();
126 m_scope = md->getOuterScope();
127 DString uniqueId = getUniqueId(md);
128 DString name;
129 if (Config_getBool(HIDE_SCOPE_NAMES))
130 {
131 name = md->name();
132 }
133 else
134 {
135 name = md->qualifiedName();
136 }
137 DString tooltip = md->briefDescriptionAsTooltip();
138 m_startNode = new DotNode(this,
139 linkToText(md->getLanguage(),name,false),
140 tooltip,
141 uniqueId,
142 true // root node
143 );
145 m_usedNodes.emplace(uniqueId.str(),m_startNode);
147
148 int maxNodes = Config_getInt(DOT_GRAPH_MAX_NODES);
149 DotNodeDeque openNodeQueue;
150 openNodeQueue.push_back(m_startNode);
151 determineVisibleNodes(openNodeQueue,maxNodes);
152 openNodeQueue.clear();
153 openNodeQueue.push_back(m_startNode);
154 determineTruncatedNodes(openNodeQueue);
155}
156
161
163{
164 return m_diskName + (m_inverse ? "_icgraph" : "_cgraph");
165}
166
168{
173 m_inverse ? "RL" : "LR",
174 false,
175 m_inverse,
177 m_theGraph);
178}
179
181{
182 return m_baseName;
183}
184
186 TextStream &out,
187 GraphOutputFormat graphFormat,
188 EmbeddedOutputFormat textFormat,
189 const DString &path,
190 const DString &fileName,
191 const DString &relPath,bool generateImageMap,
192 int graphId)
193{
195
196 return DotGraph::writeGraph(out, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
197}
198
200{
201 return m_startNode->children().empty();
202}
203
205{
206 return numNodes()>=Config_getInt(DOT_GRAPH_MAX_NODES);
207}
208
210{
211 return static_cast<int>(m_startNode->children().size());
212}
213
214bool DotCallGraph::isTrivial(const MemberDef *md,bool inverse)
215{
216 auto refs = inverse ? md->getReferencedByMembers() : md->getReferencesMembers();
217 for (const auto &rmd : refs)
218 {
219 if (rmd->isCallable())
220 {
221 return false;
222 }
223 }
224 return true;
225}
226
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
const std::string & str() const
Definition dstring.h:645
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual const DString & name() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual Definition * getOuterScope() const =0
virtual const MemberVector & getReferencedByMembers() const =0
virtual const MemberVector & getReferencesMembers() const =0
virtual DString getOutputFileBase() const =0
DotCallGraph(const MemberDef *md, bool inverse)
void computeTheGraph() override
void buildGraph(DotNode *n, const MemberDef *md, int distance)
int numNodes() const
bool isTooBig() const
DotNode * m_startNode
const Definition * m_scope
~DotCallGraph() override
DString getMapLabel() const override
DString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &relPath, bool writeImageMap=true, int graphId=-1)
DotNodeMap m_usedNodes
DString getBaseName() const override
DString m_diskName
bool isTrivial() const
void determineTruncatedNodes(DotNodeDeque &queue)
void determineVisibleNodes(DotNodeDeque &queue, int &maxNodes)
static void computeGraph(DotNode *root, GraphType gt, GraphOutputFormat format, const DString &rank, bool renderParents, bool backArrows, const DString &title, DString &graphStr)
Definition dotgraph.cpp:300
DString m_baseName
Definition dotgraph.h:94
DString m_theGraph
Definition dotgraph.h:95
GraphOutputFormat m_graphFormat
Definition dotgraph.h:85
bool m_doNotAddImageToIndex
Definition dotgraph.h:97
DString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &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:392
void markAsVisible(bool b=true)
Definition dotnode.h:120
static void deleteNodes(DotNode *node)
Definition dotnode.cpp:406
void addParent(DotNode *n)
Definition dotnode.cpp:357
bool isVisible() const
Definition dotnode.h:104
void addChild(DotNode *n, EdgeInfo::Colors edgeColor=EdgeInfo::Purple, EdgeInfo::Styles edgeStyle=EdgeInfo::Solid, const DString &edgeLab=DString(), const DString &edgeURL=DString(), int edgeLabColor=-1)
Definition dotnode.cpp:340
@ Unknown
Definition dotnode.h:76
DotNode & markAsTruncated(bool b=true)
Definition dotnode.h:121
DString label() const
Definition dotnode.h:102
const DotNodeRefVector & children() const
Definition dotnode.h:122
TruncState isTruncated() const
Definition dotnode.h:105
@ Solid
Definition dotnode.h:35
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual MemberDef * memberDefinition() const =0
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 DString getUniqueId(const MemberDef *md)
@ CallGraph
Definition dotgraph.h:31
EmbeddedOutputFormat
Definition dotgraph.h:30
GraphOutputFormat
Definition dotgraph.h:29
DString linkToText(SrcLangExt lang, const DString &link, bool ignoreDots)
Definition util.cpp:2265
A bunch of utility functions.