Skip to content

Commit 05941f3

Browse files
Barnabás Domozibarnabasdomozi
authored andcommitted
[PythonService] Make PythonDiagram friend class
1 parent c3e4ec7 commit 05941f3

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

plugins/python/service/include/service/pythonservice.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace language
2727

2828
class PythonServiceHandler : virtual public LanguageServiceIf
2929
{
30+
friend class PythonDiagram;
3031
public:
3132
PythonServiceHandler(
3233
std::shared_ptr<odb::database> db_,
@@ -151,21 +152,20 @@ class PythonServiceHandler : virtual public LanguageServiceIf
151152
CLASS_OVERVIEW
152153
};
153154

154-
model::PYName queryNodeByID(const std::string& id);
155-
model::PYName queryNodeByPosition(const core::FilePosition& fpos);
156-
std::vector<model::PYName> queryReferences(const core::AstNodeId& astNodeId, const std::int32_t referenceId);
157-
std::vector<model::PYName> queryNodesInFile(const core::FileId& fileId, bool definitions);
158-
std::vector<model::PYName> queryNodes(const odb::query<model::PYName>& odb_query);
159-
std::vector<std::uint64_t> transformReferences(const std::vector<model::PYName>& references, const model::PYNameID& id);
160-
std::string getNodeLineValue(const model::PYName& pyname);
161-
162155
private:
163156
std::shared_ptr<odb::database> _db;
164157
util::OdbTransaction _transaction;
165158
std::shared_ptr<std::string> _datadir;
166159
const cc::webserver::ServerContext& _context;
167160

168161
void setInfoProperties(AstNodeInfo& info, const model::PYName& pyname);
162+
model::PYName queryNodeByID(const std::string& id);
163+
model::PYName queryNodeByPosition(const core::FilePosition& fpos);
164+
std::vector<model::PYName> queryReferences(const core::AstNodeId& astNodeId, const std::int32_t referenceId);
165+
std::vector<model::PYName> queryNodesInFile(const core::FileId& fileId, bool definitions);
166+
std::vector<model::PYName> queryNodes(const odb::query<model::PYName>& odb_query);
167+
std::vector<std::uint64_t> transformReferences(const std::vector<model::PYName>& references, const model::PYNameID& id);
168+
std::string getNodeLineValue(const model::PYName& pyname);
169169
};
170170

171171
} // language

plugins/python/service/src/diagram.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ namespace service
66
{
77
namespace language
88
{
9-
namespace python
10-
{
11-
Diagram::Diagram(
9+
PythonDiagram::PythonDiagram(
1210
std::shared_ptr<odb::database> db_,
1311
std::shared_ptr<std::string> datadir_,
1412
const cc::webserver::ServerContext& context_)
1513
: m_pythonService(db_, datadir_, context_),
1614
m_projectService(db_, datadir_, context_){}
1715

18-
util::Graph Diagram::getFunctionCallDiagram(const model::PYName& pyname)
16+
util::Graph PythonDiagram::getFunctionCallDiagram(const model::PYName& pyname)
1917
{
2018
// Query calls
2119
const std::vector<model::PYName> this_calls = m_pythonService.queryReferences(std::to_string(pyname.id), PythonServiceHandler::THIS_CALLS);
@@ -73,7 +71,7 @@ util::Graph Diagram::getFunctionCallDiagram(const model::PYName& pyname)
7371
return graph;
7472
}
7573

76-
util::Graph Diagram::getModuleDiagram(const core::FileId& fileId)
74+
util::Graph PythonDiagram::getModuleDiagram(const core::FileId& fileId)
7775
{
7876
util::Graph graph;
7977
graph.setAttribute("rankdir", "LR");
@@ -140,7 +138,7 @@ util::Graph Diagram::getModuleDiagram(const core::FileId& fileId)
140138
return graph;
141139
}
142140

143-
util::Graph Diagram::getUsageDiagram(const model::PYName& pyname)
141+
util::Graph PythonDiagram::getUsageDiagram(const model::PYName& pyname)
144142
{
145143
util::Graph graph;
146144
graph.setAttribute("rankdir", "LR");
@@ -161,7 +159,7 @@ util::Graph Diagram::getUsageDiagram(const model::PYName& pyname)
161159
return graph;
162160
}
163161

164-
void Diagram::addFunctionNode(util::Graph& graph_, const util::Graph::Node& centerNode, const model::PYName& pyname, const NodeType& nodeType)
162+
void PythonDiagram::addFunctionNode(util::Graph& graph_, const util::Graph::Node& centerNode, const model::PYName& pyname, const NodeType& nodeType)
165163
{
166164
util::Graph::Node node = addPYNameNode(graph_, pyname, true);
167165
decorateNode(graph_, node, nodeType);
@@ -176,7 +174,7 @@ void Diagram::addFunctionNode(util::Graph& graph_, const util::Graph::Node& cent
176174
}
177175
}
178176

179-
util::Graph::Subgraph Diagram::getFileSubgraph(util::Graph& graph_, const model::PYName& pyname)
177+
util::Graph::Subgraph PythonDiagram::getFileSubgraph(util::Graph& graph_, const model::PYName& pyname)
180178
{
181179
const core::FileId fileId = std::to_string(pyname.file_id);
182180
auto it = m_subgraphs.find(fileId);
@@ -207,7 +205,7 @@ util::Graph::Subgraph Diagram::getFileSubgraph(util::Graph& graph_, const model:
207205
return subgraph;
208206
}
209207

210-
util::Graph::Node Diagram::addPYNameNode(util::Graph& graph_, const model::PYName& pyname, bool addSubgraph)
208+
util::Graph::Node PythonDiagram::addPYNameNode(util::Graph& graph_, const model::PYName& pyname, bool addSubgraph)
211209
{
212210
const util::Graph::Subgraph subgraph = (addSubgraph) ? getFileSubgraph(graph_, pyname) : util::Graph::Subgraph();
213211

@@ -225,15 +223,15 @@ util::Graph::Node Diagram::addPYNameNode(util::Graph& graph_, const model::PYNam
225223
return node;
226224
}
227225

228-
util::Graph::Node Diagram::addFileNode(util::Graph& graph_, const core::FileInfo& fileInfo)
226+
util::Graph::Node PythonDiagram::addFileNode(util::Graph& graph_, const core::FileInfo& fileInfo)
229227
{
230228
util::Graph::Node node = graph_.getOrCreateNode("f" + fileInfo.id);
231229
graph_.setNodeAttribute(node, "label", fileInfo.path);
232230

233231
return node;
234232
}
235233

236-
util::Graph::Node Diagram::addFileNode(util::Graph& graph_, const core::FileInfo& fileInfo, const util::Graph::Node& centerNode, const NodeType& nodeType)
234+
util::Graph::Node PythonDiagram::addFileNode(util::Graph& graph_, const core::FileInfo& fileInfo, const util::Graph::Node& centerNode, const NodeType& nodeType)
237235
{
238236
/* We might need to add a file path multiple times to the diagram.
239237
Since we need unique ids, we will differentiate nodes based on starting character:
@@ -256,7 +254,7 @@ util::Graph::Node Diagram::addFileNode(util::Graph& graph_, const core::FileInfo
256254
return node;
257255
}
258256

259-
void Diagram::decorateNode(util::Graph& graph_, util::Graph::Node& node_, const NodeType& nodeType)
257+
void PythonDiagram::decorateNode(util::Graph& graph_, util::Graph::Node& node_, const NodeType& nodeType)
260258
{
261259
graph_.setNodeAttribute(node_, "style", "filled");
262260

@@ -305,7 +303,7 @@ void Diagram::decorateNode(util::Graph& graph_, util::Graph::Node& node_, const
305303
}
306304
}
307305

308-
util::Graph Diagram::getFunctionCallDiagramLegend()
306+
util::Graph PythonDiagram::getFunctionCallDiagramLegend()
309307
{
310308
util::Graph graph;
311309
graph.setAttribute("rankdir", "LR");
@@ -321,7 +319,7 @@ util::Graph Diagram::getFunctionCallDiagramLegend()
321319
return graph;
322320
}
323321

324-
util::Graph Diagram::getUsageDiagramLegend()
322+
util::Graph PythonDiagram::getUsageDiagramLegend()
325323
{
326324
util::Graph graph;
327325
graph.setAttribute("rankdir", "LR");
@@ -335,7 +333,7 @@ util::Graph Diagram::getUsageDiagramLegend()
335333
return graph;
336334
}
337335

338-
util::Graph Diagram::getModuleDiagramLegend()
336+
util::Graph PythonDiagram::getModuleDiagramLegend()
339337
{
340338
util::Graph graph;
341339
graph.setAttribute("rankdir", "LR");
@@ -349,7 +347,7 @@ util::Graph Diagram::getModuleDiagramLegend()
349347
return graph;
350348
}
351349

352-
void Diagram::addLegendNode(util::Graph& graph_, const NodeType& nodeType, const std::string& text, bool shape)
350+
void PythonDiagram::addLegendNode(util::Graph& graph_, const NodeType& nodeType, const std::string& text, bool shape)
353351
{
354352
util::Graph::Node node = graph_.createNode();
355353
graph_.setNodeAttribute(node, "label", "");
@@ -368,7 +366,7 @@ void Diagram::addLegendNode(util::Graph& graph_, const NodeType& nodeType, const
368366
graph_.setNodeAttribute(explanation, "label", text);
369367
}
370368

371-
util::Graph Diagram::getClassDiagram(const model::PYName& pyname)
369+
util::Graph PythonDiagram::getClassDiagram(const model::PYName& pyname)
372370
{
373371
util::Graph graph;
374372
graph.setAttribute("rankdir", "BT");
@@ -400,7 +398,7 @@ util::Graph Diagram::getClassDiagram(const model::PYName& pyname)
400398
return graph;
401399
}
402400

403-
std::string Diagram::getClassTable(const model::PYName& pyname)
401+
std::string PythonDiagram::getClassTable(const model::PYName& pyname)
404402
{
405403
auto getVisibility = [](const std::string& str)
406404
{
@@ -496,7 +494,6 @@ std::string Diagram::getClassTable(const model::PYName& pyname)
496494
label += "</table>";
497495
return label;
498496
}
499-
} // python
500497
} // language
501498
} // service
502499
} // cc

plugins/python/service/src/diagram.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ namespace service
1717
{
1818
namespace language
1919
{
20-
namespace python
21-
{
22-
class Diagram {
20+
class PythonDiagram {
2321
public:
24-
Diagram(
22+
PythonDiagram(
2523
std::shared_ptr<odb::database> db_,
2624
std::shared_ptr<std::string> datadir_,
2725
const cc::webserver::ServerContext& context_);
@@ -60,7 +58,6 @@ namespace python
6058
util::Graph::Subgraph getFileSubgraph(util::Graph& graph_, const model::PYName& pyname);
6159
std::string getClassTable(const model::PYName& pyname);
6260
};
63-
} // python
6461
} // language
6562
} // service
6663
} // cc

plugins/python/service/src/pythonservice.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void PythonServiceHandler::getDiagram(
150150
#ifndef NDEBUG
151151
LOG(info) << "[PYTHONSERVICE]" << __func__;
152152
#endif
153-
python::Diagram diagram(_db, _datadir, _context);
153+
PythonDiagram diagram(_db, _datadir, _context);
154154

155155
model::PYName pyname = PythonServiceHandler::queryNodeByID(astNodeId_);
156156
util::Graph graph = [&]()
@@ -187,7 +187,7 @@ void PythonServiceHandler::getDiagramLegend(
187187
#ifndef NDEBUG
188188
LOG(info) << "[PYTHONSERVICE]" << __func__;
189189
#endif
190-
python::Diagram diagram(_db, _datadir, _context);
190+
PythonDiagram diagram(_db, _datadir, _context);
191191

192192
util::Graph graph = [&]()
193193
{
@@ -228,7 +228,7 @@ void PythonServiceHandler::getFileDiagram(
228228
#ifndef NDEBUG
229229
LOG(info) << "[PYTHONSERVICE]" << __func__;
230230
#endif
231-
python::Diagram diagram(_db, _datadir, _context);
231+
PythonDiagram diagram(_db, _datadir, _context);
232232

233233
util::Graph graph = [&]()
234234
{
@@ -254,7 +254,7 @@ void PythonServiceHandler::getFileDiagramLegend(
254254
#ifndef NDEBUG
255255
LOG(info) << "[PYTHONSERVICE]" << __func__;
256256
#endif
257-
python::Diagram diagram(_db, _datadir, _context);
257+
PythonDiagram diagram(_db, _datadir, _context);
258258

259259
util::Graph graph = [&]()
260260
{

0 commit comments

Comments
 (0)