Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 602

Show
Ignore:
Timestamp:
08/06/10 03:34:21 (14 years ago)
Author:
walter
Message:

Bugzilla 2931 Initialization struct with array from another struct

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/todt.c

    r428 r602  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
    66// http://www.digitalmars.com 
    77// License for redistribution is by either the Artistic License 
    88// in artistic.txt, or the GNU General Public License in gnu.txt. 
    99// See the included readme.txt for details. 
    1010 
    1111/* A dt_t is a simple structure representing data to be added 
    1212 * to the data segment of the output object file. As such, 
    1313 * it is a list of initialized bytes, 0 data, and offsets from 
    1414 * other symbols. 
    1515 * Each D symbol and type can be converted into a dt_t so it can 
    1616 * be written to the data segment. 
    1717 */ 
    1818 
    1919#include        <stdio.h> 
    2020#include        <string.h> 
    2121#include        <time.h> 
    2222#include        <assert.h> 
    2323#include        <complex.h> 
     
    675675                        break; 
    676676                    } 
    677677                    VarDeclaration *v2 = (VarDeclaration *)sd->fields.data[k]; 
    678678 
    679679                    if (v2->offset < offset2 && dts.data[k]) 
    680680                        break;                  // overlap 
    681681                } 
    682682            } 
    683683        } 
    684684        if (d) 
    685685        { 
    686686            if (v->offset < offset) 
    687687                error("duplicate union initialization for %s", v->toChars()); 
    688688            else 
    689689            {   unsigned sz = dt_size(d); 
    690690                unsigned vsz = v->type->size(); 
    691691                unsigned voffset = v->offset; 
    692692                assert(sz <= vsz); 
    693693 
    694694                unsigned dim = 1; 
    695                 for (Type *vt = v->type->toBasetype(); 
     695                Type *vt; 
     696                for (vt = v->type->toBasetype(); 
    696697                     vt->ty == Tsarray; 
    697698                     vt = vt->next->toBasetype()) 
    698699                {   TypeSArray *tsa = (TypeSArray *)vt; 
    699700                    dim *= tsa->dim->toInteger(); 
    700701                } 
    701702 
    702703                for (size_t i = 0; i < dim; i++) 
    703704                { 
    704705                    if (offset < voffset) 
    705706                        pdt = dtnzeros(pdt, voffset - offset); 
    706707                    if (!d) 
    707708                    { 
    708709                        if (v->init) 
    709710                            d = v->init->toDt(); 
    710711                        else 
    711                             v->type->toDt(&d); 
     712                            vt->toDt(&d); 
    712713                    } 
    713714                    pdt = dtcat(pdt, d); 
    714715                    d = NULL; 
    715716                    offset = voffset + sz; 
    716717                    voffset += vsz / dim; 
    717718                    if (sz == vsz) 
    718719                        break; 
    719720                } 
    720721            } 
    721722        } 
    722723    } 
    723724    if (offset < sd->structsize) 
    724725        pdt = dtnzeros(pdt, sd->structsize - offset); 
    725726 
    726727    return pdt; 
    727728} 
    728729 
    729730 
    730731dt_t **SymOffExp::toDt(dt_t **pdt) 
    731732{ 
  • trunk/src/todt.c

    r428 r602  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
    66// http://www.digitalmars.com 
    77// License for redistribution is by either the Artistic License 
    88// in artistic.txt, or the GNU General Public License in gnu.txt. 
    99// See the included readme.txt for details. 
    1010 
    1111/* A dt_t is a simple structure representing data to be added 
    1212 * to the data segment of the output object file. As such, 
    1313 * it is a list of initialized bytes, 0 data, and offsets from 
    1414 * other symbols. 
    1515 * Each D symbol and type can be converted into a dt_t so it can 
    1616 * be written to the data segment. 
    1717 */ 
    1818 
    1919#include        <stdio.h> 
    2020#include        <string.h> 
    2121#include        <time.h> 
    2222#include        <assert.h> 
    2323#include        <complex.h> 
     
    671671                        break; 
    672672                    } 
    673673                    VarDeclaration *v2 = (VarDeclaration *)sd->fields.data[k]; 
    674674 
    675675                    if (v2->offset < offset2 && dts.data[k]) 
    676676                        break;                  // overlap 
    677677                } 
    678678            } 
    679679        } 
    680680        if (d) 
    681681        { 
    682682            if (v->offset < offset) 
    683683                error("duplicate union initialization for %s", v->toChars()); 
    684684            else 
    685685            {   unsigned sz = dt_size(d); 
    686686                unsigned vsz = v->type->size(); 
    687687                unsigned voffset = v->offset; 
    688688                assert(sz <= vsz); 
    689689 
    690690                unsigned dim = 1; 
    691                 for (Type *vt = v->type->toBasetype(); 
     691                Type *vt; 
     692                for (vt = v->type->toBasetype(); 
    692693                     vt->ty == Tsarray; 
    693694                     vt = vt->nextOf()->toBasetype()) 
    694695                {   TypeSArray *tsa = (TypeSArray *)vt; 
    695696                    dim *= tsa->dim->toInteger(); 
    696697                } 
    697698 
    698699                for (size_t i = 0; i < dim; i++) 
    699700                { 
    700701                    if (offset < voffset) 
    701702                        pdt = dtnzeros(pdt, voffset - offset); 
    702703                    if (!d) 
    703704                    { 
    704705                        if (v->init) 
    705706                            d = v->init->toDt(); 
    706707                        else 
    707                             v->type->toDt(&d); 
     707                            vt->toDt(&d); 
    708708                    } 
    709709                    pdt = dtcat(pdt, d); 
    710710                    d = NULL; 
    711711                    offset = voffset + sz; 
    712712                    voffset += vsz / dim; 
    713713                    if (sz == vsz) 
    714714                        break; 
    715715                } 
    716716            } 
    717717        } 
    718718    } 
    719719    if (offset < sd->structsize) 
    720720        pdt = dtnzeros(pdt, sd->structsize - offset); 
    721721 
    722722    return pdt; 
    723723} 
    724724 
    725725 
    726726dt_t **SymOffExp::toDt(dt_t **pdt) 
    727727{