Changeset 658

Show
Ignore:
Timestamp:
07/02/07 18:16:27 (1 year ago)
Author:
Gregor
Message:

MERGE: DMD 1.017

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmdfe/expression.c

    r657 r658  
    23512351        case '"': 
    23522352        case '\\': 
    2353         buf->writeByte('\\'); 
     2353        if (!hgs->console) 
     2354            buf->writeByte('\\'); 
    23542355        default: 
    23552356        if (c <= 0xFF) 
    2356         {   if (c <= 0x7F && isprint(c)) 
     2357        {   if (c <= 0x7F && (isprint(c) || hgs->console)) 
    23572358            buf->writeByte(c); 
    23582359            else 
     
    27102711        error("overlapping initialization for %s", v->toChars()); 
    27112712    offset = v->offset + v->type->size(); 
    2712     e = e->implicitCastTo(sc, v->type); 
     2713 
     2714    Type *telem = v->type; 
     2715    while (!e->implicitConvTo(telem) && telem->toBasetype()->ty == Tsarray) 
     2716    {   /* Static array initialization, as in: 
     2717         *  T[3][5] = e; 
     2718         */ 
     2719        telem = telem->toBasetype()->nextOf(); 
     2720    } 
     2721 
     2722    e = e->implicitCastTo(sc, telem); 
     2723 
    27132724    elements->data[i] = (void *)e; 
    27142725    } 
     
    27332744        } 
    27342745        else 
    2735         e = v->type->defaultInit(); 
     2746        {   e = v->type->defaultInit(); 
     2747        e->loc = loc; 
     2748        } 
    27362749        offset = v->offset + v->type->size(); 
    27372750    } 
     
    27912804} 
    27922805 
     2806 
     2807Expression *StructLiteralExp::toLvalue(Scope *sc, Expression *e) 
     2808{ 
     2809    return this; 
     2810} 
    27932811 
    27942812 
     
    33963414    { 
    33973415    if (!v->isDataseg()) 
    3398         error("escaping reference to local %s", v->toChars()); 
     3416        error("escaping reference to local variable %s", v->toChars()); 
    33993417    } 
    34003418} 
     
    61446162    if (v) 
    61456163    { 
    6146         if (!v->isDataseg()
     6164        if (!v->isDataseg() && !v->isParameter()
    61476165        error("escaping reference to local %s", v->toChars()); 
    61486166    } 
     
    67706788    : BinExp(loc, TOKassign, sizeof(AssignExp), e1, e2) 
    67716789{ 
     6790    ismemset = 0; 
    67726791} 
    67736792 
  • branches/dmdfe/expression.h

    r656 r658  
    402402    Expression *interpret(InterState *istate); 
    403403    dt_t **toDt(dt_t **pdt); 
     404    Expression *toLvalue(Scope *sc, Expression *e); 
    404405 
    405406    int inlineCost(InlineCostState *ics); 
     
    982983 
    983984struct AssignExp : BinExp 
    984 
     985{   int ismemset;   // !=0 if setting the contents of an array 
     986 
    985987    AssignExp(Loc loc, Expression *e1, Expression *e2); 
    986988    Expression *semantic(Scope *sc); 
  • branches/dmdfe/hdrgen.h

    r458 r658  
    1414    int hdrgen;     // 1 if generating header file 
    1515    int ddoc;       // 1 if generating Ddoc file 
     16    int console;    // 1 if writing to console 
    1617    int tpltMember; 
    1718    int inCallExp; 
  • branches/dmdfe/idgen.c

    r656 r658  
    8383    { "TypeInfo_Delegate" }, 
    8484    { "TypeInfo_Tuple" }, 
     85    { "TypeInfo_Const" }, 
     86    { "TypeInfo_Invariant" }, 
    8587    { "elements" }, 
    8688    { "_arguments_typeinfo" }, 
     
    9496    { "TIME", "__TIME__" }, 
    9597    { "TIMESTAMP", "__TIMESTAMP__" }, 
     98    { "VENDOR", "__VENDOR__" }, 
     99    { "VERSIONX", "__VERSION__" }, 
    96100 
    97101    { "nan" }, 
     
    123127    { "reverse" }, 
    124128    { "dup" }, 
     129    { "idup" }, 
    125130 
    126131    // For inline assembler 
  • branches/dmdfe/inline.c

    r656 r658  
    11 
    2 // Copyright (c) 1999-2006 by Digital Mars 
     2// Copyright (c) 1999-2007 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    347347        if (s->isReturnStatement()) 
    348348        break; 
     349 
     350        /* Check for: 
     351         *  if (condition) 
     352         *      return exp1; 
     353         *  else 
     354         *      return exp2; 
     355         */ 
     356        IfStatement *ifs = s->isIfStatement(); 
     357        if (ifs && ifs->elsebody && ifs->ifbody && 
     358        ifs->ifbody->isReturnStatement() && 
     359        ifs->elsebody->isReturnStatement() 
     360           ) 
     361        break; 
     362 
    349363    } 
    350364    } 
     
    12371251     * no return expression. 
    12381252     */ 
    1239     if (type->next && type->next->ty != Tvoid && 
     1253    if (tf->next && tf->next->ty != Tvoid && 
    12401254        !(hasReturnExp & 1) && 
    12411255        !hdrscan) 
  • branches/dmdfe/interpret.c

    r657 r658  
    859859} 
    860860 
    861 Expression *getVarExp(InterState *istate, Declaration *d) 
     861Expression *getVarExp(Loc loc, InterState *istate, Declaration *d) 
    862862{ 
    863863    Expression *e = EXP_CANT_INTERPRET; 
     
    874874    {   e = v->value; 
    875875        if (!e) 
    876         error("variable %s is used before initialization", v->toChars()); 
     876        error(loc, "variable %s is used before initialization", v->toChars()); 
    877877        else if (e != EXP_CANT_INTERPRET) 
    878878        e = e->interpret(istate); 
     
    897897    printf("VarExp::interpret() %s\n", toChars()); 
    898898#endif 
    899     return getVarExp(istate, var); 
     899    return getVarExp(loc, istate, var); 
    900900} 
    901901 
     
    932932{ 
    933933#if LOG 
    934     printf("VarExp::interpret() %s\n", toChars()); 
     934    printf("TupleExp::interpret() %s\n", toChars()); 
    935935#endif 
    936936    Expressions *expsx = NULL; 
     
    14151415    if (!v || v->isDataseg()) 
    14161416        return EXP_CANT_INTERPRET; 
    1417     if (fp && !v->value) 
    1418     {   error("variable %s is used before initialization", v->toChars()); 
    1419         return e; 
     1417    if (!v->value) 
     1418    { 
     1419        if (fp) 
     1420        {   error("variable %s is used before initialization", v->toChars()); 
     1421        return e; 
     1422        } 
     1423 
     1424        Type *t = v->type->toBasetype(); 
     1425        if (t->ty == Tsarray) 
     1426        { 
     1427        /* This array was void initialized. Create a 
     1428         * default initializer for it. 
     1429         * What we should do is fill the array literal with 
     1430         * NULL data, so use-before-initialized can be detected. 
     1431         * But we're too lazy at the moment to do it, as that 
     1432         * involves redoing Index() and whoever calls it. 
     1433         */ 
     1434        Expression *ev = v->type->defaultInit(); 
     1435        size_t dim = ((TypeSArray *)t)->dim->toInteger(); 
     1436        Expressions *elements = new Expressions(); 
     1437        elements->setDim(dim); 
     1438        for (size_t i = 0; i < dim; i++) 
     1439            elements->data[i] = (void *)ev; 
     1440        ArrayLiteralExp *ae = new ArrayLiteralExp(0, elements); 
     1441        ae->type = v->type; 
     1442        v->value = ae; 
     1443        } 
     1444        else 
     1445        return EXP_CANT_INTERPRET; 
    14201446    } 
    14211447 
     
    16161642            } 
    16171643            } 
     1644            Expression *eold = v->value; 
    16181645            v->value = e; 
    1619             e = Cast(type, type, e2); 
     1646            e = Cast(type, type, eold); 
    16201647        } 
    16211648        } 
     
    17091736        if (eresult) 
    17101737            e = eresult; 
    1711         else if (fd->type->toBasetype()->next->ty == Tvoid) 
     1738        else if (fd->type->toBasetype()->nextOf()->ty == Tvoid) 
    17121739            e = EXP_VOID_INTERPRET; 
    17131740        else 
     
    18551882    e1 = this->e1->interpret(istate); 
    18561883    if (e1 == EXP_CANT_INTERPRET) 
    1857     goto Lcant; 
     1884    { 
     1885    goto Lcant; 
     1886    } 
    18581887    e2 = this->e2->interpret(istate); 
    18591888    if (e2 == EXP_CANT_INTERPRET) 
     
    18621891 
    18631892Lcant: 
     1893#if LOG 
     1894    printf("CatExp::interpret() %s CANT\n", toChars()); 
     1895#endif 
    18641896    return EXP_CANT_INTERPRET; 
    18651897} 
     
    18791911 
    18801912Lcant: 
     1913#if LOG 
     1914    printf("CastExp::interpret() %s CANT\n", toChars()); 
     1915#endif 
    18811916    return EXP_CANT_INTERPRET; 
    18821917} 
     
    19321967    VarDeclaration *v = soe->var->isVarDeclaration(); 
    19331968    if (v) 
    1934     {   Expression *ev = getVarExp(istate, v); 
     1969    {   Expression *ev = getVarExp(loc, istate, v); 
    19351970        if (ev != EXP_CANT_INTERPRET && ev->op == TOKstructliteral) 
    19361971        {   StructLiteralExp *se = (StructLiteralExp *)ev; 
     
    19672002Expression *interpret_aaKeys(InterState *istate, Expressions *arguments) 
    19682003{ 
    1969     printf("interpret_aaKeys()\n"); 
     2004    //printf("interpret_aaKeys()\n"); 
    19702005    if (!arguments || arguments->dim != 2) 
    19712006    return NULL; 
  • branches/dmdfe/lexer.c

    r656 r658  
    630630            if (mod && id == Id::FILE) 
    631631            { 
    632             t->value = TOKstring; 
    633632            t->ustring = (unsigned char *)(loc.filename ? loc.filename : mod->ident->toChars()); 
    634             goto Llen
     633            goto Lstring
    635634            } 
    636635            else if (mod && id == Id::LINE) 
     
    641640            else if (id == Id::DATE) 
    642641            { 
    643             t->value = TOKstring; 
    644642            t->ustring = (unsigned char *)date; 
    645             goto Llen
     643            goto Lstring
    646644            } 
    647645            else if (id == Id::TIME) 
    648646            { 
    649             t->value = TOKstring; 
    650647            t->ustring = (unsigned char *)time; 
    651             goto Llen; 
     648            goto Lstring; 
     649            } 
     650            else if (id == Id::VENDOR) 
     651            { 
     652            t->ustring = (unsigned char *)"Digital Mars D"; 
     653            goto Lstring; 
    652654            } 
    653655            else if (id == Id::TIMESTAMP) 
    654656            { 
     657            t->ustring = (unsigned char *)timestamp; 
     658             Lstring: 
    655659            t->value = TOKstring; 
    656             t->ustring = (unsigned char *)timestamp; 
    657660             Llen: 
    658661            t->postfix = 0; 
    659662            t->len = strlen((char *)t->ustring); 
     663            } 
     664            else if (id == Id::VERSIONX) 
     665            {   unsigned major = 0; 
     666            unsigned minor = 0; 
     667 
     668            for (char *p = global.version + 1; 1; p++) 
     669            { 
     670                char c = *p; 
     671                if (isdigit(c)) 
     672                minor = minor * 10 + c - '0'; 
     673                else if (c == '.') 
     674                {   major = minor; 
     675                minor = 0; 
     676                } 
     677                else 
     678                break; 
     679            } 
     680            t->value = TOKint64v; 
     681            t->uns64value = major * 1000 + minor; 
    660682            } 
    661683        } 
  • branches/dmdfe/mars.c

    r657 r658  
    5656    copyright = "Copyright (c) 1999-2007 by Digital Mars"; 
    5757    written = "written by Walter Bright"; 
    58     version = "v1.015"; 
     58    version = "v1.017"; 
    5959    global.structalign = 8; 
    6060 
     
    146146    global.version, global.copyright, global.written); 
    147147    printf("\ 
    148 Documentation: http://www.digitalmars.com/d/index.html\n\ 
     148Documentation: http://www.digitalmars.com/d/1.0/index.html\n\ 
    149149Usage:\n\ 
    150150  dmd files.d ... { -switch }\n\ 
  • branches/dmdfe/mtype.c

    r656 r658  
    593593    else if (ident == Id::init) 
    594594    { 
     595#if 0 
    595596        if (v->init) 
    596597        { 
     
    616617        return e; 
    617618        } 
     619#endif 
     620        return defaultInit(); 
    618621    } 
    619622    } 
     
    27212724        t = arg->type->toBasetype(); 
    27222725 
    2723         /* If arg turns out to be a tuple, the number of parameters may 
    2724          * change. 
    2725          */ 
    2726         if (t->ty == Ttuple) 
    2727         dim = Argument::dim(parameters); 
    2728  
    27292726        if (arg->storageClass & (STCout | STCref | STClazy)) 
    27302727        { 
     
    27402737        arg->defaultArg = resolveProperties(sc, arg->defaultArg); 
    27412738        arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type); 
     2739        } 
     2740 
     2741        /* If arg turns out to be a tuple, the number of parameters may 
     2742         * change. 
     2743         */ 
     2744        if (t->ty == Ttuple) 
     2745        {   dim = Argument::dim(parameters); 
     2746        i--; 
    27422747        } 
    27432748    } 
  • branches/dmdfe/mtype.h

    r458 r658  
    239239    virtual Expression *toExpression(); 
    240240    virtual int hasPointers(); 
     241    Type *nextOf() { return next; } 
    241242 
    242243    static void error(Loc loc, const char *format, ...); 
  • branches/dmdfe/statement.c

    r657 r658  
    29112911    sym = es->sds; 
    29122912    } 
     2913    else if (exp->op == TOKtype) 
     2914    {   TypeExp *es = (TypeExp *)exp; 
     2915 
     2916    sym = es->type->toDsymbol(sc)->isScopeDsymbol(); 
     2917    if (!sym) 
     2918    {   error("%s has no members", es->toChars()); 
     2919        body = body->semantic(sc); 
     2920        return this; 
     2921    } 
     2922    } 
    29132923    else 
    29142924    {   Type *t = exp->type; 
  • branches/dmdfe/statement.h

    r458 r658  
    2727struct LabelDsymbol; 
    2828struct Identifier; 
     29struct IfStatement; 
    2930struct DeclarationStatement; 
    3031struct DefaultStatement; 
     
    99100    virtual CompoundStatement *isCompoundStatement() { return NULL; } 
    100101    virtual ReturnStatement *isReturnStatement() { return NULL; } 
     102    virtual IfStatement *isIfStatement() { return NULL; } 
    101103}; 
    102104 
     
    311313    int usesEH(); 
    312314    int fallOffEnd(); 
     315    IfStatement *isIfStatement() { return this; } 
    313316 
    314317    int inlineCost(InlineCostState *ics); 
  • branches/dmdfe/staticassert.c

    r458 r658  
    1616#include "expression.h" 
    1717#include "id.h" 
     18#include "hdrgen.h" 
    1819 
    1920/********************************* AttribDeclaration ****************************/ 
     
    5455    { 
    5556    if (msg) 
    56     { 
     57    {   HdrGenState hgs; 
     58        OutBuffer buf; 
     59 
    5760        msg = msg->semantic(sc); 
    5861        msg = msg->optimize(WANTvalue | WANTinterpret); 
    59         char *p = msg->toChars(); 
    60         p = strdup(p); 
    61         error("%s", p); 
    62         free(p); 
     62        hgs.console = 1; 
     63        msg->toCBuffer(&buf, &hgs); 
     64        error("%s", buf.toChars()); 
    6365    } 
    6466    else 
  • branches/dmdfe/template.c

    r656 r658  
    564564    for (i = 0; i < fargs->dim; i++) 
    565565    {   Expression *e = (Expression *)fargs->data[i]; 
    566     printf("\tfarg[%d] = %s\n", i, e->toChars()); 
     566    printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars()); 
    567567    } 
    568568#endif 
     
    695695    {   farg = (Expression *)fargs->data[i]; 
    696696#if 0 
    697         printf("farg->type   = %s\n", farg->type->toChars()); 
    698         printf("fparam->type = %s\n", fparam->type->toChars()); 
     697        printf("\tfarg->type   = %s\n", farg->type->toChars()); 
     698        printf("\tfparam->type = %s\n", fparam->type->toChars()); 
    699699#endif 
    700700 
     
    10991099    goto Lnomatch; 
    11001100 
    1101   Lagain: 
    11021101    if (this == tparam) 
    11031102    goto Lexact; 
     
    11161115        tparam = tparam->semantic(0, sc); 
    11171116        assert(tparam->ty != Tident); 
    1118         goto Lagain
     1117        return deduceType(sc, tparam, parameters, dedtypes)
    11191118    } 
    11201119