Changeset 602
- Timestamp:
- 08/06/10 03:34:21 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/todt.c (modified) (2 diffs)
- trunk/src/todt.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/todt.c
r428 r602 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-20 09by Digital Mars3 // Copyright (c) 1999-2010 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright 6 6 // http://www.digitalmars.com 7 7 // License for redistribution is by either the Artistic License 8 8 // in artistic.txt, or the GNU General Public License in gnu.txt. 9 9 // See the included readme.txt for details. 10 10 11 11 /* A dt_t is a simple structure representing data to be added 12 12 * to the data segment of the output object file. As such, 13 13 * it is a list of initialized bytes, 0 data, and offsets from 14 14 * other symbols. 15 15 * Each D symbol and type can be converted into a dt_t so it can 16 16 * be written to the data segment. 17 17 */ 18 18 19 19 #include <stdio.h> 20 20 #include <string.h> 21 21 #include <time.h> 22 22 #include <assert.h> 23 23 #include <complex.h> … … 675 675 break; 676 676 } 677 677 VarDeclaration *v2 = (VarDeclaration *)sd->fields.data[k]; 678 678 679 679 if (v2->offset < offset2 && dts.data[k]) 680 680 break; // overlap 681 681 } 682 682 } 683 683 } 684 684 if (d) 685 685 { 686 686 if (v->offset < offset) 687 687 error("duplicate union initialization for %s", v->toChars()); 688 688 else 689 689 { unsigned sz = dt_size(d); 690 690 unsigned vsz = v->type->size(); 691 691 unsigned voffset = v->offset; 692 692 assert(sz <= vsz); 693 693 694 694 unsigned dim = 1; 695 for (Type *vt = v->type->toBasetype(); 695 Type *vt; 696 for (vt = v->type->toBasetype(); 696 697 vt->ty == Tsarray; 697 698 vt = vt->next->toBasetype()) 698 699 { TypeSArray *tsa = (TypeSArray *)vt; 699 700 dim *= tsa->dim->toInteger(); 700 701 } 701 702 702 703 for (size_t i = 0; i < dim; i++) 703 704 { 704 705 if (offset < voffset) 705 706 pdt = dtnzeros(pdt, voffset - offset); 706 707 if (!d) 707 708 { 708 709 if (v->init) 709 710 d = v->init->toDt(); 710 711 else 711 v ->type->toDt(&d);712 vt->toDt(&d); 712 713 } 713 714 pdt = dtcat(pdt, d); 714 715 d = NULL; 715 716 offset = voffset + sz; 716 717 voffset += vsz / dim; 717 718 if (sz == vsz) 718 719 break; 719 720 } 720 721 } 721 722 } 722 723 } 723 724 if (offset < sd->structsize) 724 725 pdt = dtnzeros(pdt, sd->structsize - offset); 725 726 726 727 return pdt; 727 728 } 728 729 729 730 730 731 dt_t **SymOffExp::toDt(dt_t **pdt) 731 732 { trunk/src/todt.c
r428 r602 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-20 09by Digital Mars3 // Copyright (c) 1999-2010 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright 6 6 // http://www.digitalmars.com 7 7 // License for redistribution is by either the Artistic License 8 8 // in artistic.txt, or the GNU General Public License in gnu.txt. 9 9 // See the included readme.txt for details. 10 10 11 11 /* A dt_t is a simple structure representing data to be added 12 12 * to the data segment of the output object file. As such, 13 13 * it is a list of initialized bytes, 0 data, and offsets from 14 14 * other symbols. 15 15 * Each D symbol and type can be converted into a dt_t so it can 16 16 * be written to the data segment. 17 17 */ 18 18 19 19 #include <stdio.h> 20 20 #include <string.h> 21 21 #include <time.h> 22 22 #include <assert.h> 23 23 #include <complex.h> … … 671 671 break; 672 672 } 673 673 VarDeclaration *v2 = (VarDeclaration *)sd->fields.data[k]; 674 674 675 675 if (v2->offset < offset2 && dts.data[k]) 676 676 break; // overlap 677 677 } 678 678 } 679 679 } 680 680 if (d) 681 681 { 682 682 if (v->offset < offset) 683 683 error("duplicate union initialization for %s", v->toChars()); 684 684 else 685 685 { unsigned sz = dt_size(d); 686 686 unsigned vsz = v->type->size(); 687 687 unsigned voffset = v->offset; 688 688 assert(sz <= vsz); 689 689 690 690 unsigned dim = 1; 691 for (Type *vt = v->type->toBasetype(); 691 Type *vt; 692 for (vt = v->type->toBasetype(); 692 693 vt->ty == Tsarray; 693 694 vt = vt->nextOf()->toBasetype()) 694 695 { TypeSArray *tsa = (TypeSArray *)vt; 695 696 dim *= tsa->dim->toInteger(); 696 697 } 697 698 698 699 for (size_t i = 0; i < dim; i++) 699 700 { 700 701 if (offset < voffset) 701 702 pdt = dtnzeros(pdt, voffset - offset); 702 703 if (!d) 703 704 { 704 705 if (v->init) 705 706 d = v->init->toDt(); 706 707 else 707 v ->type->toDt(&d);707 vt->toDt(&d); 708 708 } 709 709 pdt = dtcat(pdt, d); 710 710 d = NULL; 711 711 offset = voffset + sz; 712 712 voffset += vsz / dim; 713 713 if (sz == vsz) 714 714 break; 715 715 } 716 716 } 717 717 } 718 718 } 719 719 if (offset < sd->structsize) 720 720 pdt = dtnzeros(pdt, sd->structsize - offset); 721 721 722 722 return pdt; 723 723 } 724 724 725 725 726 726 dt_t **SymOffExp::toDt(dt_t **pdt) 727 727 {
