Changeset 835

Show
Ignore:
Timestamp:
11/17/07 17:11:23 (9 months ago)
Author:
Gregor
Message:

MERGE: DMD 2.004

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmdfe-2.0/aggregate.h

    r656 r835  
    149149}; 
    150150 
    151 #define CLASSINFO_SIZE  (0x3C+12) // value of ClassInfo.size 
     151#define CLASSINFO_SIZE  (0x3C+16) // value of ClassInfo.size 
    152152 
    153153struct ClassDeclaration : AggregateDeclaration 
     
    193193 
    194194    Dsymbol *search(Loc, Identifier *ident, int flags); 
     195    int isFuncHidden(FuncDeclaration *fd); 
    195196    FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); 
    196197    void interfaceSemantic(Scope *sc); 
  • branches/dmdfe-2.0/cast.c

    r783 r835  
    9696    toChars(), type->toChars(), t->toChars()); 
    9797#endif 
     98    //static int nest; if (++nest == 10) halt(); 
    9899    if (!type) 
    99100    {   error("%s is not an expression", toChars()); 
     
    101102    } 
    102103    Expression *e = optimize(WANTvalue | WANTflags); 
     104    if (e->type == t) 
     105    return MATCHexact; 
    103106    if (e != this) 
    104     {   //printf("optimzed to %s\n", e->toChars()); 
     107    {   //printf("optimized to %s\n", e->toChars()); 
    105108    return e->implicitConvTo(t); 
    106109    } 
     
    593596    toChars(), type->toChars(), t->toChars()); 
    594597#endif 
     598    if (type == t) 
     599    return this; 
    595600    e = this; 
    596601    tb = t->toBasetype(); 
     
    693698Expression *StringExp::castTo(Scope *sc, Type *t) 
    694699{ 
     700    /* This follows copy-on-write; any changes to 'this' 
     701     * will result in a copy. 
     702     * The this->string member is considered immutable. 
     703     */ 
    695704    StringExp *se; 
    696705    Type *tb; 
    697     int unique
     706    int copied = 0
    698707 
    699708    //printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed); 
     
    702711    { 
    703712    error("cannot convert string literal to void*"); 
     713    } 
     714 
     715    se = this; 
     716    if (!committed) 
     717    {   se = (StringExp *)copy(); 
     718    se->committed = 1; 
     719    copied = 1; 
     720    } 
     721 
     722    if (type == t) 
     723    { 
     724    return se; 
    704725    } 
    705726 
     
    709730    return Expression::castTo(sc, t); 
    710731 
    711     se = this; 
    712     unique = 0; 
    713     if (!committed) 
    714     { 
    715     // Copy when committing the type 
    716     void *s; 
    717  
    718     s = (unsigned char *)mem.malloc((len + 1) * sz); 
    719     memcpy(s, string, (len + 1) * sz); 
    720     se = new StringExp(loc, s, len); 
    721     se->type = type; 
    722     se->sz = sz; 
    723     se->committed = 0; 
    724     unique = 1;     // this is the only instance 
    725     } 
    726     se->type = type->toBasetype(); 
    727     if (tb == se->type) 
    728     {   se->type = t; 
    729     se->committed = 1; 
     732    Type *typeb = type->toBasetype(); 
     733    if (typeb == tb) 
     734    { 
     735    if (!copied) 
     736    {   se = (StringExp *)copy(); 
     737        copied = 1; 
     738    } 
     739    se->type = t; 
    730740    return se; 
    731741    } 
    732742 
    733743    if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) 
    734     {   se->committed = 1; 
     744    {   if (!copied) 
     745    {   se = (StringExp *)copy(); 
     746        copied = 1; 
     747    } 
    735748    goto Lcast; 
    736749    } 
    737     if (se->type->ty != Tsarray && se->type->ty != Tarray && se->type->ty != Tpointer) 
    738     {   se->committed = 1; 
     750    if (typeb->ty != Tsarray && typeb->ty != Tarray && typeb->ty != Tpointer) 
     751    {   if (!copied) 
     752    {   se = (StringExp *)copy(); 
     753        copied = 1; 
     754    } 
    739755    goto Lcast; 
    740756    } 
    741757 
    742     if (se->committed == 1) 
    743     { 
    744     if (se->type->nextOf()->size() == tb->nextOf()->size()) 
    745     {   se->type = t; 
    746         return se; 
    747     } 
     758    if (typeb->nextOf()->size() == tb->nextOf()->size()) 
     759    { 
     760    if (!copied) 
     761    {   se = (StringExp *)copy(); 
     762        copied = 1; 
     763    } 
     764    if (tb->ty == Tsarray) 
     765        goto L2;    // handle possible change in static array dimension 
     766    se->type = t; 
     767    return se; 
     768    } 
     769 
     770    if (committed) 
    748771    goto Lcast; 
    749     } 
    750  
    751     se->committed = 1; 
    752  
    753     int tfty; 
    754     int ttty; 
    755     char *p; 
    756     size_t u; 
    757     unsigned c; 
    758     size_t newlen; 
    759772 
    760773#define X(tf,tt)    ((tf) * 256 + (tt)) 
    761774    { 
    762775    OutBuffer buffer; 
    763     newlen = 0; 
    764     tfty = se->type->nextOf()->toBasetype()->ty; 
    765     ttty = tb->nextOf()->toBasetype()->ty; 
     776    size_t newlen = 0; 
     777    int tfty = typeb->nextOf()->toBasetype()->ty; 
     778    int ttty = tb->nextOf()->toBasetype()->ty; 
    766779    switch (X(tfty, ttty)) 
    767780    { 
     
    772785 
    773786    case X(Tchar, Twchar): 
    774         for (u = 0; u < len;) 
    775         { 
    776         p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
     787        for (size_t u = 0; u < len;) 
     788        {  unsigned c; 
     789        char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
    777790        if (p) 
    778791            error("%s", p); 
     
    785798 
    786799    case X(Tchar, Tdchar): 
    787         for (u = 0; u < len;) 
    788         { 
    789         p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
     800        for (size_t u = 0; u < len;) 
     801        {  unsigned c; 
     802        char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
    790803        if (p) 
    791804            error("%s", p); 
     
    797810 
    798811    case X(Twchar,Tchar): 
    799         for (u = 0; u < len;) 
    800         { 
    801         p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
     812        for (size_t u = 0; u < len;) 
     813        {  unsigned c; 
     814        char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
    802815        if (p) 
    803816            error("%s", p); 
     
    810823 
    811824    case X(Twchar,Tdchar): 
    812         for (u = 0; u < len;) 
    813         { 
    814         p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
     825        for (size_t u = 0; u < len;) 
     826        {  unsigned c; 
     827        char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
    815828        if (p) 
    816829            error("%s", p); 
     
    822835 
    823836    case X(Tdchar,Tchar): 
    824         for (u = 0; u < len; u++) 
    825         { 
    826         c = ((unsigned *)se->string)[u]; 
     837        for (size_t u = 0; u < len; u++) 
     838        { 
     839        unsigned c = ((unsigned *)se->string)[u]; 
    827840        if (!utf_isValidDchar(c)) 
    828841            error("invalid UCS-32 char \\U%08x", c); 
     
    836849 
    837850    case X(Tdchar,Twchar): 
    838         for (u = 0; u < len; u++) 
    839         { 
    840         c = ((unsigned *)se->string)[u]; 
     851        for (size_t u = 0; u < len; u++) 
     852        { 
     853        unsigned c = ((unsigned *)se->string)[u]; 
    841854        if (!utf_isValidDchar(c)) 
    842855            error("invalid UCS-32 char \\U%08x", c); 
     
    850863 
    851864    L1: 
    852         if (!unique) 
    853         se = new StringExp(loc, NULL, 0); 
     865        if (!copied) 
     866        {   se = (StringExp *)copy(); 
     867        copied = 1; 
     868        } 
    854869        se->string = buffer.extractData(); 
    855870        se->len = newlen; 
     
    858873 
    859874    default: 
    860         if (se->type->nextOf()->size() == tb->nextOf()->size()) 
    861         {   se->type = t; 
    862         return se; 
    863         } 
     875        assert(typeb->nextOf()->size() != tb->nextOf()->size()); 
    864876        goto Lcast; 
    865877    } 
    866878    } 
    867879#undef X 
     880L2: 
     881    assert(copied); 
    868882 
    869883    // See if need to truncate or extend the literal 
     
    877891    if (dim2 != se->len) 
    878892    { 
     893        // Copy when changing the string literal 
    879894        unsigned newsz = se->sz; 
    880  
    881         if (unique && dim2 < se->len) 
    882         {   se->len = dim2; 
    883         // Add terminating 0 
    884         memset((unsigned char *)se->string + dim2 * newsz, 0, newsz); 
    885         } 
    886         else 
    887         { 
    888         // Copy when changing the string literal 
    889         void *s; 
    890         int d; 
    891  
    892         d = (dim2 < se->len) ? dim2 : se->len; 
    893         s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 
    894         memcpy(s, se->string, d * newsz); 
    895         // Extend with 0, add terminating 0 
    896         memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 
    897         se = new StringExp(loc, s, dim2); 
    898         se->committed = 1;  // it now has a firm type 
    899         se->sz = newsz; 
    900         } 
     895        void *s; 
     896        int d; 
     897 
     898        d = (dim2 < se->len) ? dim2 : se->len; 
     899        s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 
     900        memcpy(s, se->string, d * newsz); 
     901        // Extend with 0, add terminating 0 
     902        memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 
     903        se->string = s; 
     904        se->len = dim2; 
    901905    } 
    902906    } 
     
    906910Lcast: 
    907911    Expression *e = new CastExp(loc, se, t); 
    908     e->type = t; 
     912    e->type = t;   // so semantic() won't be run on e 
    909913    return e; 
    910914} 
     
    967971Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t) 
    968972{ 
     973#if 0 
     974    printf("ArrayLiteralExp::castTo(this=%s, type=%s, t=%s)\n", 
     975    toChars(), type->toChars(), t->toChars()); 
     976#endif 
     977    if (type == t) 
     978    return this; 
    969979    Type *typeb = type->toBasetype(); 
    970980    Type *tb = t->toBasetype(); 
     
    11541164    Type *t = Type::tptrdiff_t; 
    11551165 
    1156     stride = t1b->nextOf()->size(); 
     1166    stride = t1b->nextOf()->size(loc); 
    11571167    if (!t->equals(t2b)) 
    11581168        e2 = e2->castTo(sc, t); 
     
    11671177    Expression *e; 
    11681178 
    1169     stride = t2b->nextOf()->size(); 
     1179    stride = t2b->nextOf()->size(loc); 
    11701180    if (!t->equals(t1b)) 
    11711181        e = e1->castTo(sc, t); 
  • branches/dmdfe-2.0/class.c

    r783 r835  
    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 
     
    767767} 
    768768 
     769/********************************************************** 
     770 * fd is in the vtbl[] for this class. 
     771 * Return 1 if function is hidden (not findable through search). 
     772 */ 
     773 
     774int isf(void *param, FuncDeclaration *fd) 
     775{ 
     776    //printf("param = %p, fd = %p %s\n", param, fd, fd->toChars()); 
     777    return param == fd; 
     778} 
     779 
     780int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 
     781{ 
     782    //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); 
     783    Dsymbol *s = search(0, fd->ident, 4|2); 
     784    if (!s) 
     785    {   //printf("not found\n"); 
     786    /* Because, due to a hack, if there are multiple definitions 
     787     * of fd->ident, NULL is returned. 
     788     */ 
     789    return 0; 
     790    } 
     791    FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration(); 
     792    //printf("%s fdstart = %p\n", s->kind(), fdstart); 
     793    return !overloadApply(fdstart, &isf, fd); 
     794} 
     795 
    769796/**************** 
    770797 * Find virtual function matching identifier and type. 
  • branches/dmdfe-2.0/constfold.c

    r783 r835  
    669669    assert(op == TOKequal || op == TOKnotequal); 
    670670 
    671     if (e1->op == TOKstring && e2->op == TOKstring) 
     671    if (e1->op == TOKnull) 
     672    { 
     673    if (e2->op == TOKnull) 
     674        cmp = 1; 
     675    else if (e2->op == TOKstring) 
     676    {   StringExp *es2 = (StringExp *)e2; 
     677        cmp = (0 == es2->len); 
     678    } 
     679    else if (e2->op == TOKarrayliteral) 
     680    {   ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; 
     681        cmp = !es2->elements || (0 == es2->elements->dim); 
     682    } 
     683    else 
     684        return EXP_CANT_INTERPRET; 
     685    } 
     686    else if (e2->op == TOKnull) 
     687    { 
     688    if (e1->op == TOKstring) 
     689    {   StringExp *es1 = (StringExp *)e1; 
     690        cmp = (0 == es1->len); 
     691    } 
     692    else if (e1->op == TOKarrayliteral) 
     693    {   ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; 
     694        cmp = !es1->elements || (0 == es1->elements->dim); 
     695    } 
     696    else 
     697        return EXP_CANT_INTERPRET; 
     698    } 
     699    else if (e1->op == TOKstring && e2->op == TOKstring) 
    672700    {   StringExp *es1 = (StringExp *)e1; 
    673701    StringExp *es2 = (StringExp *)e2; 
     
    793821    int cmp; 
    794822 
    795     if (e1->op == TOKsymoff && e2->op == TOKsymoff) 
     823    if (e1->op == TOKnull && e2->op == TOKnull) 
     824    { 
     825    cmp = 1; 
     826    } 
     827    else if (e1->op == TOKsymoff && e2->op == TOKsymoff) 
    796828    { 
    797829    SymOffExp *es1 = (SymOffExp *)e1; 
     
    10551087    else 
    10561088    { 
    1057     error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); 
     1089    error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars()); 
    10581090    e = new IntegerExp(loc, 0, type); 
    10591091    } 
     
    12521284    //printf("\tt1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); 
    12531285 
    1254     if (e1->op == TOKnull && e2->op == TOKint64
     1286    if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral)
    12551287    {   e = e2; 
    12561288    goto L2; 
    12571289    } 
    1258     else if (e1->op == TOKint64 && e2->op == TOKnull) 
     1290    else if ((e1->op == TOKint64 || e1->op == TOKstructliteral) && e2->op == TOKnull) 
    12591291    {   e = e1; 
    12601292     L2: 
  • branches/dmdfe-2.0/declaration.c

    r783 r835  
    649649{ 
    650650    //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 
    651     //printf("type = %s\n", type->toChars()); 
     651    //printf(" type = %s\n", type->toChars()); 
    652652    //printf("linkage = %d\n", sc->linkage); 
    653653    //if (strcmp(toChars(), "mul") == 0) halt(); 
     
    841841    if (type->ty == Tstruct && 
    842842        ((TypeStruct *)type)->sym->zeroInit == 1) 
    843     { 
     843    {   /* If a struct is all zeros, as a special case 
     844         * set it's initializer to the integer 0. 
     845         * In AssignExp::toElem(), we check for this and issue 
     846         * a memset() to initialize the struct. 
     847         * Must do same check in interpreter. 
     848         */ 
    844849        Expression *e = new IntegerExp(loc, 0, Type::tint32); 
    845850        Expression *e1; 
    846851        e1 = new VarExp(loc, this); 
    847852        e = new AssignExp(loc, e1, e); 
    848         e->type = e1->type; 
    849         init = new ExpInitializer(loc, e/*->type->defaultInit()*/); 
     853        e->type = e1->type;        // don't type check this, it would fail 
     854        init = new ExpInitializer(loc, e); 
    850855        return; 
    851856    } 
     
    871876    { 
    872877    ArrayInitializer *ai = init->isArrayInitializer(); 
    873     if (ai && type->toBasetype()->ty == Taarray) 
     878    if (ai && tb->ty == Taarray) 
    874879    { 
    875880        init = ai->toAssocArrayInitializer(); 
    876881    } 
    877882 
     883    StructInitializer *si = init->isStructInitializer(); 
    878884    ExpInitializer *ei = init->isExpInitializer(); 
    879885 
     
    965971         */ 
    966972 
    967         if (ei && !global.errors && !inferred) 
     973        if (!global.errors && !inferred) 
    968974        { 
    969975        unsigned errors = global.errors; 
    970976        global.gag++; 
    971977        //printf("+gag\n"); 
    972         Expression *e = ei->exp->syntaxCopy(); 
     978        Expression *e; 
     979        Initializer *i2 = init; 
    973980        inuse++; 
    974         e = e->semantic(sc); 
     981        if (ei) 
     982        { 
     983            e = ei->exp->syntaxCopy(); 
     984            e = e->semantic(sc); 
     985            e = e->implicitCastTo(sc, type); 
     986        } 
     987        else if (si || ai) 
     988        {   i2 = init->syntaxCopy(); 
     989            i2 = i2->semantic(sc, type); 
     990        } 
    975991        inuse--; 
    976         e = e->implicitCastTo(sc, type); 
    977992        global.gag--; 
    978993        //printf("-gag\n"); 
     
    982997            global.errors = errors; // act as if nothing happened 
    983998        } 
    984         else 
     999        else if (ei) 
    9851000        { 
    9861001            e = e->optimize(WANTvalue | WANTinterpret); 
     
    9901005            } 
    9911006        } 
     1007        else 
     1008            init = i2;      // no errors, keep result 
    9921009        } 
    9931010    } 
  • branches/dmdfe-2.0/declaration.h

    r783 r835  
    422422                    // this one is overriding 
    423423    int inferRetType;           // !=0 if return type is to be inferred 
    424     Scope *scope;       // !=NULL means context to use 
     424    Scope *scope;          // !=NULL means context to use 
    425425 
    426426    // Things that should really go into Scope 
  • branches/dmdfe-2.0/dsymbol.c

    r783 r835  
    266266 *  flags:  1   don't find private members 
    267267 *      2   don't give error messages 
     268 *      4   return NULL if ambiguous 
    268269 * Returns: 
    269270 *  NULL if not found 
     
    664665               ) 
    665666            { 
     667            if (flags & 4) 
     668                return NULL; 
    666669            if (!(flags & 2)) 
    667670                ss->multiplyDefined(loc, s, s2); 
     
    776779 
    777780 
     781/******************************************* 
     782 * Look for member of the form: 
     783 *  const(MemberInfo)[] getMembers(string); 
     784 * Returns NULL if not found 
     785 */ 
     786 
     787#if V2 
     788FuncDeclaration *ScopeDsymbol::findGetMembers() 
     789{ 
     790    Dsymbol *s = search_function(this, Id::getmembers); 
     791    FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; 
     792 
     793#if 0  // Finish 
     794    static TypeFunction *tfgetmembers; 
     795 
     796    if (!tfgetmembers) 
     797    { 
     798    Scope sc; 
     799    Arguments *arguments = new Arguments; 
     800    Arguments *arg = new Argument(STCin, Type::tchar->constOf()->arrayOf(), NULL, NULL); 
     801    arguments->push(arg); 
     802 
     803    Type *tret = NULL; 
     804    tfgetmembers = new TypeFunction(arguments, tret, 0, LINKd); 
     805    tfgetmembers = (TypeFunction *)tfgetmembers->semantic(0, &sc); 
     806    } 
     807    if (fdx) 
     808    fdx = fdx->overloadExactMatch(tfgetmembers); 
     809#endif 
     810    if (fdx && fdx->isVirtual()) 
     811    fdx = NULL; 
     812 
     813    return fdx; 
     814} 
     815#endif 
     816 
     817 
    778818/****************************** WithScopeSymbol ******************************/ 
    779819 
     
    873913    { 
    874914        VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); 
     915 
     916        if (ce->op == TOKvar) 
     917        {   // if ce is const, get its initializer 
     918        ce = fromConstInitializer(WANTvalue | WANTinterpret, ce); 
     919        } 
    875920 
    876921        if (ce->op == TOKstring) 
  • branches/dmdfe-2.0/dsymbol.h

    r458 r835  
    227227    Dsymbol *nameCollision(Dsymbol *s); 
    228228    char *kind(); 
     229    FuncDeclaration *findGetMembers(); 
    229230 
    230231    void emitMemberComments(Scope *sc); 
  • branches/dmdfe-2.0/enum.c

    r656 r835  
    104104        assert(e->dyncast() == DYNCAST_EXPRESSION); 
    105105        e = e->semantic(sce); 
    106         e = e->optimize(WANTvalue); 
     106        e = e->optimize(WANTvalue | WANTinterpret); 
    107107        // Need to copy it because we're going to change the type 
    108108        e = e->copy(); 
    109109        e = e->implicitCastTo(sc, memtype); 
    110         e = e->optimize(WANTvalue); 
     110        e = e->optimize(WANTvalue | WANTinterpret); 
    111111        number = e->toInteger(); 
    112112        e->type = t; 
  • branches/dmdfe-2.0/expression.c

    r783 r835  
    635635    {   Expression *arg = (Expression *)arguments->data[i]; 
    636636 
    637         if (i) 
    638         buf->writeByte(','); 
    639637        if (arg) 
     638        {   if (i) 
     639            buf->writeByte(','); 
    640640        expToCBuffer(buf, hgs, arg, PREC_assign); 
     641        } 
    641642    } 
    642643    } 
     
    11001101 
    11011102        default: 
    1102         print(); 
    11031103        type->print(); 
    11041104        assert(0); 
     
    16831683        else 
    16841684        { 
    1685         //printf("test1 %s\n", s->toChars()); 
    16861685        e = new DsymbolExp(loc, s); 
    16871686        } 
     
    18001799        } 
    18011800    } 
     1801#if 0 
    18021802    if ((v->isConst() || v->isInvariant()) && type->toBasetype()->ty != Tsarray) 
    18031803    {   // Replace v with its initializer 
     
    18281828        } 
    18291829    } 
     1830#endif 
    18301831    e = new VarExp(loc, v); 
    18311832    e->type = type; 
     
    35563557    if (v) 
    35573558    { 
     3559#if 0 
    35583560    if ((v->isConst() || v->isInvariant()) && 
    35593561        type->toBasetype()->ty != Tsarray && v->init) 
     
    35663568        } 
    35673569    } 
     3570#endif 
    35683571    v->checkNestedReference(sc, loc); 
    35693572    } 
     
    40284031/************************************************************/ 
    40294032 
    4030 IftypeExp::IftypeExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, 
    4031     Type *tspec, enum TOK tok2
    4032     : Expression(loc, TOKis, sizeof(IftypeExp)) 
     4033IsExp::IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, 
     4034    Type *tspec, enum TOK tok2, TemplateParameters *parameters
     4035    : Expression(loc, TOKis, sizeof(IsExp)) 
    40334036{ 
    40344037    this->targ = targ; 
     
    40374040    this->tspec = tspec; 
    40384041    this->tok2 = tok2; 
    4039 
    4040  
    4041 Expression *IftypeExp::syntaxCopy() 
    4042 
    4043     return new IftypeExp(loc, 
     4042    this->parameters = parameters; 
     4043
     4044 
     4045Expression *IsExp::syntaxCopy() 
     4046
     4047    // This section is identical to that in TemplateDeclaration::syntaxCopy() 
     4048    TemplateParameters *p = NULL; 
     4049    if (parameters) 
     4050    { 
     4051    p = new TemplateParameters(); 
     4052    p->setDim(parameters->dim); 
     4053    for (int i = 0; i < p->dim; i++) 
     4054    {   TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 
     4055        p->data[i] = (void *)tp->syntaxCopy(); 
     4056    } 
     4057    } 
     4058 
     4059    return new IsExp(loc, 
    40444060    targ->syntaxCopy(), 
    40454061    id, 
    40464062    tok, 
    40474063    tspec ? tspec->syntaxCopy() : NULL, 
    4048     tok2); 
    4049 
    4050  
    4051 Expression *IftypeExp::semantic(Scope *sc) 
     4064    tok2, 
     4065    p); 
     4066
     4067 
     4068Expression *IsExp::semantic(Scope *sc) 
    40524069{   Type *tded; 
    40534070 
    4054     //printf("IftypeExp::semantic()\n"); 
     4071    /* is(targ id tok tspec) 
     4072     * is(targ id == tok2) 
     4073     */ 
     4074 
     4075    //printf("IsExp::semantic(%s)\n", toChars()); 
    40554076    if (id && !(sc->flags & SCOPEstaticif)) 
    40564077    error("can only declare type aliases within static if conditionals"); 
     
    41394160 
    41404161        case TOKfunction: 
    4141         {   if (targ->ty != Tfunction) 
     4162        { 
     4163        if (targ->ty != Tfunction) 
    41424164            goto Lno; 
    41434165        tded = targ; 
     
    41894211 
    41904212    MATCH m; 
    4191     TemplateTypeParameter tp(loc, id, NULL, NULL); 
    4192  
    4193     TemplateParameters parameters; 
    4194     parameters.setDim(1); 
    4195     parameters.data[0] = (void *)&tp; 
     4213    assert(parameters && parameters->dim); 
    41964214 
    41974215    Objects dedtypes; 
    4198     dedtypes.setDim(1); 
    4199     dedtypes.data[0] = NULL
    4200  
    4201     m = targ->deduceType(NULL, tspec, &parameters, &dedtypes); 
     4216    dedtypes.setDim(parameters->dim); 
     4217    dedtypes.zero()
     4218 
     4219    m = targ->deduceType(NULL, tspec, parameters, &dedtypes); 
    42024220    if (m == MATCHnomatch || 
    42034221        (m != MATCHexact && tok == TOKequal)) 
     
    42054223    else 
    42064224    { 
    4207         assert(dedtypes.dim == 1); 
    42084225        tded = (Type *)dedtypes.data[0]; 
    42094226        if (!tded) 
    42104227        tded = targ; 
     4228 
     4229        Objects tiargs; 
     4230        tiargs.setDim(1); 
     4231        tiargs.data[0] = (void *)targ; 
     4232 
     4233        for (int i = 1; i < parameters->dim; i++) 
     4234        {   TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 
     4235        Declaration *s; 
     4236 
     4237        m = tp->matchArg(sc, &tiargs, i, parameters, &dedtypes, &s); 
     4238        if (m == MATCHnomatch) 
     4239            goto Lno; 
     4240        s->semantic(sc); 
     4241        if (!sc->insert(s)) 
     4242            error("declaration %s is already defined", s->toChars()); 
     4243#if 0 
     4244        Object *o = (Object *)dedtypes.data[i]; 
     4245        Dsymbol *s = TemplateDeclaration::declareParameter(loc, sc, tp, o); 
     4246#endif 
     4247        if (sc->sd) 
     4248            s->addMember(sc, sc->sd, 1); 
     4249        } 
     4250 
    42114251        goto Lyes; 
    42124252    } 
     
    42454285    Dsymbol *s = new AliasDeclaration(loc, id, tded); 
    42464286    s->semantic(sc); 
    4247     sc->insert(s); 
     4287    if (!sc->insert(s)) 
     4288        error("declaration %s is already defined", s->toChars()); 
    42484289    if (sc->sd) 
    42494290        s->addMember(sc, sc->sd, 1); 
    42504291    } 
    4251     return new IntegerExp(1); 
     4292    return new IntegerExp(loc, 1, Type::tbool); 
    42524293 
    42534294Lno: 
    4254     return new IntegerExp(0); 
    4255 } 
    4256  
    4257 void IftypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
     4295    return new IntegerExp(loc, 0, Type::tbool); 
     4296} 
     4297 
     4298void IsExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
    42584299{ 
    42594300    buf->writestring("is("); 
    42604301    targ->toCBuffer(buf, id, hgs); 
    4261     if (tspec) 
     4302    if (tok2 != TOKreserved) 
     4303    { 
     4304    buf->printf(" %s %s", Token::toChars(tok), Token::toChars(tok2)); 
     4305    } 
     4306    else if (tspec) 
    42624307    { 
    42634308    if (tok == TOKcolon) 
     
    42664311        buf->writestring(" == "); 
    42674312    tspec->toCBuffer(buf, NULL, hgs); 
     4313    } 
     4314    if (parameters) 
     4315    {   // First parameter is already output, so start with second 
     4316    for (int i = 1; i < parameters->dim; i++) 
     4317    { 
     4318        buf->writeByte(','); 
     4319        TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 
     4320        tp->toCBuffer(buf, hgs); 
     4321    } 
    42684322    } 
    42694323    buf->writeByte(')'); 
     
    47574811        } 
    47584812        type = v->type; 
     4813#if 0 
    47594814        if (v->isConst() || v->isInvariant()) 
    47604815        { 
     
    47814836            } 
    47824837        } 
     4838#endif 
    47834839        if (v->needThis()) 
    47844840        { 
     
    55215577        if (search_function(ad, Id::call)) 
    55225578        goto L1;    // overload of opCall, therefore it's a call 
     5579 
     5580        if (e1->op != TOKtype) 
     5581        error("%s %s does not overload ()", ad->kind(), ad->toChars()); 
    55235582        /* It's a struct literal 
    55245583         */ 
     
    68816940    { 
    68826941        e2 = e2->implicitCastTo(sc, Type::tsize_t); 
    6883         e2 = e2->optimize(WANTvalue); 
     6942        e2 = e2->optimize(WANTvalue | WANTinterpret); 
    68846943        uinteger_t index = e2->toUInteger(); 
    68856944        size_t length; 
  • branches/dmdfe-2.0/expression.h

    r783 r835  
    6161Expression *resolveProperties(Scope *sc, Expression *e); 
    6262void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d); 
    63 Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid); 
     63Dsymbol *search_function(ScopeDsymbol *ad, Identifier *funcid); 
    6464void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr); 
    6565void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs); 
     
    6767void expandTuples(Expressions *exps); 
    6868FuncDeclaration *hasThis(Scope *sc); 
     69Expression *fromConstInitializer(int result, Expression *e); 
    6970 
    7071struct Expression : Object 
     
    602603}; 
    603604 
    604 struct IftypeExp : Expression 
     605struct IsExp : Expression 
    605606{ 
    606607    /* is(targ id tok tspec) 
     
    612613    Type *tspec;    // can be NULL 
    613614    enum TOK tok2;  // 'struct', 'union', 'typedef', etc. 
    614  
    615     IftypeExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, enum TOK tok2); 
     615    TemplateParameters *parameters; 
     616 
     617    IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, 
     618    enum TOK tok2, TemplateParameters *parameters); 
    616619    Expression *syntaxCopy(); 
    617620    Expression *semantic(Scope *sc); 
  • branches/dmdfe-2.0/func.c

    <
    r783 r835  
    254254    { 
    255255        //printf("\tnot virtual\n"); 
    256         return
     256        goto Ldone
    257257    } 
    258258 
     
    284284            if (fdv->isFinal()) 
    285285                error("cannot override final function %s", fdv->toPrettyChars()); 
     286 
     287            if (!isOverride() && global.params.warnings) 
     288                error("overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars()); 
     289 
    286290            if (fdv->toParent() == parent) 
    287291            { 
     
    433437    if (introducing && isOverride()) 
    434438    { 
    435         error("function %s does not override any", toChars()); 
     439        error("does not override any function"); 
    436440    } 
    437441 
     
    525529    } 
    526530 
     531Ldone: 
    527532    /* Save scope for possible later use (if we need the 
    528533     * function internals) 
     
    21142119 
    21152120StaticCtorDeclaration::StaticCtorDeclaration(Loc loc, Loc endloc) 
    2116     : FuncDeclaration(loc, endloc, Id::staticCtor, STCstatic, NULL) 
     2121    : FuncDeclaration(loc, endloc, 
     2122      Identifier::generateId("_staticCtor"), STCstatic, NULL) 
    2117