Changeset 214

Show
Ignore:
Timestamp:
10/14/09 22:36:24 (2 years ago)
Author:
walter
Message:

bugzilla 3401

Files:

Legend:

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

    r202 r214  
    15041504    /* Implementing this is done by having the overriding function call 
    15051505     * nested functions (the fdrequire functions) nested inside the overridden 
    15061506     * function. This requires that the stack layout of the calling function's 
    15071507     * parameters and 'this' pointer be in the same place (as the nested 
    15081508     * function refers to them). 
    15091509     * This is easy for the parameters, as they are all on the stack in the same 
    15101510     * place by definition, since it's an overriding function. The problem is 
    15111511     * getting the 'this' pointer in the same place, since it is a local variable. 
    15121512     * We did some hacks in the code generator to make this happen: 
    15131513     *  1. always generate exception handler frame, or at least leave space for it 
    15141514     *     in the frame (Windows 32 SEH only) 
    15151515     *  2. always generate an EBP style frame 
    15161516     *  3. since 'this' is passed in a register that is subsequently copied into 
    15171517     *     a stack local, allocate that local immediately following the exception 
    15181518     *     handler block, so it is always at the same offset from EBP. 
    15191519     */ 
    15201520    for (int i = 0; i < foverrides.dim; i++) 
    15211521    { 
    15221522    FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i]; 
    15231523    sf = fdv->mergeFrequire(sf); 
    1524     if (fdv->frequire) 
     1524    if (fdv->fdrequire) 
    15251525    { 
    15261526        //printf("fdv->frequire: %s\n", fdv->frequire->toChars()); 
    15271527        /* Make the call: 
    15281528         *   try { __require(); } 
    15291529         *   catch { frequire; } 
    15301530         */ 
    15311531        Expression *eresult = NULL; 
    15321532        Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdrequire), eresult); 
    15331533        Statement *s2 = new ExpStatement(loc, e); 
    15341534 
    15351535        if (sf) 
    15361536        {   Catch *c = new Catch(loc, NULL, NULL, sf); 
    15371537        Array *catches = new Array(); 
    15381538        catches->push(c); 
    15391539        sf = new TryCatchStatement(loc, s2, catches); 
    15401540        } 
    15411541        else 
    15421542        sf = s2; 
    15431543    } 
    15441544    } 
     
    15481548/**************************************************** 
    15491549 * Merge into this function the 'out' contracts of all it overrides. 
    15501550 * 'out's are AND'd together, i.e. all of them need to pass. 
    15511551 */ 
    15521552 
    15531553Statement *FuncDeclaration::mergeFensure(Statement *sf) 
    15541554{ 
    15551555    /* Same comments as for mergeFrequire(), except that we take care 
    15561556     * of generating a consistent reference to the 'result' local by 
    15571557     * explicitly passing 'result' to the nested function as a reference 
    15581558     * argument. 
    15591559     * This won't work for the 'this' parameter as it would require changing 
    15601560     * the semantic code for the nested function so that it looks on the parameter 
    15611561     * list for the 'this' pointer, something that would need an unknown amount 
    15621562     * of tweaking of various parts of the compiler that I'd rather leave alone. 
    15631563     */ 
    15641564    for (int i = 0; i < foverrides.dim; i++) 
    15651565    { 
    15661566    FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i]; 
    15671567    sf = fdv->mergeFensure(sf); 
    1568     if (fdv->fensure) 
     1568    if (fdv->fdensure) 
    15691569    { 
    15701570        //printf("fdv->fensure: %s\n", fdv->fensure->toChars()); 
    15711571        // Make the call: __ensure(result) 
    15721572        Expression *eresult = NULL; 
    15731573        if (outId) 
    15741574        eresult = new IdentifierExp(loc, outId); 
    15751575        Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdensure), eresult); 
    15761576        Statement *s2 = new ExpStatement(loc, e); 
    15771577 
    15781578        if (sf) 
    15791579        { 
    15801580        sf = new CompoundStatement(fensure->loc, s2, sf); 
    15811581        } 
    15821582        else 
    15831583        sf = s2; 
    15841584    } 
    15851585    } 
    15861586    return sf; 
    15871587} 
    15881588 
  • branches/dmd-1.x/src/mars.c

    r205 r214  
    6363#elif TARGET_NET 
    6464#else 
    6565#error "fix this" 
    6666#endif 
    6767 
    6868#if TARGET_WINDOS 
    6969    lib_ext  = "lib"; 
    7070#elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS 
    7171    lib_ext  = "a"; 
    7272#elif TARGET_NET 
    7373#else 
    7474#error "fix this" 
    7575#endif 
    7676 
    7777    copyright = "Copyright (c) 1999-2009 by Digital Mars"; 
    7878    written = "written by Walter Bright" 
    7979#if TARGET_NET 
    8080    "\nMSIL back-end (alpha release) by Cristian L. Vlasceanu and associates."; 
    8181#endif 
    8282    ; 
    83     version = "v1.050"; 
     83    version = "v1.051"; 
    8484    global.structalign = 8; 
    8585 
    8686    memset(&params, 0, sizeof(Param)); 
    8787} 
    8888 
    8989char *Loc::toChars() 
    9090{ 
    9191    OutBuffer buf; 
    9292    char *p; 
    9393 
    9494    if (filename) 
    9595    { 
    9696    buf.printf("%s", filename); 
    9797    } 
    9898 
    9999    if (linnum) 
    100100    buf.printf("(%d)", linnum); 
    101101    buf.writeByte(0); 
    102102    return (char *)buf.extractData(); 
    103103} 
  • trunk/src/func.c

    r202 r214  
    15331533    /* Implementing this is done by having the overriding function call 
    15341534     * nested functions (the fdrequire functions) nested inside the overridden 
    15351535     * function. This requires that the stack layout of the calling function's 
    15361536     * parameters and 'this' pointer be in the same place (as the nested 
    15371537     * function refers to them). 
    15381538     * This is easy for the parameters, as they are all on the stack in the same 
    15391539     * place by definition, since it's an overriding function. The problem is 
    15401540     * getting the 'this' pointer in the same place, since it is a local variable. 
    15411541     * We did some hacks in the code generator to make this happen: 
    15421542     *  1. always generate exception handler frame, or at least leave space for it 
    15431543     *     in the frame (Windows 32 SEH only) 
    15441544     *  2. always generate an EBP style frame 
    15451545     *  3. since 'this' is passed in a register that is subsequently copied into 
    15461546     *     a stack local, allocate that local immediately following the exception 
    15471547     *     handler block, so it is always at the same offset from EBP. 
    15481548     */ 
    15491549    for (int i = 0; i < foverrides.dim; i++) 
    15501550    { 
    15511551    FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i]; 
    15521552    sf = fdv->mergeFrequire(sf); 
    1553     if (fdv->frequire) 
     1553    if (fdv->fdrequire) 
    15541554    { 
    15551555        //printf("fdv->frequire: %s\n", fdv->frequire->toChars()); 
    15561556        /* Make the call: 
    15571557         *   try { __require(); } 
    15581558         *   catch { frequire; } 
    15591559         */ 
    15601560        Expression *eresult = NULL; 
    15611561        Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdrequire, 0), eresult); 
    15621562        Statement *s2 = new ExpStatement(loc, e); 
    15631563 
    15641564        if (sf) 
    15651565        {   Catch *c = new Catch(loc, NULL, NULL, sf); 
    15661566        Array *catches = new Array(); 
    15671567        catches->push(c); 
    15681568        sf = new TryCatchStatement(loc, s2, catches); 
    15691569        } 
    15701570        else 
    15711571        sf = s2; 
    15721572    } 
    15731573    } 
     
    15771577/**************************************************** 
    15781578 * Merge into this function the 'out' contracts of all it overrides. 
    15791579 * 'out's are AND'd together, i.e. all of them need to pass. 
    15801580 */ 
    15811581 
    15821582Statement *FuncDeclaration::mergeFensure(Statement *sf) 
    15831583{ 
    15841584    /* Same comments as for mergeFrequire(), except that we take care 
    15851585     * of generating a consistent reference to the 'result' local by 
    15861586     * explicitly passing 'result' to the nested function as a reference 
    15871587     * argument. 
    15881588     * This won't work for the 'this' parameter as it would require changing 
    15891589     * the semantic code for the nested function so that it looks on the parameter 
    15901590     * list for the 'this' pointer, something that would need an unknown amount 
    15911591     * of tweaking of various parts of the compiler that I'd rather leave alone. 
    15921592     */ 
    15931593    for (int i = 0; i < foverrides.dim; i++) 
    15941594    { 
    15951595    FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i]; 
    15961596    sf = fdv->mergeFensure(sf); 
    1597     if (fdv->fensure) 
     1597    if (fdv->fdensure) 
    15981598    { 
    15991599        //printf("fdv->fensure: %s\n", fdv->fensure->toChars()); 
    16001600        // Make the call: __ensure(result) 
    16011601        Expression *eresult = NULL; 
    16021602        if (outId) 
    16031603        eresult = new IdentifierExp(loc, outId); 
    16041604        Expression *e = new CallExp(loc, new VarExp(loc, fdv->fdensure, 0), eresult); 
    16051605        Statement *s2 = new ExpStatement(loc, e); 
    16061606 
    16071607        if (sf) 
    16081608        { 
    16091609        sf = new CompoundStatement(fensure->loc, s2, sf); 
    16101610        } 
    16111611        else 
    16121612        sf = s2; 
    16131613    } 
    16141614    } 
    16151615    return sf; 
    16161616} 
    16171617 
  • trunk/src/json.c

    r204 r214  
    154154    buf->printf("%d", value); 
    155155    buf->writestring(",\n"); 
    156156} 
    157157 
    158158void JsonRemoveComma(OutBuffer *buf) 
    159159{ 
    160160    if (buf->offset >= 2 && 
    161161    buf->data[buf->offset - 2] == ',' && 
    162162    buf->data[buf->offset - 1] == '\n') 
    163163    buf->offset -= 2; 
    164164} 
    165165 
    166166void Dsymbol::toJsonBuffer(OutBuffer *buf) 
    167167{ 
    168168} 
    169169 
    170170void Module::toJsonBuffer(OutBuffer *buf) 
    171171{ 
    172172    buf->writestring("{\n"); 
    173173 
    174     JsonProperty(buf, Pname, md->toChars()); 
     174    if (md) 
     175    JsonProperty(buf, Pname, md->toChars()); 
    175176 
    176177    JsonProperty(buf, Pkind, kind()); 
    177178 
    178179    JsonProperty(buf, Pfile, srcfile->toChars()); 
    179180 
    180181    if (comment) 
    181182    JsonProperty(buf, Pcomment, (const char *)comment); 
    182183 
    183184    JsonString(buf, Pmembers); 
    184185    buf->writestring(" : [\n"); 
    185186 
    186187    size_t offset = buf->offset; 
    187188    for (int i = 0; i < members->dim; i++) 
    188189    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    189190    if (offset != buf->offset) 
    190     {   buf->writestring(","); 
     191    {   buf->writestring(",\n"); 
    191192        offset = buf->offset; 
    192193    } 
    193194    s->toJsonBuffer(buf); 
    194195    } 
    195196 
     197    JsonRemoveComma(buf); 
    196198    buf->writestring("]\n"); 
    197199 
    198200    buf->writestring("}\n"); 
    199201} 
    200202 
    201203void AttribDeclaration::toJsonBuffer(OutBuffer *buf) 
    202204{ 
    203205    //printf("AttribDeclaration::toJsonBuffer()\n"); 
    204206 
    205207    Array *d = include(NULL, NULL); 
    206208 
    207209    if (d) 
    208210    { 
    209211    for (unsigned i = 0; i < d->dim; i++) 
    210212    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    211213        //printf("AttribDeclaration::toJsonBuffer %s\n", s->toChars()); 
    212214        s->toJsonBuffer(buf); 
    213215    } 
    214216    } 
    215217} 
     
    272274    if (comment) 
    273275    JsonProperty(buf, Pcomment, (const char *)comment); 
    274276    if (loc.linnum) 
    275277    JsonProperty(buf, Pline, loc.linnum); 
    276278 
    277279    ClassDeclaration *cd = isClassDeclaration(); 
    278280    if (cd) 
    279281    { 
    280282    if (cd->baseClass) 
    281283    { 
    282284        JsonProperty(buf, "base", cd->baseClass->toChars()); 
    283285    } 
    284286    if (cd->interfaces_dim) 
    285287    { 
    286288        JsonString(buf, "interfaces"); 
    287289        buf->writestring(" : [\n"); 
    288290        size_t offset = buf->offset; 
    289291        for (int i = 0; i < cd->interfaces_dim; i++) 
    290292        {   BaseClass *b = cd->interfaces[i]; 
    291293        if (offset != buf->offset) 
    292         {   buf->writestring(","); 
     294        {   buf->writestring(",\n"); 
    293295            offset = buf->offset; 
    294296        } 
    295297        JsonString(buf, b->base->toChars()); 
    296298        } 
     299        JsonRemoveComma(buf); 
    297300        buf->writestring("],\n"); 
    298301    } 
    299302    } 
    300303 
    301304    JsonString(buf, Pmembers); 
    302305    buf->writestring(" : [\n"); 
    303306    size_t offset = buf->offset; 
    304307    for (int i = 0; i < members->dim; i++) 
    305308    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    306309    if (offset != buf->offset) 
    307     {   buf->writestring(","); 
     310    {   buf->writestring(",\n"); 
    308311        offset = buf->offset; 
    309312    } 
    310313    s->toJsonBuffer(buf); 
    311314    } 
     315    JsonRemoveComma(buf); 
    312316    buf->writestring("]\n"); 
    313317 
    314318    buf->writestring("}\n"); 
    315319} 
    316320 
    317321void TemplateDeclaration::toJsonBuffer(OutBuffer *buf) 
    318322{ 
    319323    //printf("TemplateDeclaration::toJsonBuffer()\n"); 
    320324 
    321325    buf->writestring("{\n"); 
    322326 
    323327    JsonProperty(buf, Pname, toChars()); 
    324328    JsonProperty(buf, Pkind, kind()); 
    325329    if (comment) 
    326330    JsonProperty(buf, Pcomment, (const char *)comment); 
    327331 
    328332    if (loc.linnum) 
    329333    JsonProperty(buf, Pline, loc.linnum); 
    330334 
    331335    JsonString(buf, Pmembers); 
    332336    buf->writestring(" : [\n"); 
    333337    size_t offset = buf->offset; 
    334338    for (int i = 0; i < members->dim; i++) 
    335339    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    336340    if (offset != buf->offset) 
    337     {   buf->writestring(","); 
     341    {   buf->writestring(",\n"); 
    338342        offset = buf->offset; 
    339343    } 
    340344    s->toJsonBuffer(buf); 
    341345    } 
     346    JsonRemoveComma(buf); 
    342347    buf->writestring("]\n"); 
    343348 
    344349    buf->writestring("}\n"); 
    345350} 
    346351 
    347352void EnumDeclaration::toJsonBuffer(OutBuffer *buf) 
    348353{ 
    349354    //printf("EnumDeclaration::toJsonBuffer()\n"); 
    350355    if (isAnonymous()) 
    351356    { 
    352357    if (members) 
    353358    { 
    354359        for (int i = 0; i < members->dim; i++) 
    355360        { 
    356361        Dsymbol *s = (Dsymbol *)members->data[i]; 
    357362        s->toJsonBuffer(buf); 
    358363        buf->writestring(",\n"); 
    359364        } 
    360365        JsonRemoveComma(buf); 
    361366    } 
     
    364369 
    365370    buf->writestring("{\n"); 
    366371 
    367372    JsonProperty(buf, Pname, toChars()); 
    368373    JsonProperty(buf, Pkind, kind()); 
    369374    if (comment) 
    370375    JsonProperty(buf, Pcomment, (const char *)comment); 
    371376 
    372377    if (loc.linnum) 
    373378    JsonProperty(buf, Pline, loc.linnum); 
    374379 
    375380    if (memtype) 
    376381    JsonProperty(buf, "base", memtype->toChars()); 
    377382 
    378383    JsonString(buf, Pmembers); 
    379384    buf->writestring(" : [\n"); 
    380385    size_t offset = buf->offset; 
    381386    for (int i = 0; i < members->dim; i++) 
    382387    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    383388    if (offset != buf->offset) 
    384     {   buf->writestring(","); 
     389    {   buf->writestring(",\n"); 
    385390        offset = buf->offset; 
    386391    } 
    387392    s->toJsonBuffer(buf); 
    388393    } 
     394    JsonRemoveComma(buf); 
    389395    buf->writestring("]\n"); 
    390396 
    391397    buf->writestring("}\n"); 
    392398} 
    393399 
    394400void EnumMember::toJsonBuffer(OutBuffer *buf) 
    395401{ 
    396402    //printf("EnumMember::toJsonBuffer()\n"); 
    397403    buf->writestring("{\n"); 
    398404 
    399405    JsonProperty(buf, Pname, toChars()); 
    400406    JsonProperty(buf, Pkind, kind()); 
    401407 
    402408    if (comment) 
    403409    JsonProperty(buf, Pcomment, (const char *)comment); 
    404410 
    405411    if (loc.linnum) 
    406412    JsonProperty(buf, Pline, loc.linnum); 
    407413 
    408414    JsonRemoveComma(buf); 
  • trunk/src/mars.c

    r208 r214  
    6363#elif TARGET_NET 
    6464#else 
    6565#error "fix this" 
    6666#endif 
    6767 
    6868#if TARGET_WINDOS 
    6969    lib_ext  = "lib"; 
    7070#elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS 
    7171    lib_ext  = "a"; 
    7272#elif TARGET_NET 
    7373#else 
    7474#error "fix this" 
    7575#endif 
    7676 
    7777    copyright = "Copyright (c) 1999-2009 by Digital Mars"; 
    7878    written = "written by Walter Bright" 
    7979#if TARGET_NET 
    8080    "\nMSIL back-end (alpha release) by Cristian L. Vlasceanu and associates."; 
    8181#endif 
    8282    ; 
    83     version = "v2.035"; 
     83    version = "v2.036"; 
    8484    global.structalign = 8; 
    8585 
    8686    memset(&params, 0, sizeof(Param)); 
    8787} 
    8888 
    8989char *Loc::toChars() 
    9090{ 
    9191    OutBuffer buf; 
    9292    char *p; 
    9393 
    9494    if (filename) 
    9595    { 
    9696    buf.printf("%s", filename); 
    9797    } 
    9898 
    9999    if (linnum) 
    100100    buf.printf("(%d)", linnum); 
    101101    buf.writeByte(0); 
    102102    return (char *)buf.extractData(); 
    103103}