aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/graph.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-13 14:05:04 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-27 09:04:18 +0000
commit5b87b64f6a6a2404d01f24b2c5a2189e406bddf8 (patch)
tree37a06a6df8276884b860dbc63d233b8b829c0283 /sources/shiboken2/ApiExtractor/graph.cpp
parent636b9a4bd5624d8ddb00da53b16add546e3944c4 (diff)
shiboken2: Improve error messages about cyclic dependencies
Return a struct instead of a plain list from Graph::topologicalSort() which contains the offending indexes and output the elements in case of failure. Task-number: PYSIDE-1202 Change-Id: Ib7f70c78be0e84272f31d802677c7fc333aa32f4 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/graph.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/graph.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/sources/shiboken2/ApiExtractor/graph.cpp b/sources/shiboken2/ApiExtractor/graph.cpp
index 53e20ebba..ccc9119b8 100644
--- a/sources/shiboken2/ApiExtractor/graph.cpp
+++ b/sources/shiboken2/ApiExtractor/graph.cpp
@@ -74,23 +74,28 @@ int Graph::nodeCount() const
return m_d->edges.size();
}
-Graph::Indexes Graph::topologicalSort() const
+Graph::SortResult Graph::topologicalSort() const
{
const int nodeCount = Graph::nodeCount();
- Indexes result;
- result.reserve(nodeCount);
+ SortResult result;
+ result.result.reserve(nodeCount);
QVector<GraphPrivate::Color> colors(nodeCount, GraphPrivate::WHITE);
for (int i = 0; i < nodeCount; ++i) {
if (colors[i] == GraphPrivate::WHITE)
- m_d->dfsVisit(i, result, colors);
+ m_d->dfsVisit(i, result.result, colors);
}
- if (result.size() == nodeCount)
- std::reverse(result.begin(), result.end());
- else
- result.clear(); // Not a DAG!
+ if (result.result.size() == nodeCount) {
+ std::reverse(result.result.begin(), result.result.end());
+ } else {
+ for (int i = 0; i < nodeCount; ++i) {
+ if (!result.result.contains(i))
+ result.cyclic.append(i);
+ }
+ result.result.clear(); // Not a DAG!
+ }
return result;
}