aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/pymethoddefentry.cpp
blob: 64d44378b302e37010663cb640bec45ed0a5fcb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "pymethoddefentry.h"
#include "textstream.h"

#include <QtCore/QDebug>

TextStream &operator<<(TextStream &str, const castToPyCFunction &c)
{
    str << "reinterpret_cast<PyCFunction>(" << c.m_function << ')';
    return str;
}

TextStream &operator<<(TextStream &s, const PyMethodDefEntry &e)
{
    s <<  "{\"" << e.name << "\", " << castToPyCFunction(e.function) <<", ";
    if (e.methFlags.isEmpty()) {
         s << '0';
    } else {
        for (qsizetype i = 0, size = e.methFlags.size(); i < size; ++i) {
            if (i)
                s << '|';
            s << e.methFlags.at(i);
        }
    }
    if (e.doc.isEmpty())
        s << ", nullptr";
    else
        s << ", R\"(" << e.doc << ")\"";
    s << '}';
    return s;
}

TextStream &operator<<(TextStream &s, const PyMethodDefEntries &entries)
{
    for (const auto &e : entries)
        s << e << ",\n";
    return s;
}

QDebug operator<<(QDebug debug, const PyMethodDefEntry &e)
{
    QDebugStateSaver saver(debug);
    debug.noquote();
    debug.nospace();
    debug << "PyMethodDefEntry(\"" << e.name << "\", " << e.function
          << ", " << e.methFlags;
    if (!e.doc.isEmpty())
        debug << ", \"" << e.doc << '"';
    debug << ')';
    return debug;
}