Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 639:8aebdf56c455

Show
Ignore:
Timestamp:
10/02/08 17:12:19 (2 months ago)
Author:
Christian Kamm <kamm incasoftware de>
branch:
default
Message:

Move check for access of context for nested class from backend into frontend.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/declaration.h

    r468 r639  
    637637 
    638638    // llvmdc stuff 
     639 
     640    // vars declared in this function that nested funcs reference 
     641    // is this is not empty, nestedFrameRef is set and these VarDecls 
     642    // probably have nestedref set too, see VarDeclaration::checkNestedReference 
    639643    std::set<VarDeclaration*> nestedVars; 
     644 
    640645    std::string intrinsicName; 
    641646 
  • dmd/expression.c

    r599 r639  
    33713371        Dsymbol *s = cd->toParent2(); 
    33723372        ClassDeclaration *cdn = s->isClassDeclaration(); 
     3373        FuncDeclaration *fdn = s->isFuncDeclaration(); 
    33733374 
    33743375        //printf("cd isNested, cdn = %s\n", cdn ? cdn->toChars() : "null"); 
     
    34223423        else if (thisexp) 
    34233424        error("e.new is only for allocating nested classes"); 
     3425        else if (fdn) 
     3426        { 
     3427        // make sure the parent context fdn of cd is reachable from sc 
     3428        for (Dsymbol *sp = sc->parent; 1; sp = sp->parent) 
     3429        { 
     3430            if (fdn == sp) 
     3431            break; 
     3432            FuncDeclaration *fsp = sp ? sp->isFuncDeclaration() : NULL; 
     3433            if (!sp || (fsp && fsp->isStatic())) 
     3434            { 
     3435            error("outer function context of %s is needed to 'new' nested class %s", fdn->toPrettyChars(), cd->toPrettyChars()); 
     3436            break; 
     3437            } 
     3438        } 
     3439         
     3440        } 
    34243441    } 
    34253442    else if (thisexp) 
  • gen/classes.cpp

    r622 r639  
    843843        LOG_SCOPE; 
    844844 
    845         if (gIR->func()->decl->isStatic()) 
    846         { 
    847             newexp->error("function %s is static and cannot access nested class %s", gIR->func()->decl->toPrettyChars(), tc->sym->toPrettyChars()); 
    848             fatal(); 
    849         } 
    850  
    851845        // get context 
    852846        LLValue* nest = DtoNestedContext(loc, tc->sym); 
  • gen/llvmhelpers.cpp

    r632 r639  
    391391 
    392392    IrFunction* irfunc = gIR->func(); 
    393      
     393 
     394    // if this func has its own vars that are accessed by nested funcs 
     395    // use its own context 
    394396    if (irfunc->nestedVar) 
    395397        return irfunc->nestedVar; 
     398    // otherwise, it may have gotten a context from the caller 
    396399    else if (irfunc->nestArg) 
    397400        return irfunc->nestArg; 
     401    // or just have a this argument 
    398402    else if (irfunc->thisArg) 
    399403    { 
Copyright © 2008, LDC Development Team.