Changeset 639:8aebdf56c455
- Timestamp:
- 10/02/08 17:12:19
(3 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
| r468 |
r639 |
|
| 637 | 637 | |
|---|
| 638 | 638 | // 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 |
|---|
| 639 | 643 | std::set<VarDeclaration*> nestedVars; |
|---|
| | 644 | |
|---|
| 640 | 645 | std::string intrinsicName; |
|---|
| 641 | 646 | |
|---|
| r599 |
r639 |
|
| 3371 | 3371 | Dsymbol *s = cd->toParent2(); |
|---|
| 3372 | 3372 | ClassDeclaration *cdn = s->isClassDeclaration(); |
|---|
| | 3373 | FuncDeclaration *fdn = s->isFuncDeclaration(); |
|---|
| 3373 | 3374 | |
|---|
| 3374 | 3375 | //printf("cd isNested, cdn = %s\n", cdn ? cdn->toChars() : "null"); |
|---|
| … | … | |
| 3422 | 3423 | else if (thisexp) |
|---|
| 3423 | 3424 | 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 | } |
|---|
| 3424 | 3441 | } |
|---|
| 3425 | 3442 | else if (thisexp) |
|---|
| r622 |
r639 |
|
| 843 | 843 | LOG_SCOPE; |
|---|
| 844 | 844 | |
|---|
| 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 | | |
|---|
| 851 | 845 | // get context |
|---|
| 852 | 846 | LLValue* nest = DtoNestedContext(loc, tc->sym); |
|---|
| r632 |
r639 |
|
| 391 | 391 | |
|---|
| 392 | 392 | 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 |
|---|
| 394 | 396 | if (irfunc->nestedVar) |
|---|
| 395 | 397 | return irfunc->nestedVar; |
|---|
| | 398 | // otherwise, it may have gotten a context from the caller |
|---|
| 396 | 399 | else if (irfunc->nestArg) |
|---|
| 397 | 400 | return irfunc->nestArg; |
|---|
| | 401 | // or just have a this argument |
|---|
| 398 | 402 | else if (irfunc->thisArg) |
|---|
| 399 | 403 | { |
|---|