diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-06-29 16:09:08 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-06-29 16:09:08 +0200 |
commit | 2f0de14dc8fa529ef61c8599ec927e440e25b467 (patch) | |
tree | a7d8431babec43827b35da3c1b458f2c90f9dcb8 /tools/dumpcpp/main.cpp | |
parent | 4eac3d1d93ee1112a3b6d5baff941986c25ac56f (diff) | |
parent | 3477ddc2613f20d6b970cffc47c1ab41995fa8e1 (diff) | |
download | qtactiveqt-2f0de14dc8fa529ef61c8599ec927e440e25b467.tar.gz |
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
.qmake.conf
Change-Id: I0308544188e73d94b836685f07e44337ca57a723
Diffstat (limited to 'tools/dumpcpp/main.cpp')
-rw-r--r-- | tools/dumpcpp/main.cpp | 87 |
1 files changed, 55 insertions, 32 deletions
diff --git a/tools/dumpcpp/main.cpp b/tools/dumpcpp/main.cpp index 673b681..c65d5cd 100644 --- a/tools/dumpcpp/main.cpp +++ b/tools/dumpcpp/main.cpp @@ -81,6 +81,7 @@ extern void qax_deleteMetaObject(QMetaObject *mo); QMap<QByteArray, QByteArray> namespaceForType; QVector<QByteArray> strings; QHash<QByteArray, int> stringIndex; // Optimization, speeds up generation +QByteArrayList vTableOnlyStubs; void writeEnums(QTextStream &out, const QMetaObject *mo) { @@ -490,7 +491,8 @@ void generateClassDecl(QTextStream &out, const QString &controlID, const QMetaOb QByteArray simpleSlotTypeWithNamespace = slotType; simpleSlotTypeWithNamespace.replace('*', ""); out << indent << " qRegisterMetaType<" << simpleSlotTypeWithNamespace << "*>(\"" << simpleSlotType << "*\", &qax_result);" << endl; - out << indent << " qRegisterMetaType<" << simpleSlotTypeWithNamespace << ">(\"" << simpleSlotType << "\", qax_result);" << endl; + if (!vTableOnlyStubs.contains(simpleSlotTypeWithNamespace)) + out << indent << " qRegisterMetaType<" << simpleSlotTypeWithNamespace << ">(\"" << simpleSlotType << "\", qax_result);" << endl; if (foreignNamespace) out << "#endif" << endl; } @@ -892,6 +894,44 @@ void generateClassImpl(QTextStream &out, const QMetaObject *mo, const QByteArray out << '}' << endl; } +static void formatCommentBlockFooter(const QString &typeLibFile, QTextStream &str) +{ + str << " generated by dumpcpp v" << QT_VERSION_STR << " using\n**"; + foreach (const QString &arg, QCoreApplication::arguments()) + str << ' ' << arg; + str << "\n** from the type library " << typeLibFile << "\n**\n" + << "****************************************************************************/\n\n"; +} + +static QByteArray classNameFromTypeInfo(ITypeInfo *typeinfo) +{ + BSTR bstr; + QByteArray result; + if (SUCCEEDED(typeinfo->GetDocumentation(-1, &bstr, 0, 0, 0))) { + result = QString::fromWCharArray(bstr).toLatin1(); + SysFreeString(bstr); + } + return result; +} + +// Extract a list of VTable only stubs from a ITypeLib. +static QByteArrayList vTableOnlyStubsFromTypeLib(ITypeLib *typelib, const QString &nameSpace) +{ + QByteArrayList result; + const QByteArray nameSpacePrefix = nameSpace.toLatin1() + "::"; + for (UINT i = 0, typeCount = typelib->GetTypeInfoCount(); i < typeCount; ++i) { + TYPEKIND typekind; + if (SUCCEEDED(typelib->GetTypeInfoType(i, &typekind)) && typekind == TKIND_INTERFACE) { + ITypeInfo *typeinfo = Q_NULLPTR; + if (SUCCEEDED(typelib->GetTypeInfo(i, &typeinfo) && typeinfo)) { + result.append(nameSpacePrefix + classNameFromTypeInfo(typeinfo)); + typeinfo->Release(); + } + } + } + return result; +} + bool generateTypeLibrary(QString typeLibFile, QString outname, const QString &nameSpace, ObjectCategory category) { @@ -912,6 +952,7 @@ bool generateTypeLibrary(QString typeLibFile, QString outname, SysFreeString(nameString); } } + vTableOnlyStubs = vTableOnlyStubsFromTypeLib(typelib, libName); QString libVersion(QLatin1String("1.0")); @@ -946,13 +987,9 @@ bool generateTypeLibrary(QString typeLibFile, QString outname, return false; } - implOut << "/****************************************************************************" << endl; - implOut << "**" << endl; - implOut << "** Metadata for " << libName << " generated by dumpcpp from type library" << endl; - implOut << "** " << typeLibFile << endl; - implOut << "**" << endl; - implOut << "****************************************************************************/" << endl; - implOut << endl; + implOut << "/****************************************************************************\n" + "**\n** Metadata for " << libName; + formatCommentBlockFooter(typeLibFile, implOut); implOut << "#define QAX_DUMPCPP_" << libName.toUpper() << "_NOINLINES" << endl; @@ -977,13 +1014,9 @@ bool generateTypeLibrary(QString typeLibFile, QString outname, return false; } - declOut << "/****************************************************************************" << endl; - declOut << "**" << endl; - declOut << "** Namespace " << libName << " generated by dumpcpp from type library" << endl; - declOut << "** " << typeLibFile << endl; - declOut << "**" << endl; - declOut << "****************************************************************************/" << endl; - declOut << endl; + declOut << "/****************************************************************************\n" + "**\n** Namespace " << libName; + formatCommentBlockFooter(typeLibFile, declOut); QFileInfo cppFileInfo(outname); writeHeader(declOut, libName, cppFileInfo.fileName()); @@ -1029,12 +1062,7 @@ bool generateTypeLibrary(QString typeLibFile, QString outname, case TKIND_ENUM: case TKIND_INTERFACE: // only for forward declarations { - QByteArray className; - BSTR bstr; - if (S_OK != typeinfo->GetDocumentation(-1, &bstr, 0, 0, 0)) - break; - className = QString::fromWCharArray(bstr).toLatin1(); - SysFreeString(bstr); + QByteArray className = classNameFromTypeInfo(typeinfo); switch (typekind) { case TKIND_RECORD: className.prepend("struct "); @@ -1172,17 +1200,12 @@ bool generateTypeLibrary(QString typeLibFile, QString outname, else metaObject = qax_readInterfaceInfo(typelib, typeinfo, &QObject::staticMetaObject); break; - case TKIND_INTERFACE: // only stub - { - QByteArray className; - BSTR bstr; - if (S_OK != typeinfo->GetDocumentation(-1, &bstr, 0, 0, 0)) - break; - className = QString::fromWCharArray(bstr).toLatin1(); - SysFreeString(bstr); - - declOut << "// stub for vtable-only interface" << endl; - declOut << "class " << className << " : public QAxObject {};" << endl << endl; + case TKIND_INTERFACE: { // only stub: QTBUG-27792, explicitly disable copy in inherited + // class to make related error messages clearer + const QByteArray className = classNameFromTypeInfo(typeinfo); + declOut << "// stub for vtable-only interface\n" + << "class " << className << " : public QAxObject { Q_DISABLE_COPY(" + << className << ") };\n\n"; } break; default: |