Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 336:aaade6ded589

Show
Ignore:
Timestamp:
07/12/08 13:38:31 (6 months ago)
Author:
lindquist
branch:
trunk
Message:

[svn r357] Merged DMD 1.033

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/access.c

    r1 r336  
    254254    { 
    255255    error(loc, "member %s is not accessible", smember->toChars()); 
    256     } 
    257 
    258  
    259 /**************************************** 
     256halt(); 
     257    } 
     258
     259 
     260/****************************************    
    260261 * Determine if this is the same or friend of cd. 
    261262 */ 
  • dmd/aggregate.h

    r159 r336  
    6565    int isdeprecated;       // !=0 if deprecated 
    6666    Scope *scope;       // !=NULL means context to use 
    67     FuncDeclarations dtors; // Array of destructors 
    68     FuncDeclaration *dtor;  // aggregate destructor 
    6967 
    7068    // Special member functions 
     
    7270    NewDeclaration *aggNew;     // allocator 
    7371    DeleteDeclaration *aggDelete;   // deallocator 
     72 
     73    FuncDeclarations dtors; // Array of destructors 
     74    FuncDeclaration *dtor;  // aggregate destructor 
    7475 
    7576#ifdef IN_GCC 
     
    120121{ 
    121122    int zeroInit;       // !=0 if initialize with 0 fill 
     123#if DMDV2 
     124    int hasIdentityAssign;  // !=0 if has identity opAssign 
     125    FuncDeclaration *cpctor;    // generated copy-constructor, if any 
     126 
     127    FuncDeclarations postblits; // Array of postblit functions 
     128    FuncDeclaration *postblit;  // aggregate postblit 
     129#endif 
    122130 
    123131    StructDeclaration(Loc loc, Identifier *id); 
     
    126134    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    127135    char *mangle(); 
    128     char *kind(); 
     136    const char *kind(); 
    129137    Expression *cloneMembers(); 
    130138    void toDocBuffer(OutBuffer *buf); 
     
    132140    PROT getAccess(Dsymbol *smember);   // determine access to smember 
    133141 
    134     void toObjFile();         // compile to .obj file 
     142    void toObjFile(int multiobj);         // compile to .obj file 
    135143    void toDt(dt_t **pdt); 
    136144    void toDebug();         // to symbolic debug info 
     
    143151    UnionDeclaration(Loc loc, Identifier *id); 
    144152    Dsymbol *syntaxCopy(Dsymbol *s); 
    145     char *kind(); 
     153    const char *kind(); 
    146154 
    147155    UnionDeclaration *isUnionDeclaration() { return this; } 
     
    169177}; 
    170178 
    171 #if V2 
     179#if DMDV2 
    172180#define CLASSINFO_SIZE  (0x3C+16)   // value of ClassInfo.size 
    173181#else 
     
    219227 
    220228    Dsymbol *search(Loc, Identifier *ident, int flags); 
    221 #if V2 
     229#if DMDV2 
    222230    int isFuncHidden(FuncDeclaration *fd); 
    223231#endif 
     
    227235    int isCOMclass(); 
    228236    virtual int isCOMinterface(); 
    229 #if V2 
     237#if DMDV2 
    230238    virtual int isCPPinterface(); 
    231239#endif 
    232240    int isAbstract(); 
    233241    virtual int vtblOffset(); 
    234     char *kind(); 
     242    const char *kind(); 
    235243    char *mangle(); 
    236244    void toDocBuffer(OutBuffer *buf); 
     
    241249 
    242250    // Back end 
    243     void toObjFile();         // compile to .obj file 
     251    void toObjFile(int multiobj);         // compile to .obj file 
    244252    void toDebug(); 
    245253    unsigned baseVtblOffset(BaseClass *bc); 
     
    259267struct InterfaceDeclaration : ClassDeclaration 
    260268{ 
    261 #if V2 
     269#if DMDV2 
    262270    int cpp;                // !=0 if this is a C++ interface 
    263271#endif 
     
    267275    int isBaseOf(ClassDeclaration *cd, int *poffset); 
    268276    int isBaseOf(BaseClass *bc, int *poffset); 
    269     char *kind(); 
     277    const char *kind(); 
    270278    int vtblOffset(); 
    271 #if V2 
     279#if DMDV2 
    272280    int isCPPinterface(); 
    273281#endif 
    274282    virtual int isCOMinterface(); 
    275283 
    276     void toObjFile();         // compile to .obj file 
     284    void toObjFile(int multiobj);         // compile to .obj file 
    277285    Symbol *toSymbol(); 
    278286 
  • dmd/attrib.c

    r159 r336  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2007 by Digital Mars 
     3// Copyright (c) 1999-2008 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    3636 
    3737extern void obj_includelib(char *name); 
     38void obj_startaddress(Symbol *s); 
    3839 
    3940 
     
    5354int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 
    5455{ 
    55     unsigned i; 
    5656    int m = 0; 
    5757    Array *d = include(sc, sd); 
     
    5959    if (d) 
    6060    { 
    61     for (i = 0; i < d->dim; i++) 
    62     {   Dsymbol *s; 
    63  
    64         s = (Dsymbol *)d->data[i]; 
     61    for (unsigned i = 0; i < d->dim; i++) 
     62    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    6563        m |= s->addMember(sc, sd, m | memnum); 
    6664    } 
     
    7371    Array *d = include(sc, NULL); 
    7472 
    75     //printf("\tAttribDeclaration::semantic '%s'\n",toChars()); 
     73    //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); 
    7674    if (d) 
    7775    { 
     
    8785void AttribDeclaration::semantic2(Scope *sc) 
    8886{ 
    89     unsigned i; 
    9087    Array *d = include(sc, NULL); 
    9188 
    9289    if (d) 
    9390    { 
    94     for (i = 0; i < d->dim; i++) 
    95     {   Dsymbol *s; 
    96  
    97         s = (Dsymbol *)d->data[i]; 
     91    for (unsigned i = 0; i < d->dim; i++) 
     92    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    9893        s->semantic2(sc); 
    9994    } 
     
    10398void AttribDeclaration::semantic3(Scope *sc) 
    10499{ 
    105     unsigned i; 
    106100    Array *d = include(sc, NULL); 
    107101 
    108102    if (d) 
    109103    { 
    110     for (i = 0; i < d->dim; i++) 
    111     {   Dsymbol *s; 
    112  
    113         s = (Dsymbol *)d->data[i]; 
     104    for (unsigned i = 0; i < d->dim; i++) 
     105    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    114106        s->semantic3(sc); 
    115107    } 
     
    119111void AttribDeclaration::inlineScan() 
    120112{ 
    121     unsigned i; 
    122113    Array *d = include(NULL, NULL); 
    123114 
    124115    if (d) 
    125116    { 
    126     for (i = 0; i < d->dim; i++) 
    127     {   Dsymbol *s; 
    128  
    129         s = (Dsymbol *)d->data[i]; 
     117    for (unsigned i = 0; i < d->dim; i++) 
     118    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    130119        //printf("AttribDeclaration::inlineScan %s\n", s->toChars()); 
    131120        s->inlineScan(); 
     
    138127    if (comment) 
    139128    { 
    140     unsigned i; 
    141129    Array *d = include(NULL, NULL); 
    142130 
    143131    if (d) 
    144132    { 
    145         for (i = 0; i < d->dim; i++) 
    146         {   Dsymbol *s; 
    147  
    148         s = (Dsymbol *)d->data[i]; 
     133        for (unsigned i = 0; i < d->dim; i++) 
     134        {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    149135        //printf("AttribDeclaration::addComment %s\n", s->toChars()); 
    150136        s->addComment(comment); 
     
    164150//  return; 
    165151 
    166     unsigned i; 
    167152    Array *d = include(NULL, NULL); 
    168153 
    169154    if (d) 
    170155    { 
    171     for (i = 0; i < d->dim; i++) 
    172     {   Dsymbol *s; 
    173  
    174         s = (Dsymbol *)d->data[i]; 
     156    for (unsigned i = 0; i < d->dim; i++) 
     157    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    175158        //printf("AttribDeclaration::emitComment %s\n", s->toChars()); 
    176159        s->emitComment(sc); 
     
    179162} 
    180163 
    181 void AttribDeclaration::toObjFile() 
    182 
    183     unsigned i; 
     164void AttribDeclaration::toObjFile(int multiobj) 
     165
    184166    Array *d = include(NULL, NULL); 
    185167 
    186168    if (d) 
    187169    { 
    188     for (i = 0; i < d->dim; i++) 
    189     {   Dsymbol *s; 
    190  
    191         s = (Dsymbol *)d->data[i]; 
    192         s->toObjFile(); 
     170    for (unsigned i = 0; i < d->dim; i++) 
     171    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
     172        s->toObjFile(multiobj); 
    193173    } 
    194174    } 
     
    197177int AttribDeclaration::cvMember(unsigned char *p) 
    198178{ 
    199     unsigned i; 
    200179    int nwritten = 0; 
    201180    int n; 
     
    204183    if (d) 
    205184    { 
    206     for (i = 0; i < d->dim; i++) 
    207     {   Dsymbol *s; 
    208  
    209         s = (Dsymbol *)d->data[i]; 
     185    for (unsigned i = 0; i < d->dim; i++) 
     186    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    210187        n = s->cvMember(p); 
    211188        if (p) 
     
    233210} 
    234211 
    235 char *AttribDeclaration::kind() 
     212const char *AttribDeclaration::kind() 
    236213{ 
    237214    return "attribute"; 
     
    247224void AttribDeclaration::checkCtorConstInit() 
    248225{ 
    249     unsigned i; 
    250226    Array *d = include(NULL, NULL); 
    251227 
    252228    if (d) 
    253229    { 
    254     for (i = 0; i < d->dim; i++) 
    255     {   Dsymbol *s; 
    256  
    257         s = (Dsymbol *)d->data[i]; 
     230    for (unsigned i = 0; i < d->dim; i++) 
     231    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    258232        s->checkCtorConstInit(); 
    259233    } 
     
    265239 
    266240void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses) 
    267 {   unsigned i; 
     241{ 
    268242    Array *d = include(NULL, NULL); 
    269243 
    270244    if (d) 
    271245    { 
    272     for (i = 0; i < d->dim; i++) 
    273     {   Dsymbol *s; 
    274  
    275         s = (Dsymbol *)d->data[i]; 
     246    for (unsigned i = 0; i < d->dim; i++) 
     247    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    276248        s->addLocalClass(aclasses); 
    277249    } 
     
    724696} 
    725697 
    726 char *AnonDeclaration::kind() 
     698const char *AnonDeclaration::kind() 
    727699{ 
    728700    return (char *)(isunion ? "anonymous union" : "anonymous struct"); 
     
    1024996} 
    1025997 
    1026 char *PragmaDeclaration::kind() 
     998const char *PragmaDeclaration::kind() 
    1027999{ 
    10281000    return "pragma"; 
    10291001} 
    10301002 
    1031 void PragmaDeclaration::toObjFile(
     1003void PragmaDeclaration::toObjFile(int multiobj
    10321004{ 
    10331005    if (ident == Id::lib) 
     
    10451017    obj_includelib(name); 
    10461018    } 
    1047     AttribDeclaration::toObjFile(); 
     1019    AttribDeclaration::toObjFile(multiobj); 
    10481020} 
    10491021 
     
    12151187int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 
    12161188{ 
     1189    //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); 
    12171190    /* This is deferred until semantic(), so that 
    12181191     * expressions in the condition can refer to declarations 
     
    12411214    Array *d = include(sc, sd); 
    12421215 
    1243     //printf("\tStaticIfDeclaration::semantic '%s'\n",toChars()); 
     1216    //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); 
    12441217    if (d) 
    12451218    { 
     
    12581231} 
    12591232 
    1260 char *StaticIfDeclaration::kind() 
     1233const char *StaticIfDeclaration::kind() 
    12611234{ 
    12621235    return "static if"; 
     
    12691242    : AttribDeclaration(NULL) 
    12701243{ 
     1244    this->loc = loc; 
    12711245    this->exp = exp; 
    12721246    this->sd = NULL; 
     1247    this->compiled = 0; 
    12731248} 
    12741249 
     
    12821257int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 
    12831258{ 
     1259    //printf("CompileDeclaration::addMember(sc = %p)\n", sc); 
    12841260    this->sd = sd; 
     1261    if (memnum == 0) 
     1262    {   /* No members yet, so parse the mixin now 
     1263     */ 
     1264    compileIt(sc); 
     1265    memnum |= AttribDeclaration::addMember(sc, sd, memnum); 
     1266    compiled = 1; 
     1267    } 
    12851268    return memnum; 
    12861269} 
    12871270 
    1288 void CompileDeclaration::semantic(Scope *sc) 
    1289 { 
    1290     //printf("CompileDeclaration::semantic()\n"); 
     1271void CompileDeclaration::compileIt(Scope *sc) 
     1272{ 
     1273    //printf("CompileDeclaration::compileIt()\n"); 
    12911274    exp = exp->semantic(sc); 
    12921275    exp = resolveProperties(sc, exp); 
    12931276    exp = exp->optimize(WANTvalue | WANTinterpret); 
    12941277    if (exp->op != TOKstring) 
    1295     {   error("argument to mixin must be a string, not (%s)", exp->toChars()); 
    1296     return; 
    1297     } 
    1298     StringExp *se = (StringExp *)exp; 
    1299     se = se->toUTF8(sc); 
    1300     Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 
    1301     p.loc = loc; 
    1302     p.nextToken(); 
    1303     decl = p.parseDeclDefs(0); 
    1304     if (p.token.value != TOKeof) 
    1305     { 
    1306     error("incomplete mixin declaration (%s)", se->toChars()); 
    1307     } 
    1308  
    1309     AttribDeclaration::addMember(sc, sd, 0); 
     1278    {   exp->error("argument to mixin must be a string, not (%s)", exp->toChars()); 
     1279    } 
     1280    else 
     1281    { 
     1282    StringExp *se = (StringExp *)exp; 
     1283    se = se->toUTF8(sc); 
     1284    Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 
     1285    p.loc = loc; 
     1286    p.nextToken(); 
     1287    decl = p.parseDeclDefs(0); 
     1288    if (p.token.value != TOKeof) 
     1289        exp->error("incomplete mixin declaration (%s)", se->toChars()); 
     1290    } 
     1291
     1292 
     1293void CompileDeclaration::semantic(Scope *sc) 
     1294
     1295    //printf("CompileDeclaration::semantic()\n"); 
     1296 
     1297    if (!compiled) 
     1298    { 
     1299    compileIt(sc); 
     1300    AttribDeclaration::addMember(sc, sd, 0); 
     1301    compiled = 1; 
     1302    } 
    13101303    AttribDeclaration::semantic(sc); 
    13111304} 
  • dmd/attrib.h

    r19 r336  
    4343    void addComment(unsigned char *comment); 
    4444    void emitComment(Scope *sc); 
    45     char *kind(); 
     45    const char *kind(); 
    4646    int oneMember(Dsymbol **ps); 
    4747    int hasPointers(); 
     
    5151    AttribDeclaration *isAttribDeclaration() { return this; } 
    5252 
    53     void toObjFile();         // compile to .obj file 
     53    void toObjFile(int multiobj);         // compile to .obj file 
    5454    int cvMember(unsigned char *p); 
    5555}; 
     
    107107    void semantic(Scope *sc); 
    108108    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    109     char *kind(); 
     109    const char *kind(); 
    110110}; 
    111111 
     
    119119    int oneMember(Dsymbol **ps); 
    120120    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    121     char *kind(); 
    122     void toObjFile();         // compile to .obj file 
     121    const char *kind(); 
     122    void toObjFile(int multiobj);         // compile to .obj file 
    123123}; 
    124124 
     
    146146    int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 
    147147    void semantic(Scope *sc); 
    148     char *kind(); 
     148    const char *kind(); 
    149149}; 
    150150 
     
    156156 
    157157    ScopeDsymbol *sd; 
     158    int compiled; 
    158159 
    159160    CompileDeclaration(Loc loc, Expression *exp); 
    160161    Dsymbol *syntaxCopy(Dsymbol *s); 
    161162    int addMember(Scope *sc, ScopeDsymbol *sd, int memnum); 
     163    void compileIt(Scope *sc); 
    162164    void semantic(Scope *sc); 
    163165    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
  • dmd/cast.c

    r215 r336  
    11 
    2 // Copyright (c) 1999-2006 by Digital Mars 
     2// Copyright (c) 1999-2008 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    13461346    } 
    13471347    else if (t1->ty == Tclass || t2->ty == Tclass) 
    1348     {   int i1; 
    1349     int i2; 
    1350  
    1351     i1 = e2->implicitConvTo(t1); 
    1352     i2 = e1->implicitConvTo(t2); 
    1353  
    1354     if (i1 && i2) 
    1355     { 
    1356         // We have the case of class vs. void*, so pick class 
    1357         if (t1->ty == Tpointer) 
    1358         i1 = 0; 
    1359         else if (t2->ty == Tpointer) 
    1360         i2 = 0; 
    1361     } 
    1362  
    1363     if (i2) 
    1364     { 
    1365         goto Lt2; 
    1366     } 
    1367     else if (i1) 
    1368     { 
    1369         goto Lt1; 
    1370     } 
    1371     else 
    1372         goto Lincompatible; 
     1348    { 
     1349    while (1) 
     1350    { 
     1351        int i1 = e2->implicitConvTo(t1); 
     1352        int i2 = e1->implicitConvTo(t2); 
     1353 
     1354        if (i1 && i2) 
     1355        { 
     1356        // We have the case of class vs. void*, so pick class 
     1357        if (t1->ty == Tpointer) 
     1358            i1 = 0; 
     1359        else if (t2->ty == Tpointer) 
     1360            i2 = 0; 
     1361        } 
     1362 
     1363        if (i2) 
     1364        { 
     1365        goto Lt2; 
     1366        } 
     1367        else if (i1) 
     1368        { 
     1369        goto Lt1; 
     1370        } 
     1371        else if (t1->ty == Tclass && t2->ty == Tclass) 
     1372        {   TypeClass *tc1 = (TypeClass *)t1; 
     1373        TypeClass *tc2 = (TypeClass *)t2; 
     1374 
     1375        /* Pick 'tightest' type 
     1376         */ 
     1377        ClassDeclaration *cd1 = tc1->sym->baseClass; 
     1378        ClassDeclaration *cd2 = tc1->sym->baseClass; 
     1379 
     1380        if (cd1 && cd2) 
     1381        {   t1 = cd1->type; 
     1382            t2 = cd2->type; 
     1383        } 
     1384        else if (cd1) 
     1385            t1 = cd1->type; 
     1386        else if (cd2) 
     1387            t2 = cd2->type; 
     1388        else 
     1389            goto Lincompatible; 
     1390        } 
     1391        else 
     1392        goto Lincompatible; 
     1393    } 
    13731394    } 
    13741395    else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 
  • dmd/class.c

    r159 r336  
    148148        } 
    149149 
    150 #if V2 
     150#if DMDV2 
    151151        if (id == Id::TypeInfo_Const) 
    152152        {   if (Type::typeinfoconst) 
     
    262262 
    263263    if (sc->stc & STCdeprecated) 
    264     {  //printf("test1: %s is deprecated\n", toChars()); 
     264    { 
    265265    isdeprecated = 1; 
    266266    } 
     
    303303    { 
    304304        tc = (TypeClass *)(tb); 
     305 
    305306        if (tc->sym->isDeprecated()) 
    306307        { 
     
    566567    scope->module->addDeferredSemantic(this); 
    567568 
    568     //printf("\tsemantic('%s') failed\n", toChars()); 
     569    //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 
    569570    return; 
    570571    } 
     
    600601    { 
    601602    //printf("Creating default this(){} for class %s\n", toChars()); 
    602     ctor = new CtorDeclaration(0, 0, NULL, 0); 
     603    ctor = new CtorDeclaration(loc, 0, NULL, 0); 
    603604    ctor->fbody = new CompoundStatement(0, new Statements()); 
    604605    members->push(ctor); 
     
    797798 */ 
    798799 
    799 #if V2 
     800#if DMDV2 
    800801int isf(void *param, FuncDeclaration *fd) 
    801802{ 
     
    858859 
    859860void ClassDeclaration::interfaceSemantic(Scope *sc) 
    860 {   int i; 
    861  
     861
    862862    vtblInterfaces = new BaseClasses(); 
    863863    vtblInterfaces->reserve(interfaces_dim); 
    864864 
    865     for (i = 0; i < interfaces_dim; i++) 
     865    for (size_t i = 0; i < interfaces_dim; i++) 
    866866    { 
    867867    BaseClass *b = interfaces[i]; 
     
    911911    return FALSE; 
    912912} 
     913 
    913914 
    914915/**************************************** 
     
    937938 */ 
    938939 
    939 char *ClassDeclaration::kind() 
     940const char *ClassDeclaration::kind() 
    940941{ 
    941942    return "class"; 
     
    12351236 */ 
    12361237 
    1237 char *InterfaceDeclaration::kind() 
     1238const char *InterfaceDeclaration::kind() 
    12381239{ 
    12391240    return "interface"; 
  • dmd/clone.c

    r159 r336  
    2929 */ 
    3030 
    31 #if V2 
     31#if DMDV2 
    3232Expression *StructDeclaration::cloneMembers() 
    3333{ 
     
    9090    Expression *e = NULL; 
    9191 
    92 #if V2 
     92#if DMDV2 
    9393    for (size_t i = 0; i < fields.dim; i++) 
    9494    { 
  • dmd/constfold.c

    r305 r336  
    14261426        e->type = type; 
    14271427    } 
    1428     else if (e1->op == TOKarrayliteral && 
     1428    else if ((e1->op == TOKarrayliteral || e1->op == TOKnull) && 
    14291429    e1->type->toBasetype()->nextOf()->equals(e2->type)) 
    14301430    { 
    1431     ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; 
    1432  
    1433     es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy()); 
    1434     es1->elements->push(e2); 
     1431    ArrayLiteralExp *es1; 
     1432    if (e1->op == TOKarrayliteral) 
     1433    {   es1 = (ArrayLiteralExp *)e1; 
     1434        es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy()); 
     1435        es1->elements->push(e2); 
     1436    } 
     1437    else 
     1438    { 
     1439        es1 = new ArrayLiteralExp(e1->loc, e2); 
     1440    } 
    14351441    e = es1; 
    14361442 
  • dmd/declaration.c

    r305 r336  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2007 by Digital Mars 
     3// Copyright (c) 1999-2008 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    4040} 
    4141 
    42 char *Declaration::kind() 
     42const char *Declaration::kind() 
    4343{ 
    4444    return "declaration"; 
     
    8080    return protection; 
    8181} 
     82 
     83/************************************* 
     84 * Check to see if declaration can be modified in this context (sc). 
     85 * Issue error if not. 
     86 */ 
     87 
     88#if DMDV2 
     89void Declaration::checkModify(Loc loc, Scope *sc, Type *t) 
     90{ 
     91    if (sc->incontract && isParameter()) 
     92    error(loc, "cannot modify parameter '%s' in contract", toChars()); 
     93 
     94    if (isCtorinit()) 
     95    {   // It's only modifiable if inside the right constructor 
     96    Dsymbol *s = sc->func; 
     97    while (1) 
     98    { 
     99        FuncDeclaration *fd = NULL; 
     100        if (s) 
     101        fd = s->isFuncDeclaration(); 
     102        if (fd && 
     103        ((fd->isCtorDeclaration() && storage_class & STCfield) || 
     104         (fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) && 
     105        fd->toParent() == toParent() 
     106           ) 
     107        { 
     108        VarDeclaration *v = isVarDeclaration(); 
     109        assert(v); 
     110        v->ctorinit = 1; 
     111        //printf("setting ctorinit\n"); 
     112        } 
     113        else 
     114        { 
     115        if (s) 
     116        {   s = s->toParent2(); 
     117            continue; 
     118        } 
     119        else 
     120        { 
     121            const char *p = isStatic() ? "static " : ""; 
     122            error(loc, "can only initialize %sconst %s inside %sconstructor", 
     123            p, toChars(), p); 
     124        } 
     125        } 
     126        break; 
     127    } 
     128    } 
     129    else 
     130    { 
     131    VarDeclaration *v = isVarDeclaration(); 
     132    if (v && v->canassign == 0) 
     133    { 
     134        char *p = NULL; 
     135        if (isConst()) 
     136        p = "const"; 
     137        else if (isInvariant()) 
     138        p = "invariant"; 
     139        else if (storage_class & STCmanifest) 
     140        p = "manifest constant"; 
     141        else if (!t->isAssignable()) 
     142        p = "struct with immutable members"; 
     143        if (p) 
     144        {   error(loc, "cannot modify %s", p); 
     145        halt(); 
     146        } 
     147    } 
     148    } 
     149} 
     150#endif 
     151 
    82152 
    83153/********************************* TupleDeclaration ****************************/ 
     
    98168} 
    99169 
    100 char *TupleDeclaration::kind() 
     170const char *TupleDeclaration::kind() 
    101171{ 
    102172    return "tuple"; 
     
    232302    if (sc->parent->isFuncDeclaration() && init) 
    233303        semantic2(sc); 
     304    storage_class |= sc->stc & STCdeprecated; 
    234305    } 
    235306    else if (sem == 1) 
     
    258329} 
    259330 
    260 char *TypedefDeclaration::kind() 
     331const char *TypedefDeclaration::kind() 
    261332{ 
    262333    return "typedef"; 
     
    319390Dsymbol *AliasDeclaration::syntaxCopy(Dsymbol *s) 
    320391{ 
     392    //printf("AliasDeclaration::syntaxCopy()\n"); 
    321393    assert(!s); 
    322394    AliasDeclaration *sa; 
     
    467539} 
    468540 
    469 char *AliasDeclaration::kind() 
     541const char *AliasDeclaration::kind() 
    470542{ 
    471543    return "alias"; 
     
    602674{ 
    603675    //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 
    604     //printf("type = %s\n", type->toChars()); 
     676    //printf(" type = %s\n", type ? type->toChars() : "null"); 
     677    //printf(" stc = x%x\n", sc->stc); 
     678    //printf(" storage_class = x%x\n", storage_class); 
    605679    //printf("linkage = %d\n", sc->linkage); 
    606680    //if (strcmp(toChars(), "mul") == 0) halt(); 
     
    630704    type = type->semantic(loc, sc); 
    631705    } 
     706    //printf(" semantic type = %s\n", type ? type->toChars() : "null"); 
    632707 
    633708    type->checkDeprecated(loc, sc); 
     
    637712    protection = sc->protection; 
    638713    //printf("sc->stc = %x\n", sc->stc); 
    639     //printf("storage_class = %x\n", storage_class); 
     714    //printf("storage_class = x%x\n", storage_class); 
    640715 
    641716    Dsymbol *parent = toParent(); 
     
    750825    } 
    751826 
     827    /* Templates cannot add fields to aggregates 
     828     */ 
    752829    TemplateInstance *ti = parent->isTemplateInstance(); 
    753830    if (ti) 
     
    854931        if (fd && !isStatic() && !isConst() && !init->isVoidInitializer()) 
    855932        { 
    856         Expression *e1; 
    857         Type *t; 
    858         int dim; 
    859  
    860933        //printf("fd = '%s', var = '%s'\n", fd->toChars(), toChars()); 
    861934        if (!ei) 
     
    875948        } 
    876949 
    877         e1 = new VarExp(loc, this); 
    878  
    879         t = type->toBasetype(); 
     950        Expression *e1 = new VarExp(loc, this); 
     951 
     952        Type *t = type->toBasetype(); 
    880953        if (t->ty == Tsarray) 
    881954        { 
     
    883956            if (!ei->exp->implicitConvTo(type)) 
    884957            { 
    885             dim = ((TypeSArray *)t)->dim->toInteger(); 
     958            int dim = ((TypeSArray *)t)->dim->toInteger(); 
    886959            // If multidimensional static array, treat as one large array 
    887960            while (1) 
     
    9751048    else 
    9761049    { 
    977     Expression *e = type->defaultInit(); 
     1050    Expression *e = type->defaultInit(loc); 
    9781051    if (e) 
    9791052        ei = new ExpInitializer(loc, e); 
     
    10021075} 
    10031076 
    1004 char *VarDeclaration::kind() 
     1077const char *VarDeclaration::kind() 
    10051078{ 
    10061079    return "variable"; 
     
    10211094    if (storage_class & STCstatic) 
    10221095    buf->writestring("static "); 
     1096    if (storage_class & STCauto) 
     1097    buf->writestring("auto "); 
     1098#if DMDV2 
     1099    if (storage_class & STCmanifest) 
     1100    buf->writestring("manifest "); 
     1101    if (storage_class & STCinvariant) 
     1102    buf->writestring("invariant "); 
     1103    if (storage_class & STCtls) 
     1104    buf->writestring("__thread "); 
     1105#endif 
     1106 
    10231107    if (type) 
    10241108    type->toCBuffer(buf, ident, hgs); 
     
    10531137 
    10541138/************************************ 
    1055  * Check to see if variable is a reference to an enclosing function 
    1056  * or not
     1139 * Check to see if this variable is actually in an enclosing function 
     1140 * rather than the current one
    10571141 */ 
    10581142 
    10591143void VarDeclaration::checkNestedReference(Scope *sc, Loc loc) 
    10601144{ 
     1145    //printf("VarDeclaration::checkNestedReference() %s\n", toChars()); 
    10611146    if (parent && !isDataseg() && parent != sc->parent) 
    10621147    { 
     1148    // The function that this variable is in 
    10631149    FuncDeclaration *fdv = toParent()->isFuncDeclaration(); 
     1150    // The current function 
    10641151    FuncDeclaration *fdthis = sc->parent->isFuncDeclaration(); 
    10651152 
     
    10781165/******************************* 
    10791166 * Does symbol go into data segment? 
     1167