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

Changeset 315

Show
Ignore:
Timestamp:
12/29/09 01:22:33 (15 years ago)
Author:
walter
Message:

bugzilla 2029 - try again

Files:

Legend:

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

    r314 r315  
    10301030    } 
    10311031    e = new IntegerExp(loc, n, type); 
    10321032    return e; 
    10331033} 
    10341034 
    10351035/* Also returns EXP_CANT_INTERPRET if cannot be computed. 
    10361036 *  to: type to cast to 
    10371037 *  type: type to paint the result 
    10381038 */ 
    10391039 
    10401040Expression *Cast(Type *type, Type *to, Expression *e1) 
    10411041{   Expression *e = EXP_CANT_INTERPRET; 
    10421042    Loc loc = e1->loc; 
    10431043 
    10441044    //printf("Cast(type = %s, to = %s, e1 = %s)\n", type->toChars(), to->toChars(), e1->toChars()); 
    10451045    //printf("e1->type = %s\n", e1->type->toChars()); 
    10461046    if (type->equals(e1->type) && to->equals(type)) 
    10471047    return e1; 
    10481048 
    10491049    Type *tb = to->toBasetype(); 
     1050    Type *typeb = type->toBasetype(); 
    10501051 
    10511052    /* Allow casting from one string type to another 
    10521053     */ 
    10531054    if (e1->op == TOKstring) 
    10541055    { 
    1055     Type *typeb = type->toBasetype(); 
    10561056    if (tb->ty == Tarray && typeb->ty == Tarray && 
    10571057        tb->nextOf()->size() == typeb->nextOf()->size()) 
    10581058    { 
    10591059        return expType(to, e1); 
    10601060    } 
    10611061    } 
    10621062 
    1063     if (e1->op == TOKarrayliteral && e1->type->toBasetype() == tb) 
     1063    if (e1->op == TOKarrayliteral && typeb == tb) 
     1064    { 
    10641065        return e1; 
     1066    } 
    10651067 
    10661068    if (e1->isConst() != 1) 
     1069    { 
    10671070    return EXP_CANT_INTERPRET; 
     1071    } 
    10681072 
    10691073    if (tb->ty == Tbool) 
    10701074    e = new IntegerExp(loc, e1->toInteger() != 0, type); 
    10711075    else if (type->isintegral()) 
    10721076    { 
    10731077    if (e1->type->isfloating()) 
    10741078    {   dinteger_t result; 
    10751079        real_t r = e1->toReal(); 
    10761080 
    10771081        switch (type->toBasetype()->ty) 
    10781082        { 
    10791083        case Tint8: result = (d_int8)r; break; 
    10801084        case Tchar: 
    10811085        case Tuns8: result = (d_uns8)r; break; 
    10821086        case Tint16:    result = (d_int16)r;    break; 
    10831087        case Twchar: 
    10841088        case Tuns16:    result = (d_uns16)r;    break; 
    10851089        case Tint32:    result = (d_int32)r;    break; 
    10861090        case Tdchar: 
    10871091        case Tuns32:    result = (d_uns32)r;    break; 
  • branches/dmd-1.x/src/declaration.c

    r314 r315  
    12941294    if (fdv && fdthis) 
    12951295    { 
    12961296        if (loc.filename) 
    12971297        fdthis->getLevel(loc, fdv); 
    12981298        nestedref = 1; 
    12991299        fdv->nestedFrameRef = 1; 
    13001300        //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars()); 
    13011301    } 
    13021302    } 
    13031303} 
    13041304 
    13051305/******************************* 
    13061306 * Does symbol go into data segment? 
    13071307 * Includes extern variables. 
    13081308 */ 
    13091309 
    13101310int VarDeclaration::isDataseg() 
    13111311{ 
    13121312#if 0 
    13131313    printf("VarDeclaration::isDataseg(%p, '%s')\n", this, toChars()); 
    1314     printf("%x, %p, %p\n", storage_class & (STCstatic | STCconst), parent->isModule(), parent->isTemplateInstance()); 
     1314    printf("%llx, %p, %p\n", storage_class & (STCstatic | STCconst), parent->isModule(), parent->isTemplateInstance()); 
    13151315    printf("parent = '%s'\n", parent->toChars()); 
    13161316#endif 
    13171317    Dsymbol *parent = this->toParent(); 
    13181318    if (!parent && !(storage_class & (STCstatic | STCconst))) 
    13191319    {   error("forward referenced"); 
    13201320    type = Type::terror; 
    13211321    return 0; 
    13221322    } 
    13231323    return (storage_class & (STCstatic | STCconst) || 
    13241324       parent->isModule() || 
    13251325       parent->isTemplateInstance()); 
    13261326} 
    13271327 
    13281328/************************************ 
    13291329 * Does symbol go into thread local storage? 
    13301330 */ 
    13311331 
    13321332int VarDeclaration::isThreadlocal() 
    13331333{ 
    13341334    return 0; 
    13351335} 
    13361336 
    13371337/******************************************** 
    13381338 * Can variable be read and written by CTFE? 
    13391339 */ 
    13401340 
    13411341int VarDeclaration::isCTFE() 
    13421342{ 
     1343    //printf("VarDeclaration::isCTFE(%p, '%s')\n", this, toChars()); 
     1344    //printf("%llx\n", storage_class); 
    13431345    return (storage_class & STCctfe) || !isDataseg(); 
    13441346} 
    13451347 
    13461348int VarDeclaration::hasPointers() 
    13471349{ 
    13481350    //printf("VarDeclaration::hasPointers() %s, ty = %d\n", toChars(), type->ty); 
    13491351    return (!isDataseg() && type->hasPointers()); 
    13501352} 
    13511353 
    13521354/****************************************** 
    13531355 * If a variable has an auto destructor call, return call for it. 
    13541356 * Otherwise, return NULL. 
    13551357 */ 
    13561358 
    13571359Expression *VarDeclaration::callAutoDtor(Scope *sc) 
    13581360{   Expression *e = NULL; 
    13591361 
    13601362    //printf("VarDeclaration::callAutoDtor() %s\n", toChars()); 
    13611363    if (storage_class & (STCauto | STCscope) && !noauto) 
    13621364    { 
  • branches/dmd-1.x/src/interpret.c

    r314 r315  
    11401140    te->type = new TypeTuple(te->exps); 
    11411141    return te; 
    11421142    } 
    11431143    return this; 
    11441144} 
    11451145 
    11461146Expression *ArrayLiteralExp::interpret(InterState *istate) 
    11471147{   Expressions *expsx = NULL; 
    11481148 
    11491149#if LOG 
    11501150    printf("ArrayLiteralExp::interpret() %s\n", toChars()); 
    11511151#endif 
    11521152    if (elements) 
    11531153    { 
    11541154    for (size_t i = 0; i < elements->dim; i++) 
    11551155    {   Expression *e = (Expression *)elements->data[i]; 
    11561156        Expression *ex; 
    11571157 
    11581158        ex = e->interpret(istate); 
    11591159        if (ex == EXP_CANT_INTERPRET) 
    1160         {   delete expsx; 
    1161         return EXP_CANT_INTERPRET; 
    1162         } 
     1160        goto Lerror; 
    11631161 
    11641162        /* If any changes, do Copy On Write 
    11651163         */ 
    11661164        if (ex != e) 
    11671165        { 
    11681166        if (!expsx) 
    11691167        {   expsx = new Expressions(); 
    11701168            expsx->setDim(elements->dim); 
    11711169            for (size_t j = 0; j < elements->dim; j++) 
    11721170            { 
    11731171            expsx->data[j] = elements->data[j]; 
    11741172            } 
    11751173        } 
    11761174        expsx->data[i] = (void *)ex; 
    11771175        } 
    11781176    } 
    11791177    } 
    11801178    if (elements && expsx) 
    11811179    { 
    11821180    expandTuples(expsx); 
    11831181    if (expsx->dim != elements->dim) 
    1184     {   delete expsx; 
    1185         return EXP_CANT_INTERPRET; 
    1186     } 
     1182        goto Lerror; 
    11871183    ArrayLiteralExp *ae = new ArrayLiteralExp(loc, expsx); 
    11881184    ae->type = type; 
    11891185    return ae; 
    11901186    } 
    11911187    return this; 
     1188 
     1189Lerror: 
     1190    if (expsx) 
     1191    delete expsx; 
     1192    error("cannot interpret array literal"); 
     1193    return EXP_CANT_INTERPRET; 
    11921194} 
    11931195 
    11941196Expression *AssocArrayLiteralExp::interpret(InterState *istate) 
    11951197{   Expressions *keysx = keys; 
    11961198    Expressions *valuesx = values; 
    11971199 
    11981200#if LOG 
    11991201    printf("AssocArrayLiteralExp::interpret() %s\n", toChars()); 
    12001202#endif 
    12011203    for (size_t i = 0; i < keys->dim; i++) 
    12021204    {   Expression *ekey = (Expression *)keys->data[i]; 
    12031205    Expression *evalue = (Expression *)values->data[i]; 
    12041206    Expression *ex; 
    12051207 
    12061208    ex = ekey->interpret(istate); 
    12071209    if (ex == EXP_CANT_INTERPRET) 
    12081210        goto Lerr; 
    12091211 
    12101212    /* If any changes, do Copy On Write 
    12111213     */ 
  • branches/dmd-1.x/src/mars.h

    r243 r315  
    347347enum DYNCAST 
    348348{ 
    349349    DYNCAST_OBJECT, 
    350350    DYNCAST_EXPRESSION, 
    351351    DYNCAST_DSYMBOL, 
    352352    DYNCAST_TYPE, 
    353353    DYNCAST_IDENTIFIER, 
    354354    DYNCAST_TUPLE, 
    355355}; 
    356356 
    357357enum MATCH 
    358358{ 
    359359    MATCHnomatch,   // no match 
    360360    MATCHconvert,   // match with conversions 
    361361#if DMDV2 
    362362    MATCHconst,     // match with conversion to const 
    363363#endif 
    364364    MATCHexact      // exact match 
    365365}; 
    366366 
    367 typedef unsigned StorageClass; 
     367typedef uint64_t StorageClass; 
    368368 
    369369 
    370370void warning(Loc loc, const char *format, ...); 
    371371void error(Loc loc, const char *format, ...); 
    372372void verror(Loc loc, const char *format, va_list); 
    373373void fatal(); 
    374374void err_nomem(); 
    375375int runLINK(); 
    376376void deleteExeFile(); 
    377377int runProgram(); 
    378378void inifile(const char *argv0, const char *inifile); 
    379379void halt(); 
    380380void util_progress(); 
    381381 
    382382/*** Where to send error messages ***/ 
    383383#if IN_GCC 
    384384#define stdmsg stderr 
    385385#else 
    386386#define stdmsg stderr 
    387387#endif 
  • branches/dmd-1.x/src/mtype.c

    r304 r315  
    52075207    { 
    52085208     Ldefault: 
    52095209    Type::resolve(loc, sc, pe, pt, ps); 
    52105210    } 
    52115211} 
    52125212 
    52135213void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 
    52145214{ 
    52155215    if (mod != this->mod) 
    52165216    {   toCBuffer3(buf, hgs, mod); 
    52175217    return; 
    52185218    } 
    52195219    next->toCBuffer2(buf, hgs, this->mod); 
    52205220 
    52215221    buf->printf("[%s .. ", lwr->toChars()); 
    52225222    buf->printf("%s]", upr->toChars()); 
    52235223} 
    52245224 
    52255225/***************************** Parameter *****************************/ 
    52265226 
    5227 Parameter::Parameter(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg) 
     5227Parameter::Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg) 
    52285228{ 
    52295229    this->type = type; 
    52305230    this->ident = ident; 
    52315231    this->storageClass = storageClass; 
    52325232    this->defaultArg = defaultArg; 
    52335233} 
    52345234 
    52355235Parameter *Parameter::syntaxCopy() 
    52365236{ 
    52375237    Parameter *a = new Parameter(storageClass, 
    52385238        type ? type->syntaxCopy() : NULL, 
    52395239        ident, 
    52405240        defaultArg ? defaultArg->syntaxCopy() : NULL); 
    52415241    return a; 
    52425242} 
    52435243 
    52445244Parameters *Parameter::arraySyntaxCopy(Parameters *args) 
    52455245{   Parameters *a = NULL; 
    52465246 
    52475247    if (args)