mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 23:50:43 +03:00
nested.cpp
: Refactor loading the this pointer, use typed loads (#4052)
This commit is contained in:
parent
b8b1a5c10c
commit
85b371e7bc
1 changed files with 13 additions and 5 deletions
|
@ -36,6 +36,15 @@ bool isNRVOVar(VarDeclaration *vd) {
|
||||||
bool captureByRef(VarDeclaration *vd) {
|
bool captureByRef(VarDeclaration *vd) {
|
||||||
return vd->isReference() || isNRVOVar(vd);
|
return vd->isReference() || isNRVOVar(vd);
|
||||||
}
|
}
|
||||||
|
LLValue *loadThisPtr(AggregateDeclaration *ad, IrFunction &irfunc) {
|
||||||
|
if (ad->isClassDeclaration()) {
|
||||||
|
return DtoLoad(DtoType(irfunc.irFty.arg_this->type),
|
||||||
|
irfunc.thisArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return irfunc.thisArg;
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
static void DtoCreateNestedContextType(FuncDeclaration *fd);
|
static void DtoCreateNestedContextType(FuncDeclaration *fd);
|
||||||
|
@ -80,8 +89,8 @@ DValue *DtoNestedVariable(const Loc &loc, Type *astype, VarDeclaration *vd,
|
||||||
} else if (AggregateDeclaration *ad = irfunc->decl->isMember2()) {
|
} else if (AggregateDeclaration *ad = irfunc->decl->isMember2()) {
|
||||||
Logger::println(
|
Logger::println(
|
||||||
"Current function is member of nested class, loading vthis");
|
"Current function is member of nested class, loading vthis");
|
||||||
LLValue *val =
|
LLValue *val = loadThisPtr(ad, *irfunc);
|
||||||
ad->isClassDeclaration() ? DtoLoad(irfunc->thisArg) : irfunc->thisArg;
|
|
||||||
for (; ad; ad = ad->toParent2()->isAggregateDeclaration()) {
|
for (; ad; ad = ad->toParent2()->isAggregateDeclaration()) {
|
||||||
assert(ad->vthis);
|
assert(ad->vthis);
|
||||||
val = DtoLoad(DtoGEP(val, 0, getVthisIdx(ad), ".vthis"));
|
val = DtoLoad(DtoGEP(val, 0, getVthisIdx(ad), ".vthis"));
|
||||||
|
@ -262,7 +271,7 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) {
|
||||||
} else if (irFunc.thisArg) {
|
} else if (irFunc.thisArg) {
|
||||||
// or just have a this argument
|
// or just have a this argument
|
||||||
AggregateDeclaration *ad = irFunc.decl->isMember2();
|
AggregateDeclaration *ad = irFunc.decl->isMember2();
|
||||||
val = ad->isClassDeclaration() ? DtoLoad(irFunc.thisArg) : irFunc.thisArg;
|
val = loadThisPtr(ad, irFunc);
|
||||||
if (!ad->vthis) {
|
if (!ad->vthis) {
|
||||||
// This is just a plain 'outer' reference of a class nested in a
|
// This is just a plain 'outer' reference of a class nested in a
|
||||||
// function (but without any variables in the nested context).
|
// function (but without any variables in the nested context).
|
||||||
|
@ -472,8 +481,7 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
|
||||||
AggregateDeclaration *ad = fd->isMember2();
|
AggregateDeclaration *ad = fd->isMember2();
|
||||||
assert(ad);
|
assert(ad);
|
||||||
assert(ad->vthis);
|
assert(ad->vthis);
|
||||||
LLValue *thisptr =
|
LLValue *thisptr = loadThisPtr(ad, irFunc);
|
||||||
ad->isClassDeclaration() ? DtoLoad(irFunc.thisArg) : irFunc.thisArg;
|
|
||||||
IF_LOG Logger::println("Indexing to 'this'");
|
IF_LOG Logger::println("Indexing to 'this'");
|
||||||
src = DtoLoad(DtoGEP(thisptr, 0, getVthisIdx(ad), ".vthis"));
|
src = DtoLoad(DtoGEP(thisptr, 0, getVthisIdx(ad), ".vthis"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue