diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-07-20 14:52:21 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-09-05 11:10:28 +0000 |
commit | 2bfd1de3495b18c0ecc251260442a9a46009861e (patch) | |
tree | 73e8392e8f3059fac87bd80d59bccb4d6b74898c /sources/shiboken2/generator/shiboken2/headergenerator.cpp | |
parent | 194df4ac3203546193dc7fb03267ede5d112009f (diff) |
shiboken: Add a typedef typesystem entry
The intention is be able to specify
typedef std::optional<int> OptionalInt
in the typesystem file and generate code for it (without having
a typedef in C++).
Task-number: PYSIDE-725
Change-Id: I5847a3c3f68556ac1d0ea3635f65a29caa6cb208
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator/shiboken2/headergenerator.cpp')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/headergenerator.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index d240cacbf..9bb5fafde 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -334,6 +334,33 @@ void HeaderGenerator::writeTypeIndexValueLines(QTextStream& s, const AbstractMet } } +// Format the typedefs for the typedef entries to be generated +static void formatTypeDefEntries(QTextStream &s) +{ + QVector<const TypedefEntry *> entries; + const auto typeDbEntries = TypeDatabase::instance()->typedefEntries(); + for (auto it = typeDbEntries.cbegin(), end = typeDbEntries.cend(); it != end; ++it) { + if (it.value()->generateCode() != 0) + entries.append(it.value()); + } + if (entries.isEmpty()) + return; + s << "\n// typedef entries\n"; + for (const auto e : entries) { + const QString name = e->qualifiedCppName(); + // Fixme: simplify by using nested namespaces in C++ 17. + const auto components = name.splitRef(QLatin1String("::")); + const int nameSpaceCount = components.size() - 1; + for (int n = 0; n < nameSpaceCount; ++n) + s << "namespace " << components.at(n) << " {\n"; + s << "using " << components.constLast() << " = " << e->sourceType() << ";\n"; + for (int n = 0; n < nameSpaceCount; ++n) + s << "}\n"; + } + s << '\n'; +} + + bool HeaderGenerator::finishGeneration() { // Generate the main header for this module. @@ -413,6 +440,9 @@ bool HeaderGenerator::finishGeneration() _writeTypeIndexValue(macrosStream, QStringLiteral("SBK_%1_CONVERTERS_IDX_COUNT") .arg(moduleName()), pCount); macrosStream << "\n};\n"; + + formatTypeDefEntries(macrosStream); + // TODO-CONVERTER ------------------------------------------------------------------------------ macrosStream << "// Macros for type check" << endl; |