##// END OF EJS Templates
fixed some badly generated fields...
florianlink -
r118:94fe64ed981d
parent child
Show More
@@ -1,306 +1,310
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
6 **
7 ** This file is part of the Qt Script Generator project on Qt Labs.
7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 **
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
14 ** this package.
15 **
15 **
16 ** GNU Lesser General Public License Usage
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
27 **
28 ** If you have questions regarding the use of this file, please contact
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
29 ** Nokia at qt-info@nokia.com.
30 **
30 **
31 **
31 **
32 **
32 **
33 **
33 **
34 **
34 **
35 **
35 **
36 **
36 **
37 **
37 **
38 ** $QT_END_LICENSE$
38 ** $QT_END_LICENSE$
39 **
39 **
40 ****************************************************************************/
40 ****************************************************************************/
41
41
42 #include "shellheadergenerator.h"
42 #include "shellheadergenerator.h"
43 #include "fileout.h"
43 #include "fileout.h"
44
44
45 #include <QtCore/QDir>
45 #include <QtCore/QDir>
46
46
47 #include <qdebug.h>
47 #include <qdebug.h>
48
48
49 QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
49 QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
50 {
50 {
51 return QString("PythonQtWrapper_%1.h").arg(meta_class->name());
51 return QString("PythonQtWrapper_%1.h").arg(meta_class->name());
52 }
52 }
53
53
54
54
55 void ShellHeaderGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *field)
55 void ShellHeaderGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *field)
56 {
56 {
57 const AbstractMetaFunction *setter = field->setter();
57 const AbstractMetaFunction *setter = field->setter();
58 const AbstractMetaFunction *getter = field->getter();
58 const AbstractMetaFunction *getter = field->getter();
59
59
60 // Uuid data4 did not work
60 // static fields are not supported (yet?)
61 if (setter->isStatic()) return;
62
63 // Uuid data4 did not work (TODO: move to typesystem...(
61 if (field->enclosingClass()->name()=="QUuid" && setter->name()=="data4") return;
64 if (field->enclosingClass()->name()=="QUuid" && setter->name()=="data4") return;
62
65 if (field->enclosingClass()->name()=="QIPv6Address") return;
66
63 if (!field->type()->isConstant()) {
67 if (!field->type()->isConstant()) {
64 writeFunctionSignature(s, setter, 0, QString(),
68 writeFunctionSignature(s, setter, 0, QString(),
65 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | ShowStatic | UnderscoreSpaces));
69 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | ShowStatic | UnderscoreSpaces));
66 s << "{ theWrappedObject->" << field->name() << " = " << setter->arguments()[0]->argumentName() << "; }\n";
70 s << "{ theWrappedObject->" << field->name() << " = " << setter->arguments()[0]->argumentName() << "; }\n";
67 }
71 }
68
72
69 writeFunctionSignature(s, getter, 0, QString(),
73 writeFunctionSignature(s, getter, 0, QString(),
70 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
74 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
71 s << "{ return theWrappedObject->" << field->name() << "; }\n";
75 s << "{ return theWrappedObject->" << field->name() << "; }\n";
72 }
76 }
73
77
74 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
78 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
75 {
79 {
76 QString builtIn = ShellGenerator::isBuiltIn(meta_class->name())?"_builtin":"";
80 QString builtIn = ShellGenerator::isBuiltIn(meta_class->name())?"_builtin":"";
77 QString pro_file_name = meta_class->package().replace(".", "_") + builtIn + "/" + meta_class->package().replace(".", "_") + builtIn + ".pri";
81 QString pro_file_name = meta_class->package().replace(".", "_") + builtIn + "/" + meta_class->package().replace(".", "_") + builtIn + ".pri";
78 priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class));
82 priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class));
79 setupGenerator->addClass(meta_class->package().replace(".", "_") + builtIn, meta_class);
83 setupGenerator->addClass(meta_class->package().replace(".", "_") + builtIn, meta_class);
80
84
81 QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H";
85 QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H";
82
86
83 s << "#ifndef " << include_block << endl
87 s << "#ifndef " << include_block << endl
84 << "#define " << include_block << endl << endl;
88 << "#define " << include_block << endl << endl;
85
89
86 Include inc = meta_class->typeEntry()->include();
90 Include inc = meta_class->typeEntry()->include();
87 ShellGenerator::writeInclude(s, inc);
91 ShellGenerator::writeInclude(s, inc);
88
92
89 s << "#include <QObject>" << endl << endl;
93 s << "#include <QObject>" << endl << endl;
90 s << "#include <PythonQt.h>" << endl << endl;
94 s << "#include <PythonQt.h>" << endl << endl;
91
95
92 IncludeList list = meta_class->typeEntry()->extraIncludes();
96 IncludeList list = meta_class->typeEntry()->extraIncludes();
93 qSort(list.begin(), list.end());
97 qSort(list.begin(), list.end());
94 foreach (const Include &inc, list) {
98 foreach (const Include &inc, list) {
95 ShellGenerator::writeInclude(s, inc);
99 ShellGenerator::writeInclude(s, inc);
96 }
100 }
97 s << endl;
101 s << endl;
98
102
99 AbstractMetaFunctionList ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors
103 AbstractMetaFunctionList ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors
100 | AbstractMetaClass::WasVisible
104 | AbstractMetaClass::WasVisible
101 | AbstractMetaClass::NotRemovedFromTargetLang);
105 | AbstractMetaClass::NotRemovedFromTargetLang);
102
106
103 // Shell-------------------------------------------------------------------
107 // Shell-------------------------------------------------------------------
104 if (meta_class->generateShellClass()) {
108 if (meta_class->generateShellClass()) {
105
109
106 AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class);
110 AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class);
107
111
108 s << "class " << shellClassName(meta_class)
112 s << "class " << shellClassName(meta_class)
109 << " : public " << meta_class->qualifiedCppName() << endl << "{" << endl;
113 << " : public " << meta_class->qualifiedCppName() << endl << "{" << endl;
110 s << "public:" << endl;
114 s << "public:" << endl;
111 foreach(AbstractMetaFunction* fun, ctors) {
115 foreach(AbstractMetaFunction* fun, ctors) {
112 s << " ";
116 s << " ";
113 writeFunctionSignature(s, fun, 0,"PythonQtShell_",
117 writeFunctionSignature(s, fun, 0,"PythonQtShell_",
114 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
118 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
115 s << ":" << meta_class->qualifiedCppName() << "(";
119 s << ":" << meta_class->qualifiedCppName() << "(";
116 QString scriptFunctionName = fun->originalName();
120 QString scriptFunctionName = fun->originalName();
117 AbstractMetaArgumentList args = fun->arguments();
121 AbstractMetaArgumentList args = fun->arguments();
118 for (int i = 0; i < args.size(); ++i) {
122 for (int i = 0; i < args.size(); ++i) {
119 if (i > 0)
123 if (i > 0)
120 s << ", ";
124 s << ", ";
121 s << args.at(i)->argumentName();
125 s << args.at(i)->argumentName();
122 }
126 }
123 s << "),_wrapper(NULL) {};" << endl;
127 s << "),_wrapper(NULL) {};" << endl;
124 }
128 }
125 s << endl;
129 s << endl;
126
130
127 foreach(AbstractMetaFunction* fun, virtualsForShell) {
131 foreach(AbstractMetaFunction* fun, virtualsForShell) {
128 s << "virtual ";
132 s << "virtual ";
129 writeFunctionSignature(s, fun, 0, QString(),
133 writeFunctionSignature(s, fun, 0, QString(),
130 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
134 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
131 s << ";" << endl;
135 s << ";" << endl;
132 }
136 }
133 s << endl;
137 s << endl;
134 s << " PythonQtInstanceWrapper* _wrapper; " << endl;
138 s << " PythonQtInstanceWrapper* _wrapper; " << endl;
135
139
136 s << "};" << endl << endl;
140 s << "};" << endl << endl;
137 }
141 }
138
142
139 // Promoter-------------------------------------------------------------------
143 // Promoter-------------------------------------------------------------------
140 AbstractMetaFunctionList promoteFunctions = getProtectedFunctionsThatNeedPromotion(meta_class);
144 AbstractMetaFunctionList promoteFunctions = getProtectedFunctionsThatNeedPromotion(meta_class);
141 if (!promoteFunctions.isEmpty()) {
145 if (!promoteFunctions.isEmpty()) {
142 s << "class " << promoterClassName(meta_class)
146 s << "class " << promoterClassName(meta_class)
143 << " : public " << meta_class->qualifiedCppName() << endl << "{ public:" << endl;
147 << " : public " << meta_class->qualifiedCppName() << endl << "{ public:" << endl;
144
148
145 foreach(AbstractMetaFunction* fun, promoteFunctions) {
149 foreach(AbstractMetaFunction* fun, promoteFunctions) {
146 s << "inline ";
150 s << "inline ";
147 writeFunctionSignature(s, fun, 0, "promoted_",
151 writeFunctionSignature(s, fun, 0, "promoted_",
148 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
152 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
149 s << " { ";
153 s << " { ";
150 QString scriptFunctionName = fun->originalName();
154 QString scriptFunctionName = fun->originalName();
151 AbstractMetaArgumentList args = fun->arguments();
155 AbstractMetaArgumentList args = fun->arguments();
152 if (fun->type())
156 if (fun->type())
153 s << "return ";
157 s << "return ";
154 s << meta_class->qualifiedCppName() << "::";
158 s << meta_class->qualifiedCppName() << "::";
155 s << fun->originalName() << "(";
159 s << fun->originalName() << "(";
156 for (int i = 0; i < args.size(); ++i) {
160 for (int i = 0; i < args.size(); ++i) {
157 if (i > 0)
161 if (i > 0)
158 s << ", ";
162 s << ", ";
159 s << args.at(i)->argumentName();
163 s << args.at(i)->argumentName();
160 }
164 }
161 s << "); }" << endl;
165 s << "); }" << endl;
162 }
166 }
163
167
164 s << "};" << endl << endl;
168 s << "};" << endl << endl;
165 }
169 }
166
170
167 // Wrapper-------------------------------------------------------------------
171 // Wrapper-------------------------------------------------------------------
168
172
169 s << "class " << wrapperClassName(meta_class)
173 s << "class " << wrapperClassName(meta_class)
170 << " : public QObject" << endl
174 << " : public QObject" << endl
171 << "{ Q_OBJECT" << endl;
175 << "{ Q_OBJECT" << endl;
172
176
173 s << "public:" << endl;
177 s << "public:" << endl;
174
178
175 AbstractMetaEnumList enums1 = meta_class->enums();
179 AbstractMetaEnumList enums1 = meta_class->enums();
176 AbstractMetaEnumList enums;
180 AbstractMetaEnumList enums;
177 QList<FlagsTypeEntry*> flags;
181 QList<FlagsTypeEntry*> flags;
178 foreach(AbstractMetaEnum* enum1, enums1) {
182 foreach(AbstractMetaEnum* enum1, enums1) {
179 // catch gadgets and enums that are not exported on QObjects...
183 // catch gadgets and enums that are not exported on QObjects...
180 if (enum1->wasPublic() && (!meta_class->isQObject() || !enum1->hasQEnumsDeclaration())) {
184 if (enum1->wasPublic() && (!meta_class->isQObject() || !enum1->hasQEnumsDeclaration())) {
181 enums << enum1;
185 enums << enum1;
182 if (enum1->typeEntry()->flags()) {
186 if (enum1->typeEntry()->flags()) {
183 flags << enum1->typeEntry()->flags();
187 flags << enum1->typeEntry()->flags();
184 }
188 }
185 }
189 }
186 }
190 }
187 if (enums.count()) {
191 if (enums.count()) {
188 s << "Q_ENUMS(";
192 s << "Q_ENUMS(";
189 foreach(AbstractMetaEnum* enum1, enums) {
193 foreach(AbstractMetaEnum* enum1, enums) {
190 s << enum1->name() << " ";
194 s << enum1->name() << " ";
191 }
195 }
192 s << ")" << endl;
196 s << ")" << endl;
193
197
194 if (flags.count()) {
198 if (flags.count()) {
195 s << "Q_FLAGS(";
199 s << "Q_FLAGS(";
196 foreach(FlagsTypeEntry* flag1, flags) {
200 foreach(FlagsTypeEntry* flag1, flags) {
197 QString origName = flag1->originalName();
201 QString origName = flag1->originalName();
198 int idx = origName.lastIndexOf("::");
202 int idx = origName.lastIndexOf("::");
199 if (idx!= -1) {
203 if (idx!= -1) {
200 origName = origName.mid(idx+2);
204 origName = origName.mid(idx+2);
201 }
205 }
202 s << origName << " ";
206 s << origName << " ";
203 }
207 }
204 s << ")" << endl;
208 s << ")" << endl;
205 }
209 }
206
210
207 foreach(AbstractMetaEnum* enum1, enums) {
211 foreach(AbstractMetaEnum* enum1, enums) {
208 s << "enum " << enum1->name() << "{" << endl;
212 s << "enum " << enum1->name() << "{" << endl;
209 bool first = true;
213 bool first = true;
210 foreach(AbstractMetaEnumValue* value, enum1->values()) {
214 foreach(AbstractMetaEnumValue* value, enum1->values()) {
211 if (first) { first = false; }
215 if (first) { first = false; }
212 else { s << ", "; }
216 else { s << ", "; }
213 s << " " << value->name() << " = " << meta_class->qualifiedCppName() << "::" << value->name();
217 s << " " << value->name() << " = " << meta_class->qualifiedCppName() << "::" << value->name();
214 }
218 }
215 s << "};" << endl;
219 s << "};" << endl;
216 }
220 }
217 if (flags.count()) {
221 if (flags.count()) {
218 foreach(AbstractMetaEnum* enum1, enums) {
222 foreach(AbstractMetaEnum* enum1, enums) {
219 if (enum1->typeEntry()->flags()) {
223 if (enum1->typeEntry()->flags()) {
220 QString origName = enum1->typeEntry()->flags()->originalName();
224 QString origName = enum1->typeEntry()->flags()->originalName();
221 int idx = origName.lastIndexOf("::");
225 int idx = origName.lastIndexOf("::");
222 if (idx!= -1) {
226 if (idx!= -1) {
223 origName = origName.mid(idx+2);
227 origName = origName.mid(idx+2);
224 }
228 }
225 s << "Q_DECLARE_FLAGS("<< origName << ", " << enum1->name() <<")"<<endl;
229 s << "Q_DECLARE_FLAGS("<< origName << ", " << enum1->name() <<")"<<endl;
226 }
230 }
227 }
231 }
228 }
232 }
229 }
233 }
230 s << "public slots:" << endl;
234 s << "public slots:" << endl;
231 if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
235 if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
232
236
233 bool copyConstructorSeen = false;
237 bool copyConstructorSeen = false;
234 bool defaultConstructorSeen = false;
238 bool defaultConstructorSeen = false;
235 foreach (const AbstractMetaFunction *fun, ctors) {
239 foreach (const AbstractMetaFunction *fun, ctors) {
236 if (!fun->isPublic() || fun->isAbstract()) { continue; }
240 if (!fun->isPublic() || fun->isAbstract()) { continue; }
237 s << meta_class->qualifiedCppName() << "* ";
241 s << meta_class->qualifiedCppName() << "* ";
238 writeFunctionSignature(s, fun, 0, "new_",
242 writeFunctionSignature(s, fun, 0, "new_",
239 Option(IncludeDefaultExpression | OriginalName | ShowStatic));
243 Option(IncludeDefaultExpression | OriginalName | ShowStatic));
240 s << ";" << endl;
244 s << ";" << endl;
241 if (fun->arguments().size()==1 && meta_class->qualifiedCppName() == fun->arguments().at(0)->type()->typeEntry()->qualifiedCppName()) {
245 if (fun->arguments().size()==1 && meta_class->qualifiedCppName() == fun->arguments().at(0)->type()->typeEntry()->qualifiedCppName()) {
242 copyConstructorSeen = true;
246 copyConstructorSeen = true;
243 }
247 }
244 if (fun->arguments().size()==0) {
248 if (fun->arguments().size()==0) {
245 defaultConstructorSeen = true;
249 defaultConstructorSeen = true;
246 }
250 }
247 }
251 }
248
252
249 if (meta_class->typeEntry()->isValue()
253 if (meta_class->typeEntry()->isValue()
250 && !copyConstructorSeen && defaultConstructorSeen) {
254 && !copyConstructorSeen && defaultConstructorSeen) {
251 QString className = meta_class->generateShellClass()?shellClassName(meta_class):meta_class->qualifiedCppName();
255 QString className = meta_class->generateShellClass()?shellClassName(meta_class):meta_class->qualifiedCppName();
252 s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const " << meta_class->qualifiedCppName() << "& other) {" << endl;
256 s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const " << meta_class->qualifiedCppName() << "& other) {" << endl;
253 s << className << "* a = new " << className << "();" << endl;
257 s << className << "* a = new " << className << "();" << endl;
254 s << "*((" << meta_class->qualifiedCppName() << "*)a) = other;" << endl;
258 s << "*((" << meta_class->qualifiedCppName() << "*)a) = other;" << endl;
255 s << "return a; }" << endl;
259 s << "return a; }" << endl;
256 }
260 }
257 }
261 }
258 if (meta_class->hasPublicDestructor() && !meta_class->isNamespace()) {
262 if (meta_class->hasPublicDestructor() && !meta_class->isNamespace()) {
259 s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } ";
263 s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } ";
260 s << endl;
264 s << endl;
261 }
265 }
262 if (meta_class->name()=="QTreeWidgetItem") {
266 if (meta_class->name()=="QTreeWidgetItem") {
263 s << "bool py_hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; }" << endl;
267 s << "bool py_hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; }" << endl;
264 } else if (meta_class->name()=="QGraphicsItem") {
268 } else if (meta_class->name()=="QGraphicsItem") {
265 s << "bool py_hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; }" << endl;
269 s << "bool py_hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; }" << endl;
266 }
270 }
267
271
268 AbstractMetaFunctionList functions = getFunctionsToWrap(meta_class);
272 AbstractMetaFunctionList functions = getFunctionsToWrap(meta_class);
269
273
270 foreach (const AbstractMetaFunction *function, functions) {
274 foreach (const AbstractMetaFunction *function, functions) {
271 if (!function->isSlot()) {
275 if (!function->isSlot()) {
272 s << " ";
276 s << " ";
273 writeFunctionSignature(s, function, 0, QString(),
277 writeFunctionSignature(s, function, 0, QString(),
274 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
278 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
275 s << ";" << endl;
279 s << ";" << endl;
276 }
280 }
277 }
281 }
278 if (meta_class->hasDefaultToStringFunction() || meta_class->hasToStringCapability()) {
282 if (meta_class->hasDefaultToStringFunction() || meta_class->hasToStringCapability()) {
279 s << " QString py_toString(" << meta_class->qualifiedCppName() << "*);" << endl;
283 s << " QString py_toString(" << meta_class->qualifiedCppName() << "*);" << endl;
280 }
284 }
281
285
282 // Field accessors
286 // Field accessors
283 foreach (const AbstractMetaField *field, meta_class->fields()) {
287 foreach (const AbstractMetaField *field, meta_class->fields()) {
284 if (field->isPublic()) {
288 if (field->isPublic()) {
285 writeFieldAccessors(s, field);
289 writeFieldAccessors(s, field);
286 }
290 }
287 }
291 }
288
292
289 // writeInjectedCode(s, meta_class);
293 // writeInjectedCode(s, meta_class);
290
294
291 // s << endl << " QScriptValue __qtscript_self;" << endl;
295 // s << endl << " QScriptValue __qtscript_self;" << endl;
292
296
293 s << "};" << endl << endl
297 s << "};" << endl << endl
294 << "#endif // " << include_block << endl;
298 << "#endif // " << include_block << endl;
295
299
296 }
300 }
297
301
298 void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
302 void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
299 {
303 {
300 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
304 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
301 foreach (const CodeSnip &cs, code_snips) {
305 foreach (const CodeSnip &cs, code_snips) {
302 if (cs.language == TypeSystem::ShellDeclaration) {
306 if (cs.language == TypeSystem::ShellDeclaration) {
303 s << cs.code() << endl;
307 s << cs.code() << endl;
304 }
308 }
305 }
309 }
306 }
310 }
@@ -1,311 +1,314
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
6 **
7 ** This file is part of the Qt Script Generator project on Qt Labs.
7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 **
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
14 ** this package.
15 **
15 **
16 ** GNU Lesser General Public License Usage
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
27 **
28 ** If you have questions regarding the use of this file, please contact
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
29 ** Nokia at qt-info@nokia.com.
30 **
30 **
31 **
31 **
32 **
32 **
33 **
33 **
34 **
34 **
35 **
35 **
36 **
36 **
37 **
37 **
38 ** $QT_END_LICENSE$
38 ** $QT_END_LICENSE$
39 **
39 **
40 ****************************************************************************/
40 ****************************************************************************/
41
41
42 #include "shellimplgenerator.h"
42 #include "shellimplgenerator.h"
43 #include "reporthandler.h"
43 #include "reporthandler.h"
44 #include "fileout.h"
44 #include "fileout.h"
45 #include <iostream>
45 #include <iostream>
46
46
47 extern void declareFunctionMetaTypes(QTextStream &stream,
47 extern void declareFunctionMetaTypes(QTextStream &stream,
48 const AbstractMetaFunctionList &functions,
48 const AbstractMetaFunctionList &functions,
49 QSet<QString> &registeredTypeNames);
49 QSet<QString> &registeredTypeNames);
50
50
51 QString ShellImplGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
51 QString ShellImplGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
52 {
52 {
53 return QString("PythonQtWrapper_%1.cpp").arg(meta_class->name());
53 return QString("PythonQtWrapper_%1.cpp").arg(meta_class->name());
54 }
54 }
55
55
56 static bool include_less_than(const Include &a, const Include &b)
56 static bool include_less_than(const Include &a, const Include &b)
57 {
57 {
58 return a.name < b.name;
58 return a.name < b.name;
59 }
59 }
60
60
61 static void writeHelperCode(QTextStream &s, const AbstractMetaClass *)
61 static void writeHelperCode(QTextStream &s, const AbstractMetaClass *)
62 {
62 {
63 }
63 }
64
64
65
65
66
66
67 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
67 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
68 {
68 {
69 QString builtIn = ShellGenerator::isBuiltIn(meta_class->name())?"_builtin":"";
69 QString builtIn = ShellGenerator::isBuiltIn(meta_class->name())?"_builtin":"";
70 QString pro_file_name = meta_class->package().replace(".", "_") + builtIn + "/" + meta_class->package().replace(".", "_") + builtIn + ".pri";
70 QString pro_file_name = meta_class->package().replace(".", "_") + builtIn + "/" + meta_class->package().replace(".", "_") + builtIn + ".pri";
71 priGenerator->addSource(pro_file_name, fileNameForClass(meta_class));
71 priGenerator->addSource(pro_file_name, fileNameForClass(meta_class));
72
72
73 s << "#include \"PythonQtWrapper_" << meta_class->name() << ".h\"" << endl << endl;
73 s << "#include \"PythonQtWrapper_" << meta_class->name() << ".h\"" << endl << endl;
74
74
75 s << "#include <PythonQtSignalReceiver.h>" << endl;
75 s << "#include <PythonQtSignalReceiver.h>" << endl;
76 s << "#include <PythonQtMethodInfo.h>" << endl;
76 s << "#include <PythonQtMethodInfo.h>" << endl;
77 s << "#include <PythonQtConversion.h>" << endl;
77 s << "#include <PythonQtConversion.h>" << endl;
78
78
79 //if (!meta_class->generateShellClass())
79 //if (!meta_class->generateShellClass())
80 // return;
80 // return;
81
81
82 IncludeList list = meta_class->typeEntry()->extraIncludes();
82 IncludeList list = meta_class->typeEntry()->extraIncludes();
83 qSort(list.begin(), list.end());
83 qSort(list.begin(), list.end());
84 foreach (const Include &inc, list) {
84 foreach (const Include &inc, list) {
85 ShellGenerator::writeInclude(s, inc);
85 ShellGenerator::writeInclude(s, inc);
86 }
86 }
87 s << endl;
87 s << endl;
88
88
89 writeHelperCode(s, meta_class);
89 writeHelperCode(s, meta_class);
90
90
91 // find constructors
91 // find constructors
92 AbstractMetaFunctionList ctors;
92 AbstractMetaFunctionList ctors;
93 ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors
93 ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors
94 | AbstractMetaClass::WasVisible
94 | AbstractMetaClass::WasVisible
95 | AbstractMetaClass::NotRemovedFromTargetLang);
95 | AbstractMetaClass::NotRemovedFromTargetLang);
96 // find member functions
96 // find member functions
97 AbstractMetaFunctionList functions = getFunctionsToWrap(meta_class);
97 AbstractMetaFunctionList functions = getFunctionsToWrap(meta_class);
98
98
99 // write metatype declarations
99 // write metatype declarations
100 {
100 {
101 // QSet<QString> registeredTypeNames = m_qmetatype_declared_typenames;
101 // QSet<QString> registeredTypeNames = m_qmetatype_declared_typenames;
102 // declareFunctionMetaTypes(s, functions, registeredTypeNames);
102 // declareFunctionMetaTypes(s, functions, registeredTypeNames);
103 // s << endl;
103 // s << endl;
104 }
104 }
105
105
106 if (meta_class->generateShellClass()) {
106 if (meta_class->generateShellClass()) {
107 AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class);
107 AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class);
108 foreach (const AbstractMetaFunction *fun, virtualsForShell) {
108 foreach (const AbstractMetaFunction *fun, virtualsForShell) {
109 bool hasReturnValue = (fun->type());
109 bool hasReturnValue = (fun->type());
110 writeFunctionSignature(s, fun, meta_class, QString(),
110 writeFunctionSignature(s, fun, meta_class, QString(),
111 Option(OriginalName | ShowStatic | UnderscoreSpaces),
111 Option(OriginalName | ShowStatic | UnderscoreSpaces),
112 "PythonQtShell_");
112 "PythonQtShell_");
113 s << endl << "{" << endl;
113 s << endl << "{" << endl;
114
114
115 Option typeOptions = Option(OriginalName | UnderscoreSpaces | SkipName);
115 Option typeOptions = Option(OriginalName | UnderscoreSpaces | SkipName);
116 AbstractMetaArgumentList args = fun->arguments();
116 AbstractMetaArgumentList args = fun->arguments();
117
117
118 s << "if (_wrapper) {" << endl;
118 s << "if (_wrapper) {" << endl;
119 s << " PyObject* obj = PyObject_GetAttrString((PyObject*)_wrapper, \"" << fun->name() << "\");" << endl;
119 s << " PyObject* obj = PyObject_GetAttrString((PyObject*)_wrapper, \"" << fun->name() << "\");" << endl;
120 s << " PyErr_Clear();" << endl;
120 s << " PyErr_Clear();" << endl;
121 s << " if (obj && !PythonQtSlotFunction_Check(obj)) {" << endl;
121 s << " if (obj && !PythonQtSlotFunction_Check(obj)) {" << endl;
122 s << " static const char* argumentList[] ={\"";
122 s << " static const char* argumentList[] ={\"";
123 if (hasReturnValue) {
123 if (hasReturnValue) {
124 // write the arguments, return type first
124 // write the arguments, return type first
125 writeTypeInfo(s, fun->type(), typeOptions);
125 writeTypeInfo(s, fun->type(), typeOptions);
126 }
126 }
127 s << "\"";
127 s << "\"";
128 for (int i = 0; i < args.size(); ++i) {
128 for (int i = 0; i < args.size(); ++i) {
129 s << " , \"";
129 s << " , \"";
130 writeTypeInfo(s, args.at(i)->type(), typeOptions);
130 writeTypeInfo(s, args.at(i)->type(), typeOptions);
131 s << "\"";
131 s << "\"";
132 }
132 }
133 s << "};" << endl;
133 s << "};" << endl;
134 s << " static const PythonQtMethodInfo* methodInfo = PythonQtMethodInfo::getCachedMethodInfoFromArgumentList(" << QString::number(args.size()+1) << ", argumentList);" << endl;
134 s << " static const PythonQtMethodInfo* methodInfo = PythonQtMethodInfo::getCachedMethodInfoFromArgumentList(" << QString::number(args.size()+1) << ", argumentList);" << endl;
135
135
136 if (hasReturnValue) {
136 if (hasReturnValue) {
137 s << " ";
137 s << " ";
138 writeTypeInfo(s, fun->type(), typeOptions);
138 writeTypeInfo(s, fun->type(), typeOptions);
139 s << " returnValue;" << endl;
139 s << " returnValue;" << endl;
140 // TODO: POD init to default is missing...
140 // TODO: POD init to default is missing...
141 }
141 }
142 s << " void* args[" << QString::number(args.size()+1) << "] = {NULL";
142 s << " void* args[" << QString::number(args.size()+1) << "] = {NULL";
143 for (int i = 0; i < args.size(); ++i) {
143 for (int i = 0; i < args.size(); ++i) {
144 s << ", (void*)&" << args.at(i)->argumentName();
144 s << ", (void*)&" << args.at(i)->argumentName();
145 }
145 }
146 s << "};" << endl;
146 s << "};" << endl;
147
147
148 s << " PyObject* result = PythonQtSignalTarget::call(obj, methodInfo, args, true);" << endl;
148 s << " PyObject* result = PythonQtSignalTarget::call(obj, methodInfo, args, true);" << endl;
149 if (hasReturnValue) {
149 if (hasReturnValue) {
150 s << " if (result) {" << endl;
150 s << " if (result) {" << endl;
151 s << " args[0] = PythonQtConv::ConvertPythonToQt(methodInfo->parameters().at(0), result, false, NULL, &returnValue);" << endl;
151 s << " args[0] = PythonQtConv::ConvertPythonToQt(methodInfo->parameters().at(0), result, false, NULL, &returnValue);" << endl;
152 s << " if (args[0]!=&returnValue) {" << endl;
152 s << " if (args[0]!=&returnValue) {" << endl;
153 s << " if (args[0]==NULL) {" << endl;
153 s << " if (args[0]==NULL) {" << endl;
154 s << " PythonQt::priv()->handleVirtualOverloadReturnError(\"" << fun->name() << "\", methodInfo, result);" << endl;
154 s << " PythonQt::priv()->handleVirtualOverloadReturnError(\"" << fun->name() << "\", methodInfo, result);" << endl;
155 s << " } else {" << endl;
155 s << " } else {" << endl;
156 s << " returnValue = *((";
156 s << " returnValue = *((";
157 writeTypeInfo(s, fun->type(), typeOptions);
157 writeTypeInfo(s, fun->type(), typeOptions);
158 s << "*)args[0]);" << endl;
158 s << "*)args[0]);" << endl;
159 s << " }" << endl;
159 s << " }" << endl;
160 s << " }" << endl;
160 s << " }" << endl;
161 s << " }" << endl;
161 s << " }" << endl;
162 }
162 }
163 s << " if (result) { Py_DECREF(result); } " << endl;
163 s << " if (result) { Py_DECREF(result); } " << endl;
164 s << " Py_DECREF(obj);" << endl;
164 s << " Py_DECREF(obj);" << endl;
165 if (hasReturnValue) {
165 if (hasReturnValue) {
166 s << " return returnValue;" << endl;
166 s << " return returnValue;" << endl;
167 } else {
167 } else {
168 s << " return;" << endl;
168 s << " return;" << endl;
169 }
169 }
170 s << " }" << endl;
170 s << " }" << endl;
171 s << "}" << endl;
171 s << "}" << endl;
172
172
173 s << " ";
173 s << " ";
174 if (fun->isAbstract()) {
174 if (fun->isAbstract()) {
175 if (fun->type()) {
175 if (fun->type()) {
176 // return empty default object
176 // return empty default object
177 writeTypeInfo(s, fun->type(), typeOptions);
177 s << "return ";
178 s << " result;" << endl;
178 if (fun->type()->indirections()>0) {
179 s << "return result";
179 s << "0;";
180 s << ";";
180 } else {
181 writeTypeInfo(s, fun->type(), typeOptions);
182 s << "();";
183 }
181 }
184 }
182 } else {
185 } else {
183 if (fun->type()) {
186 if (fun->type()) {
184 s << "return ";
187 s << "return ";
185 }
188 }
186 s << meta_class->qualifiedCppName() << "::";
189 s << meta_class->qualifiedCppName() << "::";
187 s << fun->originalName() << "(";
190 s << fun->originalName() << "(";
188 for (int i = 0; i < args.size(); ++i) {
191 for (int i = 0; i < args.size(); ++i) {
189 if (i > 0)
192 if (i > 0)
190 s << ", ";
193 s << ", ";
191 s << args.at(i)->argumentName();
194 s << args.at(i)->argumentName();
192 }
195 }
193 s << ");";
196 s << ");";
194 }
197 }
195 s << endl << "}" << endl;
198 s << endl << "}" << endl;
196 }
199 }
197 }
200 }
198
201
199 if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
202 if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
200
203
201 // write constructors
204 // write constructors
202 foreach (const AbstractMetaFunction *ctor, ctors) {
205 foreach (const AbstractMetaFunction *ctor, ctors) {
203 if (!ctor->isPublic() || ctor->isAbstract()) { continue; }
206 if (!ctor->isPublic() || ctor->isAbstract()) { continue; }
204
207
205 s << meta_class->qualifiedCppName() << "* ";
208 s << meta_class->qualifiedCppName() << "* ";
206 s << "PythonQtWrapper_" << meta_class->name() << "::";
209 s << "PythonQtWrapper_" << meta_class->name() << "::";
207 writeFunctionSignature(s, ctor, 0, "new_", Option(OriginalName | ShowStatic));
210 writeFunctionSignature(s, ctor, 0, "new_", Option(OriginalName | ShowStatic));
208 s << endl;
211 s << endl;
209 s << "{ " << endl;
212 s << "{ " << endl;
210 s << "return new " << (meta_class->generateShellClass()?shellClassName(meta_class):meta_class->qualifiedCppName()) << "(";
213 s << "return new " << (meta_class->generateShellClass()?shellClassName(meta_class):meta_class->qualifiedCppName()) << "(";
211 AbstractMetaArgumentList args = ctor->arguments();
214 AbstractMetaArgumentList args = ctor->arguments();
212 for (int i = 0; i < args.size(); ++i) {
215 for (int i = 0; i < args.size(); ++i) {
213 if (i > 0)
216 if (i > 0)
214 s << ", ";
217 s << ", ";
215 s << args.at(i)->argumentName();
218 s << args.at(i)->argumentName();
216 }
219 }
217 s << ");" << " }" << endl << endl;
220 s << ");" << " }" << endl << endl;
218 }
221 }
219 }
222 }
220
223
221 QString wrappedObject = " (*theWrappedObject)";
224 QString wrappedObject = " (*theWrappedObject)";
222
225
223 // write member functions
226 // write member functions
224 for (int i = 0; i < functions.size(); ++i) {
227 for (int i = 0; i < functions.size(); ++i) {
225 AbstractMetaFunction *fun = functions.at(i);
228 AbstractMetaFunction *fun = functions.at(i);
226 if (fun->isSlot()) continue;
229 if (fun->isSlot()) continue;
227
230
228 writeFunctionSignature(s, fun, meta_class, QString(),
231 writeFunctionSignature(s, fun, meta_class, QString(),
229 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces),
232 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces),
230 "PythonQtWrapper_");
233 "PythonQtWrapper_");
231 s << endl << "{" << endl;
234 s << endl << "{" << endl;
232 s << " ";
235 s << " ";
233 if (ShellGenerator::isSpecialStreamingOperator(fun)) {
236 if (ShellGenerator::isSpecialStreamingOperator(fun)) {
234 s << fun->arguments().at(0)->argumentName();
237 s << fun->arguments().at(0)->argumentName();
235 if (fun->originalName().startsWith("operator>>")) {
238 if (fun->originalName().startsWith("operator>>")) {
236 s << " >> ";
239 s << " >> ";
237 } else {
240 } else {
238 s << " << ";
241 s << " << ";
239 }
242 }
240 s << wrappedObject;
243 s << wrappedObject;
241 } else {
244 } else {
242 QString scriptFunctionName = fun->originalName();
245 QString scriptFunctionName = fun->originalName();
243 AbstractMetaArgumentList args = fun->arguments();
246 AbstractMetaArgumentList args = fun->arguments();
244 // call the C++ implementation
247 // call the C++ implementation
245 if (fun->type()) {
248 if (fun->type()) {
246 s << "return ";
249 s << "return ";
247 // call the C++ implementation
250 // call the C++ implementation
248 if (fun->type()->isReference()) {
251 if (fun->type()->isReference()) {
249 s << "&";
252 s << "&";
250 }
253 }
251 }
254 }
252 s << "(";
255 s << "(";
253 if (scriptFunctionName.startsWith("operator>>")) {
256 if (scriptFunctionName.startsWith("operator>>")) {
254 s << wrappedObject << " >>" << args.at(0)->argumentName();
257 s << wrappedObject << " >>" << args.at(0)->argumentName();
255 } else if (scriptFunctionName.startsWith("operator<<")) {
258 } else if (scriptFunctionName.startsWith("operator<<")) {
256 s << wrappedObject << " <<" << args.at(0)->argumentName();
259 s << wrappedObject << " <<" << args.at(0)->argumentName();
257 } else if (scriptFunctionName.startsWith("operator[]")) {
260 } else if (scriptFunctionName.startsWith("operator[]")) {
258 s << wrappedObject << "[" << args.at(0)->argumentName() << "]";
261 s << wrappedObject << "[" << args.at(0)->argumentName() << "]";
259 } else if (scriptFunctionName.startsWith("operator") && args.size()==1) {
262 } else if (scriptFunctionName.startsWith("operator") && args.size()==1) {
260 QString op = scriptFunctionName.mid(8);
263 QString op = scriptFunctionName.mid(8);
261 s << wrappedObject << op << " " << args.at(0)->argumentName();
264 s << wrappedObject << op << " " << args.at(0)->argumentName();
262 } else {
265 } else {
263 if (fun->isStatic()) {
266 if (fun->isStatic()) {
264 s << meta_class->qualifiedCppName() << "::";
267 s << meta_class->qualifiedCppName() << "::";
265 } else {
268 } else {
266 if (!fun->isPublic() || fun->isVirtual()) {
269 if (!fun->isPublic() || fun->isVirtual()) {
267 s << " ((" << promoterClassName(meta_class) << "*)theWrappedObject)->promoted_";
270 s << " ((" << promoterClassName(meta_class) << "*)theWrappedObject)->promoted_";
268 } else {
271 } else {
269 s << " theWrappedObject->";
272 s << " theWrappedObject->";
270 }
273 }
271 }
274 }
272 s << fun->originalName() << "(";
275 s << fun->originalName() << "(";
273 for (int i = 0; i < args.size(); ++i) {
276 for (int i = 0; i < args.size(); ++i) {
274 if (i > 0)
277 if (i > 0)
275 s << ", ";
278 s << ", ";
276 s << args.at(i)->argumentName();
279 s << args.at(i)->argumentName();
277 }
280 }
278 s << ")";
281 s << ")";
279 }
282 }
280 s << ")";
283 s << ")";
281 }
284 }
282 s << ";" << endl;
285 s << ";" << endl;
283
286
284 s << "}" << endl << endl;
287 s << "}" << endl << endl;
285 }
288 }
286
289
287 if (meta_class->hasDefaultToStringFunction()) {
290 if (meta_class->hasDefaultToStringFunction()) {
288 s << "QString PythonQtWrapper_" << meta_class->name() << "::py_toString(" << meta_class->qualifiedCppName() << "* obj) { return obj->toString(); }" << endl;
291 s << "QString PythonQtWrapper_" << meta_class->name() << "::py_toString(" << meta_class->qualifiedCppName() << "* obj) { return obj->toString(); }" << endl;
289 } else if (meta_class->hasToStringCapability()) {
292 } else if (meta_class->hasToStringCapability()) {
290 FunctionModelItem fun = meta_class->hasToStringCapability();
293 FunctionModelItem fun = meta_class->hasToStringCapability();
291 int indirections = fun->arguments().at(1)->type().indirections();
294 int indirections = fun->arguments().at(1)->type().indirections();
292 QString deref = QLatin1String(indirections == 0 ? "*" : "");
295 QString deref = QLatin1String(indirections == 0 ? "*" : "");
293 s << "QString PythonQtWrapper_" << meta_class->name() << "::py_toString(" << meta_class->qualifiedCppName() << "* obj) {" << endl;
296 s << "QString PythonQtWrapper_" << meta_class->name() << "::py_toString(" << meta_class->qualifiedCppName() << "* obj) {" << endl;
294 s << " QString result;" << endl;
297 s << " QString result;" << endl;
295 s << " QDebug d(&result);" << endl;
298 s << " QDebug d(&result);" << endl;
296 s << " d << " << deref << "obj;" << endl;
299 s << " d << " << deref << "obj;" << endl;
297 s << " return result;" << endl;
300 s << " return result;" << endl;
298 s << "}" << endl << endl;
301 s << "}" << endl << endl;
299 }
302 }
300
303
301 }
304 }
302
305
303 void ShellImplGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
306 void ShellImplGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
304 {
307 {
305 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
308 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
306 foreach (const CodeSnip &cs, code_snips) {
309 foreach (const CodeSnip &cs, code_snips) {
307 if (cs.language == TypeSystem::ShellCode) {
310 if (cs.language == TypeSystem::ShellCode) {
308 s << cs.code() << endl;
311 s << cs.code() << endl;
309 }
312 }
310 }
313 }
311 }
314 }
General Comments 0
You need to be logged in to leave comments. Login now