Doxygen
dotcallgraph.cpp
浏览该文件的文档.
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 
23 static QCString getUniqueId(const MemberDef *md)
24 {
25  const MemberDef *def = md->memberDefinition();
26  if (def==0) def = md;
27  QCString result = def->getReference()+"$"+
28  def->getOutputFileBase()+"#"+
29  def->anchor();
30  return result;
31 }
32 
33 void 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->showInCallGraph())
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;
45  n->addChild(bn,0,0);
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(
64  linkToText(rmd->getLanguage(),name,FALSE),
65  tooltip,
66  uniqueId,
67  0 //distance
68  );
69  n->addChild(bn,0,0);
70  bn->addParent(n);
71  bn->setDistance(distance);
72  m_usedNodes.insert(std::make_pair(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 
120 DotCallGraph::DotCallGraph(const MemberDef *md,bool inverse)
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();
137  linkToText(md->getLanguage(),name,FALSE),
138  tooltip,
139  uniqueId,
140  TRUE // root node
141  );
143  m_usedNodes.insert(std::make_pair(uniqueId.str(),m_startNode));
144  buildGraph(m_startNode,md,1);
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 
156 {
158 }
159 
161 {
162  return m_diskName + (m_inverse ? "_icgraph" : "_cgraph");
163 }
164 
166 {
167  computeGraph(
168  m_startNode,
169  CallGraph,
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 {
192  return DotGraph::writeGraph(out, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
193 }
194 
196 {
197  return m_startNode->children().empty();
198 }
199 
201 {
202  return numNodes()>=Config_getInt(DOT_GRAPH_MAX_NODES);
203 }
204 
206 {
207  return (int)m_startNode->children().size();
208 }
209 
210 bool DotCallGraph::isTrivial(const MemberDef *md,bool inverse)
211 {
212  auto refs = inverse ? md->getReferencedByMembers() : md->getReferencesMembers();
213  for (const auto &rmd : refs)
214  {
215  if (rmd->showInCallGraph())
216  {
217  return FALSE;
218  }
219  }
220  return TRUE;
221 }
222 
DotCallGraph::m_inverse
bool m_inverse
Definition: dotcallgraph.h:64
DotGraph::computeGraph
static void computeGraph(DotNode *root, GraphType gt, GraphOutputFormat format, const QCString &rank, bool renderParents, bool backArrows, const QCString &title, QCString &graphStr)
Definition: dotgraph.cpp:305
DotNode::addChild
void addChild(DotNode *n, int edgeColor=EdgeInfo::Purple, int edgeStyle=EdgeInfo::Solid, const QCString &edgeLab=QCString(), const QCString &edgeURL=QCString(), int edgeLabCol=-1)
Definition: dotnode.cpp:281
DotCallGraph::getBaseName
virtual QCString getBaseName() const
Definition: dotcallgraph.cpp:160
DotGraph::m_theGraph
QCString m_theGraph
Definition: dotgraph.h:89
DotNode::Unknown
@ Unknown
Definition: dotnode.h:65
DotNode::setDistance
void setDistance(int distance)
Definition: dotnode.cpp:333
getUniqueId
static QCString getUniqueId(const MemberDef *md)
Definition: dotcallgraph.cpp:23
dotnode.h
DotNode::markAsTruncated
void markAsTruncated(bool b=TRUE)
Definition: dotnode.h:108
Definition::getReferencedByMembers
virtual const MemberVector & getReferencedByMembers() const =0
QCString::str
std::string str() const
Definition: qcstring.h:442
DotNode::deleteNodes
static void deleteNodes(DotNode *node)
Definition: dotnode.cpp:347
DotNode::addParent
void addParent(DotNode *n)
Definition: dotnode.cpp:298
DotGraph::getNextNodeNumber
int getNextNodeNumber()
returns node numbers.
Definition: dotgraph.h:41
DotCallGraph::isTooBig
bool isTooBig() const
Definition: dotcallgraph.cpp:200
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
MemberDef::getReference
virtual QCString getReference() const =0
DotCallGraph::determineTruncatedNodes
void determineTruncatedNodes(DotNodeDeque &queue)
Definition: dotcallgraph.cpp:99
DotNode::markAsVisible
void markAsVisible(bool b=TRUE)
Definition: dotnode.h:107
Definition::getLanguage
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
DotCallGraph::DotCallGraph
DotCallGraph(const MemberDef *md, bool inverse)
Definition: dotcallgraph.cpp:120
MemberDef::anchor
virtual QCString anchor() const =0
DotNode
A node in a dot graph
Definition: dotnode.h:56
MemberDef
A model of a class/file/namespace member symbol.
Definition: memberdef.h:45
DotCallGraph::determineVisibleNodes
void determineVisibleNodes(DotNodeDeque &queue, int &maxNodes)
Definition: dotcallgraph.cpp:80
Config_getInt
#define Config_getInt(name)
Definition: config.h:34
DotCallGraph::computeTheGraph
virtual void computeTheGraph()
Definition: dotcallgraph.cpp:165
Definition::getReferencesMembers
virtual const MemberVector & getReferencesMembers() const =0
DotCallGraph::m_diskName
QCString m_diskName
Definition: dotcallgraph.h:65
DotCallGraph::m_startNode
DotNode * m_startNode
Definition: dotcallgraph.h:62
Definition::name
virtual QCString name() const =0
DotNode::label
QCString label() const
Definition: dotnode.h:89
DotGraph::m_graphFormat
GraphOutputFormat m_graphFormat
Definition: dotgraph.h:79
TRUE
#define TRUE
Definition: qcstring.h:36
DotNode::isTruncated
TruncState isTruncated() const
Definition: dotnode.h:92
DotNode::isVisible
bool isVisible() const
Definition: dotnode.h:91
memberlist.h
DotGraph::writeGraph
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:111
DotCallGraph::numNodes
int numNodes() const
Definition: dotcallgraph.cpp:205
MemberDef::memberDefinition
virtual MemberDef * memberDefinition() const =0
linkToText
QCString linkToText(SrcLangExt lang, const QCString &link, bool isFileName)
Definition: util.cpp:2943
MemberDef::qualifiedName
virtual QCString qualifiedName() const =0
DotNodeDeque
Definition: dotnode.h:137
CallGraph
@ CallGraph
Definition: dotgraph.h:29
DotCallGraph::isTrivial
bool isTrivial() const
Definition: dotcallgraph.cpp:195
MemberDef::getOutputFileBase
virtual QCString getOutputFileBase() const =0
dotcallgraph.h
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
DotNode::distance
int distance() const
Definition: dotnode.h:93
DotCallGraph::writeGraph
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
Definition: dotcallgraph.cpp:183
DotCallGraph::m_scope
const Definition * m_scope
Definition: dotcallgraph.h:66
Definition::getOuterScope
virtual Definition * getOuterScope() const =0
config.h
DotCallGraph::buildGraph
void buildGraph(DotNode *n, const MemberDef *md, int distance)
Definition: dotcallgraph.cpp:33
EmbeddedOutputFormat
EmbeddedOutputFormat
Definition: dotgraph.h:28
GraphOutputFormat
GraphOutputFormat
Definition: dotgraph.h:27
Definition::briefDescriptionAsTooltip
virtual QCString briefDescriptionAsTooltip() const =0
DotCallGraph::m_usedNodes
DotNodeMap m_usedNodes
Definition: dotcallgraph.h:63
util.h
A bunch of utility functions.
DotCallGraph::getMapLabel
virtual QCString getMapLabel() const
Definition: dotcallgraph.cpp:178
DotGraph::m_baseName
QCString m_baseName
Definition: dotgraph.h:88
DotCallGraph::~DotCallGraph
~DotCallGraph()
Definition: dotcallgraph.cpp:155
DotNode::children
const DotNodeRefVector & children() const
Definition: dotnode.h:109
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108