Mercurial > projects > qtd
comparison d2/qtd/MOC.d @ 372:a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 08 Jul 2010 17:19:05 +0300 |
parents | 185df9220ea7 |
children | e67ce7c21758 |
comparison
equal
deleted
inserted
replaced
370:7fd4b69378bf | 372:a032df77b6ab |
---|---|
12 qtd.String, | 12 qtd.String, |
13 qtd.meta.Compiletime, | 13 qtd.meta.Compiletime, |
14 qtd.ctfe.Format; | 14 qtd.ctfe.Format; |
15 | 15 |
16 import qt.core.QString; | 16 import qt.core.QString; |
17 | |
18 private: | |
17 | 19 |
18 /** | 20 /** |
19 Utils. | 21 Utils. |
20 */ | 22 */ |
21 int lastIndexOf(T)(T[] haystack, T[] needle, int from = -1) | 23 int lastIndexOf(T)(T[] haystack, T[] needle, int from = -1) |
263 */ | 265 */ |
264 bool isConstructible = false; | 266 bool isConstructible = false; |
265 | 267 |
266 FunctionDef[] propertyList, enumList, constructorList; | 268 FunctionDef[] propertyList, enumList, constructorList; |
267 int index = 12; | 269 int index = 12; |
268 gen.output ~= "private static const uint[] qt_meta_data = [\n"; | 270 gen.output ~= "private static immutable uint[] qt_meta_data = [\n"; |
269 gen.output ~= format_ctfe("\n // content:\n"); | 271 gen.output ~= format_ctfe("\n // content:\n"); |
270 gen.output ~= format_ctfe(" ${}, // revision\n", 2); | 272 gen.output ~= format_ctfe(" ${}, // revision\n", 2); |
271 gen.output ~= format_ctfe(" ${}, // classname\n", strreg(gen, gen.cdef.classname)); | 273 gen.output ~= format_ctfe(" ${}, // classname\n", strreg(gen, gen.cdef.classname)); |
272 gen.output ~= format_ctfe(" ${}, ${}, // classinfo\n", gen.cdef.classInfoList.length, gen.cdef.classInfoList.length ? index : 0); | 274 gen.output ~= format_ctfe(" ${}, ${}, // classinfo\n", gen.cdef.classInfoList.length, gen.cdef.classInfoList.length ? index : 0); |
273 index += gen.cdef.classInfoList.length * 2; | 275 index += gen.cdef.classInfoList.length * 2; |
330 gen.output ~= format_ctfe("\n 0 // eod\n];\n\n"); | 332 gen.output ~= format_ctfe("\n 0 // eod\n];\n\n"); |
331 | 333 |
332 // | 334 // |
333 // Build stringdata array | 335 // Build stringdata array |
334 // | 336 // |
335 gen.output ~= "private static const string qt_meta_stringdata = \n"; | 337 gen.output ~= "private static immutable char[] qt_meta_stringdata = \n"; |
336 gen.output ~= format_ctfe(" \""); | 338 gen.output ~= format_ctfe(" \""); |
337 int col = 0; | 339 int col = 0; |
338 int len = 0; | 340 int len = 0; |
339 foreach (i, s; gen.strings) { | 341 foreach (i, s; gen.strings) { |
340 len = s.length; | 342 len = s.length; |
403 res ~= newFunc(funcSig, args); | 405 res ~= newFunc(funcSig, args); |
404 } | 406 } |
405 return res; | 407 return res; |
406 } | 408 } |
407 | 409 |
408 template Q_OBJECT_BIND() | |
409 { | |
410 } | |
411 | |
412 // ------------------------------------------------------------------------------------------ | 410 // ------------------------------------------------------------------------------------------ |
413 | 411 |
414 string generateSignalEmitters(uint signalCount) | 412 public string generateSignalEmitters(uint signalCount) |
415 { | 413 { |
416 string res = ""; | 414 string res = ""; |
417 foreach (i; 0..signalCount) | 415 foreach (i; 0..signalCount) |
418 { | 416 { |
419 auto iStr = to!string(i); | 417 auto iStr = to!string(i); |
420 res ~= "mixin SignalEmitter!(SignalKind.NewSignal, " ~ iStr ~ ");\n"; | 418 res ~= "mixin SignalEmitter!(SignalKind.NewSignal, " ~ iStr ~ ");\n"; |
421 } | 419 } |
422 return res; | 420 return res; |
423 } | 421 } |
424 | 422 |
425 private mixin template SlotAlias(alias slot) | 423 mixin template SlotAlias(alias slot) |
426 { | 424 { |
427 mixin ("alias slot " ~ methodName!slot ~ ";"); | 425 mixin ("alias slot " ~ methodName!slot ~ ";"); |
428 } | 426 } |
429 | 427 |
430 string generateSlotAliases(uint slotCount) | 428 public string generateSlotAliases(uint slotCount) |
431 { | 429 { |
432 string res = ""; | 430 string res = ""; |
433 foreach(i; 0..slotCount) | 431 foreach(i; 0..slotCount) |
434 { | 432 { |
435 auto iStr = to!string(i); | 433 auto iStr = to!string(i); |
436 res ~= "mixin SlotAlias!(slots[" ~ iStr ~ "]);\n"; | 434 res ~= "mixin SlotAlias!(slots[" ~ iStr ~ "]);\n"; |
437 } | 435 } |
438 return res; | 436 return res; |
439 } | 437 } |
440 | 438 |
441 string generateMetaCall(string methodName, size_t argCount) | 439 public string generateMetaCall(string methodName, size_t argCount) |
442 { | 440 { |
443 string res = ""; | 441 string res = ""; |
444 foreach (i; 1..argCount) | 442 foreach (i; 1..argCount) |
445 res ~= generateConvToD(i); | 443 res ~= generateConvToD(i); |
446 | 444 |
452 res ~= "_out" ~ to!string(i); | 450 res ~= "_out" ~ to!string(i); |
453 } | 451 } |
454 return res ~ ");\n"; | 452 return res ~ ");\n"; |
455 } | 453 } |
456 | 454 |
457 string generateDispatchSwitch(size_t methodCount) | 455 public string generateDispatchSwitch(size_t methodCount) |
458 { | 456 { |
459 string res = "switch(_id) {\n"; | 457 string res = "switch(_id) {\n"; |
460 | 458 |
461 foreach(i; 0..methodCount) | 459 foreach(i; 0..methodCount) |
462 { | 460 { |
471 res ~= " default:\n"; | 469 res ~= " default:\n"; |
472 | 470 |
473 return res ~ "}\n"; | 471 return res ~ "}\n"; |
474 } | 472 } |
475 | 473 |
476 string generateMetaInfo(T)() | 474 public string generateMetaInfo(T)() |
477 { | 475 { |
478 Generator gen; | 476 Generator gen; |
479 | 477 |
480 gen.cdef.classname = T.stringof; | 478 gen.cdef.classname = T.stringof; |
481 | 479 |
486 generateCode(gen); | 484 generateCode(gen); |
487 | 485 |
488 return gen.output; | 486 return gen.output; |
489 } | 487 } |
490 | 488 |
491 mixin template Q_OBJECT() | 489 // TODO: move to a better place |
490 public mixin template Q_OBJECT() | |
492 { | 491 { |
493 import | 492 import |
494 std.typetuple, | 493 std.typetuple, |
495 std.traits, | 494 std.traits, |
496 qtd.Marshal, | 495 qtd.Marshal, |
496 qtd.Signal, | |
497 qtd.meta.Runtime, | 497 qtd.meta.Runtime, |
498 qtd.MOC, | |
499 qt.core.QMetaObject, | |
498 qt.core.QString; // for QStringUtil.toNative | 500 qt.core.QString; // for QStringUtil.toNative |
499 | 501 |
500 public: // required to override the outside scope protection. | 502 public: // required to override the outside scope protection. |
501 | 503 |
502 alias typeof(this) This; | 504 alias typeof(this) This; |
508 mixin (generateSignalEmitters(signals.length)); | 510 mixin (generateSignalEmitters(signals.length)); |
509 mixin (generateSlotAliases(slots.length)); | 511 mixin (generateSlotAliases(slots.length)); |
510 //pragma(msg, generateMetaInfo!This()); | 512 //pragma(msg, generateMetaInfo!This()); |
511 mixin (generateMetaInfo!This()); | 513 mixin (generateMetaInfo!This()); |
512 | 514 |
513 protected int qt_metacall(QMetaObject.Call _c, int _id, void **_a) | 515 protected int qt_metacall(MetaCall _c, int _id, void **_a) |
514 { | 516 { |
515 _id = super.qt_metacall(_c, _id, _a); | 517 _id = super.qt_metacall(_c, _id, _a); |
516 | 518 |
517 static if (methods.length) | 519 static if (methods.length) |
518 { | 520 { |
519 if (_id < 0) | 521 if (_id < 0) |
520 return _id; | 522 return _id; |
521 | 523 |
522 if (_c == QMetaObject.Call.InvokeMetaMethod) { | 524 if (_c == MetaCall.InvokeMetaMethod) { |
523 //pragma(msg, generateDispatchSwitch(methods.length)); | 525 //pragma(msg, generateDispatchSwitch(methods.length)); |
524 mixin (generateDispatchSwitch(methods.length)); | 526 mixin (generateDispatchSwitch(methods.length)); |
525 } | 527 } |
526 _id -= methods.length; | 528 _id -= methods.length; |
527 } | 529 } |
541 return meta!This; | 543 return meta!This; |
542 } | 544 } |
543 | 545 |
544 __gshared static QMetaObjectNative nativeStaticMetaObject_; | 546 __gshared static QMetaObjectNative nativeStaticMetaObject_; |
545 | 547 |
546 static void* qtd_nativeStaticMetaObject() | 548 static void* qtdNativeStaticMetaObject() |
547 { | 549 { |
548 alias BaseClassesTuple!(This)[0] Base; | 550 alias BaseClassesTuple!(This)[0] Base; |
549 | 551 |
550 if (!nativeStaticMetaObject_.data) | 552 if (!nativeStaticMetaObject_.data) |
551 { | 553 { |