##// END OF EJS Templates
- removed phonon temporarily...
florianlink -
r11:27e624e0d6f1
parent child
Show More
@@ -0,0 +1,1
1 qmake -tp vc -r PythonQt.pro
@@ -1,4 +1,4
1 1 TEMPLATE = subdirs
2 2
3 3 CONFIG += ordered
4 SUBDIRS = src extensions tests examples
4 SUBDIRS = generator src extensions tests examples
@@ -1,30 +1,30
1 1 PythonQt
2 2 --------
3 3
4 4 PythonQt is a dynamic Python (http://www.python.org) binding for Qt (http://www.trolltech.com).
5 5 It offers an easy way to embed the Python scripting language into
6 6 your Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt4.x.
7 7
8 8 Licensing of PythonQt
9 9 ---------------------
10 10 PythonQt is distributed under the LGPL license.
11 11
12 12 Licensing of Generator
13 13 ----------------------
14 14 The build system of PythonQt makes use of a patched version of the GPL'ed QtScript generator,
15 15 located in the "generator" directory.
16 16
17 17 See http://labs.trolltech.com/page/Projects/QtScript/Generator for details of the original project.
18 18
19 19 The PythonQt wrappers generated by the generator are distributed under the LGPL, they are not restriced by the GPL.
20 20
21 The generated wrappers are pre-generated and checked-in for Qt 4.5, so you only need to build and run the
21 The generated wrappers are pre-generated and checked-in for Qt 4.4.3, so you only need to build and run the
22 22 generator when you want to build additional wrappers or you want to upgrade/downgrade to an newer Qt version.
23 23
24 24 Documentation
25 25 -------------
26 26
27 27 More documentation is available at:
28 28
29 29 http://pythonqt.sourceforge.net/
30 30
@@ -1,62 +1,62
1 1 /*
2 2 *
3 3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
4 4 *
5 5 * This library is free software; you can redistribute it and/or
6 6 * modify it under the terms of the GNU Lesser General Public
7 7 * License as published by the Free Software Foundation; either
8 8 * version 2.1 of the License, or (at your option) any later version.
9 9 *
10 10 * This library is distributed in the hope that it will be useful,
11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 13 * Lesser General Public License for more details.
14 14 *
15 15 * Further, this software is distributed without any warranty that it is
16 16 * free of the rightful claim of any third person regarding infringement
17 17 * or the like. Any license provided herein, whether implied or
18 18 * otherwise, applies only to this software file. Patent licenses, if
19 19 * any, provided herein do not apply to combinations of this program with
20 20 * other software, or any other product whatsoever.
21 21 *
22 22 * You should have received a copy of the GNU Lesser General Public
23 23 * License along with this library; if not, write to the Free Software
24 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 25 *
26 26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
27 27 * 28359 Bremen, Germany or:
28 28 *
29 29 * http://www.mevis.de
30 30 *
31 31 */
32 32
33 33 #include "PythonQt_QtAll.h"
34 34
35 35 void PythonQt_init_QtGui();
36 36 void PythonQt_init_QtSvg();
37 37 void PythonQt_init_QtSql();
38 38 void PythonQt_init_QtNetwork();
39 39 void PythonQt_init_QtCore();
40 40 void PythonQt_init_QtWebKit();
41 41 void PythonQt_init_QtOpenGL();
42 void PythonQt_init_QtPhonon();
43 42 void PythonQt_init_QtXml();
44 43 void PythonQt_init_QtXmlPatterns();
44 //void PythonQt_init_QtPhonon();
45 45
46 46 namespace PythonQt_QtAll
47 47 {
48 48 PYTHONQT_QTALL_EXPORT void init() {
49 49 PythonQt_init_QtCore();
50 50 PythonQt_init_QtNetwork();
51 51 PythonQt_init_QtGui();
52 52 PythonQt_init_QtXml();
53 53 PythonQt_init_QtXmlPatterns();
54 54 PythonQt_init_QtSvg();
55 55 PythonQt_init_QtSql();
56 56 PythonQt_init_QtWebKit();
57 57 PythonQt_init_QtOpenGL();
58 PythonQt_init_QtPhonon();
58 // PythonQt_init_QtPhonon();
59 59 };
60 60 };
61 61
62 62
@@ -1,32 +1,34
1 1
2 2 TARGET = PythonQt_QtAll
3 3 TEMPLATE = lib
4 4
5 5 DESTDIR = ../../lib
6 6 DLLDESTDIR = ../../lib
7 7
8 8 include ( ../../build/common.prf )
9 9 include ( ../../build/PythonQt.prf )
10 10
11 11 CONFIG += dll qt
12 12
13 13 DEFINES += PYTHONQT_QTALL_EXPORTS
14 14
15 15 HEADERS += \
16 16 PythonQt_QtAll.h
17 17
18 18 SOURCES += \
19 19 PythonQt_QtAll.cpp
20 20
21 QT += webkit gui svg sql network xml xmlpatterns phonon opengl
21 QT += webkit gui svg sql network xml xmlpatterns opengl
22 #QT += phonon
22 23
23 24 include (../../generated_cpp/com_trolltech_qt_core/com_trolltech_qt_core.pri)
24 25 include (../../generated_cpp/com_trolltech_qt_gui/com_trolltech_qt_gui.pri)
25 26 include (../../generated_cpp/com_trolltech_qt_svg/com_trolltech_qt_svg.pri)
26 27 include (../../generated_cpp/com_trolltech_qt_sql/com_trolltech_qt_sql.pri)
27 28 include (../../generated_cpp/com_trolltech_qt_network/com_trolltech_qt_network.pri)
28 29 include (../../generated_cpp/com_trolltech_qt_opengl/com_trolltech_qt_opengl.pri)
29 include (../../generated_cpp/com_trolltech_qt_phonon/com_trolltech_qt_phonon.pri)
30 30 include (../../generated_cpp/com_trolltech_qt_webkit/com_trolltech_qt_webkit.pri)
31 31 include (../../generated_cpp/com_trolltech_qt_xml/com_trolltech_qt_xml.pri)
32 32 include (../../generated_cpp/com_trolltech_qt_xmlpatterns/com_trolltech_qt_xmlpatterns.pri)
33
34 #include (../../generated_cpp/com_trolltech_qt_phonon/com_trolltech_qt_phonon.pri)
@@ -1,1870 +1,1870
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 4 **
5 5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 6 **
7 7 ** This file may be used under the terms of the GNU General Public
8 8 ** License version 2.0 as published by the Free Software Foundation
9 9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 10 ** this file. Please review the following information to ensure GNU
11 11 ** General Public Licensing requirements will be met:
12 12 ** http://www.trolltech.com/products/qt/opensource.html
13 13 **
14 14 ** If you are unsure which license is appropriate for your use, please
15 15 ** review the following information:
16 16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 17 ** sales department at sales@trolltech.com.
18 18 **
19 19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 21 **
22 22 ****************************************************************************/
23 23
24 24 #include "classgenerator.h"
25 25 #include "fileout.h"
26 26
27 27 #include <QtCore/QDir>
28 28 #include <QtCore/QMetaType>
29 29
30 30 #include <qdebug.h>
31 31
32 32 #define GENERATOR_NO_PROTECTED_FUNCTIONS
33 33
34 34 ClassGenerator::ClassGenerator(PriGenerator *pri, SetupGenerator *setup) :
35 35 priGenerator(pri),
36 36 setupGenerator(setup)
37 37 {}
38 38
39 39 QString ClassGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
40 40 {
41 41 return QString("qtscript_%1.cpp").arg(meta_class->name());
42 42 }
43 43
44 44 bool ClassGenerator::shouldGenerate(const AbstractMetaClass *meta_class) const
45 45 {
46 46 return false; // DISABLED!
47 47 uint cg = meta_class->typeEntry()->codeGeneration();
48 48 return (cg & TypeEntry::GenerateCode) != 0;
49 49 }
50 50
51 51 static QString normalizedType(const AbstractMetaType *type)
52 52 {
53 53 QString str = QString::fromLatin1(QMetaObject::normalizedType(type->cppSignature().toLatin1()));
54 54 if (str.endsWith(QLatin1Char('&')))
55 55 str.chop(1);
56 56 else if (str.startsWith("const ")) {
57 57 if (str.endsWith('*') || type->hasInstantiations() || type->typeEntry()->isValue())
58 58 str.remove(0, 6);
59 59 }
60 60 if (str == QLatin1String("QBool")) // ### hack
61 61 str = QLatin1String("bool");
62 62 return str;
63 63 }
64 64
65 65 /*!
66 66 Returns true if the class \a meta_class inherits from QObject,
67 67 otherwise returns false.
68 68 */
69 69 static bool isQObjectBased(const AbstractMetaClass *meta_class)
70 70 {
71 71 while (meta_class) {
72 72 if (meta_class->name() == QLatin1String("QObject"))
73 73 return true;
74 74 meta_class = meta_class->baseClass();
75 75 }
76 76 return false;
77 77 }
78 78
79 79 /*!
80 80 Returns true if any of the given \a enums has been declared with
81 81 Q_ENUMS.
82 82 */
83 83 static bool hasQEnums(const AbstractMetaEnumList &enums)
84 84 {
85 85 for (int i = 0; i < enums.size(); ++i) {
86 86 if (enums.at(i)->hasQEnumsDeclaration())
87 87 return true;
88 88 }
89 89 return false;
90 90 }
91 91
92 92 /*!
93 93 Returns true if any of the given \a enums has a QFlags class
94 94 associated with it.
95 95 */
96 96 static bool hasFlags(const AbstractMetaEnumList &enums)
97 97 {
98 98 for (int i = 0; i < enums.size(); ++i) {
99 99 FlagsTypeEntry *flags = enums.at(i)->typeEntry()->flags();
100 100 if (flags)
101 101 return true;
102 102 }
103 103 return false;
104 104 }
105 105
106 106 static bool isSequenceType(const AbstractMetaType *tp)
107 107 {
108 108 return tp->isContainer() && (tp->instantiations().size() == 1);
109 109 }
110 110
111 111 static AbstractMetaFunction *findDefaultConstructor(const AbstractMetaFunctionList &ctors)
112 112 {
113 113 for (int i = 0; i < ctors.size(); ++i) {
114 114 if (ctors.at(i)->actualMinimumArgumentCount() == 0)
115 115 return ctors.at(i);
116 116 }
117 117 return 0;
118 118 }
119 119
120 120 static AbstractMetaFunctionList findConstructors(const AbstractMetaClass *meta_class)
121 121 {
122 122 return meta_class->queryFunctions(AbstractMetaClass::Constructors
123 123 | AbstractMetaClass::WasPublic
124 124 | AbstractMetaClass::NotRemovedFromTargetLang);
125 125 }
126 126
127 127 /*!
128 128 Returns true if \a meta_class has a default constructor, false
129 129 otherwise.
130 130 */
131 131 bool hasDefaultConstructor(const AbstractMetaClass *meta_class)
132 132 {
133 133 return findDefaultConstructor(findConstructors(meta_class)) != 0;
134 134 }
135 135
136 136 /*!
137 137 Given the list of \a functions, creates a mapping from # of
138 138 arguments to list of functions.
139 139 */
140 140 static QMap<int, AbstractMetaFunctionList> createArgcToFunctionsMap(
141 141 const AbstractMetaFunctionList &functions)
142 142 {
143 143 QMap<int, AbstractMetaFunctionList> result;
144 144 for (int i = 0; i < functions.size(); ++i) {
145 145 AbstractMetaFunction *func = functions.at(i);
146 146 int argc = func->arguments().size();
147 147 for (int k = argc; k > 0; --k) {
148 148 if (func->argumentRemoved(k))
149 149 --argc;
150 150 }
151 151 for (int j = func->actualMinimumArgumentCount(); j <= argc; ++j)
152 152 result[j].append(func);
153 153 }
154 154 return result;
155 155 }
156 156
157 157 /*!
158 158 Returns the name of the QScriptValue function to use to test if
159 159 a value is of the given \a typeName, or an empty string if there
160 160 is no such function.
161 161 */
162 162 static QString builtinTypeTesterFunction(const QString &typeName)
163 163 {
164 164 if (typeName == QLatin1String("QString"))
165 165 return QLatin1String("isString");
166 166 else if (typeName == QLatin1String("double"))
167 167 return QLatin1String("isNumber");
168 168 else if (typeName == QLatin1String("float"))
169 169 return QLatin1String("isNumber");
170 170 else if (typeName == QLatin1String("int"))
171 171 return QLatin1String("isNumber");
172 172 else if (typeName == QLatin1String("uint"))
173 173 return QLatin1String("isNumber");
174 174 else if (typeName == QLatin1String("short"))
175 175 return QLatin1String("isNumber");
176 176 else if (typeName == QLatin1String("unsigned short"))
177 177 return QLatin1String("isNumber");
178 178 else if (typeName == QLatin1String("bool"))
179 179 return QLatin1String("isBoolean");
180 180 else if (typeName == QLatin1String("QVariant"))
181 181 return QLatin1String("isVariant");
182 182 // else if (typeName == QLatin1String("QDateTime"))
183 183 // return QLatin1String("isDate");
184 184 else if (typeName == QLatin1String("QRegExp"))
185 185 return QLatin1String("isRegExp");
186 186 else if (typeName == QLatin1String("QObject*"))
187 187 return QLatin1String("isQObject");
188 188 return QString();
189 189 }
190 190
191 191 /*!
192 192 Writes the code injections for the class \a meta_class that should
193 193 be injected at position \a pos.
194 194 */
195 195 static void writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class,
196 196 CodeSnip::Position pos)
197 197 {
198 198 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
199 199 foreach (const CodeSnip &cs, code_snips) {
200 200 if ((cs.language == TypeSystem::NativeCode) && (cs.position == pos)) {
201 201 s << cs.code() << endl;
202 202 }
203 203 }
204 204 }
205 205
206 206 /*!
207 207 Writes the code injections for the function \a fun of the class \a
208 208 meta_class that should be injected at position \a pos.
209 209 */
210 210 static void writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class,
211 211 const AbstractMetaFunction *fun, CodeSnip::Position pos)
212 212 {
213 213 FunctionModificationList mods = fun->modifications(meta_class);
214 214 foreach (const FunctionModification &mod, mods) {
215 215 if (!mod.isCodeInjection())
216 216 continue;
217 217 foreach (const CodeSnip &cs, mod.snips) {
218 218 if ((cs.language == TypeSystem::NativeCode) && (cs.position == pos)) {
219 219 s << cs.code() << endl;
220 220 }
221 221 }
222 222 }
223 223 }
224 224
225 225 /*!
226 226 Writes a boolean expression that checks if the actual arguments are
227 227 compatible with what the function expects. This is used to resolve
228 228 ambiguous calls.
229 229 */
230 230 static void writeArgumentTypeTests(QTextStream &stream, const AbstractMetaFunction *fun,
231 231 const AbstractMetaArgumentList &arguments, int argc, int indent)
232 232 {
233 233 QString indentStr(indent, QLatin1Char(' '));
234 234 int j = 0;
235 235 for (int i = 0; i < argc; ++j) {
236 236 if (fun->argumentRemoved(j+1))
237 237 continue;
238 238 if (i > 0)
239 239 stream << endl << indentStr << "&& ";
240 240 const AbstractMetaType *argType = 0;
241 241 QString typeName = fun->typeReplaced(j+1);
242 242 if (typeName.isEmpty()) {
243 243 AbstractMetaArgument *arg = arguments.at(j);
244 244 argType = arg->type();
245 245 typeName = normalizedType(argType);
246 246 }
247 247 QString scriptArg = QString::fromLatin1("context->argument(%0)").arg(i);
248 248 if (argType && isSequenceType(argType)) {
249 249 stream << scriptArg << ".isArray()";
250 250 } else if (typeName == "QVariant") {
251 251 stream << "true";
252 252 } else {
253 253 QString tester = builtinTypeTesterFunction(typeName);
254 254 if (!tester.isEmpty()) {
255 255 stream << scriptArg << "." << tester << "()";
256 256 } else if (typeName.endsWith('*')) {
257 257 stream << "qscriptvalue_cast<" << typeName << ">(" << scriptArg << ")";
258 258 } else {
259 259 // typeid-based test
260 260 stream << "(qMetaTypeId<" << typeName;
261 261 if (typeName.endsWith(QLatin1Char('>')))
262 262 stream << " ";
263 263 stream << ">() == " << scriptArg << ".toVariant().userType())";
264 264 }
265 265 }
266 266 ++i;
267 267 }
268 268 }
269 269
270 270 /*!
271 271 Returns the name of the QScriptValue function to use to convert a
272 272 value is of the given \a typeName, or an empty string if there is no
273 273 such function.
274 274 */
275 275 static QString builtinConversionFunction(const QString &typeName)
276 276 {
277 277 if (typeName == QLatin1String("QString"))
278 278 return QLatin1String("toString");
279 279 else if (typeName == QLatin1String("double"))
280 280 return QLatin1String("toNumber");
281 281 else if (typeName == QLatin1String("int"))
282 282 return QLatin1String("toInt32");
283 283 else if (typeName == QLatin1String("uint"))
284 284 return QLatin1String("toUInt32");
285 285 else if (typeName == QLatin1String("bool"))
286 286 return QLatin1String("toBoolean");
287 287 else if (typeName == QLatin1String("QVariant"))
288 288 return QLatin1String("toVariant");
289 289 else if (typeName == QLatin1String("QDateTime"))
290 290 return QLatin1String("toDateTime");
291 291 else if (typeName == QLatin1String("QRegExp"))
292 292 return QLatin1String("toRegExp");
293 293 else if (typeName == QLatin1String("QObject*"))
294 294 return QLatin1String("toQObject");
295 295 return QString();
296 296 }
297 297
298 298 /*!
299 299 Generates script arguments --> C++ types conversion, in preparation
300 300 for calling the native function we are binding.
301 301 */
302 302 static int writePrepareArguments(QTextStream &stream, const AbstractMetaFunction *fun,
303 303 const AbstractMetaArgumentList &arguments,
304 304 int scriptArgc, int indent)
305 305 {
306 306 if (arguments.size() == 0) {
307 307 Q_ASSERT(scriptArgc == 0);
308 308 return 0; // nothing to do
309 309 }
310 310 QString indentStr(indent, QLatin1Char(' '));
311 311 int j = 0;
312 312 for (int scriptArgIndex = 0; j < arguments.size(); ++j) {
313 313 const AbstractMetaArgument *arg = arguments.at(j);
314 314 bool isOptional = !arg->defaultValueExpression().isEmpty();
315 315 if (isOptional && (scriptArgIndex == scriptArgc))
316 316 break;
317 317 QString conv = fun->conversionRule(TypeSystem::NativeCode, j+1);
318 318 QString actualIn = QString::fromLatin1("context->argument(%0)").arg(scriptArgIndex);
319 319 QString actualOut = QString::fromLatin1("_q_arg%0").arg(j);
320 320 if (!conv.isEmpty()) {
321 321 // custom conversion
322 322 conv.replace(QString::fromLatin1("%in%"), actualIn);
323 323 conv.replace(QString::fromLatin1("%out%"), actualOut);
324 324 conv.replace(QString::fromLatin1("%this%"), QString::fromLatin1("_q_self"));
325 325 stream << conv;
326 326 } else {
327 327 const AbstractMetaType *argType = 0;
328 328 QString typeName = fun->typeReplaced(j+1);
329 329 if (typeName.isEmpty()) {
330 330 argType = arg->type();
331 331 typeName = normalizedType(argType);
332 332 }
333 333 stream << indentStr << typeName << " " << actualOut;
334 334 QString converter;
335 335 // ### generalize the QSet check (we should check if the type has push_back())
336 336 bool useToSequence = argType && isSequenceType(argType) && !argType->name().startsWith("Set");
337 337 if (useToSequence) {
338 338 stream << ";" << endl;
339 339 stream << indentStr << "qScriptValueToSequence(";
340 340 } else {
341 341 stream << " = ";
342 342 converter = builtinConversionFunction(typeName);
343 343 if (converter.isEmpty()) {
344 344 // generic conversion
345 345 stream << "qscriptvalue_cast<" << typeName;
346 346 if (typeName.endsWith(QLatin1Char('>')))
347 347 stream << " ";
348 348 stream << ">(";
349 349 }
350 350 }
351 351 stream << actualIn;
352 352 if (useToSequence) {
353 353 stream << ", " << actualOut << ")";
354 354 } else {
355 355 if (converter.isEmpty()) {
356 356 stream << ")"; // close qscriptvalue_cast
357 357 } else {
358 358 stream << "." << converter << "()";
359 359 }
360 360 }
361 361 stream << ";" << endl;
362 362 }
363 363 if (!fun->argumentRemoved(j+1))
364 364 ++scriptArgIndex;
365 365 }
366 366 return j;
367 367 }
368 368
369 369 /*!
370 370 Writes the arguments that are passed to the native function we are
371 371 binding. Those arguments must have been prepared already in variables
372 372 _q_arg0, _q_arg1, .. in the generated code.
373 373 */
374 374 static void writeArguments(QTextStream &stream, int count)
375 375 {
376 376 for (int i = 0; i < count; ++i) {
377 377 if (i > 0)
378 378 stream << ", ";
379 379 stream << "_q_arg" << i;
380 380 }
381 381 }
382 382
383 383 /*!
384 384 Writes a constructor call.
385 385 */
386 386 static void writeConstructorCallAndReturn(QTextStream &stream, const AbstractMetaFunction *fun,
387 387 int scriptArgc, const AbstractMetaClass *meta_class,
388 388 int indent)
389 389 {
390 390 QString indentStr(indent, QLatin1Char(' '));
391 391
392 392 writeInjectedCode(stream, meta_class, fun, CodeSnip::Beginning);
393 393
394 394 AbstractMetaArgumentList arguments = fun->arguments();
395 395 Q_ASSERT(arguments.size() >= scriptArgc);
396 396 int nativeArgc = writePrepareArguments(stream, fun, arguments, scriptArgc, indent);
397 397 stream << indentStr;
398 398 if (meta_class->generateShellClass()) {
399 399 stream << "QtScriptShell_" << meta_class->name();
400 400 } else {
401 401 stream << meta_class->qualifiedCppName();
402 402 }
403 403 bool useNew = meta_class->typeEntry()->isObject() || !hasDefaultConstructor(meta_class);
404 404 if (useNew)
405 405 stream << "*";
406 406 stream << " _q_cpp_result";
407 407 if (useNew) {
408 408 stream << " = new ";
409 409 if (meta_class->generateShellClass())
410 410 stream << "QtScriptShell_" << meta_class->name();
411 411 else
412 412 stream << meta_class->qualifiedCppName();
413 413 }
414 414 if (useNew || (nativeArgc != 0)) {
415 415 stream << "(";
416 416 writeArguments(stream, nativeArgc);
417 417 stream << ")";
418 418 }
419 419 stream << ";" << endl;
420 420
421 421 stream << indentStr << "QScriptValue _q_result = context->engine()->new";
422 422 if (isQObjectBased(meta_class))
423 423 stream << "QObject";
424 424 else
425 425 stream << "Variant";
426 426 stream << "(context->thisObject(), ";
427 427 if (!isQObjectBased(meta_class))
428 428 stream << "qVariantFromValue(";
429 429 if (meta_class->generateShellClass()) {
430 430 stream << "(" << meta_class->qualifiedCppName();
431 431 if (useNew)
432 432 stream << "*";
433 433 stream << ")";
434 434 }
435 435 stream << "_q_cpp_result";
436 436 if (isQObjectBased(meta_class))
437 437 stream << ", QScriptEngine::AutoOwnership";
438 438 else
439 439 stream << ")";
440 440 stream << ");" << endl;
441 441 if (meta_class->generateShellClass()) {
442 442 stream << indentStr << "_q_cpp_result";
443 443 if (useNew)
444 444 stream << "->";
445 445 else
446 446 stream << ".";
447 447 stream << "__qtscript_self = _q_result;" << endl;
448 448 }
449 449
450 450 writeInjectedCode(stream, meta_class, fun, CodeSnip::End);
451 451
452 452 stream << indentStr << "return _q_result;" << endl;
453 453 }
454 454
455 455 /*!
456 456 Returns true if the given \a typeName has a QScriptValue constructor
457 457 we can use, false otherwise.
458 458 */
459 459 static bool hasScriptValueConstructor(const QString &typeName)
460 460 {
461 461 return (typeName == QLatin1String("bool"))
462 462 || (typeName == QLatin1String("int"))
463 463 || (typeName == QLatin1String("uint"))
464 464 || (typeName == QLatin1String("double"))
465 465 || (typeName == QLatin1String("QString"));
466 466 }
467 467
468 468 /*!
469 469 Writes a function call.
470 470 */
471 471 static void writeFunctionCallAndReturn(QTextStream &stream, const AbstractMetaFunction *fun,
472 472 int scriptArgc, const AbstractMetaClass *meta_class,
473 473 int indent)
474 474 {
475 475 QString indentStr(indent, QLatin1Char(' '));
476 476 AbstractMetaArgumentList arguments = fun->arguments();
477 477 Q_ASSERT(arguments.size() >= scriptArgc);
478 478
479 479 writeInjectedCode(stream, meta_class, fun, CodeSnip::Beginning);
480 480
481 481 int nativeArgc = writePrepareArguments(stream, fun, arguments, scriptArgc, indent);
482 482 bool returnThisObject = fun->shouldReturnThisObject();
483 483 bool ignoreReturnValue = returnThisObject || fun->shouldIgnoreReturnValue();
484 484 stream << indentStr;
485 485 AbstractMetaType *retType = fun->type();
486 486 bool constCastResult = false;
487 487 if (retType && !ignoreReturnValue) {
488 488 QString rsig = retType->cppSignature();
489 489 QString typeName = normalizedType(retType);
490 490 stream << typeName << " _q_result = ";
491 491 constCastResult = rsig.endsWith('*') && rsig.startsWith("const ");
492 492 if (constCastResult)
493 493 stream << "const_cast<" << typeName << ">(";
494 494 }
495 495
496 496 if (!fun->isStatic()) {
497 497 // ### the friendly check should be enough...
498 498 if (fun->isFriendly()
499 499 || ((fun->name() == QLatin1String("operator_equal"))
500 500 && ((meta_class->name() == QLatin1String("QPoint"))
501 501 || (meta_class->name() == QLatin1String("QPointF"))
502 502 || (meta_class->name() == QLatin1String("QRect"))
503 503 || (meta_class->name() == QLatin1String("QRectF"))
504 504 || (meta_class->name() == QLatin1String("QSize"))
505 505 || (meta_class->name() == QLatin1String("QSizeF"))))) {
506 506 stream << fun->originalName() << "(";
507 507 stream << "*_q_self, ";
508 508 } else {
509 509 stream << "_q_self->";
510 510 stream << fun->originalName() << "(";
511 511 }
512 512 } else {
513 513 stream << meta_class->qualifiedCppName() << "::";
514 514 stream << fun->originalName() << "(";
515 515 }
516 516 writeArguments(stream, nativeArgc);
517 517 if (constCastResult)
518 518 stream << ")";
519 519 stream << ");" << endl;
520 520
521 521 writeInjectedCode(stream, meta_class, fun, CodeSnip::End);
522 522
523 523 // write return statement
524 524 stream << indentStr;
525 525 if (returnThisObject) {
526 526 stream << "return context->thisObject();";
527 527 } else {
528 528 QString conv = fun->conversionRule(TypeSystem::NativeCode, 0);
529 529 if (!conv.isEmpty()) {
530 530 // custom conversion
531 531 conv.replace(QString::fromLatin1("%in%"), "_q_result");
532 532 conv.replace(QString::fromLatin1("%out%"), "_q_convertedResult");
533 533 stream << conv;
534 534 stream << "return qScriptValueFromValue(context->engine(), _q_convertedResult);";
535 535 } else {
536 536 stream << "return ";
537 537 if (retType) {
538 538 if (isSequenceType(retType))
539 539 stream << "qScriptValueFromSequence";
540 540 else if (hasScriptValueConstructor(normalizedType(retType)))
541 541 stream << "QScriptValue";
542 542 else
543 543 stream << "qScriptValueFromValue";
544 544 stream << "(context->engine(), _q_result);";
545 545 } else {
546 546 stream << "context->engine()->undefinedValue();";
547 547 }
548 548 }
549 549 }
550 550 stream << endl;
551 551 }
552 552
553 553 /*!
554 554 Returns true if the given function \a fun is operator>>() or
555 555 operator<<() that streams from/to a Q{Data,Text}Stream, false
556 556 otherwise.
557 557 */
558 558 bool ClassGenerator::isSpecialStreamingOperator(const AbstractMetaFunction *fun)
559 559 {
560 560 return ((fun->functionType() == AbstractMetaFunction::GlobalScopeFunction)
561 561 && (fun->arguments().size() == 1)
562 562 && (((fun->originalName() == "operator>>") && (fun->modifiedName() == "readFrom"))
563 563 || ((fun->originalName() == "operator<<") && (fun->modifiedName() == "writeTo"))));
564 564 }
565 565
566 566 /*!
567 567 Generates code that uses Q{Data,Text}Stream operator>>() or
568 568 operator<<() to read/write an instance of meta_class.
569 569 */
570 570 static void writeStreamingOperatorCall(QTextStream &stream, const AbstractMetaFunction *fun,
571 const AbstractMetaClass */*meta_class*/, int indent)
571 const AbstractMetaClass * /*meta_class*/, int indent)
572 572 {
573 573 QString indentStr(indent, QLatin1Char(' '));
574 574 QString streamClassName = fun->arguments().at(0)->type()->name();
575 575 stream << indentStr << streamClassName << "* _q_arg0 = qscriptvalue_cast<"
576 576 << streamClassName << "*>(context->argument(0));" << endl;
577 577 stream << indentStr << "operator";
578 578 if (fun->modifiedName() == "readFrom")
579 579 stream << ">>";
580 580 else
581 581 stream << "<<";
582 582 stream << "(*_q_arg0, *_q_self);" << endl;
583 583 stream << indentStr << "return context->engine()->undefinedValue();" << endl;
584 584 }
585 585
586 586 /*!
587 587 Writes the constructor forwarding for \a meta_class.
588 588 */
589 589 static void writeConstructorForwarding(QTextStream &stream,
590 590 const AbstractMetaFunctionList &functions,
591 591 const AbstractMetaClass *meta_class)
592 592 {
593 593 #if 0
594 594 stream << "/** signatures:" << endl;
595 595 foreach (const AbstractMetaFunction *fun, functions) {
596 596 stream << " * " << fun->signature() << endl;
597 597 }
598 598 stream << " */" << endl;
599 599 #endif
600 600
601 601 if (/*meta_class->isAbstract() ||*/ (functions.size() == 0)) {
602 602 stream << " return context->throwError(QScriptContext::TypeError," << endl
603 603 << " QString::fromLatin1(\"" << meta_class->name()
604 604 << " cannot be constructed\"));" << endl;
605 605
606 606 } else {
607 607 stream << " if (context->thisObject().strictlyEquals(context->engine()->globalObject())) {" << endl
608 608 << " return context->throwError(QString::fromLatin1(\""
609 609 << meta_class->name() << "(): Did you forget to construct with 'new'?\"));" << endl
610 610 << " }" << endl;
611 611
612 612 writeInjectedCode(stream, meta_class, CodeSnip::Constructor);
613 613
614 614 QMap<int, AbstractMetaFunctionList> argcToFunctions;
615 615 argcToFunctions = createArgcToFunctionsMap(functions);
616 616
617 617 int argcMin = argcToFunctions.keys().first();
618 618 int argcMax = argcToFunctions.keys().last();
619 619 bool needElse = false;
620 620 for (int i = argcMin; i <= argcMax; ++i) {
621 621 AbstractMetaFunctionList funcs = argcToFunctions.value(i);
622 622 if (funcs.isEmpty())
623 623 continue;
624 624 if (needElse)
625 625 stream << " else ";
626 626 else
627 627 stream << " ";
628 628 needElse = true;
629 629 stream << "if (context->argumentCount() == " << i << ") {" << endl;
630 630 if ((funcs.size() == 1) || (i == 0)) {
631 631 AbstractMetaFunction *fun = funcs.at(0);
632 632 const int indent = 8;
633 633 writeConstructorCallAndReturn(stream, fun, i, meta_class, indent);
634 634 } else {
635 635 // handle overloads
636 636 for (int j = 0; j < funcs.size(); ++j) {
637 637 AbstractMetaFunction *fun = funcs.at(j);
638 638 stream << " ";
639 639 if (j > 0)
640 640 stream << "} else ";
641 641 stream << "if (";
642 642 AbstractMetaArgumentList arguments = fun->arguments();
643 643 const int indent = 12;
644 644 writeArgumentTypeTests(stream, fun, arguments, i, indent);
645 645 stream << ") {" << endl;
646 646 writeConstructorCallAndReturn(stream, fun, i, meta_class, indent);
647 647 }
648 648 stream << " }" << endl;
649 649 }
650 650 stream << " }";
651 651 }
652 652 stream << endl;
653 653 // writeThrowAmbiguityError(stream, meta_class, 0, signatures.toList());
654 654 }
655 655 }
656 656
657 657 /*!
658 658 Returns a list of enum \a values that are actually unique.
659 659 */
660 660 QList<int> uniqueEnumValueIndexes(const AbstractMetaEnumValueList &values)
661 661 {
662 662 QMap<int, int> map;
663 663 for (int i = 0; i < values.count(); ++i) {
664 664 AbstractMetaEnumValue *val = values.at(i);
665 665 if (!map.contains(val->value()))
666 666 map.insert(val->value(), i);
667 667 }
668 668 return map.values();
669 669 }
670 670
671 671 /*!
672 672 */
673 673 static bool isContiguousEnum(const QList<int> &indexes, const AbstractMetaEnumValueList &values)
674 674 {
675 675 if (indexes.isEmpty())
676 676 return false;
677 677 int prev = values.at(indexes.at(0))->value();
678 678 for (int i = 1; i < indexes.size(); ++i) {
679 679 int curr = values.at(indexes.at(i))->value();
680 680 if (curr != prev + 1)
681 681 return false;
682 682 prev = curr;
683 683 }
684 684 return true;
685 685 }
686 686
687 687 static void writeCreateEnumClassHelper(QTextStream &stream)
688 688 {
689 689 stream << "static QScriptValue qtscript_create_enum_class_helper(" << endl
690 690 << " QScriptEngine *engine," << endl
691 691 << " QScriptEngine::FunctionSignature construct," << endl
692 692 << " QScriptEngine::FunctionSignature valueOf," << endl
693 693 << " QScriptEngine::FunctionSignature toString)" << endl
694 694 << "{" << endl
695 695 << " QScriptValue proto = engine->newObject();" << endl
696 696 << " proto.setProperty(QString::fromLatin1(\"valueOf\")," << endl
697 697 << " engine->newFunction(valueOf), QScriptValue::SkipInEnumeration);" << endl
698 698 << " proto.setProperty(QString::fromLatin1(\"toString\")," << endl
699 699 << " engine->newFunction(toString), QScriptValue::SkipInEnumeration);" << endl
700 700 << " return engine->newFunction(construct, proto, 1);" << endl
701 701 << "}" << endl << endl;
702 702 }
703 703
704 704 static void writeCreateFlagsClassHelper(QTextStream &stream)
705 705 {
706 706 stream << "static QScriptValue qtscript_create_flags_class_helper(" << endl
707 707 << " QScriptEngine *engine," << endl
708 708 << " QScriptEngine::FunctionSignature construct," << endl
709 709 << " QScriptEngine::FunctionSignature valueOf," << endl
710 710 << " QScriptEngine::FunctionSignature toString," << endl
711 711 << " QScriptEngine::FunctionSignature equals)" << endl
712 712 << "{" << endl
713 713 << " QScriptValue proto = engine->newObject();" << endl
714 714 << " proto.setProperty(QString::fromLatin1(\"valueOf\")," << endl
715 715 << " engine->newFunction(valueOf), QScriptValue::SkipInEnumeration);" << endl
716 716 << " proto.setProperty(QString::fromLatin1(\"toString\")," << endl
717 717 << " engine->newFunction(toString), QScriptValue::SkipInEnumeration);" << endl
718 718 << " proto.setProperty(QString::fromLatin1(\"equals\")," << endl
719 719 << " engine->newFunction(equals), QScriptValue::SkipInEnumeration);" << endl
720 720 << " return engine->newFunction(construct, proto);" << endl
721 721 << "}" << endl << endl;
722 722 }
723 723
724 724 /*!
725 725 Writes the enum \a enom belonging to the class \a meta_class to the
726 726 given \a stream.
727 727 */
728 728 static void writeEnumClass(QTextStream &stream, const AbstractMetaClass *meta_class,
729 729 const AbstractMetaEnum *enom)
730 730 {
731 731 QString qualifiedEnumName = meta_class->qualifiedCppName() + "::" + enom->name();
732 732 QString qtScriptEnumName = meta_class->name() + "_" + enom->name();
733 733
734 734 stream << "//" << endl;
735 735 stream << "// " << qualifiedEnumName << endl;
736 736 stream << "//" << endl << endl;
737 737
738 738 // determine unique values (aliases will cause switch statement to not compile)
739 739 AbstractMetaEnumValueList values = enom->values();
740 740 QList<int> uniqueIndexes = uniqueEnumValueIndexes(values);
741 741
742 742 bool contiguous = isContiguousEnum(uniqueIndexes, values);
743 743
744 744 // write arrays of values and keys
745 745 stream << "static const " << qualifiedEnumName
746 746 << " qtscript_" << qtScriptEnumName << "_values[] = {" << endl;
747 747 for (int i = 0; i < uniqueIndexes.size(); ++i) {
748 748 stream << " ";
749 749 if (i > 0)
750 750 stream << ", ";
751 751 stream << meta_class->qualifiedCppName() << "::" << values.at(uniqueIndexes.at(i))->name() << endl;
752 752 }
753 753 stream << "};" << endl << endl;
754 754 stream << "static const char * const qtscript_" << qtScriptEnumName << "_keys[] = {" << endl;
755 755 for (int i = 0; i < uniqueIndexes.size(); ++i) {
756 756 stream << " ";
757 757 if (i > 0)
758 758 stream << ", ";
759 759 stream << "\"" << values.at(uniqueIndexes.at(i))->name() << "\"" << endl;
760 760 }
761 761 stream << "};" << endl << endl;
762 762
763 763 // write toString helper
764 764 stream << "static QString qtscript_"
765 765 << qtScriptEnumName << "_toStringHelper"
766 766 << "(" << qualifiedEnumName << " value)" << endl;
767 767 stream << "{" << endl;
768 768 if (enom->hasQEnumsDeclaration() && (meta_class->qualifiedCppName() != "QTransform")) {
769 769 stream << " const QMetaObject *meta = qtscript_" << meta_class->name() << "_metaObject();" << endl;
770 770 stream << " int idx = meta->indexOfEnumerator(\"" << enom->name() << "\");" << endl;
771 771 stream << " Q_ASSERT(idx != -1);" << endl;
772 772 stream << " QMetaEnum menum = meta->enumerator(idx);" << endl;
773 773 stream << " return QString::fromLatin1(menum.valueToKey(value));" << endl;
774 774 } else {
775 775 if (contiguous) {
776 776 stream << " if ((value >= " << meta_class->qualifiedCppName()
777 777 << "::" << values.at(uniqueIndexes.first())->name() << ")"
778 778 << " && (value <= " << meta_class->qualifiedCppName()
779 779 << "::" << values.at(uniqueIndexes.last())->name() << "))" << endl
780 780 << " return qtscript_" << qtScriptEnumName
781 781 << "_keys[static_cast<int>(value)-static_cast<int>("
782 782 << meta_class->qualifiedCppName() << "::"
783 783 << values.at(uniqueIndexes.first())->name() << ")];" << endl;
784 784 } else {
785 785 stream << " for (int i = 0; i < " << uniqueIndexes.size() << "; ++i) {" << endl
786 786 << " if (qtscript_" << qtScriptEnumName << "_values[i] == value)" << endl
787 787 << " return QString::fromLatin1(qtscript_" << qtScriptEnumName << "_keys[i]);" << endl
788 788 << " }" << endl;
789 789 }
790 790 stream << " return QString();" << endl;
791 791 }
792 792 stream << "}" << endl << endl;
793 793
794 794 // write QScriptValue <--> C++ conversion functions
795 795 stream << "static QScriptValue qtscript_"
796 796 << qtScriptEnumName << "_toScriptValue("
797 797 << "QScriptEngine *engine, const " << qualifiedEnumName << " &value)" << endl
798 798 << "{" << endl
799 799 << " QScriptValue clazz = engine->globalObject().property(QString::fromLatin1(\""
800 800 << meta_class->name() << "\"));" << endl
801 801 // << " QScriptValue enumClazz = clazz.property(QString::fromLatin1(\""
802 802 // << enom->name() << "\"));" << endl
803 803 << " return clazz.property(qtscript_" << qtScriptEnumName << "_toStringHelper(value));" << endl
804 804 << "}" << endl << endl;
805 805 stream << "static void qtscript_"
806 806 << qtScriptEnumName << "_fromScriptValue("
807 807 << "const QScriptValue &value, " << qualifiedEnumName << " &out)" << endl
808 808 << "{" << endl
809 809 << " out = qvariant_cast<" << qualifiedEnumName << ">(value.toVariant());" << endl
810 810 << "}" << endl << endl;
811 811
812 812 // write constructor
813 813 stream << "static QScriptValue qtscript_construct_"
814 814 << qtScriptEnumName
815 815 << "(QScriptContext *context, QScriptEngine *engine)" << endl;
816 816 stream << "{" << endl;
817 817 stream << " int arg = context->argument(0).toInt32();" << endl;
818 818 if (enom->hasQEnumsDeclaration() && (meta_class->qualifiedCppName() != "QTransform")) {
819 819 stream << " const QMetaObject *meta = qtscript_" << meta_class->name() << "_metaObject();" << endl;
820 820 stream << " int idx = meta->indexOfEnumerator(\"" << enom->name() << "\");" << endl;
821 821 stream << " Q_ASSERT(idx != -1);" << endl;
822 822 stream << " QMetaEnum menum = meta->enumerator(idx);" << endl;
823 823 stream << " if (menum.valueToKey(arg) != 0)" << endl;
824 824 stream << " return qScriptValueFromValue(engine, static_cast<"
825 825 << qualifiedEnumName << ">(arg));" << endl;
826 826 } else {
827 827 if (contiguous) {
828 828 stream << " if ((arg >= " << meta_class->qualifiedCppName()
829 829 << "::" << values.at(uniqueIndexes.first())->name() << ")"
830 830 << " && (arg <= " << meta_class->qualifiedCppName()
831 831 << "::" << values.at(uniqueIndexes.last())->name() << "))" << endl;
832 832 stream << " return qScriptValueFromValue(engine, static_cast<"
833 833 << qualifiedEnumName << ">(arg));" << endl;
834 834 } else {
835 835 stream << " for (int i = 0; i < " << uniqueIndexes.size() << "; ++i) {" << endl
836 836 << " if (qtscript_" << qtScriptEnumName << "_values[i] == arg)" << endl;
837 837 stream << " return qScriptValueFromValue(engine, static_cast<"
838 838 << qualifiedEnumName << ">(arg));" << endl;
839 839 stream << " }" << endl;
840 840 }
841 841 }
842 842 stream << " return context->throwError(QString::fromLatin1(\""
843 843 << enom->name() << "(): invalid enum value (%0)\").arg(arg));" << endl;
844 844 stream << "}" << endl;
845 845 stream << endl;
846 846
847 847 // write prototype.valueOf()
848 848 stream << "static QScriptValue qtscript_" << qtScriptEnumName
849 849 << "_valueOf(QScriptContext *context, QScriptEngine *engine)" << endl;
850 850 stream << "{" << endl;
851 851 stream << " " << qualifiedEnumName << " value = "
852 852 << "qscriptvalue_cast<" << qualifiedEnumName
853 853 << ">(context->thisObject());" << endl;
854 854 stream << " return QScriptValue(engine, static_cast<int>(value));" << endl;
855 855 stream << "}" << endl;
856 856 stream << endl;
857 857
858 858 // write prototype.toString()
859 859 stream << "static QScriptValue qtscript_" << qtScriptEnumName
860 860 << "_toString(QScriptContext *context, QScriptEngine *engine)" << endl;
861 861 stream << "{" << endl;
862 862 stream << " " << qualifiedEnumName << " value = "
863 863 << "qscriptvalue_cast<" << qualifiedEnumName
864 864 << ">(context->thisObject());" << endl;
865 865 stream << " return QScriptValue(engine, qtscript_" << qtScriptEnumName << "_toStringHelper(value));" << endl;
866 866 stream << "}" << endl;
867 867 stream << endl;
868 868
869 869 // write class creation function
870 870 stream << "static QScriptValue qtscript_create_"
871 871 << qtScriptEnumName
872 872 << "_class(QScriptEngine *engine, QScriptValue &clazz)" << endl;
873 873 stream << "{" << endl;
874 874
875 875 stream << " QScriptValue ctor = qtscript_create_enum_class_helper(" << endl
876 876 << " engine, qtscript_construct_" << qtScriptEnumName << "," << endl
877 877 << " qtscript_" << qtScriptEnumName << "_valueOf, qtscript_"
878 878 << qtScriptEnumName << "_toString);" << endl;
879 879
880 880 stream << " qScriptRegisterMetaType<" << qualifiedEnumName << ">(engine, "
881 881 << "qtscript_" << qtScriptEnumName << "_toScriptValue," << endl
882 882 << " qtscript_" << qtScriptEnumName << "_fromScriptValue,"
883 883 << " ctor.property(QString::fromLatin1(\"prototype\")));" << endl;
884 884
885 885 // enum values are properties of the constructor
886 886 stream << " for (int i = 0; i < " << uniqueIndexes.size() << "; ++i) {" << endl
887 887 << " clazz.setProperty(QString::fromLatin1(qtscript_"
888 888 << qtScriptEnumName << "_keys[i])," << endl
889 889 << " engine->newVariant(qVariantFromValue(qtscript_"
890 890 << qtScriptEnumName << "_values[i]))," << endl
891 891 << " QScriptValue::ReadOnly | QScriptValue::Undeletable);" << endl
892 892 << " }" << endl;
893 893
894 894 stream << " return ctor;" << endl;
895 895 stream << "}" << endl;
896 896 stream << endl;
897 897
898 898 // write flags class too, if any
899 899 FlagsTypeEntry *flags = enom->typeEntry()->flags();
900 900 if (!flags)
901 901 return;
902 902
903 903 QString qualifiedFlagsName = meta_class->qualifiedCppName() + "::" + flags->targetLangName();
904 904 QString qtScriptFlagsName = meta_class->name() + "_" + flags->targetLangName();
905 905
906 906 stream << "//" << endl;
907 907 stream << "// " << qualifiedFlagsName << endl;
908 908 stream << "//" << endl << endl;
909 909
910 910 // write QScriptValue <--> C++ conversion functions
911 911 stream << "static QScriptValue qtscript_"
912 912 << qtScriptFlagsName << "_toScriptValue("
913 913 << "QScriptEngine *engine, const " << qualifiedFlagsName << " &value)" << endl
914 914 << "{" << endl
915 915 << " return engine->newVariant(qVariantFromValue(value));" << endl
916 916 << "}" << endl << endl;
917 917 stream << "static void qtscript_"
918 918 << qtScriptFlagsName << "_fromScriptValue("
919 919 << "const QScriptValue &value, " << qualifiedFlagsName << " &out)" << endl
920 920 << "{" << endl
921 921 << " QVariant var = value.toVariant();" << endl
922 922 << " if (var.userType() == qMetaTypeId<" << qualifiedFlagsName << ">())" << endl
923 923 << " out = qvariant_cast<" << qualifiedFlagsName << ">(var);" << endl
924 924 << " else if (var.userType() == qMetaTypeId<" << qualifiedEnumName << ">())" << endl
925 925 << " out = qvariant_cast<" << qualifiedEnumName << ">(var);" << endl
926 926 << " else" << endl
927 927 << " out = 0;" << endl
928 928 << "}" << endl << endl;
929 929
930 930 // write constructor
931 931 stream << "static QScriptValue qtscript_construct_"
932 932 << qtScriptFlagsName
933 933 << "(QScriptContext *context, QScriptEngine *engine)" << endl;
934 934 stream << "{" << endl;
935 935 stream << " " << qualifiedFlagsName << " result = 0;" << endl;
936 936 stream << " if ((context->argumentCount() == 1) && context->argument(0).isNumber()) {" << endl;
937 937 stream << " result = static_cast<" << qualifiedFlagsName << ">(context->argument(0).toInt32());" << endl;
938 938 stream << " } else {" << endl;
939 939 stream << " for (int i = 0; i < context->argumentCount(); ++i) {" << endl;
940 940 stream << " QVariant v = context->argument(i).toVariant();" << endl;
941 941 stream << " if (v.userType() != qMetaTypeId<" << qualifiedEnumName << ">()) {" << endl;
942 942 stream << " return context->throwError(QScriptContext::TypeError," << endl
943 943 << " QString::fromLatin1(\"" << flags->targetLangName()
944 944 << "(): argument %0 is not of type " << enom->name() << "\").arg(i));" << endl;
945 945 stream << " }" << endl;
946 946 stream << " result |= qvariant_cast<" << qualifiedEnumName
947 947 << ">(v);" << endl;
948 948 stream << " }" << endl;
949 949 stream << " }" << endl;
950 950 stream << " return engine->newVariant(qVariantFromValue(result));" << endl;
951 951 stream << "}" << endl;
952 952 stream << endl;
953 953
954 954 // write prototype.valueOf()
955 955 stream << "static QScriptValue qtscript_" << qtScriptFlagsName
956 956 << "_valueOf(QScriptContext *context, QScriptEngine *engine)" << endl;
957 957 stream << "{" << endl;
958 958 stream << " " << qualifiedFlagsName << " value = "
959 959 << "qscriptvalue_cast<" << qualifiedFlagsName
960 960 << ">(context->thisObject());" << endl;
961 961 stream << " return QScriptValue(engine, static_cast<int>(value));" << endl;
962 962 stream << "}" << endl;
963 963 stream << endl;
964 964
965 965 // write prototype.toString()
966 966 stream << "static QScriptValue qtscript_" << qtScriptFlagsName
967 967 << "_toString(QScriptContext *context, QScriptEngine *engine)" << endl;
968 968 stream << "{" << endl;
969 969 stream << " " << qualifiedFlagsName << " value = "
970 970 << "qscriptvalue_cast<" << qualifiedFlagsName
971 971 << ">(context->thisObject());" << endl;
972 972 stream << " QString result;" << endl;
973 973 stream << " for (int i = 0; i < " << uniqueIndexes.size() << "; ++i) {" << endl
974 974 << " if ((value & qtscript_" << qtScriptEnumName << "_values[i])"
975 975 << " == qtscript_" << qtScriptEnumName << "_values[i]) {" << endl
976 976 << " if (!result.isEmpty())" << endl
977 977 << " result.append(QString::fromLatin1(\",\"));" << endl
978 978 << " result.append(QString::fromLatin1(qtscript_" << qtScriptEnumName << "_keys[i]));" << endl
979 979 << " }" << endl
980 980 << " }" << endl
981 981 << " return QScriptValue(engine, result);" << endl
982 982 << "}" << endl
983 983 << endl;
984 984
985 985 // write prototype.equals()
986 986 stream << "static QScriptValue qtscript_" << qtScriptFlagsName
987 987 << "_equals(QScriptContext *context, QScriptEngine *engine)" << endl
988 988 << "{" << endl
989 989 << " QVariant thisObj = context->thisObject().toVariant();" << endl
990 990 << " QVariant otherObj = context->argument(0).toVariant();" << endl
991 991
992 992 << " return QScriptValue(engine, ((thisObj.userType() == otherObj.userType()) &&" << endl
993 993 << " (thisObj.value<" << qualifiedFlagsName << ">() == otherObj.value<" << qualifiedFlagsName << ">())));" << endl
994 994 << "}" << endl << endl;
995 995
996 996 // write class creation function
997 997 stream << "static QScriptValue qtscript_create_" << qtScriptFlagsName << "_class(QScriptEngine *engine)" << endl;
998 998 stream << "{" << endl;
999 999 stream << " QScriptValue ctor = qtscript_create_flags_class_helper(" << endl
1000 1000 << " engine, qtscript_construct_" << qtScriptFlagsName
1001 1001 << ", qtscript_" << qtScriptFlagsName << "_valueOf," << endl
1002 1002 << " qtscript_" << qtScriptFlagsName << "_toString, qtscript_"
1003 1003 << qtScriptFlagsName << "_equals);" << endl;
1004 1004
1005 1005 stream << " qScriptRegisterMetaType<" << qualifiedFlagsName << ">(engine, "
1006 1006 << "qtscript_" << qtScriptFlagsName << "_toScriptValue," << endl
1007 1007 << " qtscript_" << qtScriptFlagsName << "_fromScriptValue,"
1008 1008 << " ctor.property(QString::fromLatin1(\"prototype\")));" << endl;
1009 1009
1010 1010 stream << " return ctor;" << endl;
1011 1011 stream << "}" << endl;
1012 1012 stream << endl;
1013 1013 }
1014 1014
1015 1015 /*!
1016 1016 Declares the given \a typeName if it hasn't been declared already,
1017 1017 and adds it to the set of registered type names.
1018 1018 */
1019 1019 void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
1020 1020 QSet<QString> &registeredTypeNames)
1021 1021 {
1022 1022 QString name = typeName;
1023 1023 if (name.endsWith(QLatin1Char('&')))
1024 1024 name.chop(1);
1025 1025 if (registeredTypeNames.contains(name) || (QMetaType::type(typeName.toLatin1()) != 0))
1026 1026 return;
1027 1027 if (name.contains(QLatin1Char(','))) {
1028 1028 // need to expand the Q_DECLARE_METATYPE macro manually,
1029 1029 // otherwise the compiler will choke
1030 1030 stream << "template <> \\" << endl
1031 1031 << "struct QMetaTypeId< " << name << " > \\" << endl
1032 1032 << "{ \\" << endl
1033 1033 << " enum { Defined = 1 }; \\" << endl
1034 1034 << " static int qt_metatype_id() \\" << endl
1035 1035 << " { \\" << endl
1036 1036 << " static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \\" << endl
1037 1037 << " if (!metatype_id) \\" << endl
1038 1038 << " metatype_id = qRegisterMetaType< " << name << " >(\"" << name << "\"); \\" << endl
1039 1039 << " return metatype_id; \\" << endl
1040 1040 << " } \\" << endl
1041 1041 << "};" << endl;
1042 1042 } else {
1043 1043 stream << "Q_DECLARE_METATYPE(" << name << ")" << endl;
1044 1044 }
1045 1045 registeredTypeNames << name;
1046 1046 }
1047 1047
1048 1048 /*!
1049 1049 Declares the given \a type recursively (i.e. subtypes of a composite
1050 1050 type are also declared).
1051 1051 */
1052 1052 static void declareTypeRecursive(QTextStream &stream, const AbstractMetaType *type,
1053 1053 QSet<QString> &registeredTypeNames)
1054 1054 {
1055 1055 if (!type)
1056 1056 return;
1057 1057 QList<AbstractMetaType *> subTypes = type->instantiations();
1058 1058 for (int i = 0; i < subTypes.size(); ++i)
1059 1059 declareTypeRecursive(stream, subTypes.at(i), registeredTypeNames);
1060 1060 QString typeName = normalizedType(type);
1061 1061 if (typeName == QLatin1String("QStringList<QString>"))
1062 1062 return; // ### wtf...
1063 1063 maybeDeclareMetaType(stream, typeName, registeredTypeNames);
1064 1064 }
1065 1065
1066 1066 /*!
1067 1067 Declares the types associated with the given \a functions.
1068 1068 */
1069 1069 void declareFunctionMetaTypes(QTextStream &stream, const AbstractMetaFunctionList &functions,
1070 1070 QSet<QString> &registeredTypeNames)
1071 1071 {
1072 1072 for (int i = 0; i < functions.size(); ++i) {
1073 1073 AbstractMetaFunction *fun = functions.at(i);
1074 1074 if (ClassGenerator::isSpecialStreamingOperator(fun)) {
1075 1075 maybeDeclareMetaType(stream, fun->arguments().at(0)->type()->name() + "*",
1076 1076 registeredTypeNames);
1077 1077 continue;
1078 1078 }
1079 1079 AbstractMetaArgumentList arguments = fun->arguments();
1080 1080 for (int j = 0; j < arguments.size(); ++j) {
1081 1081 if (fun->argumentRemoved(j+1))
1082 1082 continue;
1083 1083 QString repl = fun->typeReplaced(j+1);
1084 1084 if (!repl.isEmpty()) {
1085 1085 maybeDeclareMetaType(stream, repl, registeredTypeNames);
1086 1086 } else {
1087 1087 const AbstractMetaArgument *arg = arguments.at(j);
1088 1088 declareTypeRecursive(stream, arg->type(), registeredTypeNames);
1089 1089 }
1090 1090 }
1091 1091 QString retRepl = fun->typeReplaced(0);
1092 1092 if (!retRepl.isEmpty())
1093 1093 maybeDeclareMetaType(stream, retRepl, registeredTypeNames);
1094 1094 else
1095 1095 declareTypeRecursive(stream, fun->type(), registeredTypeNames);
1096 1096 }
1097 1097 }
1098 1098
1099 1099 /*!
1100 1100 Returns true if we don't care about the given enum \a enom,
1101 1101 false otherwise.
1102 1102 */
1103 1103 static bool shouldIgnoreEnum(const AbstractMetaEnum *enom)
1104 1104 {
1105 1105 return !enom->wasPublic() || (enom->name() == "enum_1");
1106 1106 }
1107 1107
1108 1108 /*!
1109 1109 Declares the types associated with the enums of the given \a
1110 1110 meta_class.
1111 1111 */
1112 1112 void declareEnumMetaTypes(QTextStream &stream, const AbstractMetaClass *meta_class,
1113 1113 QSet<QString> &registeredTypeNames)
1114 1114 {
1115 1115 AbstractMetaEnumList enums = meta_class->enums();
1116 1116 for (int i = 0; i < enums.size(); ++i) {
1117 1117 const AbstractMetaEnum *enom = enums.at(i);
1118 1118 if (shouldIgnoreEnum(enom))
1119 1119 continue;
1120 1120 maybeDeclareMetaType(stream, QString::fromLatin1("%0::%1")
1121 1121 .arg(meta_class->qualifiedCppName()).arg(enom->name()),
1122 1122 registeredTypeNames);
1123 1123 FlagsTypeEntry *flags = enom->typeEntry()->flags();
1124 1124 if (flags) {
1125 1125 maybeDeclareMetaType(stream, QString::fromLatin1("QFlags<%0::%1>")
1126 1126 .arg(meta_class->qualifiedCppName()).arg(enom->name()),
1127 1127 registeredTypeNames);
1128 1128 }
1129 1129 }
1130 1130 }
1131 1131
1132 1132 /*!
1133 1133 Returns the maximum function length among \a functions.
1134 1134 */
1135 1135 static int maxFunctionLength(const AbstractMetaFunctionList &functions)
1136 1136 {
1137 1137 int result = 0;
1138 1138 for (int i = 0; i < functions.size(); ++i)
1139 1139 result = qMax(result, functions.at(i)->arguments().size());
1140 1140 return result;
1141 1141 }
1142 1142
1143 1143 /*!
1144 1144 Writes a prototype/static function.
1145 1145 */
1146 1146 static void writeFunctionForwarding(QTextStream &stream, const AbstractMetaClass *meta_class,
1147 1147 const AbstractMetaFunctionList &functions)
1148 1148 {
1149 1149 #if 0
1150 1150 stream << "/** signatures:" << endl;
1151 1151 foreach (const AbstractMetaFunction *fun, functions) {
1152 1152 stream << " * " << fun->signature() << endl;
1153 1153 }
1154 1154 stream << " */" << endl;
1155 1155 #endif
1156 1156 QMap<int, AbstractMetaFunctionList> argcToFunctions;
1157 1157 argcToFunctions = createArgcToFunctionsMap(functions);
1158 1158 QSet<QString> signatures;
1159 1159 int argcMin = argcToFunctions.keys().first();
1160 1160 int argcMax = argcToFunctions.keys().last();
1161 1161 for (int i = argcMin; i <= argcMax; ++i) {
1162 1162 AbstractMetaFunctionList funcs = argcToFunctions.value(i);
1163 1163 if (funcs.isEmpty())
1164 1164 continue;
1165 1165 stream << " if (context->argumentCount() == " << i << ") {" << endl;
1166 1166 if (funcs.size() == 1) {
1167 1167 AbstractMetaFunction *fun = funcs.at(0);
1168 1168 const int indent = 8;
1169 1169 // special case for Q{Data,Text}Stream streaming operators
1170 1170 if (ClassGenerator::isSpecialStreamingOperator(fun))
1171 1171 writeStreamingOperatorCall(stream, fun, meta_class, indent);
1172 1172 else
1173 1173 writeFunctionCallAndReturn(stream, fun, i, meta_class, indent);
1174 1174 signatures.insert(fun->targetLangSignature());
1175 1175 } else {
1176 1176 // handle overloads
1177 1177 QStringList sigs;
1178 1178 for (int j = 0; j < funcs.size(); ++j) {
1179 1179 AbstractMetaFunction *fun = funcs.at(j);
1180 1180 sigs.append(fun->signature());
1181 1181 stream << " ";
1182 1182 if (j > 0)
1183 1183 stream << "} else ";
1184 1184 stream << "if (";
1185 1185 AbstractMetaArgumentList arguments = fun->arguments();
1186 1186 const int indent = 12;
1187 1187 writeArgumentTypeTests(stream, fun, arguments, i, indent);
1188 1188 stream << ") {" << endl;
1189 1189 writeFunctionCallAndReturn(stream, fun, i, meta_class, indent);
1190 1190 signatures.insert(fun->targetLangSignature());
1191 1191 }
1192 1192 stream << " }" << endl;
1193 1193 }
1194 1194 stream << " }" << endl;
1195 1195 }
1196 1196 }
1197 1197
1198 1198 static void writePrototypeCall(QTextStream &s, const AbstractMetaClass *meta_class,
1199 1199 const QMap<QString, AbstractMetaFunctionList> &nameToFunctions,
1200 1200 int prototypeFunctionsOffset)
1201 1201 {
1202 1202 s << "static QScriptValue qtscript_" << meta_class->name()
1203 1203 << "_prototype_call(QScriptContext *context, QScriptEngine *)" << endl
1204 1204 << "{" << endl;
1205 1205
1206 1206 s << "#if QT_VERSION > 0x040400" << endl;
1207 1207
1208 1208 s << " Q_ASSERT(context->callee().isFunction());" << endl
1209 1209 << " uint _id = context->callee().data().toUInt32();" << endl;
1210 1210
1211 1211 s << "#else" << endl
1212 1212 << " uint _id;" << endl
1213 1213 << " if (context->callee().isFunction())" << endl
1214 1214 << " _id = context->callee().data().toUInt32();" << endl
1215 1215 << " else" << endl
1216 1216 << " _id = 0xBABE0000 + " << nameToFunctions.size() << ";" << endl;
1217 1217
1218 1218 s << "#endif" << endl;
1219 1219
1220 1220 s << " Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);" << endl
1221 1221 << " _id &= 0x0000FFFF;" << endl;
1222 1222
1223 1223 // cast the thisObject to C++ type
1224 1224 s << " ";
1225 1225 #ifndef GENERATOR_NO_PROTECTED_FUNCTIONS
1226 1226 if (meta_class->hasProtectedFunctions())
1227 1227 s << "qtscript_";
1228 1228 #endif
1229 1229 s << meta_class->qualifiedCppName() << "* _q_self = ";
1230 1230 #ifndef GENERATOR_NO_PROTECTED_FUNCTIONS
1231 1231 if (meta_class->hasProtectedFunctions())
1232 1232 s << "reinterpret_cast<qtscript_" << meta_class->name() << "*>(";
1233 1233 #endif
1234 1234 s << "qscriptvalue_cast<" << meta_class->qualifiedCppName()
1235 1235 << "*>(context->thisObject())";
1236 1236 #ifndef GENERATOR_NO_PROTECTED_FUNCTIONS
1237 1237 if (meta_class->hasProtectedFunctions())
1238 1238 s << ")";
1239 1239 #endif
1240 1240 s << ";" << endl
1241 1241 << " if (!_q_self) {" << endl
1242 1242 << " return context->throwError(QScriptContext::TypeError," << endl
1243 1243 << " QString::fromLatin1(\"" << meta_class->name()
1244 1244 << ".%0(): this object is not a " << meta_class->name() << "\")" << endl
1245 1245 << " .arg(qtscript_" << meta_class->name()
1246 1246 << "_function_names[_id+" << prototypeFunctionsOffset <<"]));" << endl
1247 1247 << " }" << endl << endl;
1248 1248
1249 1249 s << " switch (_id) {" << endl;
1250 1250
1251 1251 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1252 1252 int index = 0;
1253 1253 for (it = nameToFunctions.constBegin(); it != nameToFunctions.constEnd(); ++it) {
1254 1254 s << " case " << index << ":" << endl;
1255 1255 writeFunctionForwarding(s, meta_class, it.value());
1256 1256 s << " break;" << endl << endl;
1257 1257 ++index;
1258 1258 }
1259 1259
1260 1260 if (!meta_class->hasDefaultToStringFunction()) {
1261 1261 s << " case " << index << ": {" << endl;
1262 1262 s << " QString result";
1263 1263 FunctionModelItem fun = meta_class->hasToStringCapability();
1264 1264 if (fun) {
1265 1265 int indirections = fun->arguments().at(1)->type().indirections();
1266 1266 QString deref = QLatin1String(indirections == 0 ? "*" : "");
1267 1267 s << ";" << endl
1268 1268 << " QDebug d(&result);" << endl
1269 1269 << " d << " << deref << "_q_self;" << endl;
1270 1270 } else {
1271 1271 // ### FIXME: can cause compile error
1272 1272 // s << "=QString(\"" << meta_class->name() << "(0x%1)\").arg((int)_q_self, 0, 16);" << endl;
1273 1273 s << " = QString::fromLatin1(\"" << meta_class->name() << "\");" << endl;
1274 1274 }
1275 1275 s << " return QScriptValue(context->engine(), result);" << endl
1276 1276 << " }" << endl << endl;
1277 1277 }
1278 1278
1279 1279 s << " default:" << endl
1280 1280 << " Q_ASSERT(false);" << endl
1281 1281 << " }" << endl;
1282 1282
1283 1283 s << " return qtscript_" << meta_class->name() << "_throw_ambiguity_error_helper(context," << endl
1284 1284 << " qtscript_" << meta_class->name()
1285 1285 << "_function_names[_id+" << prototypeFunctionsOffset << "]," << endl
1286 1286 << " qtscript_" << meta_class->name()
1287 1287 << "_function_signatures[_id+" << prototypeFunctionsOffset << "]);" << endl;
1288 1288
1289 1289 s << "}" << endl << endl;
1290 1290 }
1291 1291
1292 1292 static void writeStaticCall(QTextStream &s, const AbstractMetaClass *meta_class,
1293 1293 const AbstractMetaFunctionList &constructors,
1294 1294 const QMap<QString, AbstractMetaFunctionList> &nameToFunctions)
1295 1295 {
1296 1296 s << "static QScriptValue qtscript_" << meta_class->name()
1297 1297 << "_static_call(QScriptContext *context, QScriptEngine *)" << endl
1298 1298 << "{" << endl;
1299 1299
1300 1300 s << " uint _id = context->callee().data().toUInt32();" << endl
1301 1301 << " Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);" << endl
1302 1302 << " _id &= 0x0000FFFF;" << endl;
1303 1303
1304 1304 s << " switch (_id) {" << endl;
1305 1305
1306 1306 s << " case 0:" << endl;
1307 1307 writeConstructorForwarding(s, constructors, meta_class);
1308 1308 s << " break;" << endl << endl;
1309 1309
1310 1310 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1311 1311 int index = 1;
1312 1312 for (it = nameToFunctions.constBegin(); it != nameToFunctions.constEnd(); ++it) {
1313 1313 s << " case " << index << ":" << endl;
1314 1314 writeFunctionForwarding(s, meta_class, it.value());
1315 1315 s << " break;" << endl << endl;
1316 1316 ++index;
1317 1317 }
1318 1318
1319 1319 s << " default:" << endl
1320 1320 << " Q_ASSERT(false);" << endl
1321 1321 << " }" << endl;
1322 1322
1323 1323 s << " return qtscript_" << meta_class->name() << "_throw_ambiguity_error_helper(context," << endl
1324 1324 << " qtscript_" << meta_class->name() << "_function_names[_id]," << endl
1325 1325 << " qtscript_" << meta_class->name() << "_function_signatures[_id]);" << endl;
1326 1326
1327 1327 s << "}" << endl << endl;
1328 1328 }
1329 1329
1330 1330 /*!
1331 1331 Writes the include defined by \a inc to \a stream.
1332 1332 */
1333 1333 void ClassGenerator::writeInclude(QTextStream &stream, const Include &inc)
1334 1334 {
1335 1335 if (inc.name.isEmpty())
1336 1336 return;
1337 1337 if (inc.type == Include::TargetLangImport)
1338 1338 return;
1339 1339 stream << "#include ";
1340 1340 if (inc.type == Include::IncludePath)
1341 1341 stream << "<";
1342 1342 else
1343 1343 stream << "\"";
1344 1344 stream << inc.name;
1345 1345 if (inc.type == Include::IncludePath)
1346 1346 stream << ">";
1347 1347 else
1348 1348 stream << "\"";
1349 1349 stream << endl;
1350 1350 }
1351 1351
1352 1352 static void writeHelperFunctions(QTextStream &stream, const AbstractMetaClass *meta_class)
1353 1353 {
1354 1354 stream << "static QScriptValue qtscript_" << meta_class->name() << "_throw_ambiguity_error_helper(" << endl
1355 1355 << " QScriptContext *context, const char *functionName, const char *signatures)" << endl
1356 1356 << "{" << endl
1357 1357 << " QStringList lines = QString::fromLatin1(signatures).split(QLatin1Char('\\n'));" << endl
1358 1358 << " QStringList fullSignatures;" << endl
1359 1359 << " for (int i = 0; i < lines.size(); ++i)" << endl
1360 1360 << " fullSignatures.append(QString::fromLatin1(\"%0(%1)\").arg(functionName).arg(lines.at(i)));" << endl
1361 1361 << " return context->throwError(QString::fromLatin1(\"" << meta_class->name()
1362 1362 << "::%0(): could not find a function match; candidates are:\\n%1\")" << endl
1363 1363 << " .arg(functionName).arg(fullSignatures.join(QLatin1String(\"\\n\"))));" << endl
1364 1364 << "}" << endl << endl;
1365 1365 }
1366 1366
1367 1367 void writeQtScriptQtBindingsLicense(QTextStream &stream)
1368 1368 {
1369 1369 stream
1370 1370 << "/****************************************************************************" << endl
1371 1371 << "**" << endl
1372 1372 << "** Copyright (C) 2008 Trolltech ASA. All rights reserved." << endl
1373 1373 << "**" << endl
1374 1374 << "** This file is part of the Qt Script Qt Bindings project on Trolltech Labs." << endl
1375 1375 << "**" << endl
1376 1376 << "** This file may be used under the terms of the GNU General Public" << endl
1377 1377 << "** License version 2.0 as published by the Free Software Foundation" << endl
1378 1378 << "** and appearing in the file LICENSE.GPL included in the packaging of" << endl
1379 1379 << "** this file. Please review the following information to ensure GNU" << endl
1380 1380 << "** General Public Licensing requirements will be met:" << endl
1381 1381 << "** http://www.trolltech.com/products/qt/opensource.html" << endl
1382 1382 << "**" << endl
1383 1383 << "** If you are unsure which license is appropriate for your use, please" << endl
1384 1384 << "** review the following information:" << endl
1385 1385 << "** http://www.trolltech.com/products/qt/licensing.html or contact the" << endl
1386 1386 << "** sales department at sales@trolltech.com." << endl
1387 1387 << "**" << endl
1388 1388 << "** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE" << endl
1389 1389 << "** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE." << endl
1390 1390 << "**" << endl
1391 1391 << "****************************************************************************/" << endl
1392 1392 << endl;
1393 1393 }
1394 1394
1395 1395 /*!
1396 1396 Finds the functions in \a meta_class that we actually want to
1397 1397 generate bindings for.
1398 1398 */
1399 1399 void findPrototypeAndStaticFunctions(
1400 1400 const AbstractMetaClass *meta_class,
1401 1401 QMap<QString, AbstractMetaFunctionList> &nameToPrototypeFunctions,
1402 1402 QMap<QString, AbstractMetaFunctionList> &nameToStaticFunctions)
1403 1403 {
1404 1404 AbstractMetaFunctionList functions = meta_class->functionsInTargetLang();
1405 1405 for (int i = 0; i < functions.size(); ++i) {
1406 1406 AbstractMetaFunction* func = functions.at(i);
1407 1407 if (!func->isNormal())
1408 1408 continue;
1409 1409 #ifdef GENERATOR_NO_PROTECTED_FUNCTIONS
1410 1410 if (func->wasProtected())
1411 1411 continue;
1412 1412 #endif
1413 1413 if (func->declaringClass() != meta_class)
1414 1414 continue; // function inherited through prototype
1415 1415 if (func->isPropertyReader() || func->isPropertyWriter())
1416 1416 continue; // no point in including property accessors
1417 1417 if (func->isSlot() || func->isSignal() || func->isInvokable())
1418 1418 continue; // no point in including signals and slots
1419 1419 QMap<QString, AbstractMetaFunctionList> &map =
1420 1420 func->isStatic() ? nameToStaticFunctions : nameToPrototypeFunctions;
1421 1421 map[func->modifiedName()].append(func);
1422 1422 }
1423 1423 }
1424 1424
1425 1425 static void writeFunctionSignaturesString(QTextStream &s, const AbstractMetaFunctionList &functions)
1426 1426 {
1427 1427 s << "\"";
1428 1428 for (int i = 0; i < functions.size(); ++i) {
1429 1429 if (i > 0)
1430 1430 s << "\\n";
1431 1431 QString sig = functions.at(i)->targetLangSignature();
1432 1432 sig = sig.mid(sig.indexOf('(') + 1);
1433 1433 sig.chop(1);
1434 1434 s << sig;
1435 1435 }
1436 1436 s << "\"";
1437 1437 }
1438 1438
1439 1439 /*!
1440 1440 Writes the whole native binding for the class \a meta_class.
1441 1441 */
1442 1442 void ClassGenerator::write(QTextStream &stream, const AbstractMetaClass *meta_class)
1443 1443 {
1444 1444 if (meta_class->name() == "Global") // ### hmmmmmm
1445 1445 return;
1446 1446
1447 1447 if (FileOut::license)
1448 1448 writeQtScriptQtBindingsLicense(stream);
1449 1449
1450 1450 // write common includes
1451 1451 stream << "#include <QtScript/QScriptEngine>" << endl;
1452 1452 stream << "#include <QtScript/QScriptContext>" << endl;
1453 1453 stream << "#include <QtScript/QScriptValue>" << endl;
1454 1454 stream << "#include <QtCore/QStringList>" << endl;
1455 1455 stream << "#include <QtCore/QDebug>" << endl;
1456 1456 stream << "#include <qmetaobject.h>" << endl;
1457 1457 stream << endl;
1458 1458
1459 1459 // write class-specific includes
1460 1460 {
1461 1461 Include inc = meta_class->typeEntry()->include();
1462 1462 writeInclude(stream, inc);
1463 1463 }
1464 1464 {
1465 1465 IncludeList includes = meta_class->typeEntry()->extraIncludes();
1466 1466 qSort(includes.begin(), includes.end());
1467 1467
1468 1468 foreach (const Include &i, includes) {
1469 1469 writeInclude(stream, i);
1470 1470 }
1471 1471 }
1472 1472 stream << endl;
1473 1473
1474 1474 if (meta_class->generateShellClass()) {
1475 1475 stream << "#include \"qtscriptshell_" << meta_class->name() << ".h\"" << endl;
1476 1476 stream << endl;
1477 1477 }
1478 1478
1479 1479 AbstractMetaEnumList enums = meta_class->enums();
1480 1480 {
1481 1481 // kill the enums we don't care about
1482 1482 AbstractMetaEnumList::iterator it;
1483 1483 for (it = enums.begin(); it != enums.end(); ) {
1484 1484 if (shouldIgnoreEnum(*it))
1485 1485 it = enums.erase(it);
1486 1486 else
1487 1487 ++it;
1488 1488 }
1489 1489 }
1490 1490
1491 1491 // find constructors
1492 1492 AbstractMetaFunctionList ctors = findConstructors(meta_class);
1493 1493 bool hasDefaultCtor = findDefaultConstructor(ctors) != 0;
1494 1494
1495 1495 // find interesting functions
1496 1496 QMap<QString, AbstractMetaFunctionList> nameToPrototypeFunctions;
1497 1497 QMap<QString, AbstractMetaFunctionList> nameToStaticFunctions;
1498 1498 findPrototypeAndStaticFunctions(meta_class, nameToPrototypeFunctions, nameToStaticFunctions);
1499 1499
1500 1500 int staticFunctionsOffset = 1;
1501 1501 int prototypeFunctionsOffset = staticFunctionsOffset + nameToStaticFunctions.size();
1502 1502
1503 1503 // write table of function names
1504 1504 stream << "static const char * const qtscript_"
1505 1505 << meta_class->name() << "_function_names[] = {" << endl;
1506 1506 stream << " \"" << meta_class->name() << "\"" << endl;
1507 1507 {
1508 1508 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1509 1509 stream << " // static" << endl;
1510 1510 for (it = nameToStaticFunctions.constBegin(); it != nameToStaticFunctions.constEnd(); ++it) {
1511 1511 stream << " , ";
1512 1512 stream << "\"" << it.key() << "\"" << endl;
1513 1513 }
1514 1514 stream << " // prototype" << endl;
1515 1515 for (it = nameToPrototypeFunctions.constBegin(); it != nameToPrototypeFunctions.constEnd(); ++it) {
1516 1516 QString functionName = it.key();
1517 1517 QString scriptName = functionName;
1518 1518 if (functionName == QLatin1String("operator_equal"))
1519 1519 scriptName = QLatin1String("equals");
1520 1520 stream << " , ";
1521 1521 stream << "\"" << scriptName << "\"" << endl;
1522 1522 }
1523 1523 if (!meta_class->hasDefaultToStringFunction())
1524 1524 stream << " , \"toString\"" << endl;
1525 1525 }
1526 1526 stream << "};" << endl << endl;
1527 1527
1528 1528 // write table of function signatures
1529 1529 stream << "static const char * const qtscript_"
1530 1530 << meta_class->name() << "_function_signatures[] = {" << endl;
1531 1531 stream << " ";
1532 1532 writeFunctionSignaturesString(stream, ctors);
1533 1533 stream << endl;
1534 1534 {
1535 1535 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1536 1536 stream << " // static" << endl;
1537 1537 for (it = nameToStaticFunctions.constBegin(); it != nameToStaticFunctions.constEnd(); ++it) {
1538 1538 stream << " , ";
1539 1539 writeFunctionSignaturesString(stream, it.value());
1540 1540 stream << endl;
1541 1541 }
1542 1542 stream << " // prototype" << endl;
1543 1543 for (it = nameToPrototypeFunctions.constBegin(); it != nameToPrototypeFunctions.constEnd(); ++it) {
1544 1544 stream << " , ";
1545 1545 writeFunctionSignaturesString(stream, it.value());
1546 1546 stream << endl;
1547 1547 }
1548 1548 if (!meta_class->hasDefaultToStringFunction())
1549 1549 stream << "\"\"" << endl;
1550 1550 }
1551 1551 stream << "};" << endl << endl;
1552 1552
1553 1553 #ifndef GENERATOR_NO_PROTECTED_FUNCTIONS
1554 1554 if (meta_class->hasProtectedFunctions()) {
1555 1555 // write a friendly class
1556 1556 stream << "class qtscript_" << meta_class->name()
1557 1557 << " : public " << meta_class->qualifiedCppName() << endl;
1558 1558 stream << "{" << endl;
1559 1559 for (int x = 0; x < 2; ++x) {
1560 1560 QMap<QString, AbstractMetaFunctionList> &map =
1561 1561 x ? nameToStaticFunctions : nameToPrototypeFunctions;
1562 1562 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1563 1563 for (it = map.constBegin(); it != map.constEnd(); ++it) {
1564 1564 AbstractMetaFunctionList functions = it.value();
1565 1565 for (int i = 0; i < functions.size(); ++i) {
1566 1566 if (functions.at(i)->isProtected()) {
1567 1567 stream << " friend QScriptValue qtscript_" << meta_class->name()
1568 1568 << "_" << it.key();
1569 1569 if (functions.at(i)->isStatic())
1570 1570 stream << "_static";
1571 1571 stream << "(QScriptContext *, QScriptEngine *);" << endl;
1572 1572 break;
1573 1573 }
1574 1574 }
1575 1575 }
1576 1576 }
1577 1577 stream << "};" << endl;
1578 1578 stream << endl;
1579 1579 }
1580 1580 #endif
1581 1581
1582 1582 writeHelperFunctions(stream, meta_class);
1583 1583
1584 1584 // write metaobject getter if we need it
1585 1585 if (hasQEnums(enums) && (meta_class->qualifiedCppName() != "QTransform")) {
1586 1586 if (meta_class->qualifiedCppName() == "Qt") {
1587 1587 stream << "struct qtscript_Qt_metaObject_helper : private QObject" << endl
1588 1588 << "{" << endl
1589 1589 << " static const QMetaObject *get()" << endl
1590 1590 << " { return &static_cast<qtscript_Qt_metaObject_helper*>(0)->staticQtMetaObject; }" << endl
1591 1591 << "};" << endl << endl;
1592 1592 }
1593 1593 stream << "static const QMetaObject *qtscript_" << meta_class->name() << "_metaObject()" << endl
1594 1594 << "{" << endl
1595 1595 << " return ";
1596 1596 if (meta_class->qualifiedCppName() == "Qt")
1597 1597 stream << "qtscript_Qt_metaObject_helper::get()";
1598 1598 else
1599 1599 stream << "&" << meta_class->qualifiedCppName() << "::staticMetaObject";
1600 1600 stream << ";" << endl
1601 1601 << "}" << endl << endl;
1602 1602 }
1603 1603
1604 1604 // write metatype declarations
1605 1605 {
1606 1606 QSet<QString> registeredTypeNames = m_qmetatype_declared_typenames;
1607 1607
1608 1608 if (!meta_class->isNamespace()) {
1609 1609 if (meta_class->typeEntry()->isValue() && hasDefaultCtor)
1610 1610 maybeDeclareMetaType(stream, meta_class->qualifiedCppName(), registeredTypeNames);
1611 1611 else
1612 1612 registeredTypeNames << meta_class->qualifiedCppName();
1613 1613 maybeDeclareMetaType(stream, meta_class->qualifiedCppName() + "*", registeredTypeNames);
1614 1614 }
1615 1615 if (meta_class->generateShellClass()) {
1616 1616 if (meta_class->typeEntry()->isValue()) {
1617 1617 maybeDeclareMetaType(stream, "QtScriptShell_" + meta_class->name(),
1618 1618 registeredTypeNames);
1619 1619 }
1620 1620 maybeDeclareMetaType(stream, "QtScriptShell_" + meta_class->name() + "*",
1621 1621 registeredTypeNames);
1622 1622 }
1623 1623
1624 1624 declareEnumMetaTypes(stream, meta_class, registeredTypeNames);
1625 1625
1626 1626 for (int x = 0; x < 2; ++x) {
1627 1627 QMap<QString, AbstractMetaFunctionList> &map =
1628 1628 x ? nameToStaticFunctions : nameToPrototypeFunctions;
1629 1629 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1630 1630 for (it = map.constBegin(); it != map.constEnd(); ++it) {
1631 1631 declareFunctionMetaTypes(stream, it.value(), registeredTypeNames);
1632 1632 }
1633 1633 }
1634 1634
1635 1635 declareFunctionMetaTypes(stream, ctors, registeredTypeNames);
1636 1636
1637 1637 if (meta_class->baseClass() != 0) {
1638 1638 maybeDeclareMetaType(stream, meta_class->baseClass()->qualifiedCppName()
1639 1639 + QLatin1String("*"), registeredTypeNames);
1640 1640 }
1641 1641 foreach (AbstractMetaClass *iface, meta_class->interfaces()) {
1642 1642 AbstractMetaClass *impl = iface->primaryInterfaceImplementor();
1643 1643 maybeDeclareMetaType(stream, impl->qualifiedCppName() + QLatin1String("*"),
1644 1644 registeredTypeNames);
1645 1645 }
1646 1646
1647 1647 // ### hackety hack
1648 1648 if (meta_class->name().endsWith("Gradient"))
1649 1649 maybeDeclareMetaType(stream, "QGradient", registeredTypeNames);
1650 1650
1651 1651 stream << endl;
1652 1652 }
1653 1653
1654 1654 writeInjectedCode(stream, meta_class, CodeSnip::Beginning);
1655 1655
1656 1656 // write enum classes
1657 1657 if (!enums.isEmpty()) {
1658 1658 writeCreateEnumClassHelper(stream);
1659 1659 if (hasFlags(enums))
1660 1660 writeCreateFlagsClassHelper(stream);
1661 1661
1662 1662 for (int i = 0; i < enums.size(); ++i) {
1663 1663 const AbstractMetaEnum *enom = enums.at(i);
1664 1664 writeEnumClass(stream, meta_class, enom);
1665 1665 }
1666 1666 }
1667 1667
1668 1668 stream << "//" << endl;
1669 1669 stream << "// " << meta_class->name() << endl;
1670 1670 stream << "//" << endl << endl;
1671 1671
1672 1672 if (!meta_class->isNamespace()) {
1673 1673 if (!nameToPrototypeFunctions.isEmpty() || !meta_class->hasDefaultToStringFunction())
1674 1674 writePrototypeCall(stream, meta_class, nameToPrototypeFunctions, prototypeFunctionsOffset);
1675 1675 }
1676 1676
1677 1677 writeStaticCall(stream, meta_class, ctors, nameToStaticFunctions);
1678 1678
1679 1679 if (isQObjectBased(meta_class)) {
1680 1680 // write C++ <--> script conversion functions
1681 1681 stream << "static QScriptValue qtscript_" << meta_class->name() << "_toScriptValue(QScriptEngine *engine, "
1682 1682 << meta_class->qualifiedCppName() << "* const &in)" << endl
1683 1683 << "{" << endl
1684 1684 << " return engine->newQObject(in, QScriptEngine::QtOwnership, QScriptEngine::PreferExistingWrapperObject);" << endl
1685 1685 << "}" << endl << endl;
1686 1686 stream << "static void qtscript_" << meta_class->name() << "_fromScriptValue(const QScriptValue &value, "
1687 1687 << meta_class->qualifiedCppName() << "* &out)" << endl
1688 1688 << "{" << endl
1689 1689 << " out = qobject_cast<" << meta_class->qualifiedCppName() << "*>(value.toQObject());" << endl
1690 1690 << "}" << endl << endl;
1691 1691 }
1692 1692
1693 1693 //
1694 1694 // write exported function that creates the QtScript class
1695 1695 //
1696 1696 stream << "QScriptValue qtscript_create_" << meta_class->name()
1697 1697 << "_class(QScriptEngine *engine)" << endl;
1698 1698 stream << "{" << endl;
1699 1699
1700 1700 // write lengths array
1701 1701 stream << " static const int function_lengths[] = {" << endl;
1702 1702 stream << " " << maxFunctionLength(ctors) << endl;
1703 1703 {
1704 1704 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1705 1705 stream << " // static" << endl;
1706 1706 for (it = nameToStaticFunctions.constBegin(); it != nameToStaticFunctions.constEnd(); ++it) {
1707 1707 stream << " , " << maxFunctionLength(it.value()) << endl;
1708 1708 }
1709 1709 stream << " // prototype" << endl;
1710 1710 for (it = nameToPrototypeFunctions.constBegin(); it != nameToPrototypeFunctions.constEnd(); ++it) {
1711 1711 stream << " , " << maxFunctionLength(it.value()) << endl;
1712 1712 }
1713 1713 if (!meta_class->hasDefaultToStringFunction())
1714 1714 stream << " , 0" << endl;
1715 1715 }
1716 1716 stream << " };" << endl;
1717 1717
1718 1718 // setup prototype
1719 1719 if (!meta_class->isNamespace()) {
1720 1720 stream << " engine->setDefaultPrototype(qMetaTypeId<"
1721 1721 << meta_class->qualifiedCppName() << "*>(), QScriptValue());" << endl;
1722 1722 stream << " QScriptValue proto = engine->newVariant(qVariantFromValue(("
1723 1723 << meta_class->qualifiedCppName() << "*)0));" << endl;
1724 1724 bool havePrototypePrototype = false;
1725 1725 if (meta_class->baseClass() != 0) {
1726 1726 stream << " proto.setPrototype(engine->defaultPrototype(qMetaTypeId<"
1727 1727 << meta_class->baseClass()->qualifiedCppName() << "*>()));" << endl;
1728 1728 havePrototypePrototype = true;
1729 1729 }
1730 1730 foreach (AbstractMetaClass *iface, meta_class->interfaces()) {
1731 1731 AbstractMetaClass *impl = iface->primaryInterfaceImplementor();
1732 1732 if (impl == meta_class)
1733 1733 continue;
1734 1734 if (!havePrototypePrototype) {
1735 1735 stream << " proto.setPrototype(engine->defaultPrototype(qMetaTypeId<"
1736 1736 << impl->qualifiedCppName() << "*>()));" << endl;
1737 1737 havePrototypePrototype = true;
1738 1738 } else {
1739 1739 // alternative would be to copy the properties from the secondary
1740 1740 // prototype to the primary prototype.
1741 1741 stream << " proto.setProperty(QString::fromLatin1(\"__"
1742 1742 << impl->name() << "__\")," << endl
1743 1743 << " engine->defaultPrototype(qMetaTypeId<"
1744 1744 << impl->qualifiedCppName() << "*>())," << endl
1745 1745 << " QScriptValue::SkipInEnumeration);" << endl;
1746 1746 }
1747 1747 }
1748 1748 if (!nameToPrototypeFunctions.isEmpty()) {
1749 1749 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1750 1750 int count = nameToPrototypeFunctions.size();
1751 1751 if (!meta_class->hasDefaultToStringFunction())
1752 1752 ++count;
1753 1753 stream << " for (int i = 0; i < " << count << "; ++i) {" << endl
1754 1754 << " QScriptValue fun = engine->newFunction(qtscript_"
1755 1755 << meta_class->name() << "_prototype_call, function_lengths[i+"
1756 1756 << prototypeFunctionsOffset << "]);" << endl
1757 1757 << " fun.setData(QScriptValue(engine, uint(0xBABE0000 + i)));" << endl
1758 1758 << " proto.setProperty(QString::fromLatin1(qtscript_"
1759 1759 << meta_class->name() << "_function_names[i+" << prototypeFunctionsOffset << "])," << endl
1760 1760 << " fun, QScriptValue::SkipInEnumeration);" << endl
1761 1761 << " }" << endl;
1762 1762 }
1763 1763 writeInjectedCode(stream, meta_class, CodeSnip::PrototypeInitialization);
1764 1764 stream << endl;
1765 1765
1766 1766 // register the prototype
1767 1767 // stream << " qDebug() << \"registering " << meta_class->name() << " prototype\";" << endl;
1768 1768 if (meta_class->typeEntry()->isValue() && hasDefaultCtor) {
1769 1769 stream << " engine->setDefaultPrototype(qMetaTypeId<"
1770 1770 << meta_class->qualifiedCppName() << ">(), proto);" << endl;
1771 1771 }
1772 1772 if (isQObjectBased(meta_class)) {
1773 1773 stream << " qScriptRegisterMetaType<" << meta_class->qualifiedCppName() << "*>(engine, qtscript_"
1774 1774 << meta_class->name() << "_toScriptValue, " << endl << " qtscript_"
1775 1775 << meta_class->name() << "_fromScriptValue, proto);" << endl;
1776 1776 } else {
1777 1777 stream << " engine->setDefaultPrototype(qMetaTypeId<"
1778 1778 << meta_class->qualifiedCppName() << "*>(), proto);" << endl;
1779 1779 }
1780 1780 stream << endl;
1781 1781 } else {
1782 1782 stream << " QScriptValue proto = QScriptValue();" << endl;
1783 1783 }
1784 1784
1785 1785 // setup constructor
1786 1786 stream << " QScriptValue ctor = engine->newFunction(qtscript_" << meta_class->name()
1787 1787 << "_static_call, proto, function_lengths[0]);" << endl;
1788 1788 stream << " ctor.setData(QScriptValue(engine, uint(0xBABE0000 + 0)));" << endl;
1789 1789 if (!nameToStaticFunctions.isEmpty()) {
1790 1790 // static functions
1791 1791 QMap<QString, AbstractMetaFunctionList>::const_iterator it;
1792 1792 stream << " for (int i = 0; i < " << nameToStaticFunctions.size() << "; ++i) {" << endl
1793 1793 << " QScriptValue fun = engine->newFunction(qtscript_" << meta_class->name()
1794 1794 << "_static_call," << endl
1795 1795 << " function_lengths[i+" << staticFunctionsOffset << "]);" << endl
1796 1796 << " fun.setData(QScriptValue(engine, uint(0xBABE0000 + i+1)));" << endl
1797 1797 << " ctor.setProperty(QString::fromLatin1(qtscript_"
1798 1798 << meta_class->name() << "_function_names[i+" << staticFunctionsOffset << "])," << endl
1799 1799 << " fun, QScriptValue::SkipInEnumeration);" << endl
1800 1800 << " }" << endl;
1801 1801 }
1802 1802 stream << endl;
1803 1803 // enums and flags classes
1804 1804 {
1805 1805 for (int i = 0; i < enums.size(); ++i) {
1806 1806 const AbstractMetaEnum *enom = enums.at(i);
1807 1807 stream << " ctor.setProperty(QString::fromLatin1(\""
1808 1808 << enom->name() << "\")," << endl
1809 1809 << " qtscript_create_" << meta_class->name()
1810 1810 << "_" << enom->name() << "_class(engine, ctor));" << endl;
1811 1811 FlagsTypeEntry *flags = enom->typeEntry()->flags();
1812 1812 if (flags) {
1813 1813 stream << " ctor.setProperty(QString::fromLatin1(\""
1814 1814 << flags->targetLangName() << "\")," << endl
1815 1815 << " qtscript_create_" << meta_class->name()
1816 1816 << "_" << flags->targetLangName() << "_class(engine));" << endl;
1817 1817 }
1818 1818 }
1819 1819 }
1820 1820
1821 1821 writeInjectedCode(stream, meta_class, CodeSnip::ConstructorInitialization);
1822 1822
1823 1823 stream << " return ctor;" << endl;
1824 1824 stream << "}" << endl;
1825 1825
1826 1826 writeInjectedCode(stream, meta_class, CodeSnip::End);
1827 1827
1828 1828 QString pro_file_name = meta_class->package().replace(".", "_") + "/" + meta_class->package().replace(".", "_") + ".pri";
1829 1829 priGenerator->addSource(pro_file_name, fileNameForClass(meta_class));
1830 1830 setupGenerator->addClass(meta_class);
1831 1831 }
1832 1832
1833 1833 bool ClassGenerator::isBuiltIn(const QString& name) {
1834 1834
1835 1835 static QSet<QString> builtIn;
1836 1836 if (builtIn.isEmpty()) {
1837 1837 builtIn.insert("Qt");
1838 1838 builtIn.insert("QFont");
1839 1839 builtIn.insert("QPixmap");
1840 1840 builtIn.insert("QBrush");
1841 1841 builtIn.insert("QPalette");
1842 1842 builtIn.insert("QIcon");
1843 1843 builtIn.insert("QImage");
1844 1844 builtIn.insert("QPolygon");
1845 1845 builtIn.insert("QRegion");
1846 1846 builtIn.insert("QBitmap");
1847 1847 builtIn.insert("QCursor");
1848 1848 builtIn.insert("QColor");
1849 1849 builtIn.insert("QSizePolicy");
1850 1850 builtIn.insert("QKeySequence");
1851 1851 builtIn.insert("QTextLength");
1852 1852 builtIn.insert("QTextFormat");
1853 1853 builtIn.insert("QMatrix");
1854 1854 builtIn.insert("QDate");
1855 1855 builtIn.insert("QTime");
1856 1856 builtIn.insert("QDateTime");
1857 1857 builtIn.insert("QUrl");
1858 1858 builtIn.insert("QLocale");
1859 1859 builtIn.insert("QRect");
1860 1860 builtIn.insert("QRectF");
1861 1861 builtIn.insert("QSize");
1862 1862 builtIn.insert("QSizeF");
1863 1863 builtIn.insert("QLine");
1864 1864 builtIn.insert("QLineF");
1865 1865 builtIn.insert("QPoint");
1866 1866 builtIn.insert("QPointF");
1867 1867 builtIn.insert("QRegExp");
1868 1868 }
1869 1869 return builtIn.contains(name);
1870 1870 }
@@ -1,27 +1,30
1 TARGET = pythonqt_generator
2 CONFIG -= debug
3 CONFIG += release
4 DESTDIR = .
5
1 6 include(generator.pri)
2 7
8
3 9 # Input
4 10 HEADERS += \
5 11 generatorsetqtscript.h \
6 12 metaqtscriptbuilder.h \
7 13 metaqtscript.h \
8 14 classgenerator.h \
9 15 shellgenerator.h \
10 16 shellimplgenerator.h \
11 17 shellheadergenerator.h \
12 18 setupgenerator.h \
13 19 docgenerator.h
14 20
15 21 SOURCES += \
16 22 generatorsetqtscript.cpp \
17 23 metaqtscriptbuilder.cpp \
18 24 metaqtscript.cpp \
19 25 classgenerator.cpp \
20 26 shellgenerator.cpp \
21 27 shellimplgenerator.cpp \
22 28 shellheadergenerator.cpp \
23 29 setupgenerator.cpp \
24 30 docgenerator.cpp
25
26 CONFIG -= debug
27 CONFIG += release
@@ -1,67 +1,70
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 4 **
5 5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 6 **
7 7 ** This file may be used under the terms of the GNU General Public
8 8 ** License version 2.0 as published by the Free Software Foundation
9 9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 10 ** this file. Please review the following information to ensure GNU
11 11 ** General Public Licensing requirements will be met:
12 12 ** http://www.trolltech.com/products/qt/opensource.html
13 13 **
14 14 ** If you are unsure which license is appropriate for your use, please
15 15 ** review the following information:
16 16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 17 ** sales department at sales@trolltech.com.
18 18 **
19 19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 21 **
22 22 ****************************************************************************/
23 23
24 24 #include "prigenerator.h"
25 25 #include "reporthandler.h"
26 26 #include "fileout.h"
27 27
28 28 void PriGenerator::addHeader(const QString &folder, const QString &header)
29 29 {
30 30 priHash[folder].headers << header;
31 31 }
32 32
33 33 void PriGenerator::addSource(const QString &folder, const QString &source)
34 34 {
35 35 priHash[folder].sources << source;
36 36 }
37 37
38 38 void PriGenerator::generate()
39 39 {
40 40 QHashIterator<QString, Pri> pri(priHash);
41 41 while (pri.hasNext()) {
42 42 pri.next();
43 43 QStringList list = pri.value().headers;
44 44 if (list.isEmpty())
45 45 continue;
46 46
47 47 FileOut file(m_out_dir + "/generated_cpp/" + pri.key());
48 48 file.stream << "HEADERS += \\\n";
49 49 qSort(list.begin(), list.end());
50 50 foreach (const QString &entry, list) {
51 51 file.stream << " $$PWD/" << entry << " \\\n";
52 52 }
53 53
54 54 file.stream << "\n";
55 55 file.stream << "SOURCES += \\\n";
56 56 list = pri.value().sources;
57 57 qSort(list.begin(), list.end());
58 58 foreach (const QString &entry, list) {
59 59 file.stream << " $$PWD/" << entry << " \\\n";
60 60 }
61 file.stream << " $$PWD/init.cpp\n";
61 QString initName = pri.key();
62 initName = initName.mid(initName.indexOf('/')+1);
63 initName = initName.left(initName.length()-4);
64 file.stream << " $$PWD/" + initName + "_init.cpp\n";
62 65
63 66 if (file.done())
64 67 ++m_num_generated_written;
65 68 ++m_num_generated;
66 69 }
67 70 }
@@ -1,1134 +1,1134
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 4 **
5 5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 6 **
7 7 ** This file may be used under the terms of the GNU General Public
8 8 ** License version 2.0 as published by the Free Software Foundation
9 9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 10 ** this file. Please review the following information to ensure GNU
11 11 ** General Public Licensing requirements will be met:
12 12 ** http://www.trolltech.com/products/qt/opensource.html
13 13 **
14 14 ** If you are unsure which license is appropriate for your use, please
15 15 ** review the following information:
16 16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 17 ** sales department at sales@trolltech.com.
18 18 **
19 19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 21 **
22 22 ****************************************************************************/
23 23
24 24 #define QT_NO_STL
25 25 #include <QtCore/QtCore>
26 26 #include <QtGui/QtGui>
27 27 #include <QtNetwork/QtNetwork>
28 28 #include <QtSql/QtSql>
29 29 #include <QtSvg/QtSvg>
30 30 #include <QtXml/QtXml>
31 31
32 32 #include <QtUiTools/QtUiTools>
33 33
34 34 #ifndef QT_NO_XMLPATTERNS
35 35 # include <QtXmlPatterns/QtXmlPatterns>
36 36 #endif
37 37
38 38 #ifndef QT_NO_WEBKIT
39 39 # include <QtWebKit/QtWebKit>
40 40 #endif
41 41
42 42 #ifndef QT_NO_PHONON
43 43 # include <phonon/phonon>
44 44 #endif
45 45
46 #include "../qtbindings/qtscript_core/qtscriptconcurrent.h"
46 //#include "../qtbindings/qtscript_core/qtscriptconcurrent.h"
47 47
48 48 #ifndef QT_NO_OPENGL
49 49 #define GL_ACCUM 0x0100
50 50 #define GL_LOAD 0x0101
51 51 #define GL_RETURN 0x0102
52 52 #define GL_MULT 0x0103
53 53 #define GL_ADD 0x0104
54 54
55 55 /* AlphaFunction */
56 56 #define GL_NEVER 0x0200
57 57 #define GL_LESS 0x0201
58 58 #define GL_EQUAL 0x0202
59 59 #define GL_LEQUAL 0x0203
60 60 #define GL_GREATER 0x0204
61 61 #define GL_NOTEQUAL 0x0205
62 62 #define GL_GEQUAL 0x0206
63 63 #define GL_ALWAYS 0x0207
64 64
65 65 /* AttribMask */
66 66 #define GL_CURRENT_BIT 0x00000001
67 67 #define GL_POINT_BIT 0x00000002
68 68 #define GL_LINE_BIT 0x00000004
69 69 #define GL_POLYGON_BIT 0x00000008
70 70 #define GL_POLYGON_STIPPLE_BIT 0x00000010
71 71 #define GL_PIXEL_MODE_BIT 0x00000020
72 72 #define GL_LIGHTING_BIT 0x00000040
73 73 #define GL_FOG_BIT 0x00000080
74 74 #define GL_DEPTH_BUFFER_BIT 0x00000100
75 75 #define GL_ACCUM_BUFFER_BIT 0x00000200
76 76 #define GL_STENCIL_BUFFER_BIT 0x00000400
77 77 #define GL_VIEWPORT_BIT 0x00000800
78 78 #define GL_TRANSFORM_BIT 0x00001000
79 79 #define GL_ENABLE_BIT 0x00002000
80 80 #define GL_COLOR_BUFFER_BIT 0x00004000
81 81 #define GL_HINT_BIT 0x00008000
82 82 #define GL_EVAL_BIT 0x00010000
83 83 #define GL_LIST_BIT 0x00020000
84 84 #define GL_TEXTURE_BIT 0x00040000
85 85 #define GL_SCISSOR_BIT 0x00080000
86 86 #define GL_ALL_ATTRIB_BITS 0x000fffff
87 87
88 88 /* BeginMode */
89 89 #define GL_POINTS 0x0000
90 90 #define GL_LINES 0x0001
91 91 #define GL_LINE_LOOP 0x0002
92 92 #define GL_LINE_STRIP 0x0003
93 93 #define GL_TRIANGLES 0x0004
94 94 #define GL_TRIANGLE_STRIP 0x0005
95 95 #define GL_TRIANGLE_FAN 0x0006
96 96 #define GL_QUADS 0x0007
97 97 #define GL_QUAD_STRIP 0x0008
98 98 #define GL_POLYGON 0x0009
99 99
100 100 /* BlendingFactorDest */
101 101 #define GL_ZERO 0
102 102 #define GL_ONE 1
103 103 #define GL_SRC_COLOR 0x0300
104 104 #define GL_ONE_MINUS_SRC_COLOR 0x0301
105 105 #define GL_SRC_ALPHA 0x0302
106 106 #define GL_ONE_MINUS_SRC_ALPHA 0x0303
107 107 #define GL_DST_ALPHA 0x0304
108 108 #define GL_ONE_MINUS_DST_ALPHA 0x0305
109 109
110 110 /* BlendingFactorSrc */
111 111 /* GL_ZERO */
112 112 /* GL_ONE */
113 113 #define GL_DST_COLOR 0x0306
114 114 #define GL_ONE_MINUS_DST_COLOR 0x0307
115 115 #define GL_SRC_ALPHA_SATURATE 0x0308
116 116 /* GL_SRC_ALPHA */
117 117 /* GL_ONE_MINUS_SRC_ALPHA */
118 118 /* GL_DST_ALPHA */
119 119 /* GL_ONE_MINUS_DST_ALPHA */
120 120
121 121 /* Boolean */
122 122 #define GL_TRUE 1
123 123 #define GL_FALSE 0
124 124
125 125 /* ClearBufferMask */
126 126 /* GL_COLOR_BUFFER_BIT */
127 127 /* GL_ACCUM_BUFFER_BIT */
128 128 /* GL_STENCIL_BUFFER_BIT */
129 129 /* GL_DEPTH_BUFFER_BIT */
130 130
131 131 /* ClientArrayType */
132 132 /* GL_VERTEX_ARRAY */
133 133 /* GL_NORMAL_ARRAY */
134 134 /* GL_COLOR_ARRAY */
135 135 /* GL_INDEX_ARRAY */
136 136 /* GL_TEXTURE_COORD_ARRAY */
137 137 /* GL_EDGE_FLAG_ARRAY */
138 138
139 139 /* ClipPlaneName */
140 140 #define GL_CLIP_PLANE0 0x3000
141 141 #define GL_CLIP_PLANE1 0x3001
142 142 #define GL_CLIP_PLANE2 0x3002
143 143 #define GL_CLIP_PLANE3 0x3003
144 144 #define GL_CLIP_PLANE4 0x3004
145 145 #define GL_CLIP_PLANE5 0x3005
146 146
147 147 /* ColorMaterialFace */
148 148 /* GL_FRONT */
149 149 /* GL_BACK */
150 150 /* GL_FRONT_AND_BACK */
151 151
152 152 /* ColorMaterialParameter */
153 153 /* GL_AMBIENT */
154 154 /* GL_DIFFUSE */
155 155 /* GL_SPECULAR */
156 156 /* GL_EMISSION */
157 157 /* GL_AMBIENT_AND_DIFFUSE */
158 158
159 159 /* ColorPointerType */
160 160 /* GL_BYTE */
161 161 /* GL_UNSIGNED_BYTE */
162 162 /* GL_SHORT */
163 163 /* GL_UNSIGNED_SHORT */
164 164 /* GL_INT */
165 165 /* GL_UNSIGNED_INT */
166 166 /* GL_FLOAT */
167 167 /* GL_DOUBLE */
168 168
169 169 /* CullFaceMode */
170 170 /* GL_FRONT */
171 171 /* GL_BACK */
172 172 /* GL_FRONT_AND_BACK */
173 173
174 174 /* DataType */
175 175 #define GL_BYTE 0x1400
176 176 #define GL_UNSIGNED_BYTE 0x1401
177 177 #define GL_SHORT 0x1402
178 178 #define GL_UNSIGNED_SHORT 0x1403
179 179 #define GL_INT 0x1404
180 180 #define GL_UNSIGNED_INT 0x1405
181 181 #define GL_FLOAT 0x1406
182 182 #define GL_2_BYTES 0x1407
183 183 #define GL_3_BYTES 0x1408
184 184 #define GL_4_BYTES 0x1409
185 185 #define GL_DOUBLE 0x140A
186 186
187 187 /* DepthFunction */
188 188 /* GL_NEVER */
189 189 /* GL_LESS */
190 190 /* GL_EQUAL */
191 191 /* GL_LEQUAL */
192 192 /* GL_GREATER */
193 193 /* GL_NOTEQUAL */
194 194 /* GL_GEQUAL */
195 195 /* GL_ALWAYS */
196 196
197 197 /* DrawBufferMode */
198 198 #define GL_NONE 0
199 199 #define GL_FRONT_LEFT 0x0400
200 200 #define GL_FRONT_RIGHT 0x0401
201 201 #define GL_BACK_LEFT 0x0402
202 202 #define GL_BACK_RIGHT 0x0403
203 203 #define GL_FRONT 0x0404
204 204 #define GL_BACK 0x0405
205 205 #define GL_LEFT 0x0406
206 206 #define GL_RIGHT 0x0407
207 207 #define GL_FRONT_AND_BACK 0x0408
208 208 #define GL_AUX0 0x0409
209 209 #define GL_AUX1 0x040A
210 210 #define GL_AUX2 0x040B
211 211 #define GL_AUX3 0x040C
212 212
213 213 /* Enable */
214 214 /* GL_FOG */
215 215 /* GL_LIGHTING */
216 216 /* GL_TEXTURE_1D */
217 217 /* GL_TEXTURE_2D */
218 218 /* GL_LINE_STIPPLE */
219 219 /* GL_POLYGON_STIPPLE */
220 220 /* GL_CULL_FACE */
221 221 /* GL_ALPHA_TEST */
222 222 /* GL_BLEND */
223 223 /* GL_INDEX_LOGIC_OP */
224 224 /* GL_COLOR_LOGIC_OP */
225 225 /* GL_DITHER */
226 226 /* GL_STENCIL_TEST */
227 227 /* GL_DEPTH_TEST */
228 228 /* GL_CLIP_PLANE0 */
229 229 /* GL_CLIP_PLANE1 */
230 230 /* GL_CLIP_PLANE2 */
231 231 /* GL_CLIP_PLANE3 */
232 232 /* GL_CLIP_PLANE4 */
233 233 /* GL_CLIP_PLANE5 */
234 234 /* GL_LIGHT0 */
235 235 /* GL_LIGHT1 */
236 236 /* GL_LIGHT2 */
237 237 /* GL_LIGHT3 */
238 238 /* GL_LIGHT4 */
239 239 /* GL_LIGHT5 */
240 240 /* GL_LIGHT6 */
241 241 /* GL_LIGHT7 */
242 242 /* GL_TEXTURE_GEN_S */
243 243 /* GL_TEXTURE_GEN_T */
244 244 /* GL_TEXTURE_GEN_R */
245 245 /* GL_TEXTURE_GEN_Q */
246 246 /* GL_MAP1_VERTEX_3 */
247 247 /* GL_MAP1_VERTEX_4 */
248 248 /* GL_MAP1_COLOR_4 */
249 249 /* GL_MAP1_INDEX */
250 250 /* GL_MAP1_NORMAL */
251 251 /* GL_MAP1_TEXTURE_COORD_1 */
252 252 /* GL_MAP1_TEXTURE_COORD_2 */
253 253 /* GL_MAP1_TEXTURE_COORD_3 */
254 254 /* GL_MAP1_TEXTURE_COORD_4 */
255 255 /* GL_MAP2_VERTEX_3 */
256 256 /* GL_MAP2_VERTEX_4 */
257 257 /* GL_MAP2_COLOR_4 */
258 258 /* GL_MAP2_INDEX */
259 259 /* GL_MAP2_NORMAL */
260 260 /* GL_MAP2_TEXTURE_COORD_1 */
261 261 /* GL_MAP2_TEXTURE_COORD_2 */
262 262 /* GL_MAP2_TEXTURE_COORD_3 */
263 263 /* GL_MAP2_TEXTURE_COORD_4 */
264 264 /* GL_POINT_SMOOTH */
265 265 /* GL_LINE_SMOOTH */
266 266 /* GL_POLYGON_SMOOTH */
267 267 /* GL_SCISSOR_TEST */
268 268 /* GL_COLOR_MATERIAL */
269 269 /* GL_NORMALIZE */
270 270 /* GL_AUTO_NORMAL */
271 271 /* GL_VERTEX_ARRAY */
272 272 /* GL_NORMAL_ARRAY */
273 273 /* GL_COLOR_ARRAY */
274 274 /* GL_INDEX_ARRAY */
275 275 /* GL_TEXTURE_COORD_ARRAY */
276 276 /* GL_EDGE_FLAG_ARRAY */
277 277 /* GL_POLYGON_OFFSET_POINT */
278 278 /* GL_POLYGON_OFFSET_LINE */
279 279 /* GL_POLYGON_OFFSET_FILL */
280 280
281 281 /* ErrorCode */
282 282 #define GL_NO_ERROR 0
283 283 #define GL_INVALID_ENUM 0x0500
284 284 #define GL_INVALID_VALUE 0x0501
285 285 #define GL_INVALID_OPERATION 0x0502
286 286 #define GL_STACK_OVERFLOW 0x0503
287 287 #define GL_STACK_UNDERFLOW 0x0504
288 288 #define GL_OUT_OF_MEMORY 0x0505
289 289
290 290 /* FeedBackMode */
291 291 #define GL_2D 0x0600
292 292 #define GL_3D 0x0601
293 293 #define GL_3D_COLOR 0x0602
294 294 #define GL_3D_COLOR_TEXTURE 0x0603
295 295 #define GL_4D_COLOR_TEXTURE 0x0604
296 296
297 297 /* FeedBackToken */
298 298 #define GL_PASS_THROUGH_TOKEN 0x0700
299 299 #define GL_POINT_TOKEN 0x0701
300 300 #define GL_LINE_TOKEN 0x0702
301 301 #define GL_POLYGON_TOKEN 0x0703
302 302 #define GL_BITMAP_TOKEN 0x0704
303 303 #define GL_DRAW_PIXEL_TOKEN 0x0705
304 304 #define GL_COPY_PIXEL_TOKEN 0x0706
305 305 #define GL_LINE_RESET_TOKEN 0x0707
306 306
307 307 /* FogMode */
308 308 /* GL_LINEAR */
309 309 #define GL_EXP 0x0800
310 310 #define GL_EXP2 0x0801
311 311
312 312
313 313 /* FogParameter */
314 314 /* GL_FOG_COLOR */
315 315 /* GL_FOG_DENSITY */
316 316 /* GL_FOG_END */
317 317 /* GL_FOG_INDEX */
318 318 /* GL_FOG_MODE */
319 319 /* GL_FOG_START */
320 320
321 321 /* FrontFaceDirection */
322 322 #define GL_CW 0x0900
323 323 #define GL_CCW 0x0901
324 324
325 325 /* GetMapTarget */
326 326 #define GL_COEFF 0x0A00
327 327 #define GL_ORDER 0x0A01
328 328 #define GL_DOMAIN 0x0A02
329 329
330 330 /* GetPixelMap */
331 331 /* GL_PIXEL_MAP_I_TO_I */
332 332 /* GL_PIXEL_MAP_S_TO_S */
333 333 /* GL_PIXEL_MAP_I_TO_R */
334 334 /* GL_PIXEL_MAP_I_TO_G */
335 335 /* GL_PIXEL_MAP_I_TO_B */
336 336 /* GL_PIXEL_MAP_I_TO_A */
337 337 /* GL_PIXEL_MAP_R_TO_R */
338 338 /* GL_PIXEL_MAP_G_TO_G */
339 339 /* GL_PIXEL_MAP_B_TO_B */
340 340 /* GL_PIXEL_MAP_A_TO_A */
341 341
342 342 /* GetPointerTarget */
343 343 /* GL_VERTEX_ARRAY_POINTER */
344 344 /* GL_NORMAL_ARRAY_POINTER */
345 345 /* GL_COLOR_ARRAY_POINTER */
346 346 /* GL_INDEX_ARRAY_POINTER */
347 347 /* GL_TEXTURE_COORD_ARRAY_POINTER */
348 348 /* GL_EDGE_FLAG_ARRAY_POINTER */
349 349
350 350 /* GetTarget */
351 351 #define GL_CURRENT_COLOR 0x0B00
352 352 #define GL_CURRENT_INDEX 0x0B01
353 353 #define GL_CURRENT_NORMAL 0x0B02
354 354 #define GL_CURRENT_TEXTURE_COORDS 0x0B03
355 355 #define GL_CURRENT_RASTER_COLOR 0x0B04
356 356 #define GL_CURRENT_RASTER_INDEX 0x0B05
357 357 #define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06
358 358 #define GL_CURRENT_RASTER_POSITION 0x0B07
359 359 #define GL_CURRENT_RASTER_POSITION_VALID 0x0B08
360 360 #define GL_CURRENT_RASTER_DISTANCE 0x0B09
361 361 #define GL_POINT_SMOOTH 0x0B10
362 362 #define GL_POINT_SIZE 0x0B11
363 363 #define GL_POINT_SIZE_RANGE 0x0B12
364 364 #define GL_POINT_SIZE_GRANULARITY 0x0B13
365 365 #define GL_LINE_SMOOTH 0x0B20
366 366 #define GL_LINE_WIDTH 0x0B21
367 367 #define GL_LINE_WIDTH_RANGE 0x0B22
368 368 #define GL_LINE_WIDTH_GRANULARITY 0x0B23
369 369 #define GL_LINE_STIPPLE 0x0B24
370 370 #define GL_LINE_STIPPLE_PATTERN 0x0B25
371 371 #define GL_LINE_STIPPLE_REPEAT 0x0B26
372 372 #define GL_LIST_MODE 0x0B30
373 373 #define GL_MAX_LIST_NESTING 0x0B31
374 374 #define GL_LIST_BASE 0x0B32
375 375 #define GL_LIST_INDEX 0x0B33
376 376 #define GL_POLYGON_MODE 0x0B40
377 377 #define GL_POLYGON_SMOOTH 0x0B41
378 378 #define GL_POLYGON_STIPPLE 0x0B42
379 379 #define GL_EDGE_FLAG 0x0B43
380 380 #define GL_CULL_FACE 0x0B44
381 381 #define GL_CULL_FACE_MODE 0x0B45
382 382 #define GL_FRONT_FACE 0x0B46
383 383 #define GL_LIGHTING 0x0B50
384 384 #define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
385 385 #define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
386 386 #define GL_LIGHT_MODEL_AMBIENT 0x0B53
387 387 #define GL_SHADE_MODEL 0x0B54
388 388 #define GL_COLOR_MATERIAL_FACE 0x0B55
389 389 #define GL_COLOR_MATERIAL_PARAMETER 0x0B56
390 390 #define GL_COLOR_MATERIAL 0x0B57
391 391 #define GL_FOG 0x0B60
392 392 #define GL_FOG_INDEX 0x0B61
393 393 #define GL_FOG_DENSITY 0x0B62
394 394 #define GL_FOG_START 0x0B63
395 395 #define GL_FOG_END 0x0B64
396 396 #define GL_FOG_MODE 0x0B65
397 397 #define GL_FOG_COLOR 0x0B66
398 398 #define GL_DEPTH_RANGE 0x0B70
399 399 #define GL_DEPTH_TEST 0x0B71
400 400 #define GL_DEPTH_WRITEMASK 0x0B72
401 401 #define GL_DEPTH_CLEAR_VALUE 0x0B73
402 402 #define GL_DEPTH_FUNC 0x0B74
403 403 #define GL_ACCUM_CLEAR_VALUE 0x0B80
404 404 #define GL_STENCIL_TEST 0x0B90
405 405 #define GL_STENCIL_CLEAR_VALUE 0x0B91
406 406 #define GL_STENCIL_FUNC 0x0B92
407 407 #define GL_STENCIL_VALUE_MASK 0x0B93
408 408 #define GL_STENCIL_FAIL 0x0B94
409 409 #define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
410 410 #define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
411 411 #define GL_STENCIL_REF 0x0B97
412 412 #define GL_STENCIL_WRITEMASK 0x0B98
413 413 #define GL_MATRIX_MODE 0x0BA0
414 414 #define GL_NORMALIZE 0x0BA1
415 415 #define GL_VIEWPORT 0x0BA2
416 416 #define GL_MODELVIEW_STACK_DEPTH 0x0BA3
417 417 #define GL_PROJECTION_STACK_DEPTH 0x0BA4
418 418 #define GL_TEXTURE_STACK_DEPTH 0x0BA5
419 419 #define GL_MODELVIEW_MATRIX 0x0BA6
420 420 #define GL_PROJECTION_MATRIX 0x0BA7
421 421 #define GL_TEXTURE_MATRIX 0x0BA8
422 422 #define GL_ATTRIB_STACK_DEPTH 0x0BB0
423 423 #define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1
424 424 #define GL_ALPHA_TEST 0x0BC0
425 425 #define GL_ALPHA_TEST_FUNC 0x0BC1
426 426 #define GL_ALPHA_TEST_REF 0x0BC2
427 427 #define GL_DITHER 0x0BD0
428 428 #define GL_BLEND_DST 0x0BE0
429 429 #define GL_BLEND_SRC 0x0BE1
430 430 #define GL_BLEND 0x0BE2
431 431 #define GL_LOGIC_OP_MODE 0x0BF0
432 432 #define GL_INDEX_LOGIC_OP 0x0BF1
433 433 #define GL_COLOR_LOGIC_OP 0x0BF2
434 434 #define GL_AUX_BUFFERS 0x0C00
435 435 #define GL_DRAW_BUFFER 0x0C01
436 436 #define GL_READ_BUFFER 0x0C02
437 437 #define GL_SCISSOR_BOX 0x0C10
438 438 #define GL_SCISSOR_TEST 0x0C11
439 439 #define GL_INDEX_CLEAR_VALUE 0x0C20
440 440 #define GL_INDEX_WRITEMASK 0x0C21
441 441 #define GL_COLOR_CLEAR_VALUE 0x0C22
442 442 #define GL_COLOR_WRITEMASK 0x0C23
443 443 #define GL_INDEX_MODE 0x0C30
444 444 #define GL_RGBA_MODE 0x0C31
445 445 #define GL_DOUBLEBUFFER 0x0C32
446 446 #define GL_STEREO 0x0C33
447 447 #define GL_RENDER_MODE 0x0C40
448 448 #define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
449 449 #define GL_POINT_SMOOTH_HINT 0x0C51
450 450 #define GL_LINE_SMOOTH_HINT 0x0C52
451 451 #define GL_POLYGON_SMOOTH_HINT 0x0C53
452 452 #define GL_FOG_HINT 0x0C54
453 453 #define GL_TEXTURE_GEN_S 0x0C60
454 454 #define GL_TEXTURE_GEN_T 0x0C61
455 455 #define GL_TEXTURE_GEN_R 0x0C62
456 456 #define GL_TEXTURE_GEN_Q 0x0C63
457 457 #define GL_PIXEL_MAP_I_TO_I 0x0C70
458 458 #define GL_PIXEL_MAP_S_TO_S 0x0C71
459 459 #define GL_PIXEL_MAP_I_TO_R 0x0C72
460 460 #define GL_PIXEL_MAP_I_TO_G 0x0C73
461 461 #define GL_PIXEL_MAP_I_TO_B 0x0C74
462 462 #define GL_PIXEL_MAP_I_TO_A 0x0C75
463 463 #define GL_PIXEL_MAP_R_TO_R 0x0C76
464 464 #define GL_PIXEL_MAP_G_TO_G 0x0C77
465 465 #define GL_PIXEL_MAP_B_TO_B 0x0C78
466 466 #define GL_PIXEL_MAP_A_TO_A 0x0C79
467 467 #define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0
468 468 #define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1
469 469 #define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2
470 470 #define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3
471 471 #define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4
472 472 #define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5
473 473 #define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6
474 474 #define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7
475 475 #define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8
476 476 #define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9
477 477 #define GL_UNPACK_SWAP_BYTES 0x0CF0
478 478 #define GL_UNPACK_LSB_FIRST 0x0CF1
479 479 #define GL_UNPACK_ROW_LENGTH 0x0CF2
480 480 #define GL_UNPACK_SKIP_ROWS 0x0CF3
481 481 #define GL_UNPACK_SKIP_PIXELS 0x0CF4
482 482 #define GL_UNPACK_ALIGNMENT 0x0CF5
483 483 #define GL_PACK_SWAP_BYTES 0x0D00
484 484 #define GL_PACK_LSB_FIRST 0x0D01
485 485 #define GL_PACK_ROW_LENGTH 0x0D02
486 486 #define GL_PACK_SKIP_ROWS 0x0D03
487 487 #define GL_PACK_SKIP_PIXELS 0x0D04
488 488 #define GL_PACK_ALIGNMENT 0x0D05
489 489 #define GL_MAP_COLOR 0x0D10
490 490 #define GL_MAP_STENCIL 0x0D11
491 491 #define GL_INDEX_SHIFT 0x0D12
492 492 #define GL_INDEX_OFFSET 0x0D13
493 493 #define GL_RED_SCALE 0x0D14
494 494 #define GL_RED_BIAS 0x0D15
495 495 #define GL_ZOOM_X 0x0D16
496 496 #define GL_ZOOM_Y 0x0D17
497 497 #define GL_GREEN_SCALE 0x0D18
498 498 #define GL_GREEN_BIAS 0x0D19
499 499 #define GL_BLUE_SCALE 0x0D1A
500 500 #define GL_BLUE_BIAS 0x0D1B
501 501 #define GL_ALPHA_SCALE 0x0D1C
502 502 #define GL_ALPHA_BIAS 0x0D1D
503 503 #define GL_DEPTH_SCALE 0x0D1E
504 504 #define GL_DEPTH_BIAS 0x0D1F
505 505 #define GL_MAX_EVAL_ORDER 0x0D30
506 506 #define GL_MAX_LIGHTS 0x0D31
507 507 #define GL_MAX_CLIP_PLANES 0x0D32
508 508 #define GL_MAX_TEXTURE_SIZE 0x0D33
509 509 #define GL_MAX_PIXEL_MAP_TABLE 0x0D34
510 510 #define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35
511 511 #define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
512 512 #define GL_MAX_NAME_STACK_DEPTH 0x0D37
513 513 #define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
514 514 #define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
515 515 #define GL_MAX_VIEWPORT_DIMS 0x0D3A
516 516 #define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B
517 517 #define GL_SUBPIXEL_BITS 0x0D50
518 518 #define GL_INDEX_BITS 0x0D51
519 519 #define GL_RED_BITS 0x0D52
520 520 #define GL_GREEN_BITS 0x0D53
521 521 #define GL_BLUE_BITS 0x0D54
522 522 #define GL_ALPHA_BITS 0x0D55
523 523 #define GL_DEPTH_BITS 0x0D56
524 524 #define GL_STENCIL_BITS 0x0D57
525 525 #define GL_ACCUM_RED_BITS 0x0D58
526 526 #define GL_ACCUM_GREEN_BITS 0x0D59
527 527 #define GL_ACCUM_BLUE_BITS 0x0D5A
528 528 #define GL_ACCUM_ALPHA_BITS 0x0D5B
529 529 #define GL_NAME_STACK_DEPTH 0x0D70
530 530 #define GL_AUTO_NORMAL 0x0D80
531 531 #define GL_MAP1_COLOR_4 0x0D90
532 532 #define GL_MAP1_INDEX 0x0D91
533 533 #define GL_MAP1_NORMAL 0x0D92
534 534 #define GL_MAP1_TEXTURE_COORD_1 0x0D93
535 535 #define GL_MAP1_TEXTURE_COORD_2 0x0D94
536 536 #define GL_MAP1_TEXTURE_COORD_3 0x0D95
537 537 #define GL_MAP1_TEXTURE_COORD_4 0x0D96
538 538 #define GL_MAP1_VERTEX_3 0x0D97
539 539 #define GL_MAP1_VERTEX_4 0x0D98
540 540 #define GL_MAP2_COLOR_4 0x0DB0
541 541 #define GL_MAP2_INDEX 0x0DB1
542 542 #define GL_MAP2_NORMAL 0x0DB2
543 543 #define GL_MAP2_TEXTURE_COORD_1 0x0DB3
544 544 #define GL_MAP2_TEXTURE_COORD_2 0x0DB4
545 545 #define GL_MAP2_TEXTURE_COORD_3 0x0DB5
546 546 #define GL_MAP2_TEXTURE_COORD_4 0x0DB6
547 547 #define GL_MAP2_VERTEX_3 0x0DB7
548 548 #define GL_MAP2_VERTEX_4 0x0DB8
549 549 #define GL_MAP1_GRID_DOMAIN 0x0DD0
550 550 #define GL_MAP1_GRID_SEGMENTS 0x0DD1
551 551 #define GL_MAP2_GRID_DOMAIN 0x0DD2
552 552 #define GL_MAP2_GRID_SEGMENTS 0x0DD3
553 553 #define GL_TEXTURE_1D 0x0DE0
554 554 #define GL_TEXTURE_2D 0x0DE1
555 555 #define GL_FEEDBACK_BUFFER_POINTER 0x0DF0
556 556 #define GL_FEEDBACK_BUFFER_SIZE 0x0DF1
557 557 #define GL_FEEDBACK_BUFFER_TYPE 0x0DF2
558 558 #define GL_SELECTION_BUFFER_POINTER 0x0DF3
559 559 #define GL_SELECTION_BUFFER_SIZE 0x0DF4
560 560 /* GL_TEXTURE_BINDING_1D */
561 561 /* GL_TEXTURE_BINDING_2D */
562 562 /* GL_VERTEX_ARRAY */
563 563 /* GL_NORMAL_ARRAY */
564 564 /* GL_COLOR_ARRAY */
565 565 /* GL_INDEX_ARRAY */
566 566 /* GL_TEXTURE_COORD_ARRAY */
567 567 /* GL_EDGE_FLAG_ARRAY */
568 568 /* GL_VERTEX_ARRAY_SIZE */
569 569 /* GL_VERTEX_ARRAY_TYPE */
570 570 /* GL_VERTEX_ARRAY_STRIDE */
571 571 /* GL_NORMAL_ARRAY_TYPE */
572 572 /* GL_NORMAL_ARRAY_STRIDE */
573 573 /* GL_COLOR_ARRAY_SIZE */
574 574 /* GL_COLOR_ARRAY_TYPE */
575 575 /* GL_COLOR_ARRAY_STRIDE */
576 576 /* GL_INDEX_ARRAY_TYPE */
577 577 /* GL_INDEX_ARRAY_STRIDE */
578 578 /* GL_TEXTURE_COORD_ARRAY_SIZE */
579 579 /* GL_TEXTURE_COORD_ARRAY_TYPE */
580 580 /* GL_TEXTURE_COORD_ARRAY_STRIDE */
581 581 /* GL_EDGE_FLAG_ARRAY_STRIDE */
582 582 /* GL_POLYGON_OFFSET_FACTOR */
583 583 /* GL_POLYGON_OFFSET_UNITS */
584 584
585 585 /* GetTextureParameter */
586 586 /* GL_TEXTURE_MAG_FILTER */
587 587 /* GL_TEXTURE_MIN_FILTER */
588 588 /* GL_TEXTURE_WRAP_S */
589 589 /* GL_TEXTURE_WRAP_T */
590 590 #define GL_TEXTURE_WIDTH 0x1000
591 591 #define GL_TEXTURE_HEIGHT 0x1001
592 592 #define GL_TEXTURE_INTERNAL_FORMAT 0x1003
593 593 #define GL_TEXTURE_BORDER_COLOR 0x1004
594 594 #define GL_TEXTURE_BORDER 0x1005
595 595 /* GL_TEXTURE_RED_SIZE */
596 596 /* GL_TEXTURE_GREEN_SIZE */
597 597 /* GL_TEXTURE_BLUE_SIZE */
598 598 /* GL_TEXTURE_ALPHA_SIZE */
599 599 /* GL_TEXTURE_LUMINANCE_SIZE */
600 600 /* GL_TEXTURE_INTENSITY_SIZE */
601 601 /* GL_TEXTURE_PRIORITY */
602 602 /* GL_TEXTURE_RESIDENT */
603 603
604 604 /* HintMode */
605 605 #define GL_DONT_CARE 0x1100
606 606 #define GL_FASTEST 0x1101
607 607 #define GL_NICEST 0x1102
608 608
609 609 /* HintTarget */
610 610 /* GL_PERSPECTIVE_CORRECTION_HINT */
611 611 /* GL_POINT_SMOOTH_HINT */
612 612 /* GL_LINE_SMOOTH_HINT */
613 613 /* GL_POLYGON_SMOOTH_HINT */
614 614 /* GL_FOG_HINT */
615 615 /* GL_PHONG_HINT */
616 616
617 617 /* IndexPointerType */
618 618 /* GL_SHORT */
619 619 /* GL_INT */
620 620 /* GL_FLOAT */
621 621 /* GL_DOUBLE */
622 622
623 623 /* LightModelParameter */
624 624 /* GL_LIGHT_MODEL_AMBIENT */
625 625 /* GL_LIGHT_MODEL_LOCAL_VIEWER */
626 626 /* GL_LIGHT_MODEL_TWO_SIDE */
627 627
628 628 /* LightName */
629 629 #define GL_LIGHT0 0x4000
630 630 #define GL_LIGHT1 0x4001
631 631 #define GL_LIGHT2 0x4002
632 632 #define GL_LIGHT3 0x4003
633 633 #define GL_LIGHT4 0x4004
634 634 #define GL_LIGHT5 0x4005
635 635 #define GL_LIGHT6 0x4006
636 636 #define GL_LIGHT7 0x4007
637 637
638 638 /* LightParameter */
639 639 #define GL_AMBIENT 0x1200
640 640 #define GL_DIFFUSE 0x1201
641 641 #define GL_SPECULAR 0x1202
642 642 #define GL_POSITION 0x1203
643 643 #define GL_SPOT_DIRECTION 0x1204
644 644 #define GL_SPOT_EXPONENT 0x1205
645 645 #define GL_SPOT_CUTOFF 0x1206
646 646 #define GL_CONSTANT_ATTENUATION 0x1207
647 647 #define GL_LINEAR_ATTENUATION 0x1208
648 648 #define GL_QUADRATIC_ATTENUATION 0x1209
649 649
650 650 /* InterleavedArrays */
651 651 /* GL_V2F */
652 652 /* GL_V3F */
653 653 /* GL_C4UB_V2F */
654 654 /* GL_C4UB_V3F */
655 655 /* GL_C3F_V3F */
656 656 /* GL_N3F_V3F */
657 657 /* GL_C4F_N3F_V3F */
658 658 /* GL_T2F_V3F */
659 659 /* GL_T4F_V4F */
660 660 /* GL_T2F_C4UB_V3F */
661 661 /* GL_T2F_C3F_V3F */
662 662 /* GL_T2F_N3F_V3F */
663 663 /* GL_T2F_C4F_N3F_V3F */
664 664 /* GL_T4F_C4F_N3F_V4F */
665 665
666 666 /* ListMode */
667 667 #define GL_COMPILE 0x1300
668 668 #define GL_COMPILE_AND_EXECUTE 0x1301
669 669
670 670 /* ListNameType */
671 671 /* GL_BYTE */
672 672 /* GL_UNSIGNED_BYTE */
673 673 /* GL_SHORT */
674 674 /* GL_UNSIGNED_SHORT */
675 675 /* GL_INT */
676 676 /* GL_UNSIGNED_INT */
677 677 /* GL_FLOAT */
678 678 /* GL_2_BYTES */
679 679 /* GL_3_BYTES */
680 680 /* GL_4_BYTES */
681 681
682 682 /* LogicOp */
683 683 #define GL_CLEAR 0x1500
684 684 #define GL_AND 0x1501
685 685 #define GL_AND_REVERSE 0x1502
686 686 #define GL_COPY 0x1503
687 687 #define GL_AND_INVERTED 0x1504
688 688 #define GL_NOOP 0x1505
689 689 #define GL_XOR 0x1506
690 690 #define GL_OR 0x1507
691 691 #define GL_NOR 0x1508
692 692 #define GL_EQUIV 0x1509
693 693 #define GL_INVERT 0x150A
694 694 #define GL_OR_REVERSE 0x150B
695 695 #define GL_COPY_INVERTED 0x150C
696 696 #define GL_OR_INVERTED 0x150D
697 697 #define GL_NAND 0x150E
698 698 #define GL_SET 0x150F
699 699
700 700 /* MapTarget */
701 701 /* GL_MAP1_COLOR_4 */
702 702 /* GL_MAP1_INDEX */
703 703 /* GL_MAP1_NORMAL */
704 704 /* GL_MAP1_TEXTURE_COORD_1 */
705 705 /* GL_MAP1_TEXTURE_COORD_2 */
706 706 /* GL_MAP1_TEXTURE_COORD_3 */
707 707 /* GL_MAP1_TEXTURE_COORD_4 */
708 708 /* GL_MAP1_VERTEX_3 */
709 709 /* GL_MAP1_VERTEX_4 */
710 710 /* GL_MAP2_COLOR_4 */
711 711 /* GL_MAP2_INDEX */
712 712 /* GL_MAP2_NORMAL */
713 713 /* GL_MAP2_TEXTURE_COORD_1 */
714 714 /* GL_MAP2_TEXTURE_COORD_2 */
715 715 /* GL_MAP2_TEXTURE_COORD_3 */
716 716 /* GL_MAP2_TEXTURE_COORD_4 */
717 717 /* GL_MAP2_VERTEX_3 */
718 718 /* GL_MAP2_VERTEX_4 */
719 719
720 720 /* MaterialFace */
721 721 /* GL_FRONT */
722 722 /* GL_BACK */
723 723 /* GL_FRONT_AND_BACK */
724 724
725 725 /* MaterialParameter */
726 726 #define GL_EMISSION 0x1600
727 727 #define GL_SHININESS 0x1601
728 728 #define GL_AMBIENT_AND_DIFFUSE 0x1602
729 729 #define GL_COLOR_INDEXES 0x1603
730 730 /* GL_AMBIENT */
731 731 /* GL_DIFFUSE */
732 732 /* GL_SPECULAR */
733 733
734 734 /* MatrixMode */
735 735 #define GL_MODELVIEW 0x1700
736 736 #define GL_PROJECTION 0x1701
737 737 #define GL_TEXTURE 0x1702
738 738
739 739 /* MeshMode1 */
740 740 /* GL_POINT */
741 741 /* GL_LINE */
742 742
743 743 /* MeshMode2 */
744 744 /* GL_POINT */
745 745 /* GL_LINE */
746 746 /* GL_FILL */
747 747
748 748 /* NormalPointerType */
749 749 /* GL_BYTE */
750 750 /* GL_SHORT */
751 751 /* GL_INT */
752 752 /* GL_FLOAT */
753 753 /* GL_DOUBLE */
754 754
755 755 /* PixelCopyType */
756 756 #define GL_COLOR 0x1800
757 757 #define GL_DEPTH 0x1801
758 758 #define GL_STENCIL 0x1802
759 759
760 760 /* PixelFormat */
761 761 #define GL_COLOR_INDEX 0x1900
762 762 #define GL_STENCIL_INDEX 0x1901
763 763 #define GL_DEPTH_COMPONENT 0x1902
764 764 #define GL_RED 0x1903
765 765 #define GL_GREEN 0x1904
766 766 #define GL_BLUE 0x1905
767 767 #define GL_ALPHA 0x1906
768 768 #define GL_RGB 0x1907
769 769 #define GL_RGBA 0x1908
770 770 #define GL_LUMINANCE 0x1909
771 771 #define GL_LUMINANCE_ALPHA 0x190A
772 772
773 773 /* PixelMap */
774 774 /* GL_PIXEL_MAP_I_TO_I */
775 775 /* GL_PIXEL_MAP_S_TO_S */
776 776 /* GL_PIXEL_MAP_I_TO_R */
777 777 /* GL_PIXEL_MAP_I_TO_G */
778 778 /* GL_PIXEL_MAP_I_TO_B */
779 779 /* GL_PIXEL_MAP_I_TO_A */
780 780 /* GL_PIXEL_MAP_R_TO_R */
781 781 /* GL_PIXEL_MAP_G_TO_G */
782 782 /* GL_PIXEL_MAP_B_TO_B */
783 783 /* GL_PIXEL_MAP_A_TO_A */
784 784
785 785 /* PixelStore */
786 786 /* GL_UNPACK_SWAP_BYTES */
787 787 /* GL_UNPACK_LSB_FIRST */
788 788 /* GL_UNPACK_ROW_LENGTH */
789 789 /* GL_UNPACK_SKIP_ROWS */
790 790 /* GL_UNPACK_SKIP_PIXELS */
791 791 /* GL_UNPACK_ALIGNMENT */
792 792 /* GL_PACK_SWAP_BYTES */
793 793 /* GL_PACK_LSB_FIRST */
794 794 /* GL_PACK_ROW_LENGTH */
795 795 /* GL_PACK_SKIP_ROWS */
796 796 /* GL_PACK_SKIP_PIXELS */
797 797 /* GL_PACK_ALIGNMENT */
798 798
799 799 /* PixelTransfer */
800 800 /* GL_MAP_COLOR */
801 801 /* GL_MAP_STENCIL */
802 802 /* GL_INDEX_SHIFT */
803 803 /* GL_INDEX_OFFSET */
804 804 /* GL_RED_SCALE */
805 805 /* GL_RED_BIAS */
806 806 /* GL_GREEN_SCALE */
807 807 /* GL_GREEN_BIAS */
808 808 /* GL_BLUE_SCALE */
809 809 /* GL_BLUE_BIAS */
810 810 /* GL_ALPHA_SCALE */
811 811 /* GL_ALPHA_BIAS */
812 812 /* GL_DEPTH_SCALE */
813 813 /* GL_DEPTH_BIAS */
814 814
815 815 /* PixelType */
816 816 #define GL_BITMAP 0x1A00
817 817 /* GL_BYTE */
818 818 /* GL_UNSIGNED_BYTE */
819 819 /* GL_SHORT */
820 820 /* GL_UNSIGNED_SHORT */
821 821 /* GL_INT */
822 822 /* GL_UNSIGNED_INT */
823 823 /* GL_FLOAT */
824 824
825 825 /* PolygonMode */
826 826 #define GL_POINT 0x1B00
827 827 #define GL_LINE 0x1B01
828 828 #define GL_FILL 0x1B02
829 829
830 830 /* ReadBufferMode */
831 831 /* GL_FRONT_LEFT */
832 832 /* GL_FRONT_RIGHT */
833 833 /* GL_BACK_LEFT */
834 834 /* GL_BACK_RIGHT */
835 835 /* GL_FRONT */
836 836 /* GL_BACK */
837 837 /* GL_LEFT */
838 838 /* GL_RIGHT */
839 839 /* GL_AUX0 */
840 840 /* GL_AUX1 */
841 841 /* GL_AUX2 */
842 842 /* GL_AUX3 */
843 843
844 844 /* RenderingMode */
845 845 #define GL_RENDER 0x1C00
846 846 #define GL_FEEDBACK 0x1C01
847 847 #define GL_SELECT 0x1C02
848 848
849 849 /* ShadingModel */
850 850 #define GL_FLAT 0x1D00
851 851 #define GL_SMOOTH 0x1D01
852 852
853 853
854 854 /* StencilFunction */
855 855 /* GL_NEVER */
856 856 /* GL_LESS */
857 857 /* GL_EQUAL */
858 858 /* GL_LEQUAL */
859 859 /* GL_GREATER */
860 860 /* GL_NOTEQUAL */
861 861 /* GL_GEQUAL */
862 862 /* GL_ALWAYS */
863 863
864 864 /* StencilOp */
865 865 /* GL_ZERO */
866 866 #define GL_KEEP 0x1E00
867 867 #define GL_REPLACE 0x1E01
868 868 #define GL_INCR 0x1E02
869 869 #define GL_DECR 0x1E03
870 870 /* GL_INVERT */
871 871
872 872 /* StringName */
873 873 #define GL_VENDOR 0x1F00
874 874 #define GL_RENDERER 0x1F01
875 875 #define GL_VERSION 0x1F02
876 876 #define GL_EXTENSIONS 0x1F03
877 877
878 878 /* TextureCoordName */
879 879 #define GL_S 0x2000
880 880 #define GL_T 0x2001
881 881 #define GL_R 0x2002
882 882 #define GL_Q 0x2003
883 883
884 884 /* TexCoordPointerType */
885 885 /* GL_SHORT */
886 886 /* GL_INT */
887 887 /* GL_FLOAT */
888 888 /* GL_DOUBLE */
889 889
890 890 /* TextureEnvMode */
891 891 #define GL_MODULATE 0x2100
892 892 #define GL_DECAL 0x2101
893 893 /* GL_BLEND */
894 894 /* GL_REPLACE */
895 895
896 896 /* TextureEnvParameter */
897 897 #define GL_TEXTURE_ENV_MODE 0x2200
898 898 #define GL_TEXTURE_ENV_COLOR 0x2201
899 899
900 900 /* TextureEnvTarget */
901 901 #define GL_TEXTURE_ENV 0x2300
902 902
903 903 /* TextureGenMode */
904 904 #define GL_EYE_LINEAR 0x2400
905 905 #define GL_OBJECT_LINEAR 0x2401
906 906 #define GL_SPHERE_MAP 0x2402
907 907
908 908 /* TextureGenParameter */
909 909 #define GL_TEXTURE_GEN_MODE 0x2500
910 910 #define GL_OBJECT_PLANE 0x2501
911 911 #define GL_EYE_PLANE 0x2502
912 912
913 913 /* TextureMagFilter */
914 914 #define GL_NEAREST 0x2600
915 915 #define GL_LINEAR 0x2601
916 916
917 917 /* TextureMinFilter */
918 918 /* GL_NEAREST */
919 919 /* GL_LINEAR */
920 920 #define GL_NEAREST_MIPMAP_NEAREST 0x2700
921 921 #define GL_LINEAR_MIPMAP_NEAREST 0x2701
922 922 #define GL_NEAREST_MIPMAP_LINEAR 0x2702
923 923 #define GL_LINEAR_MIPMAP_LINEAR 0x2703
924 924
925 925 /* TextureParameterName */
926 926 #define GL_TEXTURE_MAG_FILTER 0x2800
927 927 #define GL_TEXTURE_MIN_FILTER 0x2801
928 928 #define GL_TEXTURE_WRAP_S 0x2802
929 929 #define GL_TEXTURE_WRAP_T 0x2803
930 930 /* GL_TEXTURE_BORDER_COLOR */
931 931 /* GL_TEXTURE_PRIORITY */
932 932
933 933 /* TextureTarget */
934 934 /* GL_TEXTURE_1D */
935 935 /* GL_TEXTURE_2D */
936 936 /* GL_PROXY_TEXTURE_1D */
937 937 /* GL_PROXY_TEXTURE_2D */
938 938
939 939 /* TextureWrapMode */
940 940 #define GL_CLAMP 0x2900
941 941 #define GL_REPEAT 0x2901
942 942
943 943 /* VertexPointerType */
944 944 /* GL_SHORT */
945 945 /* GL_INT */
946 946 /* GL_FLOAT */
947 947 /* GL_DOUBLE */
948 948
949 949 /* ClientAttribMask */
950 950 #define GL_CLIENT_PIXEL_STORE_BIT 0x00000001
951 951 #define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002
952 952 #define GL_CLIENT_ALL_ATTRIB_BITS 0xffffffff
953 953
954 954 /* polygon_offset */
955 955 #define GL_POLYGON_OFFSET_FACTOR 0x8038
956 956 #define GL_POLYGON_OFFSET_UNITS 0x2A00
957 957 #define GL_POLYGON_OFFSET_POINT 0x2A01
958 958 #define GL_POLYGON_OFFSET_LINE 0x2A02
959 959 #define GL_POLYGON_OFFSET_FILL 0x8037
960 960
961 961 /* texture */
962 962 #define GL_ALPHA4 0x803B
963 963 #define GL_ALPHA8 0x803C
964 964 #define GL_ALPHA12 0x803D
965 965 #define GL_ALPHA16 0x803E
966 966 #define GL_LUMINANCE4 0x803F
967 967 #define GL_LUMINANCE8 0x8040
968 968 #define GL_LUMINANCE12 0x8041
969 969 #define GL_LUMINANCE16 0x8042
970 970 #define GL_LUMINANCE4_ALPHA4 0x8043
971 971 #define GL_LUMINANCE6_ALPHA2 0x8044
972 972 #define GL_LUMINANCE8_ALPHA8 0x8045
973 973 #define GL_LUMINANCE12_ALPHA4 0x8046
974 974 #define GL_LUMINANCE12_ALPHA12 0x8047
975 975 #define GL_LUMINANCE16_ALPHA16 0x8048
976 976 #define GL_INTENSITY 0x8049
977 977 #define GL_INTENSITY4 0x804A
978 978 #define GL_INTENSITY8 0x804B
979 979 #define GL_INTENSITY12 0x804C
980 980 #define GL_INTENSITY16 0x804D
981 981 #define GL_R3_G3_B2 0x2A10
982 982 #define GL_RGB4 0x804F
983 983 #define GL_RGB5 0x8050
984 984 #define GL_RGB8 0x8051
985 985 #define GL_RGB10 0x8052
986 986 #define GL_RGB12 0x8053
987 987 #define GL_RGB16 0x8054
988 988 #define GL_RGBA2 0x8055
989 989 #define GL_RGBA4 0x8056
990 990 #define GL_RGB5_A1 0x8057
991 991 #define GL_RGBA8 0x8058
992 992 #define GL_RGB10_A2 0x8059
993 993 #define GL_RGBA12 0x805A
994 994 #define GL_RGBA16 0x805B
995 995 #define GL_TEXTURE_RED_SIZE 0x805C
996 996 #define GL_TEXTURE_GREEN_SIZE 0x805D
997 997 #define GL_TEXTURE_BLUE_SIZE 0x805E
998 998 #define GL_TEXTURE_ALPHA_SIZE 0x805F
999 999 #define GL_TEXTURE_LUMINANCE_SIZE 0x8060
1000 1000 #define GL_TEXTURE_INTENSITY_SIZE 0x8061
1001 1001 #define GL_PROXY_TEXTURE_1D 0x8063
1002 1002 #define GL_PROXY_TEXTURE_2D 0x8064
1003 1003
1004 1004 /* texture_object */
1005 1005 #define GL_TEXTURE_PRIORITY 0x8066
1006 1006 #define GL_TEXTURE_RESIDENT 0x8067
1007 1007 #define GL_TEXTURE_BINDING_1D 0x8068
1008 1008 #define GL_TEXTURE_BINDING_2D 0x8069
1009 1009
1010 1010 /* vertex_array */
1011 1011 #define GL_VERTEX_ARRAY 0x8074
1012 1012 #define GL_NORMAL_ARRAY 0x8075
1013 1013 #define GL_COLOR_ARRAY 0x8076
1014 1014 #define GL_INDEX_ARRAY 0x8077
1015 1015 #define GL_TEXTURE_COORD_ARRAY 0x8078
1016 1016 #define GL_EDGE_FLAG_ARRAY 0x8079
1017 1017 #define GL_VERTEX_ARRAY_SIZE 0x807A
1018 1018 #define GL_VERTEX_ARRAY_TYPE 0x807B
1019 1019 #define GL_VERTEX_ARRAY_STRIDE 0x807C
1020 1020 #define GL_NORMAL_ARRAY_TYPE 0x807E
1021 1021 #define GL_NORMAL_ARRAY_STRIDE 0x807F
1022 1022 #define GL_COLOR_ARRAY_SIZE 0x8081
1023 1023 #define GL_COLOR_ARRAY_TYPE 0x8082
1024 1024 #define GL_COLOR_ARRAY_STRIDE 0x8083
1025 1025 #define GL_INDEX_ARRAY_TYPE 0x8085
1026 1026 #define GL_INDEX_ARRAY_STRIDE 0x8086
1027 1027 #define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088
1028 1028 #define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089
1029 1029 #define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A
1030 1030 #define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C
1031 1031 #define GL_VERTEX_ARRAY_POINTER 0x808E
1032 1032 #define GL_NORMAL_ARRAY_POINTER 0x808F
1033 1033 #define GL_COLOR_ARRAY_POINTER 0x8090
1034 1034 #define GL_INDEX_ARRAY_POINTER 0x8091
1035 1035 #define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092
1036 1036 #define GL_EDGE_FLAG_ARRAY_POINTER 0x8093
1037 1037 #define GL_V2F 0x2A20
1038 1038 #define GL_V3F 0x2A21
1039 1039 #define GL_C4UB_V2F 0x2A22
1040 1040 #define GL_C4UB_V3F 0x2A23
1041 1041 #define GL_C3F_V3F 0x2A24
1042 1042 #define GL_N3F_V3F 0x2A25
1043 1043 #define GL_C4F_N3F_V3F 0x2A26
1044 1044 #define GL_T2F_V3F 0x2A27
1045 1045 #define GL_T4F_V4F 0x2A28
1046 1046 #define GL_T2F_C4UB_V3F 0x2A29
1047 1047 #define GL_T2F_C3F_V3F 0x2A2A
1048 1048 #define GL_T2F_N3F_V3F 0x2A2B
1049 1049 #define GL_T2F_C4F_N3F_V3F 0x2A2C
1050 1050 #define GL_T4F_C4F_N3F_V4F 0x2A2D
1051 1051
1052 1052 /* Extensions */
1053 1053 #define GL_EXT_vertex_array 1
1054 1054 #define GL_EXT_bgra 1
1055 1055 #define GL_EXT_paletted_texture 1
1056 1056 #define GL_WIN_swap_hint 1
1057 1057 #define GL_WIN_draw_range_elements 1
1058 1058 // #define GL_WIN_phong_shading 1
1059 1059 // #define GL_WIN_specular_fog 1
1060 1060
1061 1061 /* EXT_vertex_array */
1062 1062 #define GL_VERTEX_ARRAY_EXT 0x8074
1063 1063 #define GL_NORMAL_ARRAY_EXT 0x8075
1064 1064 #define GL_COLOR_ARRAY_EXT 0x8076
1065 1065 #define GL_INDEX_ARRAY_EXT 0x8077
1066 1066 #define GL_TEXTURE_COORD_ARRAY_EXT 0x8078
1067 1067 #define GL_EDGE_FLAG_ARRAY_EXT 0x8079
1068 1068 #define GL_VERTEX_ARRAY_SIZE_EXT 0x807A
1069 1069 #define GL_VERTEX_ARRAY_TYPE_EXT 0x807B
1070 1070 #define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C
1071 1071 #define GL_VERTEX_ARRAY_COUNT_EXT 0x807D
1072 1072 #define GL_NORMAL_ARRAY_TYPE_EXT 0x807E
1073 1073 #define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F
1074 1074 #define GL_NORMAL_ARRAY_COUNT_EXT 0x8080
1075 1075 #define GL_COLOR_ARRAY_SIZE_EXT 0x8081
1076 1076 #define GL_COLOR_ARRAY_TYPE_EXT 0x8082
1077 1077 #define GL_COLOR_ARRAY_STRIDE_EXT 0x8083
1078 1078 #define GL_COLOR_ARRAY_COUNT_EXT 0x8084
1079 1079 #define GL_INDEX_ARRAY_TYPE_EXT 0x8085
1080 1080 #define GL_INDEX_ARRAY_STRIDE_EXT 0x8086
1081 1081 #define GL_INDEX_ARRAY_COUNT_EXT 0x8087
1082 1082 #define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088
1083 1083 #define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089
1084 1084 #define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A
1085 1085 #define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B
1086 1086 #define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C
1087 1087 #define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D
1088 1088 #define GL_VERTEX_ARRAY_POINTER_EXT 0x808E
1089 1089 #define GL_NORMAL_ARRAY_POINTER_EXT 0x808F
1090 1090 #define GL_COLOR_ARRAY_POINTER_EXT 0x8090
1091 1091 #define GL_INDEX_ARRAY_POINTER_EXT 0x8091
1092 1092 #define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092
1093 1093 #define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093
1094 1094 #define GL_DOUBLE_EXT GL_DOUBLE
1095 1095
1096 1096 /* EXT_bgra */
1097 1097 #define GL_BGR_EXT 0x80E0
1098 1098 #define GL_BGRA_EXT 0x80E1
1099 1099
1100 1100 /* EXT_paletted_texture */
1101 1101
1102 1102 /* These must match the GL_COLOR_TABLE_*_SGI enumerants */
1103 1103 #define GL_COLOR_TABLE_FORMAT_EXT 0x80D8
1104 1104 #define GL_COLOR_TABLE_WIDTH_EXT 0x80D9
1105 1105 #define GL_COLOR_TABLE_RED_SIZE_EXT 0x80DA
1106 1106 #define GL_COLOR_TABLE_GREEN_SIZE_EXT 0x80DB
1107 1107 #define GL_COLOR_TABLE_BLUE_SIZE_EXT 0x80DC
1108 1108 #define GL_COLOR_TABLE_ALPHA_SIZE_EXT 0x80DD
1109 1109 #define GL_COLOR_TABLE_LUMINANCE_SIZE_EXT 0x80DE
1110 1110 #define GL_COLOR_TABLE_INTENSITY_SIZE_EXT 0x80DF
1111 1111
1112 1112 #define GL_COLOR_INDEX1_EXT 0x80E2
1113 1113 #define GL_COLOR_INDEX2_EXT 0x80E3
1114 1114 #define GL_COLOR_INDEX4_EXT 0x80E4
1115 1115 #define GL_COLOR_INDEX8_EXT 0x80E5
1116 1116 #define GL_COLOR_INDEX12_EXT 0x80E6
1117 1117 #define GL_COLOR_INDEX16_EXT 0x80E7
1118 1118
1119 1119 /* WIN_draw_range_elements */
1120 1120 #define GL_MAX_ELEMENTS_VERTICES_WIN 0x80E8
1121 1121 #define GL_MAX_ELEMENTS_INDICES_WIN 0x80E9
1122 1122
1123 1123 /* WIN_phong_shading */
1124 1124 #define GL_PHONG_WIN 0x80EA
1125 1125 #define GL_PHONG_HINT_WIN 0x80EB
1126 1126
1127 1127 /* WIN_specular_fog */
1128 1128 #define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC
1129 1129
1130 1130 /* For compatibility with OpenGL v1.0 */
1131 1131 #define GL_LOGIC_OP GL_INDEX_LOGIC_OP
1132 1132 #define GL_TEXTURE_COMPONENTS GL_TEXTURE_INTERNAL_FORMAT
1133 1133 #include <QtOpenGL/QtOpenGL>
1134 1134 #endif // QT_NO_OPENGL
@@ -1,109 +1,111
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 4 **
5 5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 6 **
7 7 ** This file may be used under the terms of the GNU General Public
8 8 ** License version 2.0 as published by the Free Software Foundation
9 9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 10 ** this file. Please review the following information to ensure GNU
11 11 ** General Public Licensing requirements will be met:
12 12 ** http://www.trolltech.com/products/qt/opensource.html
13 13 **
14 14 ** If you are unsure which license is appropriate for your use, please
15 15 ** review the following information:
16 16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 17 ** sales department at sales@trolltech.com.
18 18 **
19 19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 21 **
22 22 ****************************************************************************/
23 23
24 24 #include "setupgenerator.h"
25 25 #include "classgenerator.h"
26 26 #include "reporthandler.h"
27 27 #include "fileout.h"
28 28
29 29 //#define Q_SCRIPT_LAZY_GENERATOR
30 30
31 31 void SetupGenerator::addClass(const AbstractMetaClass *cls)
32 32 {
33 33 packHash[cls->package()].append(cls);
34 34 }
35 35
36 36 void writeQtScriptQtBindingsLicense(QTextStream &stream);
37 37
38 38 void maybeDeclareMetaType(QTextStream &stream, const QString &typeName,
39 39 QSet<QString> &registeredTypeNames);
40 40 bool hasDefaultConstructor(const AbstractMetaClass *meta_class);
41 41
42 42 void SetupGenerator::generate()
43 43 {
44 44 QHashIterator<QString, QList<const AbstractMetaClass*> > pack(packHash);
45 45 while (pack.hasNext()) {
46 46 pack.next();
47 47 QList<const AbstractMetaClass*> list = pack.value();
48 48 if (list.isEmpty())
49 49 continue;
50 50
51 QString packKey = pack.key();
51 52 QString packName = pack.key();
52 53 QStringList components = packName.split(".");
53 54 if ((components.size() > 2) && (components.at(0) == "com")
54 55 && (components.at(1) == "trolltech")) {
55 56 // kill com.trolltech in key
56 57 components.removeAt(0);
57 58 components.removeAt(0);
58 59 }
59 60 packName.replace(".", "_");
61 packKey.replace(".", "_");
60 62
61 63 QString shortPackName;
62 64 foreach (QString comp, components) {
63 65 comp[0] = comp[0].toUpper();
64 66 shortPackName += comp;
65 67 }
66 68 // add missing camel case (workaround..)
67 69 if (shortPackName == "QtWebkit") {
68 70 shortPackName = "QtWebKit";
69 71 } else if (shortPackName == "QtXmlpatterns") {
70 72 shortPackName = "QtXmlPatterns";
71 73 } else if (shortPackName == "QtOpengl") {
72 74 shortPackName = "QtOpenGL";
73 75 }
74 76
75 77
76 78 {
77 FileOut initFile(m_out_dir + "/generated_cpp/" + packName + "/init.cpp");
79 FileOut initFile(m_out_dir + "/generated_cpp/" + packName + "/" + packKey + "_init.cpp");
78 80 QTextStream &s = initFile.stream;
79 81
80 82 if (FileOut::license)
81 83 writeQtScriptQtBindingsLicense(s);
82 84
83 85 s << "#include <PythonQt.h>" << endl;
84 86
85 87 foreach (const AbstractMetaClass *cls, list) {
86 88 s << "#include \"PythonQtWrapper_" << cls->name() << ".h\"" << endl;
87 89 }
88 90 s << endl;
89 91
90 92 // declare individual class creation functions
91 93 s << "void PythonQt_init_" << shortPackName << "() {" << endl;
92 94 QStringList cppClassNames;
93 95 foreach (const AbstractMetaClass *cls, list) {
94 96 if (ClassGenerator::isBuiltIn(cls->name())) { continue; }
95 97
96 98 if (cls->isQObject()) {
97 99 s << "PythonQt::self()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">);" << endl;
98 100 } else {
99 101 QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():"";
100 102 s << "PythonQt::self()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << shortPackName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">);" << endl;
101 103 }
102 104 }
103 105 s << endl;
104 106
105 107 s << "}";
106 108 s << endl;
107 109 }
108 110 }
109 111 }
1 NO CONTENT: file was removed, binary diff hidden
General Comments 0
You need to be logged in to leave comments. Login now