##// END OF EJS Templates
added return value conversion from reference to pointer to work around moc limitations, added toString method generation...
florianlink -
r70:dadaf215f719
parent child
Show More
@@ -502,6 +502,7 bool AbstractMetaBuilder::build()
502 traverseCompareOperator(item);
502 traverseCompareOperator(item);
503 }
503 }
504 }
504 }
505 // TODO XXX search and add operator+ etc. to the classes here!
505
506
506 {
507 {
507 FunctionList stream_operators = m_dom->findFunctions("operator<<") + m_dom->findFunctions("operator>>");
508 FunctionList stream_operators = m_dom->findFunctions("operator<<") + m_dom->findFunctions("operator>>");
@@ -65,6 +65,7 public:
65 NoBlockedSlot = 0x00100000,
65 NoBlockedSlot = 0x00100000,
66 SuperCall = 0x00200000,
66 SuperCall = 0x00200000,
67 FirstArgIsWrappedObject = 0x00400000,
67 FirstArgIsWrappedObject = 0x00400000,
68 ConvertReferenceToPtr = 0x00800000,
68
69
69 GlobalRefJObject = 0x00100000,
70 GlobalRefJObject = 0x00100000,
70
71
@@ -88,9 +88,14 void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type,
88
88
89 s << QString(type->indirections(), '*');
89 s << QString(type->indirections(), '*');
90
90
91 if (type->isReference() && !(options & ExcludeReference))
91 if (type->isReference() && !(options & ExcludeReference) && !(options & ConvertReferenceToPtr))
92 s << "&";
92 s << "&";
93
93
94 if (type->isReference() && (options & ConvertReferenceToPtr)) {
95 s << "*";
96 }
97
98
94 if (!(options & SkipName))
99 if (!(options & SkipName))
95 s << ' ';
100 s << ' ';
96 }
101 }
@@ -216,7 +221,7 void ShellGenerator::writeFunctionSignature(QTextStream &s,
216 }
221 }
217 }
222 }
218
223
219 writeFunctionArguments(s, meta_function->ownerClass(), meta_function->arguments(), option, numArguments);
224 writeFunctionArguments(s, meta_function->ownerClass(), meta_function->arguments(), Option(option & Option(~ConvertReferenceToPtr)), numArguments);
220
225
221 // The extra arguments...
226 // The extra arguments...
222 for (int i=0; i<extra_arguments.size(); ++i) {
227 for (int i=0; i<extra_arguments.size(); ++i) {
@@ -244,10 +244,13 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c
244 if (!function->isSlot()) {
244 if (!function->isSlot()) {
245 s << " ";
245 s << " ";
246 writeFunctionSignature(s, function, 0, QString(),
246 writeFunctionSignature(s, function, 0, QString(),
247 Option(FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
247 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
248 s << ";" << endl;
248 s << ";" << endl;
249 }
249 }
250 }
250 }
251 if (!meta_class->hasDefaultToStringFunction() && meta_class->hasToStringCapability()) {
252 s << " QString toString(" << meta_class->qualifiedCppName() << "*);" << endl;
253 }
251
254
252 // writeInjectedCode(s, meta_class);
255 // writeInjectedCode(s, meta_class);
253
256
@@ -169,7 +169,6 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
169 if (fun->type()) {
169 if (fun->type()) {
170 s << "return ";
170 s << "return ";
171 }
171 }
172 // call the C++ implementation
173 s << meta_class->qualifiedCppName() << "::";
172 s << meta_class->qualifiedCppName() << "::";
174 s << fun->originalName() << "(";
173 s << fun->originalName() << "(";
175 for (int i = 0; i < args.size(); ++i) {
174 for (int i = 0; i < args.size(); ++i) {
@@ -213,7 +212,7 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
213 if (fun->isSlot()) continue;
212 if (fun->isSlot()) continue;
214
213
215 writeFunctionSignature(s, fun, meta_class, QString(),
214 writeFunctionSignature(s, fun, meta_class, QString(),
216 Option(FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces),
215 Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces),
217 "PythonQtWrapper_");
216 "PythonQtWrapper_");
218 s << endl << "{" << endl;
217 s << endl << "{" << endl;
219 s << " ";
218 s << " ";
@@ -229,8 +228,14 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
229 QString scriptFunctionName = fun->originalName();
228 QString scriptFunctionName = fun->originalName();
230 AbstractMetaArgumentList args = fun->arguments();
229 AbstractMetaArgumentList args = fun->arguments();
231 // call the C++ implementation
230 // call the C++ implementation
232 if (fun->type())
231 if (fun->type()) {
233 s << "return ";
232 s << "return ";
233 // call the C++ implementation
234 if (fun->type()->isReference()) {
235 s << "&";
236 }
237 }
238 s << "(";
234 if (scriptFunctionName.startsWith("operator>>")) {
239 if (scriptFunctionName.startsWith("operator>>")) {
235 s << wrappedObject << " >>" << args.at(0)->argumentName();
240 s << wrappedObject << " >>" << args.at(0)->argumentName();
236 } else if (scriptFunctionName.startsWith("operator<<")) {
241 } else if (scriptFunctionName.startsWith("operator<<")) {
@@ -258,11 +263,25 void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
258 }
263 }
259 s << ")";
264 s << ")";
260 }
265 }
266 s << ")";
261 }
267 }
262 s << ";" << endl;
268 s << ";" << endl;
263
269
264 s << "}" << endl << endl;
270 s << "}" << endl << endl;
265 }
271 }
272
273 if (!meta_class->hasDefaultToStringFunction() && meta_class->hasToStringCapability()) {
274 FunctionModelItem fun = meta_class->hasToStringCapability();
275 int indirections = fun->arguments().at(1)->type().indirections();
276 QString deref = QLatin1String(indirections == 0 ? "*" : "");
277 s << "QString PythonQtWrapper_" << meta_class->name() << "::toString(" << meta_class->qualifiedCppName() << "* obj) {" << endl;
278 s << " QString result;" << endl;
279 s << " QDebug d(&result);" << endl;
280 s << " d << " << deref << "obj;" << endl;
281 s << " return result;" << endl;
282 s << "}" << endl << endl;
283 }
284
266 }
285 }
267
286
268 void ShellImplGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
287 void ShellImplGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
General Comments 0
You need to be logged in to leave comments. Login now