Mercurial > projects > ldc
comparison runtime/internal/genobj.d @ 1512:09734fb929c0
Make == for associative arrays test for equality, not identity.
_aaEq was added to runtime/internal/aaA.d which forwards to
TypeInfo_AssociativeArray.equals in genobj.d. On the codegen side, DtoAAEquals
was added to gen/aa.cpp and is called from EqualExp::toElem in gen/toir.cpp.
I assume that the frontend will produce an error if == is used on associative
arrays of different type.
This fixes DMD bug 1429.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 21 Jun 2009 19:05:24 +0200 |
parents | 0a5f7890f327 |
children |
comparison
equal
deleted
inserted
replaced
1511:5b66008246bb | 1512:09734fb929c0 |
---|---|
45 import tango.stdc.string; // : memcmp, memcpy, memmove; | 45 import tango.stdc.string; // : memcmp, memcpy, memmove; |
46 import tango.stdc.stdlib; // : calloc, realloc, free; | 46 import tango.stdc.stdlib; // : calloc, realloc, free; |
47 import util.string; | 47 import util.string; |
48 import tango.stdc.stdio; // : printf, snprintf; | 48 import tango.stdc.stdio; // : printf, snprintf; |
49 import tango.core.Version; | 49 import tango.core.Version; |
50 | |
51 import aaA; | |
50 | 52 |
51 extern (C) void onOutOfMemoryError(); | 53 extern (C) void onOutOfMemoryError(); |
52 extern (C) Object _d_allocclass(ClassInfo ci); | 54 extern (C) Object _d_allocclass(ClassInfo ci); |
53 } | 55 } |
54 | 56 |
553 this.key == c.key && | 555 this.key == c.key && |
554 this.value == c.value); | 556 this.value == c.value); |
555 } | 557 } |
556 | 558 |
557 // BUG: need to add the rest of the functions | 559 // BUG: need to add the rest of the functions |
560 | |
561 int equals(void *p1, void *p2) | |
562 { | |
563 AA aa = *cast(AA*)p1; | |
564 AA ab = *cast(AA*)p2; | |
565 | |
566 if (_aaLen(aa) != _aaLen(ab)) | |
567 return 0; | |
568 | |
569 int equal = 1; | |
570 int eq_x(void* k, void* va) | |
571 { | |
572 void* vb = _aaIn(ab, key, k); | |
573 if (!vb || !value.equals(va, vb)) | |
574 { | |
575 equal = 0; | |
576 return 1; // break | |
577 } | |
578 return 0; | |
579 } | |
580 _aaApply2(aa, key.tsize(), &eq_x); | |
581 return equal; | |
582 } | |
558 | 583 |
559 size_t tsize() | 584 size_t tsize() |
560 { | 585 { |
561 return (char[int]).sizeof; | 586 return (char[int]).sizeof; |
562 } | 587 } |