Changeset 639

Show
Ignore:
Timestamp:
08/28/10 03:15:45 (1 year ago)
Author:
walter
Message:

Issue 2716 - Confusion of auto and scope as the class attribute

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/aggregate.h

    r638 r639  
    221221    int com;                            // !=0 if this is a COM class (meaning 
    222222                                        // it derives from IUnknown) 
    223     int isauto;                         // !=0 if this is an auto class 
     223    int isscope;                        // !=0 if this is an auto class 
    224224    int isabstract;                     // !=0 if abstract class 
    225225#if DMDV1 
  • branches/dmd-1.x/src/class.c

    r638 r639  
    192192 
    193193    com = 0; 
    194     isauto = 0; 
     194    isscope = 0; 
    195195    isabstract = 0; 
    196196    isnested = 0; 
     
    472472        // Inherit properties from base class 
    473473        com = baseClass->isCOMclass(); 
    474         isauto = baseClass->isauto
     474        isscope = baseClass->isscope
    475475        vthis = baseClass->vthis; 
    476476    } 
     
    554554    } 
    555555 
    556     if (storage_class & (STCauto | STCscope)) 
    557         isauto = 1; 
     556    if (storage_class & STCauto) 
     557        error("storage class 'auto' is invalid when declaring a class, did you mean to use 'scope'?"); 
     558    if (storage_class & STCscope) 
     559        isscope = 1; 
    558560    if (storage_class & STCabstract) 
    559561        isabstract = 1; 
  • branches/dmd-1.x/src/declaration.c

    r608 r639  
    675675    this->loc = loc; 
    676676    offset = 0; 
    677     noauto = 0; 
     677    noscope = 0; 
    678678#if DMDV2 
    679679    isargptr = FALSE; 
     
    805805        } 
    806806    } 
     807    if ((storage_class & STCauto) && !inferred) 
     808       error("storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?"); 
    807809 
    808810    if (tb->ty == Ttuple) 
     
    938940#endif 
    939941 
    940     if (type->isauto() && !noauto
     942    if (type->isscope() && !noscope
    941943    { 
    942944        if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd) 
     
    945947        } 
    946948 
    947         if (!(storage_class & (STCauto | STCscope))) 
     949        if (!(storage_class & STCscope)) 
    948950        { 
    949951            if (!(storage_class & STCparameter) && ident != Id::withSym) 
     
    13791381 
    13801382/****************************************** 
    1381  * If a variable has an auto destructor call, return call for it. 
     1383 * If a variable has a scope destructor call, return call for it. 
    13821384 * Otherwise, return NULL. 
    13831385 */ 
    13841386 
    1385 Expression *VarDeclaration::callAutoDtor(Scope *sc) 
     1387Expression *VarDeclaration::callScopeDtor(Scope *sc) 
    13861388{   Expression *e = NULL; 
    13871389 
    1388     //printf("VarDeclaration::callAutoDtor() %s\n", toChars()); 
    1389     if (storage_class & (STCauto | STCscope) && !noauto
     1390    //printf("VarDeclaration::callScopeDtor() %s\n", toChars()); 
     1391    if (storage_class & (STCauto | STCscope) && !noscope
    13901392    { 
    13911393        for (ClassDeclaration *cd = type->isClassHandle(); 
     
    15931595   : VarDeclaration(loc, t, Id::This, NULL) 
    15941596{ 
    1595     noauto = 1; 
     1597    noscope = 1; 
    15961598} 
    15971599 
  • branches/dmd-1.x/src/declaration.h

    r591 r639  
    142142    int isImmutable()    { return storage_class & STCimmutable; } 
    143143    int isAuto()         { return storage_class & STCauto; } 
    144     int isScope()        { return storage_class & (STCscope | STCauto); } 
     144    int isScope()        { return storage_class & STCscope; } 
    145145    int isSynchronized() { return storage_class & STCsynchronized; } 
    146146    int isParameter()    { return storage_class & STCparameter; } 
     
    244244    Initializer *init; 
    245245    unsigned offset; 
    246     int noauto;                 // no auto semantics 
     246    int noscope;                 // no auto semantics 
    247247#if DMDV2 
    248248    FuncDeclarations nestedrefs; // referenced by these lexically nested functions 
     
    284284    int needsAutoDtor(); 
    285285#endif 
    286     Expression *callAutoDtor(Scope *sc); 
     286    Expression *callScopeDtor(Scope *sc); 
    287287    ExpInitializer *getExpInitializer(); 
    288288    Expression *getConstInitializer(); 
  • branches/dmd-1.x/src/expression.c

    r637 r639  
    40084008        if (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tclass) 
    40094009        { 
    4010             if ((v->isAuto() || v->isScope()) && !v->noauto
     4010            if (v->isScope() && !v->noscope
    40114011                error("escaping reference to auto local %s", v->toChars()); 
    40124012            else if (v->storage_class & STCvariadic) 
  • branches/dmd-1.x/src/func.c

    r603 r639  
    958958 
    959959                v = new VarDeclaration(loc, type->nextOf(), outId, NULL); 
    960                 v->noauto = 1; 
     960                v->noscope = 1; 
    961961#if DMDV2 
    962962                if (!isVirtual()) 
     
    13681368                        continue; 
    13691369 
    1370                     Expression *e = v->callAutoDtor(sc); 
     1370                    Expression *e = v->callScopeDtor(sc); 
    13711371                    if (e) 
    13721372                    {   Statement *s = new ExpStatement(0, e); 
  • branches/dmd-1.x/src/mtype.c

    r619 r639  
    505505} 
    506506 
    507 int Type::isauto() 
     507int Type::isscope() 
    508508{ 
    509509    return FALSE; 
     
    19281928            break; 
    19291929    } 
    1930     if (tbn->isauto()) 
     1930    if (tbn->isscope()) 
    19311931        error(loc, "cannot have array of auto %s", tbn->toChars()); 
    19321932    return merge(); 
     
    21062106            break; 
    21072107    } 
    2108     if (tn->isauto()) 
    2109         error(loc, "cannot have array of auto %s", tn->toChars()); 
     2108    if (tn->isscope()) 
     2109        error(loc, "cannot have array of scope %s", tn->toChars()); 
    21102110    if (next != tn) 
    21112111        //deco = NULL;                  // redo 
     
    23032303            break; 
    23042304    } 
    2305     if (next->isauto()) 
     2305    if (next->isscope()) 
    23062306        error(loc, "cannot have array of auto %s", next->toChars()); 
    23072307 
     
    28732873            tf->next = Type::terror; 
    28742874        } 
    2875         if (tf->next->isauto() && !(sc->flags & SCOPEctor)) 
    2876             error(loc, "functions cannot return auto %s", tf->next->toChars()); 
     2875        if (tf->next->isscope() && !(sc->flags & SCOPEctor)) 
     2876            error(loc, "functions cannot return scope %s", tf->next->toChars()); 
    28772877    } 
    28782878 
     
    50135013} 
    50145014 
    5015 int TypeClass::isauto() 
    5016 { 
    5017     return sym->isauto
     5015int TypeClass::isscope() 
     5016{ 
     5017    return sym->isscope
    50185018} 
    50195019 
  • branches/dmd-1.x/src/mtype.h

    r619 r639  
    218218    virtual int isscalar(); 
    219219    virtual int isunsigned(); 
    220     virtual int isauto(); 
     220    virtual int isscope(); 
    221221    virtual int isString(); 
    222222    virtual int checkBoolean(); // if can be converted to boolean value 
     
    672672    int isZeroInit(Loc loc); 
    673673    MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes); 
    674     int isauto(); 
     674    int isscope(); 
    675675    int checkBoolean(); 
    676676    TypeInfoDeclaration *getTypeInfoDeclaration(); 
  • branches/dmd-1.x/src/statement.c

    r586 r639  
    371371            {   Expression *e; 
    372372 
    373                 e = v->callAutoDtor(sc); 
     373                e = v->callScopeDtor(sc); 
    374374                if (e) 
    375375                { 
     
    16961696            { 
    16971697                VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL); 
    1698                 v->noauto = 1; 
     1698                v->noscope = 1; 
    16991699                v->semantic(sc); 
    17001700                if (!sc->insert(v)) 
     
    22242224        Type *t = arg->type ? arg->type : condition->type; 
    22252225        match = new VarDeclaration(loc, t, arg->ident, NULL); 
    2226         match->noauto = 1; 
     2226        match->noscope = 1; 
    22272227        match->semantic(scd); 
    22282228        if (!scd->insert(match)) 
     
    32983298            {   // Declare vresult 
    32993299                VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL); 
    3300                 v->noauto = 1; 
     3300                v->noscope = 1; 
    33013301                v->semantic(scx); 
    33023302                if (!scx->insert(v)) 
  • trunk/src/aggregate.h

    r638 r639  
    224224    int com;                            // !=0 if this is a COM class (meaning 
    225225                                        // it derives from IUnknown) 
    226     int isauto;                         // !=0 if this is an auto class 
     226    int isscope;                         // !=0 if this is an auto class 
    227227    int isabstract;                     // !=0 if abstract class 
    228228#if DMDV1 
  • trunk/src/class.c

    r638 r639  
    197197 
    198198    com = 0; 
    199     isauto = 0; 
     199    isscope = 0; 
    200200    isabstract = 0; 
    201201    inuse = 0; 
     
    480480        // Inherit properties from base class 
    481481        com = baseClass->isCOMclass(); 
    482         isauto = baseClass->isauto
     482        isscope = baseClass->isscope
    483483        vthis = baseClass->vthis; 
    484484        storage_class |= baseClass->storage_class & STC_TYPECTOR; 
     
    564564    } 
    565565 
    566     if (storage_class & (STCauto | STCscope)) 
    567         isauto = 1; 
     566    if (storage_class & STCauto) 
     567        error("storage class 'auto' is invalid when declaring a class, did you mean to use 'scope'?"); 
     568    if (storage_class & STCscope) 
     569        isscope = 1; 
    568570    if (storage_class & STCabstract) 
    569571        isabstract = 1; 
  • trunk/src/clone.c

    r581 r639  
    158158        { 
    159159            tmp = new VarDeclaration(0, type, idtmp, new VoidInitializer(0)); 
    160             tmp->noauto = 1; 
     160            tmp->noscope = 1; 
    161161            tmp->storage_class |= STCctfe; 
    162162            e = new DeclarationExp(0, tmp); 
  • trunk/src/declaration.c

    r610 r639  
    653653    this->loc = loc; 
    654654    offset = 0; 
    655     noauto = 0; 
     655    noscope = 0; 
    656656#if DMDV2 
    657657    isargptr = FALSE; 
     
    825825        } 
    826826    } 
     827    if ((storage_class & STCauto) && !inferred) 
     828       error("storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?"); 
    827829 
    828830    if (tb->ty == Ttuple) 
     
    976978#endif 
    977979 
    978     if (type->isauto() && !noauto
     980    if (type->isscope() && !noscope
    979981    { 
    980982        if (storage_class & (STCfield | STCout | STCref | STCstatic | STCmanifest | STCtls | STCgshared) || !fd) 
     
    983985        } 
    984986 
    985         if (!(storage_class & (STCauto | STCscope))) 
     987        if (!(storage_class & STCscope)) 
    986988        { 
    987989            if (!(storage_class & STCparameter) && ident != Id::withSym) 
     
    15911593    //printf("VarDeclaration::needsAutoDtor() %s\n", toChars()); 
    15921594 
    1593     if (noauto || storage_class & STCnodtor) 
     1595    if (noscope || storage_class & STCnodtor) 
    15941596        return FALSE; 
    15951597 
     
    16181620 
    16191621/****************************************** 
    1620  * If a variable has an auto destructor call, return call for it. 
     1622 * If a variable has a scope destructor call, return call for it. 
    16211623 * Otherwise, return NULL. 
    16221624 */ 
    16231625 
    1624 Expression *VarDeclaration::callAutoDtor(Scope *sc) 
     1626Expression *VarDeclaration::callScopeDtor(Scope *sc) 
    16251627{   Expression *e = NULL; 
    16261628 
    1627     //printf("VarDeclaration::callAutoDtor() %s\n", toChars()); 
    1628  
    1629     if (noauto || storage_class & STCnodtor) 
     1629    //printf("VarDeclaration::callScopeDtor() %s\n", toChars()); 
     1630 
     1631    if (noscope || storage_class & STCnodtor) 
    16301632        return NULL; 
    16311633 
     
    18981900   : VarDeclaration(loc, t, Id::This, NULL) 
    18991901{ 
    1900     noauto = 1; 
     1902    noscope = 1; 
    19011903} 
    19021904 
  • trunk/src/declaration.h

    r591 r639  
    141141    int isImmutable()    { return storage_class & STCimmutable; } 
    142142    int isAuto()         { return storage_class & STCauto; } 
    143     int isScope()        { return storage_class & (STCscope | STCauto); } 
     143    int isScope()        { return storage_class & STCscope; } 
    144144    int isSynchronized() { return storage_class & STCsynchronized; } 
    145145    int isParameter()    { return storage_class & STCparameter; } 
     
    240240    Initializer *init; 
    241241    unsigned offset; 
    242     int noauto;                 // no auto semantics 
     242    int noscope;                 // no auto semantics 
    243243#if DMDV2 
    244244    FuncDeclarations nestedrefs; // referenced by these lexically nested functions 
     
    280280    int needsAutoDtor(); 
    281281#endif 
    282     Expression *callAutoDtor(Scope *sc); 
     282    Expression *callScopeDtor(Scope *sc); 
    283283    ExpInitializer *getExpInitializer(); 
    284284    Expression *getConstInitializer(); 
  • trunk/src/expression.c

    r634 r639  
    43424342        if (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tclass) 
    43434343        { 
    4344             if ((v->isAuto() || v->isScope()) && !v->noauto
     4344            if (v->isScope() && !v->noscope
    43454345                error("escaping reference to scope local %s", v->toChars()); 
    43464346            else if (v->storage_class & STCvariadic) 
  • trunk/src/func.c

    r611 r639  
    11081108 
    11091109                VarDeclaration *v = new VarDeclaration(loc, type->nextOf(), outId, NULL); 
    1110                 v->noauto = 1; 
     1110                v->noscope = 1; 
    11111111                v->storage_class |= STCresult; 
    11121112#if DMDV2 
     
    15191519                        continue; 
    15201520 
    1521                     Expression *e = v->callAutoDtor(sc2); 
     1521                    Expression *e = v->callScopeDtor(sc2); 
    15221522                    if (e) 
    15231523                    {   Statement *s = new ExpStatement(0, e); 
  • trunk/src/mtype.c

    r638 r639  
    15771577} 
    15781578 
    1579 int Type::isauto() 
     1579int Type::isscope() 
    15801580{ 
    15811581    return FALSE; 
     
    33983398            break; 
    33993399    } 
    3400     if (tbn->isauto()) 
    3401         error(loc, "cannot have array of auto %s", tbn->toChars()); 
     3400    if (tbn->isscope()) 
     3401        error(loc, "cannot have array of scope %s", tbn->toChars()); 
    34023402    return merge(); 
    34033403} 
     
    36273627        } 
    36283628    } 
    3629     if (tn->isauto()) 
    3630         error(loc, "cannot have array of auto %s", tn->toChars()); 
     3629    if (tn->isscope()) 
     3630        error(loc, "cannot have array of scope %s", tn->toChars()); 
    36313631 
    36323632    next = tn; 
     
    38303830        } 
    38313831    } 
    3832     if (tn->isauto()) 
    3833         error(loc, "cannot have array of auto %s", tn->toChars()); 
     3832    if (tn->isscope()) 
     3833        error(loc, "cannot have array of scope %s", tn->toChars()); 
    38343834 
    38353835    next = tn; 
     
    39583958            return Type::terror; 
    39593959    } 
    3960     if (next->isauto()) 
    3961     {   error(loc, "cannot have array of auto %s", next->toChars()); 
     3960    if (next->isscope()) 
     3961    {   error(loc, "cannot have array of scope %s", next->toChars()); 
    39623962        return Type::terror; 
    39633963    } 
     
    48584858            tf->next = Type::terror; 
    48594859        } 
    4860         if (tf->next->isauto() && !(sc->flags & SCOPEctor)) 
     4860        if (tf->next->isscope() && !(sc->flags & SCOPEctor)) 
    48614861            error(loc, "functions cannot return scope %s", tf->next->toChars()); 
    48624862        if (tf->next->toBasetype()->ty == Tvoid) 
     
    74207420} 
    74217421 
    7422 int TypeClass::isauto() 
    7423 { 
    7424     return sym->isauto
     7422int TypeClass::isscope() 
     7423{ 
     7424    return sym->isscope
    74257425} 
    74267426 
  • trunk/src/mtype.h

    r619 r639  
    247247    virtual int isscalar(); 
    248248    virtual int isunsigned(); 
    249     virtual int isauto(); 
     249    virtual int isscope(); 
    250250    virtual int isString(); 
    251251    virtual int isAssignable(); 
     
    815815    int isZeroInit(Loc loc); 
    816816    MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes); 
    817     int isauto(); 
     817    int isscope(); 
    818818    int checkBoolean(); 
    819819    TypeInfoDeclaration *getTypeInfoDeclaration(); 
  • trunk/src/statement.c

    r636 r639  
    387387            {   Expression *e; 
    388388 
    389                 e = v->callAutoDtor(sc); 
     389                e = v->callScopeDtor(sc); 
    390390                if (e) 
    391391                { 
     
    17611761            { 
    17621762                VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL); 
    1763                 v->noauto = 1; 
     1763                v->noscope = 1; 
    17641764                v->semantic(sc); 
    17651765                if (!sc->insert(v)) 
     
    23412341        Type *t = arg->type ? arg->type : condition->type; 
    23422342        match = new VarDeclaration(loc, t, arg->ident, NULL); 
    2343         match->noauto = 1; 
     2343        match->noscope = 1; 
    23442344        match->semantic(scd); 
    23452345        if (!scd->insert(match)) 
     
    34973497            {   // Declare vresult 
    34983498                VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL); 
    3499                 v->noauto = 1; 
     3499                v->noscope = 1; 
    35003500                v->storage_class |= STCresult; 
    35013501                v->semantic(scx);