Mercurial > projects > qtd
comparison generator/containergenerator.cpp @ 357:9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Q_CLASSINFO implementation
Now Qtd can be built on Windows
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Wed, 02 Jun 2010 19:38:05 +0300 |
parents | 08c1ca7975ab |
children | a032df77b6ab |
comparison
equal
deleted
inserted
replaced
356:12cec2d14e1c | 357:9784459f0750 |
---|---|
218 s << "// stuff for passing D function pointers" << endl << endl | 218 s << "// stuff for passing D function pointers" << endl << endl |
219 << "#include \"qtd_masterinclude.h\"" << endl << endl | 219 << "#include \"qtd_masterinclude.h\"" << endl << endl |
220 << "#include \"qtd_core.h\"" << endl | 220 << "#include \"qtd_core.h\"" << endl |
221 << "#include \"ArrayOps_" << package << ".h\"" << endl | 221 << "#include \"ArrayOps_" << package << ".h\"" << endl |
222 << "#include \"ArrayOps_qt_core.h\"" << endl | 222 << "#include \"ArrayOps_qt_core.h\"" << endl |
223 << "#include \"ArrayOpsPrimitive.h\"" << endl << endl | 223 << "#include \"ArrayOpsPrimitive.h\"" << endl << endl; |
224 << "#ifdef CPP_SHARED" << endl << endl; | |
225 | |
226 | 224 |
227 foreach (const TypeEntry *te, containerTypes) { | 225 foreach (const TypeEntry *te, containerTypes) { |
228 if (te->javaPackage() == cls->package()) { | 226 if (te->javaPackage() == cls->package()) { |
229 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | 227 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); |
230 QString cls_name = centry->name(); | 228 QString cls_name = centry->name(); |
231 | 229 |
230 QString module = packageToQtModule(cls->package()); | |
232 setFuncNames(cls_name); | 231 setFuncNames(cls_name); |
233 s << "QTD_EXPORT_VAR(" << all_name << ")" << endl | 232 s << "QTD_EXPORT(" << module << ", " << all_name << ")" << endl |
234 << "QTD_EXPORT_VAR(" << ass_name << ")" << endl | 233 << "QTD_EXPORT(" << module << ", " << ass_name << ")" << endl |
235 << "QTD_EXPORT_VAR(" << get_name << ")" << endl << endl; | 234 << "QTD_EXPORT(" << module << ", " << get_name << ")" << endl << endl; |
236 } | 235 } |
237 } | 236 } |
238 | 237 |
239 s << endl | 238 /* |
240 << "extern \"C\" DLL_PUBLIC void qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(pfunc_abstr *callbacks)" << endl | |
241 << "{" << endl; | |
242 | |
243 int num_funcs = 0; | |
244 foreach (const TypeEntry *te, containerTypes) { | |
245 if (te->javaPackage() == cls->package()) { | |
246 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
247 QString cls_name = centry->name(); | |
248 | |
249 setFuncNames(cls_name); | |
250 s << " QTD_EXPORT_VAR_SET(" << all_name << ", callbacks[" << num_funcs + 0 << "]);" << endl | |
251 << " QTD_EXPORT_VAR_SET(" << ass_name << ", callbacks[" << num_funcs + 1 << "]);" << endl | |
252 << " QTD_EXPORT_VAR_SET(" << get_name << ", callbacks[" << num_funcs + 2 << "]);" << endl << endl; | |
253 | |
254 num_funcs += NUM_ARRAY_FUNCS; | |
255 } | |
256 } | |
257 s << "}" << endl | |
258 << "#endif" << endl; | |
259 /* | |
260 QMap<const TypeEntry*, AbstractMetaType*> typeList = signalEntries[cls->package()]; | 239 QMap<const TypeEntry*, AbstractMetaType*> typeList = signalEntries[cls->package()]; |
261 | 240 |
262 QMapIterator<const TypeEntry*, AbstractMetaType*> i(typeList); | 241 QMapIterator<const TypeEntry*, AbstractMetaType*> i(typeList); |
263 while (i.hasNext()) { | 242 while (i.hasNext()) { |
264 i.next(); | 243 i.next(); |
265 s << "// " << i.key()->targetLangName() << endl | 244 s << "// " << i.key()->targetLangName() << endl |
266 << "extern \"C\" DLL_PUBLIC void qtd_" << package << "_" << i.key()->targetLangName() << "_to_d_array(void *cpp_ptr, DArray* __d_container) {" << endl; | 245 << "QTD_EXTERN QTD_DLL_PUBLIC void qtd_" << package << "_" << i.key()->targetLangName() << "_to_d_array(void *cpp_ptr, DArray* __d_container) {" << endl; |
267 | 246 |
268 AbstractMetaType *arg_type = i.value(); | 247 AbstractMetaType *arg_type = i.value(); |
269 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); | 248 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
270 s << "container = (*reinterpret_cast< "; | 249 s << "container = (*reinterpret_cast< "; |
271 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); | 250 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
278 s << "// signal conversion functions" << endl; | 257 s << "// signal conversion functions" << endl; |
279 | 258 |
280 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { | 259 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
281 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); | 260 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
282 s << "// " << te->targetLangName() << endl | 261 s << "// " << te->targetLangName() << endl |
283 << "extern \"C\" DLL_PUBLIC void " << cppContainerConversionName(cls, arg_type, FromCpp) << "(void *cpp_ptr, DArray* __d_container) {" << endl; | 262 << "QTD_EXTERN QTD_DLL_PUBLIC void " << cppContainerConversionName(cls, arg_type, FromCpp) << "(void *cpp_ptr, DArray* __d_container) {" << endl; |
284 | 263 |
285 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); | 264 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
286 s << "container = (*reinterpret_cast< "; | 265 s << "container = (*reinterpret_cast< "; |
287 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); | 266 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
288 s << "(*)>(cpp_ptr));" << endl; | 267 s << "(*)>(cpp_ptr));" << endl; |
314 s << "#endif // " << file_upper << endl; | 293 s << "#endif // " << file_upper << endl; |
315 } | 294 } |
316 | 295 |
317 void ContainerGenerator::setFuncNames(const QString& cls_name) | 296 void ContainerGenerator::setFuncNames(const QString& cls_name) |
318 { | 297 { |
319 all_name = QString("qtd_allocate_%1_array").arg(cls_name); | 298 all_name = QString("allocate_%1_array").arg(cls_name); |
320 ass_name = QString("qtd_assign_%1_array_element").arg(cls_name); | 299 ass_name = QString("assign_%1_array_element").arg(cls_name); |
321 get_name = QString("qtd_get_%1_from_array").arg(cls_name); | 300 get_name = QString("get_%1_from_array").arg(cls_name); |
322 } | 301 } |
323 | 302 |
324 void ContainerGenerator::writeHeaderArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | 303 void ContainerGenerator::writeHeaderArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) |
325 { | 304 { |
326 QString cls_name = centry->name(); | 305 QString cls_name = centry->name(); |
335 cpp_type = "void*"; | 314 cpp_type = "void*"; |
336 } | 315 } |
337 | 316 |
338 setFuncNames(cls_name); | 317 setFuncNames(cls_name); |
339 | 318 |
340 s << "QTD_EXPORT(void, " << all_name << ", (void* arr, size_t len))" << endl | 319 QString module = packageToQtModule(centry->javaPackage()); |
341 << "QTD_EXPORT(void, " << ass_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl | 320 |
342 << "QTD_EXPORT(void, " << get_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl; | 321 s << "QTD_EXPORT_DECL(" << module << ", void, " << all_name << ", (void* arr, size_t len))" << endl |
343 | 322 << "QTD_EXPORT_DECL(" << module << ", void, " << ass_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl |
344 s << "#ifdef CPP_SHARED" << endl | 323 << "QTD_EXPORT_DECL(" << module << ", void, " << get_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl; |
345 << "#define " << all_name << " qtd_get_" << all_name << "()" << endl | |
346 << "#define " << ass_name << " qtd_get_" << ass_name << "()" << endl | |
347 << "#define " << get_name << " qtd_get_" << get_name << "()" << endl | |
348 << "#endif" << endl; | |
349 | 324 |
350 s << endl; | 325 s << endl; |
326 | |
351 } | 327 } |
352 | 328 |
353 void ContainerGenerator::writeDContent(QTextStream &s, AbstractMetaClass *cls) | 329 void ContainerGenerator::writeDContent(QTextStream &s, AbstractMetaClass *cls) |
354 { | 330 { |
355 s << "module " << cls->package() << ".ArrayOps;" << endl << endl; | 331 s << "module " << cls->package() << ".ArrayOps;" << endl << endl; |
369 num_funcs += NUM_ARRAY_FUNCS; | 345 num_funcs += NUM_ARRAY_FUNCS; |
370 } | 346 } |
371 } | 347 } |
372 if (num_funcs == 0) | 348 if (num_funcs == 0) |
373 return; | 349 return; |
374 | |
375 s << "version (cpp_shared) {" << endl | |
376 << " private extern (C) void qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(void* callbacks);" << endl << endl | |
377 << " static this() {" << endl | |
378 << " void*[" << num_funcs << "] callbacks; " << endl << endl; | |
379 | |
380 num_funcs = 0; | |
381 foreach (const TypeEntry *te, containerTypes) { | |
382 if (te->javaPackage() == cls->package()) { | |
383 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
384 | |
385 QString cls_name = centry->name(); | |
386 setFuncNames(cls_name); | |
387 | |
388 s << " callbacks[" << num_funcs + 0 << "] = &" << all_name << ";" << endl | |
389 << " callbacks[" << num_funcs + 1 << "] = &" << ass_name << ";" << endl | |
390 << " callbacks[" << num_funcs + 2 << "] = &" << get_name << ";" << endl; | |
391 | |
392 s << endl; | |
393 num_funcs += NUM_ARRAY_FUNCS; | |
394 } | |
395 } | |
396 s << " qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(callbacks.ptr);" << endl | |
397 << " }" << endl | |
398 << "}" << endl; | |
399 | |
400 | |
401 } | 350 } |
402 | 351 |
403 void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls) | 352 void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls) |
404 { | 353 { |
405 s << "module " << cls->package() << ".ArrayOps2;" << endl << endl | 354 s << "module " << cls->package() << ".ArrayOps2;" << endl << endl |
420 << "** This is a generated file, please don't touch." << endl | 369 << "** This is a generated file, please don't touch." << endl |
421 << "**" << endl | 370 << "**" << endl |
422 << "****************************************************************************/" << endl << endl; | 371 << "****************************************************************************/" << endl << endl; |
423 } | 372 } |
424 | 373 |
374 | |
375 // TODO: rewrite | |
425 void ContainerGenerator::writeArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | 376 void ContainerGenerator::writeArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) |
426 { | 377 { |
427 QString cls_name = centry->name(); | 378 QString cls_name = centry->name(); |
428 QString type_name = cls_name; | 379 QString type_name = cls_name; |
429 | 380 |
455 if (centry->designatedInterface()) { | 406 if (centry->designatedInterface()) { |
456 type_name = centry->designatedInterface()->name(); | 407 type_name = centry->designatedInterface()->name(); |
457 nativeId = ".__ptr_" + type_name; | 408 nativeId = ".__ptr_" + type_name; |
458 } | 409 } |
459 | 410 |
460 s << "private extern(C) void qtd_allocate_" << cls_name << "_array(" << type_name << "[]* arr, size_t len)" << endl | 411 DGenerator::writeDExport(s, "void", QString("allocate_%1_array").arg(cls_name), QString("%1[]* arr, size_t len").arg(type_name), |
461 << "{" << endl | 412 QString(" *arr = new %1[len]; ").arg(type_name)); |
462 << INDENT << "*arr = new " << type_name << "[len];" << endl | 413 |
463 << "}" << endl << endl; | 414 DGenerator::writeDExport(s, "void", QString("assign_%1_array_element").arg(cls_name), QString("%1[]* arr, size_t pos, %2 elem").arg(type_name, cpp_type), |
464 | 415 QString(" (*arr)[pos] = %1; ").arg(convert)); |
465 s << "private extern(C) void qtd_assign_" << cls_name << "_array_element(" << type_name << "[]* arr, size_t pos, " << cpp_type << " elem)" << endl | 416 |
466 << "{" << endl | 417 DGenerator::writeDExport(s, "void", QString("get_%1_from_array").arg(cls_name), QString("%1* arr, size_t pos, %2 elem").arg(type_name, cpp_assign_type), |
467 << INDENT << "(*arr)[pos] = " << convert << ";" << endl | 418 QString(" *elem = arr[pos]%1; ").arg(nativeId)); |
468 << "}" << endl << endl | 419 |
469 | 420 s << "package " << d_type << " qtd_" << cls_name << "_cpp_to_d(" << cpp_type << " ret)" << endl |
470 << "private extern(C) void qtd_get_" << cls_name << "_from_array(" << type_name << "* arr, size_t pos, " << cpp_assign_type << " elem)" << endl | |
471 << "{" << endl | |
472 << INDENT << "*elem = arr[pos]" << nativeId << ";" << endl | |
473 << "}" << endl << endl | |
474 | |
475 << "package " << d_type << " qtd_" << cls_name << "_cpp_to_d(" << cpp_type << " ret)" << endl | |
476 << "{" << endl; | 421 << "{" << endl; |
477 | 422 |
478 marshalFromCppToD(s, centry); | 423 marshalFromCppToD(s, centry); |
479 | 424 |
480 s << "}" << endl; | 425 s << "}" << endl; |