##// END OF EJS Templates
added support for QStringRef as return value...
added support for QStringRef as return value git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@232 ea8d5007-eb21-0410-b261-ccb3ea6e24a9

File last commit:

r170:193dbb137eb2
r191:86312d1bca38
Show More
setupgenerator.cpp
306 lines | 10.9 KiB | text/x-c | CppLexer
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 /****************************************************************************
**
florianlink
updated generator to LGPLed version from gitorious...
r87 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 **
florianlink
updated generator to LGPLed version from gitorious...
r87 ** This file is part of the Qt Script Generator project on Qt Labs.
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 **
florianlink
updated generator to LGPLed version from gitorious...
r87 ** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 **
florianlink
updated generator to LGPLed version from gitorious...
r87 ** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 **
florianlink
updated generator to LGPLed version from gitorious...
r87 ** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 **
****************************************************************************/
#include "setupgenerator.h"
florianlink
- added support for deriving CPP classes in Python and to override all public and protected virtual functions from PythonQt...
r24 #include "shellgenerator.h"
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 #include "reporthandler.h"
#include "fileout.h"
//#define Q_SCRIPT_LAZY_GENERATOR
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93 void SetupGenerator::addClass(const QString& package, const AbstractMetaClass *cls)
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 {
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93 packHash[package].append(cls);
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }
void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
QSet<QString> &registeredTypeNames);
bool hasDefaultConstructor(const AbstractMetaClass *meta_class);
florianlink
added support for operators and rich compare...
r119 static QStringList getOperatorCodes(const AbstractMetaClass* cls) {
QSet<QString> operatorCodes;
AbstractMetaFunctionList returned;
AbstractMetaFunctionList functions = cls->functions();
foreach (AbstractMetaFunction *function, functions) {
if (function->originalName().startsWith("operator")) {
QString op = function->originalName().mid(8);
operatorCodes.insert(op);
}
}
QSet<QString> r;
foreach(QString op, operatorCodes.toList()) {
if (op == ">" || op == "<" || op == ">=" || op == "<=" || op == "==" || op == "!=") {
r.insert("PythonQt::Type_RichCompare");
} else if (op == "+") {
r.insert("PythonQt::Type_Add");
} else if (op == "-") {
r.insert("PythonQt::Type_Subtract");
} else if (op == "/") {
r.insert("PythonQt::Type_Divide");
} else if (op == "*") {
r.insert("PythonQt::Type_Multiply");
} else if (op == "%") {
r.insert("PythonQt::Type_Mod");
} else if (op == "&") {
r.insert("PythonQt::Type_And");
} else if (op == "|") {
r.insert("PythonQt::Type_Or");
} else if (op == "^") {
r.insert("PythonQt::Type_Xor");
} else if (op == "~") {
r.insert("PythonQt::Type_Invert");
} else if (op == "+=") {
r.insert("PythonQt::Type_InplaceAdd");
} else if (op == "-=") {
r.insert("PythonQt::Type_InplaceSubtract");
} else if (op == "/=") {
r.insert("PythonQt::Type_InplaceDivide");
} else if (op == "*=") {
r.insert("PythonQt::Type_InplaceMultiply");
} else if (op == "%=") {
r.insert("PythonQt::Type_InplaceMod");
} else if (op == "&=") {
r.insert("PythonQt::Type_InplaceAnd");
} else if (op == "|=") {
r.insert("PythonQt::Type_InplaceOr");
} else if (op == "^=") {
r.insert("PythonQt::Type_InplaceXor");
}
}
if (cls->hasDefaultIsNull()) {
r.insert("PythonQt::Type_NonZero");
}
QStringList result = r.toList();
return result;
}
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 static bool class_less_than(const AbstractMetaClass *a, const AbstractMetaClass *b)
{
return a->name() < b->name();
}
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 void SetupGenerator::generate()
{
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 AbstractMetaClassList classes_with_polymorphic_id;
{
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
while (pack.hasNext()) {
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 pack.next();
QList<const AbstractMetaClass*> list = pack.value();
foreach (const AbstractMetaClass *cls, list) {
if (cls->typeEntry()->isPolymorphicBase()) {
classes_with_polymorphic_id.append((AbstractMetaClass*)cls);
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 }
}
}
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 qSort(classes_with_polymorphic_id.begin(), classes_with_polymorphic_id.end(), class_less_than);
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29
QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
while (pack.hasNext()) {
pack.next();
QList<const AbstractMetaClass*> list = pack.value();
if (list.isEmpty())
continue;
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 qSort(list.begin(), list.end(), class_less_than);
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29
QString packKey = pack.key();
QString packName = pack.key();
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93 QStringList components = packName.split("_");
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 if ((components.size() > 2) && (components.at(0) == "com")
&& (components.at(1) == "trolltech")) {
// kill com.trolltech in key
components.removeAt(0);
components.removeAt(0);
}
florianlink
- added quitools...
r12
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 QString shortPackName;
foreach (QString comp, components) {
comp[0] = comp[0].toUpper();
shortPackName += comp;
}
// add missing camel case (workaround..)
if (shortPackName == "QtWebkit") {
shortPackName = "QtWebKit";
} else if (shortPackName == "QtXmlpatterns") {
shortPackName = "QtXmlPatterns";
} else if (shortPackName == "QtOpengl") {
shortPackName = "QtOpenGL";
} else if (shortPackName == "QtUitools") {
shortPackName = "QtUiTools";
}
florianlink
- added quitools...
r12
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 {
florianlink
merged contributions from https://github.com/commontk/PythonQt/compare/svn-mirror...patched...
r162 QString fileName(packName + "/" + packKey + "_init.cpp");
FileOut initFile(m_out_dir + "/generated_cpp/" + fileName);
ReportHandler::debugSparse(QString("generating: %1").arg(fileName));
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 QTextStream &s = initFile.stream;
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 s << "#include <PythonQt.h>" << endl;
florianlink
added experimental compacting to avoid generation of hundreds of files that all include the same stuff...
r92 for (int i=0; i<(list.count()+MAX_CLASSES_PER_FILE-1) / MAX_CLASSES_PER_FILE; i++) {
s << "#include \"" << packKey << QString::number(i) << ".h\"" << endl;
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 }
s << endl;
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93 QStringList polymorphicHandlers;
if (!packName.endsWith("_builtin")) {
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 polymorphicHandlers = writePolymorphicHandler(s, list.at(0)->package(), classes_with_polymorphic_id, list);
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93 s << endl;
}
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 // declare individual class creation functions
florianlink
update to Qt 4.6 xml files...
r108 s << "void PythonQt_init_" << shortPackName << "(PyObject* module) {" << endl;
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93
if (shortPackName.endsWith("Builtin")) {
florianlink
fixed builtin package name...
r94 shortPackName = shortPackName.mid(0, shortPackName.length()-strlen("builtin"));
florianlink
added builtin support for variants etc., this will replace the direct includes in PythonQt...
r93 }
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 QStringList cppClassNames;
foreach (const AbstractMetaClass *cls, list) {
QString shellCreator;
if (cls->generateShellClass()) {
shellCreator = ", PythonQtSetInstanceWrapperOnShell<" + ShellGenerator::shellClassName(cls) + ">";
florianlink
update to Qt 4.6 xml files...
r108 } else {
shellCreator = ", NULL";
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 }
florianlink
added support for operators and rich compare...
r119 QString operatorCodes = getOperatorCodes(cls).join("|");
if (operatorCodes.isEmpty()) {
operatorCodes = "0";
}
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 if (cls->isQObject()) {
florianlink
added support for operators and rich compare...
r119 s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 } else {
QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():"";
florianlink
added support for operators and rich compare...
r119 s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 }
foreach(AbstractMetaClass* interface, cls->interfaces()) {
// the interface might be our own class... (e.g. QPaintDevice)
if (interface->qualifiedCppName() != cls->qualifiedCppName()) {
s << "PythonQt::self()->addParentClass(\""<< cls->qualifiedCppName() << "\", \"" << interface->qualifiedCppName() << "\",PythonQtUpcastingOffset<" << cls->qualifiedCppName() <<","<<interface->qualifiedCppName()<<">());" << endl;
}
}
}
s << endl;
foreach (QString handler, polymorphicHandlers) {
s << "PythonQt::self()->addPolymorphicHandler(\""<< handler << "\", polymorphichandler_" << handler << ");" << endl;
}
s << "}";
s << endl;
}
}
}
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 QStringList SetupGenerator::writePolymorphicHandler(QTextStream &s, const QString &package,
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 const AbstractMetaClassList &polybase, QList<const AbstractMetaClass*>& allClasses)
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 {
QStringList handlers;
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 foreach (AbstractMetaClass *cls, polybase) {
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 const ComplexTypeEntry *centry = cls->typeEntry();
if (!centry->isPolymorphicBase())
continue;
bool isGraphicsItem = (cls->qualifiedCppName()=="QGraphicsItem");
bool first = true;
florianlink
added sorting of polymorphic id classes to avoid changes on each code generation...
r131 foreach (const AbstractMetaClass *clazz, allClasses) {
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 bool inherits = false;
if (isGraphicsItem) {
florianlink
fixed polymorphic id handler for QGraphicsItem...
r170 const AbstractMetaClass *currentClazz = clazz;
while (!inherits && currentClazz) {
foreach(AbstractMetaClass* interfaze, currentClazz->interfaces()) {
if (interfaze->qualifiedCppName()=="QGraphicsItem") {
inherits = true;
break;
}
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }
florianlink
fixed polymorphic id handler for QGraphicsItem...
r170 currentClazz = currentClazz->baseClass();
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 }
} else {
inherits = clazz->inheritsFrom(cls);
}
if (clazz->package() == package && inherits) {
florianlink
fixed polymorphic id handler for QGraphicsItem...
r170 if (!clazz->typeEntry()->polymorphicIdValue().isEmpty()) {
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 // On first find, open the function
if (first) {
first = false;
QString handler = cls->name();
handlers.append(handler);
s << "static void* polymorphichandler_" << handler
florianlink
merged contributions from https://github.com/commontk/PythonQt/compare/svn-mirror...patched...
r162 << "(const void *ptr, const char **class_name)" << endl
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 << "{" << endl
<< " Q_ASSERT(ptr != 0);" << endl
<< " " << cls->qualifiedCppName() << " *object = ("
<< cls->qualifiedCppName() << " *)ptr;" << endl;
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }
florianlink
- added quitools...
r12
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 // For each, add case label
QString polyId = clazz->typeEntry()->polymorphicIdValue();
s << " if ("
<< polyId.replace("%1", "object")
<< ") {" << endl
<< " *class_name = \"" << clazz->name() << "\";" << endl
<< " return (" << clazz->qualifiedCppName() << "*)object;" << endl
<< " }" << endl;
} else {
QString warning = QString("class '%1' inherits from polymorphic class '%2', but has no polymorphic id set")
.arg(clazz->name())
.arg(cls->name());
ReportHandler::warning(warning);
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29 }
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }
florianlink
- upgraded generator to generate polymorphic handlers for downcasting...
r29
// Close the function if it has been opened
if (!first) {
s << " return NULL;" << endl
<< "}" << endl;
}
}
return handlers;
florianlink
syncing with my current work, updating to 1.2, see changelog...
r10 }