/runtime/typeinfo/ti_interface.d

http://github.com/wilkie/djehuty · D · 69 lines · 49 code · 13 blank · 7 comment · 9 complexity · fb69eac00bc04590cdb12ed6740bf62d MD5 · raw file

  1. /*
  2. * ti_interface.d
  3. *
  4. * This module implements the TypeInfo for interfaces.
  5. *
  6. */
  7. class TypeInfo_Interface : TypeInfo {
  8. char[] toString() {
  9. return info.name;
  10. }
  11. int opEquals(Object o) {
  12. TypeInfo_Interface c;
  13. return this is o ||
  14. ((c = cast(TypeInfo_Interface)o) !is null &&
  15. this.info.name == c.classinfo.name);
  16. }
  17. hash_t getHash(void *p) {
  18. Interface* pi = **cast(Interface ***)*cast(void**)p;
  19. Object o = cast(Object)(*cast(void**)p - pi.offset);
  20. assert(o);
  21. return o.toHash();
  22. }
  23. int equals(void *p1, void *p2) {
  24. Interface* pi = **cast(Interface ***)*cast(void**)p1;
  25. Object o1 = cast(Object)(*cast(void**)p1 - pi.offset);
  26. pi = **cast(Interface ***)*cast(void**)p2;
  27. Object o2 = cast(Object)(*cast(void**)p2 - pi.offset);
  28. return o1 == o2 || (o1 && o1.opCmp(o2) == 0);
  29. }
  30. int compare(void *p1, void *p2) {
  31. Interface* pi = **cast(Interface ***)*cast(void**)p1;
  32. Object o1 = cast(Object)(*cast(void**)p1 - pi.offset);
  33. pi = **cast(Interface ***)*cast(void**)p2;
  34. Object o2 = cast(Object)(*cast(void**)p2 - pi.offset);
  35. int c = 0;
  36. // Regard null references as always being "less than"
  37. if (o1 != o2) {
  38. if (o1) {
  39. if (!o2)
  40. c = 1;
  41. else
  42. c = o1.opCmp(o2);
  43. }
  44. else
  45. c = -1;
  46. }
  47. return c;
  48. }
  49. size_t tsize() {
  50. return Object.sizeof;
  51. }
  52. uint flags() {
  53. return 1;
  54. }
  55. ClassInfo info;
  56. }