Changeset 740

Show
Ignore:
Timestamp:
08/07/07 23:33:56 (1 year ago)
Author:
Gregor
Message:

MERGE: DMD 1.019

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmdfe/Makefile

    r362 r740  
    22CXX=$(CROSS)g++ 
    33NATIVECXX=g++ 
    4 CXXFLAGS=-O2 -
     4CXXFLAGS=-
    55 
    66EXEEXT= 
  • branches/dmdfe/attrib.c

    r659 r740  
    255255    } 
    256256    else 
    257     buf->writeByte(':'); 
     257    buf->writeByte(';'); 
    258258    buf->writenl(); 
    259259} 
  • branches/dmdfe/cast.c

    r657 r740  
    8888 */ 
    8989 
    90 int Expression::implicitConvTo(Type *t) 
     90MATCH Expression::implicitConvTo(Type *t) 
    9191{ 
    9292#if 0 
     
    105105    return e->implicitConvTo(t); 
    106106    } 
    107     int match = type->implicitConvTo(t); 
     107    MATCH match = type->implicitConvTo(t); 
    108108    if (match) 
    109109    return match; 
     
    130130 
    131131 
    132 int IntegerExp::implicitConvTo(Type *t) 
     132MATCH IntegerExp::implicitConvTo(Type *t) 
    133133{ 
    134134#if 0 
     
    143143 
    144144    if (type->implicitConvTo(t) == MATCHnomatch && t->ty == Tenum) 
     145    { 
    145146    return MATCHnomatch; 
     147    } 
    146148 
    147149    switch (ty) 
     
    303305 
    304306Lyes: 
     307    //printf("MATCHconvert\n"); 
    305308    return MATCHconvert; 
    306309 
    307310Lno: 
     311    //printf("MATCHnomatch\n"); 
    308312    return MATCHnomatch; 
    309313} 
    310314 
    311 int NullExp::implicitConvTo(Type *t) 
     315MATCH NullExp::implicitConvTo(Type *t) 
    312316{ 
    313317#if 0 
     
    330334} 
    331335 
    332 int StringExp::implicitConvTo(Type *t) 
     336MATCH StringExp::implicitConvTo(Type *t) 
    333337{   MATCH m; 
    334338 
     
    382386} 
    383387 
    384 int ArrayLiteralExp::implicitConvTo(Type *t) 
     388MATCH ArrayLiteralExp::implicitConvTo(Type *t) 
    385389{   MATCH result = MATCHexact; 
    386390 
     
    410414} 
    411415 
    412 int AssocArrayLiteralExp::implicitConvTo(Type *t) 
     416MATCH AssocArrayLiteralExp::implicitConvTo(Type *t) 
    413417{   MATCH result = MATCHexact; 
    414418 
     
    437441} 
    438442 
    439 int AddrExp::implicitConvTo(Type *t) 
     443MATCH AddrExp::implicitConvTo(Type *t) 
    440444{ 
    441445#if 0 
     
    443447    toChars(), type->toChars(), t->toChars()); 
    444448#endif 
    445     int result; 
     449    MATCH result; 
    446450 
    447451    result = type->implicitConvTo(t); 
     
    469473} 
    470474 
    471 int SymOffExp::implicitConvTo(Type *t) 
     475MATCH SymOffExp::implicitConvTo(Type *t) 
    472476{ 
    473477#if 0 
     
    475479    toChars(), type->toChars(), t->toChars()); 
    476480#endif 
    477     int result; 
     481    MATCH result; 
    478482 
    479483    result = type->implicitConvTo(t); 
     
    498502} 
    499503 
    500 int DelegateExp::implicitConvTo(Type *t) 
     504MATCH DelegateExp::implicitConvTo(Type *t) 
    501505{ 
    502506#if 0 
     
    504508    toChars(), type->toChars(), t->toChars()); 
    505509#endif 
    506     int result; 
     510    MATCH result; 
    507511 
    508512    result = type->implicitConvTo(t); 
     
    518522    { 
    519523        if (func && func->overloadExactMatch(t->next)) 
    520         result = 2
     524        result = MATCHexact
    521525    } 
    522526    } 
     
    524528} 
    525529 
    526 int CondExp::implicitConvTo(Type *t) 
    527 { 
    528     int m1; 
    529     int m2; 
     530MATCH CondExp::implicitConvTo(Type *t) 
     531{ 
     532    MATCH m1; 
     533    MATCH m2; 
    530534 
    531535    m1 = e1->implicitConvTo(t); 
  • branches/dmdfe/constfold.c

    r656 r740  
    2323#include "mtype.h" 
    2424#include "expression.h" 
     25#include "aggregate.h" 
     26#include "declaration.h" 
    2527 
    2628#ifdef IN_GCC 
     
    10271029    else if (tb->isscalar()) 
    10281030    e = new IntegerExp(loc, e1->toInteger(), type); 
     1031    else if (tb->ty == Tvoid) 
     1032    e = EXP_CANT_INTERPRET; 
     1033    else if (tb->ty == Tstruct && e1->op == TOKint64) 
     1034    {   // Struct = 0; 
     1035    StructDeclaration *sd = tb->toDsymbol(NULL)->isStructDeclaration(); 
     1036    assert(sd); 
     1037    Expressions *elements = new Expressions; 
     1038    for (size_t i = 0; i < sd->fields.dim; i++) 
     1039    {   Dsymbol *s = (Dsymbol *)sd->fields.data[i]; 
     1040        VarDeclaration *v = s->isVarDeclaration(); 
     1041        assert(v); 
     1042 
     1043        Expression *exp = new IntegerExp(0); 
     1044        exp = Cast(v->type, v->type, exp); 
     1045        if (exp == EXP_CANT_INTERPRET) 
     1046        return exp; 
     1047        elements->push(exp); 
     1048    } 
     1049    e = new StructLiteralExp(loc, sd, elements); 
     1050    e->type = type; 
     1051    } 
    10291052    else 
    10301053    { 
    1031     if (tb->ty == Tvoid) 
    1032         e = EXP_CANT_INTERPRET; 
    1033     else 
    1034     {   error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); 
    1035         e = new IntegerExp(loc, 0, type); 
    1036     } 
     1054    error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); 
     1055    e = new IntegerExp(loc, 0, type); 
    10371056    } 
    10381057    return e; 
     
    10801099 
    10811100    if (i >= es1->len) 
    1082         e1->error("string index %ju is out of bounds [0 .. %ju]", i, es1->len); 
     1101        e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); 
    10831102    else 
    10841103    {   integer_t value; 
  • branches/dmdfe/declaration.h

    r458 r740  
    7575 
    7676void overloadResolveX(Match *m, FuncDeclaration *f, Expressions *arguments); 
     77int overloadApply(FuncDeclaration *fstart, 
     78    int (*fp)(void *, FuncDeclaration *), 
     79    void *param); 
    7780 
    7881/**************************************************************/ 
  • branches/dmdfe/expression.c

    r659 r740  
    31323132    if (cd->isInterfaceDeclaration()) 
    31333133        error("cannot create instance of interface %s", cd->toChars()); 
    3134     if (cd->isAbstract()) 
     3134    else if (cd->isAbstract()) 
    31353135        error("cannot create instance of abstract class %s", cd->toChars()); 
    31363136    checkDeprecated(sc, cd); 
  • branches/dmdfe/expression.h

    r659 r740  
    100100    virtual Expression *modifiableLvalue(Scope *sc, Expression *e); 
    101101    Expression *implicitCastTo(Scope *sc, Type *t); 
    102     virtual int implicitConvTo(Type *t); 
     102    virtual MATCH implicitConvTo(Type *t); 
    103103    virtual Expression *castTo(Scope *sc, Type *t); 
    104104    virtual void checkEscape(); 
     
    156156    int isConst(); 
    157157    int isBool(int result); 
    158     int implicitConvTo(Type *t); 
     158    MATCH implicitConvTo(Type *t); 
    159159    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    160160    void toMangleBuffer(OutBuffer *buf); 
     
    275275    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    276276    void toMangleBuffer(OutBuffer *buf); 
    277     int implicitConvTo(Type *t); 
     277    MATCH implicitConvTo(Type *t); 
    278278    Expression *castTo(Scope *sc, Type *t); 
    279279    Expression *interpret(InterState *istate); 
     
    297297    Expression *interpret(InterState *istate); 
    298298    StringExp *toUTF8(Scope *sc); 
    299     int implicitConvTo(Type *t); 
     299    MATCH implicitConvTo(Type *t); 
    300300    Expression *castTo(Scope *sc, Type *t); 
    301301    int compare(Object *obj); 
     
    345345    Expression *optimize(int result); 
    346346    Expression *interpret(InterState *istate); 
    347     int implicitConvTo(Type *t); 
     347    MATCH implicitConvTo(Type *t); 
    348348    Expression *castTo(Scope *sc, Type *t); 
    349349    dt_t **toDt(dt_t **pdt); 
     
    371371    Expression *optimize(int result); 
    372372    Expression *interpret(InterState *istate); 
    373     int implicitConvTo(Type *t); 
     373    MATCH implicitConvTo(Type *t); 
    374374    Expression *castTo(Scope *sc, Type *t); 
    375375 
     
    504504    int isBool(int result); 
    505505    Expression *doInline(InlineDoState *ids); 
    506     int implicitConvTo(Type *t); 
     506    MATCH implicitConvTo(Type *t); 
    507507    Expression *castTo(Scope *sc, Type *t); 
    508508    void scanForNestedRef(Scope *sc); 
     
    649649    Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *)); 
    650650    Expression *interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *)); 
    651     Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *)); 
     651    Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0); 
    652652 
    653653    int inlineCost(InlineCostState *ics); 
     
    745745    DelegateExp(Loc loc, Expression *e, FuncDeclaration *func); 
    746746    Expression *semantic(Scope *sc); 
    747     int implicitConvTo(Type *t); 
     747    MATCH implicitConvTo(Type *t); 
    748748    Expression *castTo(Scope *sc, Type *t); 
    749749    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
     
    790790    AddrExp(Loc loc, Expression *e); 
    791791    Expression *semantic(Scope *sc); 
    792     int implicitConvTo(Type *t); 
     792    elem *toElem(IRState *irs); 
     793    MATCH implicitConvTo(Type *t); 
    793794    Expression *castTo(Scope *sc, Type *t); 
    794795    Expression *optimize(int result); 
     
    12621263    int checkSideEffect(int flag); 
    12631264    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    1264     int implicitConvTo(Type *t); 
     1265    MATCH implicitConvTo(Type *t); 
    12651266    Expression *castTo(Scope *sc, Type *t); 
    12661267    void scanForNestedRef(Scope *sc); 
  • branches/dmdfe/func.c

    r659 r740  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2006 by Digital Mars 
     3// Copyright (c) 1999-2007 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    6868    introducing = 0; 
    6969    tintro = NULL; 
    70     inferRetType = (type && type->next == NULL); 
     70    inferRetType = (type && type->nextOf() == NULL); 
    7171    scope = NULL; 
    7272    hasReturnExp = 0; 
     
    110110#endif 
    111111 
    112     if (type->next
     112    if (type->nextOf()
    113113    type = type->semantic(loc, sc); 
    114114    //type->print(); 
     
    145145    if (isStaticConstructor() || isStaticDestructor()) 
    146146    { 
    147     if (!isStatic() || type->next->ty != Tvoid) 
     147    if (!isStatic() || type->nextOf()->ty != Tvoid) 
    148148        error("static constructors / destructors must be static void"); 
    149149    if (f->arguments && f->arguments->dim) 
     
    317317                 */ 
    318318                int offset; 
    319                 if (fdv->type->next->isBaseOf(type->next, &offset)) 
     319                if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) 
    320320                { 
    321321                tintro = fdv->type; 
     
    398398                 */ 
    399399                int offset; 
    400                 if (fdv->type->next->isBaseOf(type->next, &offset)) 
     400                if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) 
    401401                { 
    402402                ti = fdv->type; 
     
    490490    } 
    491491 
    492     if (f->next->ty != Tint32 && f->next->ty != Tvoid) 
    493         error("must return int or void, not %s", f->next->toChars()); 
     492    if (f->nextOf()->ty != Tint32 && f->nextOf()->ty != Tvoid) 
     493        error("must return int or void, not %s", f->nextOf()->toChars()); 
    494494    if (f->varargs) 
    495495    { 
     
    513513        Type *tb = sd ? sd->type : cd->type; 
    514514        if (arg0->type->implicitConvTo(tb) || 
    515         (sd && t0->ty == Tpointer && t0->next->implicitConvTo(tb)) 
     515        (sd && t0->ty == Tpointer && t0->nextOf()->implicitConvTo(tb)) 
    516516           ) 
    517517        { 
     
    794794        sc2 = sc2->push(sym); 
    795795 
    796         assert(type->next); 
    797         if (type->next->ty == Tvoid) 
     796        assert(type->nextOf()); 
     797        if (type->nextOf()->ty == Tvoid) 
    798798        { 
    799799        if (outId) 
     
    814814            loc = fensure->loc; 
    815815 
    816         v = new VarDeclaration(loc, type->next, outId, NULL); 
     816        v = new VarDeclaration(loc, type->nextOf(), outId, NULL); 
    817817        v->noauto = 1; 
    818818        sc2->incontract--; 
     
    910910        if (inferRetType) 
    911911        {   // If no return type inferred yet, then infer a void 
    912         if (!type->next
     912        if (!type->nextOf()
    913913        { 
    914914            type->next = Type::tvoid; 
     
    976976        assert(!returnLabel); 
    977977        } 
    978         else if (!hasReturnExp && type->next->ty != Tvoid) 
    979         error("expected to return a value of type %s", type->next->toChars()); 
     978        else if (!hasReturnExp && type->nextOf()->ty != Tvoid) 
     979        error("expected to return a value of type %s", type->nextOf()->toChars()); 
    980980        else if (!inlineAsm) 
    981981        { 
    982         if (type->next->ty == Tvoid) 
     982        if (type->nextOf()->ty == Tvoid) 
    983983        { 
    984984            if (offend && isMain()) 
     
    10061006                  endloc, 
    10071007                  new IntegerExp(0), 
    1008                   new StringExp(0, "missing return expression") 
     1008                  new StringExp(loc, "missing return expression") 
    10091009                ); 
    10101010            } 
    10111011            else 
    10121012                e = new HaltExp(endloc); 
    1013             e = new CommaExp(0, e, type->next->defaultInit()); 
     1013            e = new CommaExp(0, e, type->nextOf()->defaultInit()); 
    10141014            e = e->semantic(sc2); 
    10151015            Statement *s = new ExpStatement(0, e); 
     
    11381138        a->push(returnLabel->statement); 
    11391139 
    1140         if (type->next->ty != Tvoid) 
     1140        if (type->nextOf()->ty != Tvoid) 
    11411141        { 
    11421142            // Create: return vresult; 
     
    11441144            Expression *e = new VarExp(0, vresult); 
    11451145            if (tintro) 
    1146             {   e = e->implicitCastTo(sc, tintro->next); 
     1146            {   e = e->implicitCastTo(sc, tintro->nextOf()); 
    11471147            e = e->semantic(sc); 
    11481148            } 
     
    12831283 */ 
    12841284 
     1285/*************************************************** 
     1286 * Visit each overloaded function in turn, and call 
     1287 * (*fp)(param, f) on it. 
     1288 * Exit when no more, or (*fp)(param, f) returns 1. 
     1289 * Returns: 
     1290 *  0   continue 
     1291 *  1   done 
     1292 */ 
     1293 
     1294int overloadApply(FuncDeclaration *fstart, 
     1295    int (*fp)(void *, FuncDeclaration *), 
     1296    void *param) 
     1297{ 
     1298    FuncDeclaration *f; 
     1299    Declaration *d; 
     1300    Declaration *next; 
     1301 
     1302    for (d = fstart; d; d = next) 
     1303    {   FuncAliasDeclaration *fa = d->isFuncAliasDeclaration(); 
     1304 
     1305    if (fa) 
     1306    { 
     1307        if (overloadApply(fa->funcalias, fp, param)) 
     1308        return 1; 
     1309        next = fa->overnext; 
     1310    } 
     1311    else 
     1312    { 
     1313        AliasDeclaration *a = d->isAliasDeclaration(); 
     1314 
     1315        if (a) 
     1316        { 
     1317        Dsymbol *s = a->toAlias(); 
     1318        next = s->isDeclaration(); 
     1319        if (next == a) 
     1320            break; 
     1321        if (next == fstart) 
     1322            break; 
     1323        } 
     1324        else 
     1325        { 
     1326        f = d->isFuncDeclaration(); 
     1327        if (!f) 
     1328        {   d->error("is aliased to a function"); 
     1329            break;      // BUG: should print error message? 
     1330        } 
     1331        if ((*fp)(param, f)) 
     1332            return 1; 
     1333 
     1334        next = f->overnext; 
     1335        } 
     1336    } 
     1337    } 
     1338    return 0; 
     1339} 
     1340 
     1341/******************************************** 
     1342 * Find function in overload list that exactly matches t. 
     1343 */ 
     1344 
     1345struct Param1 
     1346{ 
     1347    Type *t;        // type to match 
     1348    FuncDeclaration *f; // return value 
     1349}; 
     1350 
     1351int fp1(void *param, FuncDeclaration *f) 
     1352{   Param1 *p = (Param1 *)param; 
     1353    Type *t = p->t; 
     1354 
     1355    if (t->equals(f->type)) 
     1356    {   p->f = f; 
     1357    return 1; 
     1358    } 
     1359 
     1360#if V2 
     1361    /* Allow covariant matches, if it's just a const conversion 
     1362     * of the return type 
     1363     */ 
     1364    if (t->ty == Tfunction) 
     1365    {   TypeFunction *tf = (TypeFunction *)f->type; 
     1366    if (tf->covariant(t) == 1 && 
     1367        tf->nextOf()->implicitConvTo(t->nextOf()) >= MATCHconst) 
     1368    { 
     1369        p->f = f; 
     1370        return 1; 
     1371    } 
     1372    } 
     1373#endif 
     1374    return 0; 
     1375} 
     1376 
     1377FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) 
     1378{ 
     1379    Param1 p; 
     1380    p.t = t; 
     1381    p.f = NULL; 
     1382    overloadApply(this, &fp1, &p); 
     1383    return p.f; 
     1384} 
     1385 
     1386#if 0 
    12851387FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) 
    12861388{ 
     
    13231425    return NULL; 
    13241426} 
     1427#endif 
    13251428 
    13261429/******************************************** 
     
    13281431 */ 
    13291432 
     1433struct Param2 
     1434{ 
     1435    Match *m; 
     1436    Expressions *arguments; 
     1437}; 
     1438 
     1439int fp2(void *param, FuncDeclaration *f) 
     1440{   Param2 *p = (Param2 *)param; 
     1441    Match *m = p->m; 
     1442    Expressions *arguments = p->arguments; 
     1443    MATCH match; 
     1444 
     1445    if (f != m->lastf)      // skip duplicates 
     1446    { 
     1447    TypeFunction *tf; 
     1448 
     1449    m->anyf = f; 
     1450    tf = (TypeFunction *)f->type; 
     1451    match = (MATCH) tf->callMatch(arguments); 
     1452    //printf("match = %d\n", match); 
     1453    if (match != MATCHnomatch) 
     1454    { 
     1455        if (match > m->last) 
     1456        goto LfIsBetter; 
     1457 
     1458        if (match < m->last) 
     1459        goto LlastIsBetter; 
     1460 
     1461        /* See if one of the matches overrides the other. 
     1462         */ 
     1463        if (m->lastf->overrides(f)) 
     1464        goto LlastIsBetter; 
     1465        else if (f->overrides(m->lastf)) 
     1466        goto LfIsBetter; 
     1467 
     1468    Lambiguous: 
     1469        m->nextf = f; 
     1470        m->count++; 
     1471        return 0; 
     1472 
     1473    LfIsBetter: 
     1474        m->last = match; 
     1475        m->lastf = f; 
     1476        m->count = 1; 
     1477        return 0; 
     1478 
     1479    LlastIsBetter: 
     1480        return 0; 
     1481    } 
     1482    } 
     1483    return 0; 
     1484} 
     1485 
     1486 
     1487void overloadResolveX(Match *m, FuncDeclaration *fstart, Expressions *arguments) 
     1488{ 
     1489    Param2 p; 
     1490    p.m = m; 
     1491    p.arguments = arguments; 
     1492    overloadApply(fstart, &fp2, &p); 
     1493} 
     1494 
     1495#if 0 
    13301496// Recursive helper function 
    13311497 
     
    14071573    } 
    14081574} 
     1575#endif 
    14091576 
    14101577FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments) 
     
    17321899    fd = s->isFuncDeclaration(); 
    17331900    assert(fd); 
    1734     assert(fd->type->next->equals(treturn)); 
     1901    assert(fd->type->nextOf()->equals(treturn)); 
    17351902    } 
    17361903    else 
     
    20772244{ 
    20782245    if (hgs->hdrgen) 
     2246    {   buf->writestring("static this(){}\n"); 
    20792247    return; 
     2248    } 
    20802249    buf->writestring("static this()"); 
    20812250    bodyToCBuffer(buf, hgs); 
  • branches/dmdfe/inline.c

    r659 r740  
    503503    //if (!ids->vthis) 
    504504    //error("no 'this' when inlining %s", ids->parent->toChars()); 
    505     assert(ids->vthis); 
     505    if (!ids->vthis) 
     506    { 
     507    return this; 
     508    } 
    506509 
    507510    VarExp *ve = new VarExp(loc, ids->vthis); 
     
    855858    return this; 
    856859} 
     860 
     861 
     862#if V2 
     863Statement *ForeachRangeStatement::inlineScan(InlineScanState *iss) 
     864{ 
     865    lwr = lwr->inlineScan(iss); 
     866    upr = upr->inlineScan(iss); 
     867    body = body->inlineScan(iss); 
     868    return this; 
     869} 
     870#endif 
    857871 
    858872 
  • branches/dmdfe/interpret.c

    r659 r740  
    636636    return EXP_CANT_INTERPRET; 
    637637 
     638    Expression *keysave = key ? key->value : NULL; 
     639    Expression *valuesave = value->value; 
     640 
    638641    uinteger_t d = dim->toUInteger(); 
    639642    uinteger_t index; 
     
    646649        if (key) 
    647650        key->value = ekey; 
    648         value->value = Index(value->type, eaggr, ekey); 
    649         if (value->value == EXP_CANT_INTERPRET) 
    650         return EXP_CANT_INTERPRET; 
     651        e = Index(value->type, eaggr, ekey); 
     652        if (e == EXP_CANT_INTERPRET) 
     653        break; 
     654        value->value = e; 
    651655 
    652656        e = body ? body->interpret(istate) : NULL; 
     
    670674        if (key) 
    671675        key->value = ekey; 
    672         value->value = Index(value->type, eaggr, ekey); 
    673         if (value->value == EXP_CANT_INTERPRET) 
    674         return EXP_CANT_INTERPRET; 
     676        e = Index(value->type, eaggr, ekey); 
     677        if (e == EXP_CANT_INTERPRET) 
     678        break; 
     679        value->value = e; 
    675680 
    676681        e = body ? body->interpret(istate) : NULL; 
     
    687692    } 
    688693    } 
    689     return e; 
    690 
     694    value->value = valuesave; 
     695    if (key) 
     696    key->value = keysave; 
     697    return e; 
     698
     699 
     700#if V2 
     701Expression *ForeachRangeStatement::interpret(InterState *istate) 
     702
     703#if LOG 
     704    printf("ForeachRangeStatement::interpret()\n"); 
     705#endif 
     706    if (istate->start == this) 
     707    istate->start = NULL; 
     708    if (istate->start) 
     709    return NULL; 
     710 
     711    Expression *e = NULL; 
     712    Expression *elwr = lwr->interpret(istate); 
     713    if (elwr == EXP_CANT_INTERPRET) 
     714    return EXP_CANT_INTERPRET; 
     715 
     716    Expression *eupr = upr->interpret(istate); 
     717    if (eupr == EXP_CANT_INTERPRET) 
     718    return EXP_CANT_INTERPRET; 
     719 
     720    Expression *keysave = key->value; 
     721 
     722    if (op == TOKforeach) 
     723    { 
     724    key->value = elwr; 
     725 
     726    while (1) 
     727    { 
     728        e = Cmp(TOKlt, key->value->type, key->value, upr); 
     729        if (e == EXP_CANT_INTERPRET) 
     730        break; 
     731        if (e->isBool(TRUE) == FALSE) 
     732        {   e = NULL; 
     733        break; 
     734        } 
     735 
     736        e = body ? body->interpret(istate) : NULL; 
     737        if (e == EXP_CANT_INTERPRET) 
     738        break; 
     739        if (e == EXP_BREAK_INTERPRET) 
     740        {   e = NULL; 
     741        break; 
     742        } 
     743        e = Add(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type)); 
     744        if (e == EXP_CANT_INTERPRET) 
     745        break; 
     746        key->value = e; 
     747    } 
     748    } 
     749    else // TOKforeach_reverse 
     750    { 
     751    key->value = eupr; 
     752 
     753    while (1) 
     754    { 
     755        e = Cmp(TOKgt, key->value->type, key->value, lwr); 
     756        if (e == EXP_CANT_INTERPRET) 
     757        break; 
     758        if (e->isBool(TRUE) == FALSE) 
     759        {   e = NULL; 
     760        break; 
     761        } 
     762 
     763        e = Min(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type)); 
     764        if (e == EXP_CANT_INTERPRET) 
     765        break; 
     766        key->value = e; 
     767 
     768        e = body ? body->interpret(istate) : NULL; 
     769        if (e == EXP_CANT_INTERPRET) 
     770        break; 
     771        if (e == EXP_BREAK_INTERPRET) 
     772        {   e = NULL; 
     773        break; 
     774        } 
     775    } 
     776    } 
     777    key->value = keysave; 
     778    return e; 
     779
     780#endif 
    691781 
    692782Expression *SwitchStatement::interpret(InterState *istate) 
     
    12841374BIN_INTERPRET2(Cmp) 
    12851375 
    1286 Expression *BinExp::interpretAssignCommon(InterState *istate, fp_t fp
     1376Expression *BinExp::interpretAssignCommon(InterState *istate, fp_t fp, int post
    12871377{ 
    12881378#if LOG 
     
    13231413        } 
    13241414 
    1325         if (fp && !v->value) 
     1415        Expression *ev = v->value; 
     1416        if (fp && !ev) 
    13261417        {   error("variable %s is used before initialization", v->toChars()); 
    13271418        return e; 
    13281419        } 
    13291420        if (fp) 
    1330         e2 = (*fp)(v->type, v->value, e2); 
     1421        e2 = (*fp)(v->type, ev, e2); 
    13311422        else 
    13321423        e2 = Cast(v->type, v->type, e2); 
     
    13461437        } 
    13471438        v->value = e2; 
    1348         e = Cast(type, type, e2); 
     1439        e = Cast(type, type, post ? ev : e2); 
    13491440        } 
    13501441    } 
     
    14021493    } 
    14031494    v->value = new StructLiteralExp(se->loc, se->sd, expsx); 
    1404  
    1405     e = Cast(type, type, e2); 
     1495    v->value->type = se->type; 
     1496 
     1497    e = Cast(type, type, post ? ev : e2); 
    14061498    } 
    14071499    /* Assignment to array element of the form: 
     
    15631655        assert(0); 
    15641656 
    1565     e = Cast(type, type, e2); 
     1657    e = Cast(type, type, post ? ev : e2); 
    15661658    } 
    15671659    else 
     
    16031695    printf("PostExp::interpret() %s\n", toChars()); 
    16041696#endif 
    1605     Expression *e = EXP_CANT_INTERPRET; 
    1606  
    1607     if (e1->op == TOKvar) 
    1608     { 
    1609     VarExp *ve = (VarExp *)e1; 
    1610     VarDeclaration *v = ve->var->isVarDeclaration(); 
    1611     if (v && !v->isDataseg()) 
    1612     { 
    1613         /* Chase down rebinding of out and ref 
    1614          */ 
    1615         if (v->value && v->value->op == TOKvar) 
    1616         { 
    1617         ve = (VarExp *)v->value; 
    1618         v = ve->var->isVarDeclaration(); 
    1619         assert(v); 
    1620         } 
    1621  
    1622         if (!v->value) 
    1623         {   error("variable %s is used before initialization", v->toChars()); 
    1624         return e; 
    1625         } 
    1626         Expression *e2 = this->e2->interpret(istate); 
    1627         if (e2 != EXP_CANT_INTERPRET) 
    1628         { 
    1629         e = ((op == TOKplusplus) ? &Add : &Min)(v->type, v->value, e2); 
    1630         if (e != EXP_CANT_INTERPRET) 
    1631         { 
    1632             if (v->isAuto()) 
    1633             { 
    1634             for (size_t i = 0; 1; i++) 
    1635             { 
    1636                 if (i == istate->vars.dim) 
    1637                 {   istate->vars.push(v); 
    1638                 break; 
    1639                 } 
    1640                 if (v == (VarDeclaration *)istate->vars.data[i]) 
    1641                 break; 
    1642             } 
    1643             } 
    1644             Expression *eold = v->value; 
    1645             v->value = e; 
    1646             e = Cast(type, type, eold); 
    1647         } 
    1648         } 
    1649     } 
    1650     } 
     1697    Expression *e; 
     1698    if (op == TOKplusplus) 
     1699    e = interpretAssignCommon(istate, &Add, 1); 
     1700    else 
     1701    e = interpretAssignCommon(istate, &Min, 1); 
     1702#if LOG 
     1703    if (e == EXP_CANT_INTERPRET) 
     1704    printf("PostExp::interpret() CANT\n"); 
     1705#endif 
    16511706    return e; 
    16521707} 
     
    19612016    // Constant fold *(&structliteral + offset) 
    19622017    if (e1->op == TOKadd) 
    1963     { 
     2018    {   AddExp *ae = (AddExp *)e1; 
     2019    if (ae->e1->op == TOKaddress && ae->e2->op == TOKint64) 
     2020    {   AddrExp *ade = (AddrExp *)ae->e1; 
     2021        Expression *ex = ade->e1; 
     2022        ex = ex->interpret(istate); 
     2023        if (ex != EXP_CANT_INTERPRET) 
     2024        { 
     2025        if (ex->op == TOKstructliteral) 
     2026        {   StructLiteralExp *se = (StructLiteralExp *)ex; 
     2027            unsigned offset = ae->e2->toInteger(); 
     2028            e = se->getField(type, offset); 
     2029            if (!e) 
     2030            e = EXP_CANT_INTERPRET; 
     2031            return e; 
     2032        } 
     2033        } 
     2034    } 
    19642035    e = Ptr(type, e1); 
    19652036    } 
  • branches/dmdfe/mars.c

    r659 r740  
    5656    copyright = "Copyright (c) 1999-2007 by Digital Mars"; 
    5757    written = "written by Walter Bright"; 
    58     version = "v1.018"; 
     58    version = "v1.019"; 
    5959    global.structalign = 8; 
    6060 
  • branches/dmdfe/mars.h

    r659 r740  
    252252}; 
    253253 
     254enum MATCH 
     255{ 
     256    MATCHnomatch,   // no match 
     257    MATCHconvert,   // match with conversions 
     258#if V2 
     259    MATCHconst,     // match with conversion to const 
     260#endif 
     261    MATCHexact      // exact match 
     262}; 
     263 
    254264void error(Loc loc, const char *format, ...); 
    255265void verror(Loc loc, const char *format, va_list); 
  • branches/dmdfe/mtype.c

    r659 r740  
    496496 */ 
    497497 
    498 int Type::implicitConvTo(Type *to) 
     498MATCH Type::implicitConvTo(Type *to) 
    499499{ 
    500500    //printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to); 
     
    504504//    if (to->ty == Tvoid) 
    505505//  return 1; 
    506     return 0
     506    return MATCHnomatch
    507507} 
    508508 
     
    13961396} 
    13971397 
    1398 int TypeBasic::implicitConvTo(Type *to) 
     1398MATCH TypeBasic::implicitConvTo(Type *to) 
    13991399{ 
    14001400    //printf("TypeBasic::implicitConvTo(%s) from %s\n", to->toChars(), toChars()); 
     
    19121912} 
    19131913 
    1914 int TypeSArray::implicitConvTo(Type *to) 
     1914MATCH TypeSArray::implicitConvTo(Type *to) 
    19151915{ 
    19161916    //printf("TypeSArray::implicitConvTo()\n"); 
     
    19211921     /*|| to->next->isBaseOf(next)*/)) 
    19221922    { 
    1923     return 1
     1923    return MATCHconvert
    19241924    } 
    19251925    if (to->ty == Tarray) 
     
    19381938    if (next->equals(tsa->next) && dim->equals(tsa->dim)) 
    19391939    { 
    1940         return 1
     1940        return MATCHconvert
    19411941    } 
    19421942    } 
     
    20812081} 
    20822082 
    2083 int TypeDArray::implicitConvTo(Type *to) 
     2083MATCH TypeDArray::implicitConvTo(Type *to) 
    20842084{ 
    20852085    //printf("TypeDArray::implicitConvTo()\n"); 
     
    23902390} 
    23912391 
    2392 int TypePointer::implicitConvTo(Type *to) 
     2392MATCH TypePointer::implicitConvTo(Type *to) 
    23932393{ 
    23942394    //printf("TypePointer::implicitConvTo()\n"); 
     
    38023802} 
    38033803 
    3804 int TypeEnum::implicitConvTo