##// END OF EJS Templates
florianlink -
r162:1182b71738ca
parent child
Show More
@@ -1,182 +1,188
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
6 **
7 ** This file is part of the Qt Script Generator project on Qt Labs.
7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 **
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
14 ** this package.
15 **
15 **
16 ** GNU Lesser General Public License Usage
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
27 **
28 ** If you have questions regarding the use of this file, please contact
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
29 ** Nokia at qt-info@nokia.com.
30 **
30 **
31 **
31 **
32 **
32 **
33 **
33 **
34 **
34 **
35 **
35 **
36 **
36 **
37 **
37 **
38 ** $QT_END_LICENSE$
38 ** $QT_END_LICENSE$
39 **
39 **
40 ****************************************************************************/
40 ****************************************************************************/
41
41
42 #include "main.h"
42 #include "main.h"
43 #include "asttoxml.h"
43 #include "asttoxml.h"
44 #include "reporthandler.h"
44 #include "reporthandler.h"
45 #include "typesystem.h"
45 #include "typesystem.h"
46 #include "generatorset.h"
46 #include "generatorset.h"
47 #include "fileout.h"
47 #include "fileout.h"
48
48
49 #include <QDir>
49 #include <QDir>
50
50
51 void displayHelp(GeneratorSet *generatorSet);
51 void displayHelp(GeneratorSet *generatorSet);
52
52
53 #include <QDebug>
53 #include <QDebug>
54 int main(int argc, char *argv[])
54 int main(int argc, char *argv[])
55 {
55 {
56 GeneratorSet *gs = GeneratorSet::getInstance();
56 GeneratorSet *gs = GeneratorSet::getInstance();
57
57
58 QString default_file = ":/trolltech/generator/qtscript_masterinclude.h";
58 QString default_file = ":/trolltech/generator/qtscript_masterinclude.h";
59 QString default_system = ":/trolltech/generator/build_all.txt";
59 QString default_system = ":/trolltech/generator/build_all.txt";
60
60
61 QString fileName;
61 QString fileName;
62 QString typesystemFileName;
62 QString typesystemFileName;
63 QString pp_file = ".preprocessed.tmp";
63 QString pp_file = ".preprocessed.tmp";
64 QStringList rebuild_classes;
64 QStringList rebuild_classes;
65
65
66 QMap<QString, QString> args;
66 QMap<QString, QString> args;
67
67
68 int argNum = 0;
68 int argNum = 0;
69 for (int i=1; i<argc; ++i) {
69 for (int i=1; i<argc; ++i) {
70 QString arg(argv[i]);
70 QString arg(argv[i]);
71 arg = arg.trimmed();
71 arg = arg.trimmed();
72 if( arg.startsWith("--") ) {
72 if( arg.startsWith("--") ) {
73 int split = arg.indexOf("=");
73 int split = arg.indexOf("=");
74 if( split > 0 )
74 if( split > 0 )
75 args[arg.mid(2).left(split-2)] = arg.mid(split + 1).trimmed();
75 args[arg.mid(2).left(split-2)] = arg.mid(split + 1).trimmed();
76 else
76 else
77 args[arg.mid(2)] = QString();
77 args[arg.mid(2)] = QString();
78 } else if( arg.startsWith("-")) {
78 } else if( arg.startsWith("-")) {
79 args[arg.mid(1)] = QString();
79 args[arg.mid(1)] = QString();
80 } else {
80 } else {
81 argNum++;
81 argNum++;
82 args[QString("arg-%1").arg(argNum)] = arg;
82 args[QString("arg-%1").arg(argNum)] = arg;
83 }
83 }
84 }
84 }
85
85
86 if (args.contains("no-suppress-warnings")) {
86 if (args.contains("no-suppress-warnings")) {
87 TypeDatabase *db = TypeDatabase::instance();
87 TypeDatabase *db = TypeDatabase::instance();
88 db->setSuppressWarnings(false);
88 db->setSuppressWarnings(false);
89 }
89 }
90
90
91 if (args.contains("debug-level")) {
91 if (args.contains("debug-level")) {
92 QString level = args.value("debug-level");
92 QString level = args.value("debug-level");
93 if (level == "sparse")
93 if (level == "sparse")
94 ReportHandler::setDebugLevel(ReportHandler::SparseDebug);
94 ReportHandler::setDebugLevel(ReportHandler::SparseDebug);
95 else if (level == "medium")
95 else if (level == "medium")
96 ReportHandler::setDebugLevel(ReportHandler::MediumDebug);
96 ReportHandler::setDebugLevel(ReportHandler::MediumDebug);
97 else if (level == "full")
97 else if (level == "full")
98 ReportHandler::setDebugLevel(ReportHandler::FullDebug);
98 ReportHandler::setDebugLevel(ReportHandler::FullDebug);
99 }
99 }
100
100
101 if (args.contains("dummy")) {
101 if (args.contains("dummy")) {
102 FileOut::dummy = true;
102 FileOut::dummy = true;
103 }
103 }
104
104
105 if (args.contains("diff")) {
105 if (args.contains("diff")) {
106 FileOut::diff = true;
106 FileOut::diff = true;
107 }
107 }
108
108
109 if (args.contains("license"))
109 if (args.contains("license"))
110 FileOut::license = true;
110 FileOut::license = true;
111
111
112 if (args.contains("rebuild-only")) {
112 if (args.contains("rebuild-only")) {
113 QStringList classes = args.value("rebuild-only").split(",", QString::SkipEmptyParts);
113 QStringList classes = args.value("rebuild-only").split(",", QString::SkipEmptyParts);
114 TypeDatabase::instance()->setRebuildClasses(classes);
114 TypeDatabase::instance()->setRebuildClasses(classes);
115 }
115 }
116
116
117 fileName = args.value("arg-1");
117 fileName = args.value("arg-1");
118
118
119 typesystemFileName = args.value("arg-2");
119 typesystemFileName = args.value("arg-2");
120 if (args.contains("arg-3"))
120 if (args.contains("arg-3"))
121 displayHelp(gs);
121 displayHelp(gs);
122
122
123 if (fileName.isEmpty())
123 if (fileName.isEmpty())
124 fileName = default_file;
124 fileName = default_file;
125
125
126 if (typesystemFileName.isEmpty())
126 if (typesystemFileName.isEmpty())
127 typesystemFileName = default_system;
127 typesystemFileName = default_system;
128
128
129 if (fileName.isEmpty() || typesystemFileName.isEmpty() )
129 if (fileName.isEmpty() || typesystemFileName.isEmpty() )
130 displayHelp(gs);
130 displayHelp(gs);
131
131
132 if (!gs->readParameters(args))
132 if (!gs->readParameters(args))
133 displayHelp(gs);
133 displayHelp(gs);
134
134
135 printf("Please wait while source files are being generated...\n");
135 printf("Please wait while source files are being generated...\n");
136
136
137 printf("Parsing typesystem file [%s]\n", qPrintable(typesystemFileName));
137 if (!TypeDatabase::instance()->parseFile(typesystemFileName))
138 if (!TypeDatabase::instance()->parseFile(typesystemFileName))
138 qFatal("Cannot parse file: '%s'", qPrintable(typesystemFileName));
139 qFatal("Cannot parse file: '%s'", qPrintable(typesystemFileName));
139
140
141 printf("PreProcessing - Generate [%s] using [%s] and include-paths [%s]\n",
142 qPrintable(pp_file), qPrintable(fileName), qPrintable(args.value("include-paths")));
140 if (!Preprocess::preprocess(fileName, pp_file, args.value("include-paths"))) {
143 if (!Preprocess::preprocess(fileName, pp_file, args.value("include-paths"))) {
141 fprintf(stderr, "Preprocessor failed on file: '%s'\n", qPrintable(fileName));
144 fprintf(stderr, "Preprocessor failed on file: '%s'\n", qPrintable(fileName));
142 return 1;
145 return 1;
143 }
146 }
144
147
145 if (args.contains("ast-to-xml")) {
148 if (args.contains("ast-to-xml")) {
146 astToXML(pp_file);
149 printf("Running ast-to-xml on file [%s] using pp_file [%s] and include-paths [%s]\n",
147 return 0;
150 qPrintable(fileName), qPrintable(pp_file), qPrintable(args.value("include-paths")));
151 astToXML(pp_file);
152 return 0;
148 }
153 }
149
154
155 printf("Building model using [%s]\n", qPrintable(pp_file));
150 gs->buildModel(pp_file);
156 gs->buildModel(pp_file);
151 if (args.contains("dump-object-tree")) {
157 if (args.contains("dump-object-tree")) {
152 gs->dumpObjectTree();
158 gs->dumpObjectTree();
153 return 0;
159 return 0;
154 }
160 }
155 printf("%s\n", qPrintable(gs->generate()));
161 printf("%s\n", qPrintable(gs->generate()));
156
162
157 printf("Done, %d warnings (%d known issues)\n", ReportHandler::warningCount(),
163 printf("Done, %d warnings (%d known issues)\n", ReportHandler::warningCount(),
158 ReportHandler::suppressedCount());
164 ReportHandler::suppressedCount());
159 }
165 }
160
166
161
167
162 void displayHelp(GeneratorSet* generatorSet) {
168 void displayHelp(GeneratorSet* generatorSet) {
163 #if defined(Q_OS_WIN32)
169 #if defined(Q_OS_WIN32)
164 char path_splitter = ';';
170 char path_splitter = ';';
165 #else
171 #else
166 char path_splitter = ':';
172 char path_splitter = ':';
167 #endif
173 #endif
168 printf("Usage:\n generator [options] header-file typesystem-file\n\n");
174 printf("Usage:\n generator [options] header-file typesystem-file\n\n");
169 printf("Available options:\n\n");
175 printf("Available options:\n\n");
170 printf("General:\n");
176 printf("General:\n");
171 printf(" --debug-level=[sparse|medium|full] \n"
177 printf(" --debug-level=[sparse|medium|full] \n"
172 " --dump-object-tree \n"
178 " --dump-object-tree \n"
173 " --help, -h or -? \n"
179 " --help, -h or -? \n"
174 " --no-suppress-warnings \n"
180 " --no-suppress-warnings \n"
175 " --output-directory=[dir] \n"
181 " --output-directory=[dir] \n"
176 " --include-paths=<path>[%c<path>%c...] \n"
182 " --include-paths=<path>[%c<path>%c...] \n"
177 " --print-stdout \n",
183 " --print-stdout \n",
178 path_splitter, path_splitter);
184 path_splitter, path_splitter);
179
185
180 printf("%s", qPrintable( generatorSet->usage()));
186 printf("%s", qPrintable( generatorSet->usage()));
181 exit(0);
187 exit(0);
182 }
188 }
@@ -1,74 +1,74
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
6 **
7 ** This file is part of the Qt Script Generator project on Qt Labs.
7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 **
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
14 ** this package.
15 **
15 **
16 ** GNU Lesser General Public License Usage
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
27 **
28 ** If you have questions regarding the use of this file, please contact
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
29 ** Nokia at qt-info@nokia.com.
30 **
30 **
31 **
31 **
32 **
32 **
33 **
33 **
34 **
34 **
35 **
35 **
36 **
36 **
37 **
37 **
38 ** $QT_END_LICENSE$
38 ** $QT_END_LICENSE$
39 **
39 **
40 ****************************************************************************/
40 ****************************************************************************/
41
41
42 #include "reporthandler.h"
42 #include "reporthandler.h"
43 #include "typesystem.h"
43 #include "typesystem.h"
44
44
45 int ReportHandler::m_warning_count = 0;
45 int ReportHandler::m_warning_count = 0;
46 int ReportHandler::m_suppressed_count = 0;
46 int ReportHandler::m_suppressed_count = 0;
47 QString ReportHandler::m_context;
47 QString ReportHandler::m_context;
48 ReportHandler::DebugLevel ReportHandler::m_debug_level = NoDebug;
48 ReportHandler::DebugLevel ReportHandler::m_debug_level = NoDebug;
49 QSet<QString> ReportHandler::m_reported_warnings;
49 QSet<QString> ReportHandler::m_reported_warnings;
50
50
51
51
52 void ReportHandler::warning(const QString &text)
52 void ReportHandler::warning(const QString &text)
53 {
53 {
54 QString warningText = QString("WARNING(%1) :: %2").arg(m_context).arg(text);
54 QString warningText = QString("WARNING(%1) :: %2").arg(m_context).arg(text);
55
55
56 TypeDatabase *db = TypeDatabase::instance();
56 TypeDatabase *db = TypeDatabase::instance();
57 if (db && db->isSuppressedWarning(warningText)) {
57 if (db && db->isSuppressedWarning(warningText)) {
58 ++m_suppressed_count;
58 ++m_suppressed_count;
59 } else if (!m_reported_warnings.contains(warningText)) {
59 } else if (!m_reported_warnings.contains(warningText)) {
60 qDebug(qPrintable(warningText));
60 qDebug("%s", qPrintable(warningText));
61 ++m_warning_count;
61 ++m_warning_count;
62
62
63 m_reported_warnings.insert(warningText);
63 m_reported_warnings.insert(warningText);
64 }
64 }
65 }
65 }
66
66
67 void ReportHandler::debug(DebugLevel level, const QString &text)
67 void ReportHandler::debug(DebugLevel level, const QString &text)
68 {
68 {
69 if (m_debug_level == NoDebug)
69 if (m_debug_level == NoDebug)
70 return;
70 return;
71
71
72 if (level <= m_debug_level)
72 if (level <= m_debug_level)
73 qDebug(" - DEBUG(%s) :: %s", qPrintable(m_context), qPrintable(text));
73 qDebug(" - DEBUG(%s) :: %s", qPrintable(m_context), qPrintable(text));
74 }
74 }
@@ -1,303 +1,305
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
6 **
7 ** This file is part of the Qt Script Generator project on Qt Labs.
7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 **
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
14 ** this package.
15 **
15 **
16 ** GNU Lesser General Public License Usage
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
27 **
28 ** If you have questions regarding the use of this file, please contact
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
29 ** Nokia at qt-info@nokia.com.
30 **
30 **
31 **
31 **
32 **
32 **
33 **
33 **
34 **
34 **
35 **
35 **
36 **
36 **
37 **
37 **
38 ** $QT_END_LICENSE$
38 ** $QT_END_LICENSE$
39 **
39 **
40 ****************************************************************************/
40 ****************************************************************************/
41
41
42 #include "setupgenerator.h"
42 #include "setupgenerator.h"
43 #include "shellgenerator.h"
43 #include "shellgenerator.h"
44 #include "reporthandler.h"
44 #include "reporthandler.h"
45 #include "fileout.h"
45 #include "fileout.h"
46
46
47 //#define Q_SCRIPT_LAZY_GENERATOR
47 //#define Q_SCRIPT_LAZY_GENERATOR
48
48
49 void SetupGenerator::addClass(const QString& package, const AbstractMetaClass *cls)
49 void SetupGenerator::addClass(const QString& package, const AbstractMetaClass *cls)
50 {
50 {
51 packHash[package].append(cls);
51 packHash[package].append(cls);
52 }
52 }
53
53
54 void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
54 void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
55 QSet<QString> &registeredTypeNames);
55 QSet<QString> &registeredTypeNames);
56 bool hasDefaultConstructor(const AbstractMetaClass *meta_class);
56 bool hasDefaultConstructor(const AbstractMetaClass *meta_class);
57
57
58 static QStringList getOperatorCodes(const AbstractMetaClass* cls) {
58 static QStringList getOperatorCodes(const AbstractMetaClass* cls) {
59 QSet<QString> operatorCodes;
59 QSet<QString> operatorCodes;
60 AbstractMetaFunctionList returned;
60 AbstractMetaFunctionList returned;
61 AbstractMetaFunctionList functions = cls->functions();
61 AbstractMetaFunctionList functions = cls->functions();
62 foreach (AbstractMetaFunction *function, functions) {
62 foreach (AbstractMetaFunction *function, functions) {
63 if (function->originalName().startsWith("operator")) {
63 if (function->originalName().startsWith("operator")) {
64 QString op = function->originalName().mid(8);
64 QString op = function->originalName().mid(8);
65 operatorCodes.insert(op);
65 operatorCodes.insert(op);
66 }
66 }
67 }
67 }
68 QSet<QString> r;
68 QSet<QString> r;
69 foreach(QString op, operatorCodes.toList()) {
69 foreach(QString op, operatorCodes.toList()) {
70 if (op == ">" || op == "<" || op == ">=" || op == "<=" || op == "==" || op == "!=") {
70 if (op == ">" || op == "<" || op == ">=" || op == "<=" || op == "==" || op == "!=") {
71 r.insert("PythonQt::Type_RichCompare");
71 r.insert("PythonQt::Type_RichCompare");
72 } else if (op == "+") {
72 } else if (op == "+") {
73 r.insert("PythonQt::Type_Add");
73 r.insert("PythonQt::Type_Add");
74 } else if (op == "-") {
74 } else if (op == "-") {
75 r.insert("PythonQt::Type_Subtract");
75 r.insert("PythonQt::Type_Subtract");
76 } else if (op == "/") {
76 } else if (op == "/") {
77 r.insert("PythonQt::Type_Divide");
77 r.insert("PythonQt::Type_Divide");
78 } else if (op == "*") {
78 } else if (op == "*") {
79 r.insert("PythonQt::Type_Multiply");
79 r.insert("PythonQt::Type_Multiply");
80 } else if (op == "%") {
80 } else if (op == "%") {
81 r.insert("PythonQt::Type_Mod");
81 r.insert("PythonQt::Type_Mod");
82 } else if (op == "&") {
82 } else if (op == "&") {
83 r.insert("PythonQt::Type_And");
83 r.insert("PythonQt::Type_And");
84 } else if (op == "|") {
84 } else if (op == "|") {
85 r.insert("PythonQt::Type_Or");
85 r.insert("PythonQt::Type_Or");
86 } else if (op == "^") {
86 } else if (op == "^") {
87 r.insert("PythonQt::Type_Xor");
87 r.insert("PythonQt::Type_Xor");
88 } else if (op == "~") {
88 } else if (op == "~") {
89 r.insert("PythonQt::Type_Invert");
89 r.insert("PythonQt::Type_Invert");
90
90
91 } else if (op == "+=") {
91 } else if (op == "+=") {
92 r.insert("PythonQt::Type_InplaceAdd");
92 r.insert("PythonQt::Type_InplaceAdd");
93 } else if (op == "-=") {
93 } else if (op == "-=") {
94 r.insert("PythonQt::Type_InplaceSubtract");
94 r.insert("PythonQt::Type_InplaceSubtract");
95 } else if (op == "/=") {
95 } else if (op == "/=") {
96 r.insert("PythonQt::Type_InplaceDivide");
96 r.insert("PythonQt::Type_InplaceDivide");
97 } else if (op == "*=") {
97 } else if (op == "*=") {
98 r.insert("PythonQt::Type_InplaceMultiply");
98 r.insert("PythonQt::Type_InplaceMultiply");
99 } else if (op == "%=") {
99 } else if (op == "%=") {
100 r.insert("PythonQt::Type_InplaceMod");
100 r.insert("PythonQt::Type_InplaceMod");
101 } else if (op == "&=") {
101 } else if (op == "&=") {
102 r.insert("PythonQt::Type_InplaceAnd");
102 r.insert("PythonQt::Type_InplaceAnd");
103 } else if (op == "|=") {
103 } else if (op == "|=") {
104 r.insert("PythonQt::Type_InplaceOr");
104 r.insert("PythonQt::Type_InplaceOr");
105 } else if (op == "^=") {
105 } else if (op == "^=") {
106 r.insert("PythonQt::Type_InplaceXor");
106 r.insert("PythonQt::Type_InplaceXor");
107 }
107 }
108 }
108 }
109 if (cls->hasDefaultIsNull()) {
109 if (cls->hasDefaultIsNull()) {
110 r.insert("PythonQt::Type_NonZero");
110 r.insert("PythonQt::Type_NonZero");
111 }
111 }
112 QStringList result = r.toList();
112 QStringList result = r.toList();
113 return result;
113 return result;
114 }
114 }
115
115
116 static bool class_less_than(const AbstractMetaClass *a, const AbstractMetaClass *b)
116 static bool class_less_than(const AbstractMetaClass *a, const AbstractMetaClass *b)
117 {
117 {
118 return a->name() < b->name();
118 return a->name() < b->name();
119 }
119 }
120
120
121 void SetupGenerator::generate()
121 void SetupGenerator::generate()
122 {
122 {
123 AbstractMetaClassList classes_with_polymorphic_id;
123 AbstractMetaClassList classes_with_polymorphic_id;
124 {
124 {
125 QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
125 QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
126 while (pack.hasNext()) {
126 while (pack.hasNext()) {
127 pack.next();
127 pack.next();
128 QList<const AbstractMetaClass*> list = pack.value();
128 QList<const AbstractMetaClass*> list = pack.value();
129 foreach (const AbstractMetaClass *cls, list) {
129 foreach (const AbstractMetaClass *cls, list) {
130 if (cls->typeEntry()->isPolymorphicBase()) {
130 if (cls->typeEntry()->isPolymorphicBase()) {
131 classes_with_polymorphic_id.append((AbstractMetaClass*)cls);
131 classes_with_polymorphic_id.append((AbstractMetaClass*)cls);
132 }
132 }
133 }
133 }
134 }
134 }
135 }
135 }
136 qSort(classes_with_polymorphic_id.begin(), classes_with_polymorphic_id.end(), class_less_than);
136 qSort(classes_with_polymorphic_id.begin(), classes_with_polymorphic_id.end(), class_less_than);
137
137
138 QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
138 QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
139 while (pack.hasNext()) {
139 while (pack.hasNext()) {
140 pack.next();
140 pack.next();
141 QList<const AbstractMetaClass*> list = pack.value();
141 QList<const AbstractMetaClass*> list = pack.value();
142 if (list.isEmpty())
142 if (list.isEmpty())
143 continue;
143 continue;
144 qSort(list.begin(), list.end(), class_less_than);
144 qSort(list.begin(), list.end(), class_less_than);
145
145
146 QString packKey = pack.key();
146 QString packKey = pack.key();
147 QString packName = pack.key();
147 QString packName = pack.key();
148 QStringList components = packName.split("_");
148 QStringList components = packName.split("_");
149 if ((components.size() > 2) && (components.at(0) == "com")
149 if ((components.size() > 2) && (components.at(0) == "com")
150 && (components.at(1) == "trolltech")) {
150 && (components.at(1) == "trolltech")) {
151 // kill com.trolltech in key
151 // kill com.trolltech in key
152 components.removeAt(0);
152 components.removeAt(0);
153 components.removeAt(0);
153 components.removeAt(0);
154 }
154 }
155
155
156 QString shortPackName;
156 QString shortPackName;
157 foreach (QString comp, components) {
157 foreach (QString comp, components) {
158 comp[0] = comp[0].toUpper();
158 comp[0] = comp[0].toUpper();
159 shortPackName += comp;
159 shortPackName += comp;
160 }
160 }
161 // add missing camel case (workaround..)
161 // add missing camel case (workaround..)
162 if (shortPackName == "QtWebkit") {
162 if (shortPackName == "QtWebkit") {
163 shortPackName = "QtWebKit";
163 shortPackName = "QtWebKit";
164 } else if (shortPackName == "QtXmlpatterns") {
164 } else if (shortPackName == "QtXmlpatterns") {
165 shortPackName = "QtXmlPatterns";
165 shortPackName = "QtXmlPatterns";
166 } else if (shortPackName == "QtOpengl") {
166 } else if (shortPackName == "QtOpengl") {
167 shortPackName = "QtOpenGL";
167 shortPackName = "QtOpenGL";
168 } else if (shortPackName == "QtUitools") {
168 } else if (shortPackName == "QtUitools") {
169 shortPackName = "QtUiTools";
169 shortPackName = "QtUiTools";
170 }
170 }
171
171
172
172
173 {
173 {
174 FileOut initFile(m_out_dir + "/generated_cpp/" + packName + "/" + packKey + "_init.cpp");
174 QString fileName(packName + "/" + packKey + "_init.cpp");
175 FileOut initFile(m_out_dir + "/generated_cpp/" + fileName);
176 ReportHandler::debugSparse(QString("generating: %1").arg(fileName));
175 QTextStream &s = initFile.stream;
177 QTextStream &s = initFile.stream;
176
178
177 s << "#include <PythonQt.h>" << endl;
179 s << "#include <PythonQt.h>" << endl;
178
180
179 for (int i=0; i<(list.count()+MAX_CLASSES_PER_FILE-1) / MAX_CLASSES_PER_FILE; i++) {
181 for (int i=0; i<(list.count()+MAX_CLASSES_PER_FILE-1) / MAX_CLASSES_PER_FILE; i++) {
180 s << "#include \"" << packKey << QString::number(i) << ".h\"" << endl;
182 s << "#include \"" << packKey << QString::number(i) << ".h\"" << endl;
181 }
183 }
182 s << endl;
184 s << endl;
183
185
184 QStringList polymorphicHandlers;
186 QStringList polymorphicHandlers;
185 if (!packName.endsWith("_builtin")) {
187 if (!packName.endsWith("_builtin")) {
186 polymorphicHandlers = writePolymorphicHandler(s, list.at(0)->package(), classes_with_polymorphic_id, list);
188 polymorphicHandlers = writePolymorphicHandler(s, list.at(0)->package(), classes_with_polymorphic_id, list);
187 s << endl;
189 s << endl;
188 }
190 }
189
191
190 // declare individual class creation functions
192 // declare individual class creation functions
191 s << "void PythonQt_init_" << shortPackName << "(PyObject* module) {" << endl;
193 s << "void PythonQt_init_" << shortPackName << "(PyObject* module) {" << endl;
192
194
193 if (shortPackName.endsWith("Builtin")) {
195 if (shortPackName.endsWith("Builtin")) {
194 shortPackName = shortPackName.mid(0, shortPackName.length()-strlen("builtin"));
196 shortPackName = shortPackName.mid(0, shortPackName.length()-strlen("builtin"));
195 }
197 }
196
198
197 QStringList cppClassNames;
199 QStringList cppClassNames;
198 foreach (const AbstractMetaClass *cls, list) {
200 foreach (const AbstractMetaClass *cls, list) {
199
201
200 QString shellCreator;
202 QString shellCreator;
201 if (cls->generateShellClass()) {
203 if (cls->generateShellClass()) {
202 shellCreator = ", PythonQtSetInstanceWrapperOnShell<" + ShellGenerator::shellClassName(cls) + ">";
204 shellCreator = ", PythonQtSetInstanceWrapperOnShell<" + ShellGenerator::shellClassName(cls) + ">";
203 } else {
205 } else {
204 shellCreator = ", NULL";
206 shellCreator = ", NULL";
205 }
207 }
206 QString operatorCodes = getOperatorCodes(cls).join("|");
208 QString operatorCodes = getOperatorCodes(cls).join("|");
207 if (operatorCodes.isEmpty()) {
209 if (operatorCodes.isEmpty()) {
208 operatorCodes = "0";
210 operatorCodes = "0";
209 }
211 }
210 if (cls->isQObject()) {
212 if (cls->isQObject()) {
211 s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
213 s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
212 } else {
214 } else {
213 QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():"";
215 QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():"";
214 s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
216 s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
215 }
217 }
216 foreach(AbstractMetaClass* interface, cls->interfaces()) {
218 foreach(AbstractMetaClass* interface, cls->interfaces()) {
217 // the interface might be our own class... (e.g. QPaintDevice)
219 // the interface might be our own class... (e.g. QPaintDevice)
218 if (interface->qualifiedCppName() != cls->qualifiedCppName()) {
220 if (interface->qualifiedCppName() != cls->qualifiedCppName()) {
219 s << "PythonQt::self()->addParentClass(\""<< cls->qualifiedCppName() << "\", \"" << interface->qualifiedCppName() << "\",PythonQtUpcastingOffset<" << cls->qualifiedCppName() <<","<<interface->qualifiedCppName()<<">());" << endl;
221 s << "PythonQt::self()->addParentClass(\""<< cls->qualifiedCppName() << "\", \"" << interface->qualifiedCppName() << "\",PythonQtUpcastingOffset<" << cls->qualifiedCppName() <<","<<interface->qualifiedCppName()<<">());" << endl;
220 }
222 }
221 }
223 }
222 }
224 }
223 s << endl;
225 s << endl;
224 foreach (QString handler, polymorphicHandlers) {
226 foreach (QString handler, polymorphicHandlers) {
225 s << "PythonQt::self()->addPolymorphicHandler(\""<< handler << "\", polymorphichandler_" << handler << ");" << endl;
227 s << "PythonQt::self()->addPolymorphicHandler(\""<< handler << "\", polymorphichandler_" << handler << ");" << endl;
226 }
228 }
227
229
228 s << "}";
230 s << "}";
229 s << endl;
231 s << endl;
230 }
232 }
231 }
233 }
232 }
234 }
233
235
234 QStringList SetupGenerator::writePolymorphicHandler(QTextStream &s, const QString &package,
236 QStringList SetupGenerator::writePolymorphicHandler(QTextStream &s, const QString &package,
235 const AbstractMetaClassList &polybase, QList<const AbstractMetaClass*>& allClasses)
237 const AbstractMetaClassList &polybase, QList<const AbstractMetaClass*>& allClasses)
236 {
238 {
237 QStringList handlers;
239 QStringList handlers;
238 foreach (AbstractMetaClass *cls, polybase) {
240 foreach (AbstractMetaClass *cls, polybase) {
239 const ComplexTypeEntry *centry = cls->typeEntry();
241 const ComplexTypeEntry *centry = cls->typeEntry();
240 if (!centry->isPolymorphicBase())
242 if (!centry->isPolymorphicBase())
241 continue;
243 continue;
242 bool isGraphicsItem = (cls->qualifiedCppName()=="QGraphicsItem");
244 bool isGraphicsItem = (cls->qualifiedCppName()=="QGraphicsItem");
243
245
244 bool first = true;
246 bool first = true;
245 foreach (const AbstractMetaClass *clazz, allClasses) {
247 foreach (const AbstractMetaClass *clazz, allClasses) {
246 bool inherits = false;
248 bool inherits = false;
247 if (isGraphicsItem) {
249 if (isGraphicsItem) {
248 foreach(AbstractMetaClass* interfaze, clazz->interfaces()) {
250 foreach(AbstractMetaClass* interfaze, clazz->interfaces()) {
249 if (interfaze->qualifiedCppName()=="QGraphicsItem") {
251 if (interfaze->qualifiedCppName()=="QGraphicsItem") {
250 inherits = true;
252 inherits = true;
251 break;
253 break;
252 }
254 }
253 }
255 }
254 } else {
256 } else {
255 inherits = clazz->inheritsFrom(cls);
257 inherits = clazz->inheritsFrom(cls);
256 }
258 }
257 if (clazz->package() == package && inherits) {
259 if (clazz->package() == package && inherits) {
258 if (!clazz->typeEntry()->polymorphicIdValue().isEmpty() || isGraphicsItem) {
260 if (!clazz->typeEntry()->polymorphicIdValue().isEmpty() || isGraphicsItem) {
259 // On first find, open the function
261 // On first find, open the function
260 if (first) {
262 if (first) {
261 first = false;
263 first = false;
262
264
263 QString handler = cls->name();
265 QString handler = cls->name();
264 handlers.append(handler);
266 handlers.append(handler);
265
267
266 s << "static void* polymorphichandler_" << handler
268 s << "static void* polymorphichandler_" << handler
267 << "(const void *ptr, char **class_name)" << endl
269 << "(const void *ptr, const char **class_name)" << endl
268 << "{" << endl
270 << "{" << endl
269 << " Q_ASSERT(ptr != 0);" << endl
271 << " Q_ASSERT(ptr != 0);" << endl
270 << " " << cls->qualifiedCppName() << " *object = ("
272 << " " << cls->qualifiedCppName() << " *object = ("
271 << cls->qualifiedCppName() << " *)ptr;" << endl;
273 << cls->qualifiedCppName() << " *)ptr;" << endl;
272 }
274 }
273
275
274 // For each, add case label
276 // For each, add case label
275 QString polyId = clazz->typeEntry()->polymorphicIdValue();
277 QString polyId = clazz->typeEntry()->polymorphicIdValue();
276 if (isGraphicsItem) {
278 if (isGraphicsItem) {
277 polyId = "%1->type() == " + clazz->qualifiedCppName() + "::Type";
279 polyId = "%1->type() == " + clazz->qualifiedCppName() + "::Type";
278 }
280 }
279 s << " if ("
281 s << " if ("
280 << polyId.replace("%1", "object")
282 << polyId.replace("%1", "object")
281 << ") {" << endl
283 << ") {" << endl
282 << " *class_name = \"" << clazz->name() << "\";" << endl
284 << " *class_name = \"" << clazz->name() << "\";" << endl
283 << " return (" << clazz->qualifiedCppName() << "*)object;" << endl
285 << " return (" << clazz->qualifiedCppName() << "*)object;" << endl
284 << " }" << endl;
286 << " }" << endl;
285 } else {
287 } else {
286 QString warning = QString("class '%1' inherits from polymorphic class '%2', but has no polymorphic id set")
288 QString warning = QString("class '%1' inherits from polymorphic class '%2', but has no polymorphic id set")
287 .arg(clazz->name())
289 .arg(clazz->name())
288 .arg(cls->name());
290 .arg(cls->name());
289
291
290 ReportHandler::warning(warning);
292 ReportHandler::warning(warning);
291 }
293 }
292 }
294 }
293 }
295 }
294
296
295 // Close the function if it has been opened
297 // Close the function if it has been opened
296 if (!first) {
298 if (!first) {
297 s << " return NULL;" << endl
299 s << " return NULL;" << endl
298 << "}" << endl;
300 << "}" << endl;
299 }
301 }
300 }
302 }
301
303
302 return handlers;
304 return handlers;
303 }
305 }
General Comments 0
You need to be logged in to leave comments. Login now