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