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

Changeset 610

Show
Ignore:
Timestamp:
08/10/10 10:24:07 (14 years ago)
Author:
walter
Message:

wrong scope for function parameter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/declaration.c

    r608 r610  
    13931393        (storage_class & STCstatic || parent->isModule())) 
    13941394        return TRUE; 
    13951395    return FALSE; 
    13961396} 
    13971397 
    13981398void VarDeclaration::checkCtorConstInit() 
    13991399{ 
    14001400#if 0 /* doesn't work if more than one static ctor */ 
    14011401    if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield)) 
    14021402        error("missing initializer in static constructor for const variable"); 
    14031403#endif 
    14041404} 
    14051405 
    14061406/************************************ 
    14071407 * Check to see if this variable is actually in an enclosing function 
    14081408 * rather than the current one. 
    14091409 */ 
    14101410 
    14111411void VarDeclaration::checkNestedReference(Scope *sc, Loc loc) 
    14121412{ 
     1413    //printf("VarDeclaration::checkNestedReference() %s\n", toChars()); 
    14131414    if (parent && !isDataseg() && parent != sc->parent && 
    14141415        !(storage_class & STCmanifest)) 
    14151416    { 
    14161417        // The function that this variable is in 
    14171418        FuncDeclaration *fdv = toParent()->isFuncDeclaration(); 
    14181419        // The current function 
    14191420        FuncDeclaration *fdthis = sc->parent->isFuncDeclaration(); 
    14201421 
    14211422        if (fdv && fdthis && fdv != fdthis) 
    14221423        { 
    14231424            if (loc.filename) 
    14241425                fdthis->getLevel(loc, fdv); 
    14251426 
    14261427            for (int i = 0; i < nestedrefs.dim; i++) 
    14271428            {   FuncDeclaration *f = (FuncDeclaration *)nestedrefs.data[i]; 
    14281429                if (f == fdthis) 
    14291430                    goto L1; 
    14301431            } 
    14311432            nestedrefs.push(fdthis); 
    14321433          L1: ; 
  • trunk/src/func.c

    r603 r610  
    15011501 
    15021502            fbody = new CompoundStatement(0, a); 
    15031503#if DMDV2 
    15041504            /* Append destructor calls for parameters as finally blocks. 
    15051505             */ 
    15061506            if (parameters) 
    15071507            {   for (size_t i = 0; i < parameters->dim; i++) 
    15081508                { 
    15091509                    VarDeclaration *v = (VarDeclaration *)parameters->data[i]; 
    15101510 
    15111511                    if (v->storage_class & (STCref | STCout)) 
    15121512                        continue; 
    15131513 
    15141514                    /* Don't do this for static arrays, since static 
    15151515                     * arrays are called by reference. Remove this 
    15161516                     * when we change them to call by value. 
    15171517                     */ 
    15181518                    if (v->type->toBasetype()->ty == Tsarray) 
    15191519                        continue; 
    15201520 
    1521                     Expression *e = v->callAutoDtor(sc); 
     1521                    Expression *e = v->callAutoDtor(sc2); 
    15221522                    if (e) 
    15231523                    {   Statement *s = new ExpStatement(0, e); 
    1524                         s = s->semantic(sc); 
     1524                        s = s->semantic(sc2); 
    15251525                        if (fbody->blockExit() == BEfallthru) 
    15261526                            fbody = new CompoundStatement(0, fbody, s); 
    15271527                        else 
    15281528                            fbody = new TryFinallyStatement(0, fbody, s); 
    15291529                    } 
    15301530                } 
    15311531            } 
    15321532#endif 
    15331533 
    15341534#if 1 
    15351535            if (isSynchronized()) 
    15361536            {   /* Wrap the entire function body in a synchronized statement 
    15371537                 */ 
    15381538                ClassDeclaration *cd = parent->isClassDeclaration(); 
    15391539                if (cd) 
    15401540                { 
    15411541#if TARGET_WINDOS 
    15421542                    if (/*config.flags2 & CFG2seh &&*/  // always on for WINDOS 
    15431543                        !isStatic() && !fbody->usesEH()) 
    15441544                    { 
     
    23522352 * Error if this cannot call fd. 
    23532353 * Returns: 
    23542354 *      0       same level 
    23552355 *      -1      increase nesting by 1 (fd is nested within 'this') 
    23562356 *      >0      decrease nesting by number 
    23572357 */ 
    23582358 
    23592359int FuncDeclaration::getLevel(Loc loc, FuncDeclaration *fd) 
    23602360{   int level; 
    23612361    Dsymbol *s; 
    23622362    Dsymbol *fdparent; 
    23632363 
    23642364    //printf("FuncDeclaration::getLevel(fd = '%s')\n", fd->toChars()); 
    23652365    fdparent = fd->toParent2(); 
    23662366    if (fdparent == this) 
    23672367        return -1; 
    23682368    s = this; 
    23692369    level = 0; 
    23702370    while (fd != s && fdparent != s->toParent2()) 
    23712371    { 
    2372         //printf("\ts = '%s'\n", s->toChars()); 
     2372        //printf("\ts = %s, '%s'\n", s->kind(), s->toChars()); 
    23732373        FuncDeclaration *thisfd = s->isFuncDeclaration(); 
    23742374        if (thisfd) 
    23752375        {   if (!thisfd->isNested() && !thisfd->vthis) 
    23762376                goto Lerr; 
    23772377        } 
    23782378        else 
    23792379        { 
    23802380            AggregateDeclaration *thiscd = s->isAggregateDeclaration(); 
    23812381            if (thiscd) 
    23822382            {   if (!thiscd->isNested()) 
    23832383                    goto Lerr; 
    23842384            } 
    23852385            else 
    23862386                goto Lerr; 
    23872387        } 
    23882388 
    23892389        s = s->toParent2(); 
    23902390        assert(s); 
    23912391        level++; 
    23922392    } 
    23932393    return level; 
    23942394 
    23952395Lerr: 
    2396     error(loc, "cannot access frame of function %s", fd->toChars()); 
     2396    error(loc, "cannot access frame of function %s", fd->toPrettyChars()); 
     2397halt(); 
    23972398    return 1; 
    23982399} 
    23992400 
    24002401void FuncDeclaration::appendExp(Expression *e) 
    24012402{   Statement *s; 
    24022403 
    24032404    s = new ExpStatement(0, e); 
    24042405    appendState(s); 
    24052406} 
    24062407 
    24072408void FuncDeclaration::appendState(Statement *s) 
    24082409{ 
    24092410    if (!fbody) 
    24102411        fbody = s; 
    24112412    else 
    24122413    { 
    24132414        CompoundStatement *cs = fbody->isCompoundStatement(); 
    24142415        if (cs) 
    24152416        { 
    24162417            if (!cs->statements)