mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-07 19:36:06 +03:00
Random comment cleanup [nfc]
This commit is contained in:
parent
e3e2a2a1e0
commit
6c15b4bc8e
2 changed files with 22 additions and 41 deletions
|
@ -873,23 +873,21 @@ void DtoVarDeclaration(VarDeclaration *vd) {
|
||||||
|
|
||||||
if (isIrLocalCreated(vd)) {
|
if (isIrLocalCreated(vd)) {
|
||||||
// Nothing to do if it has already been allocated.
|
// Nothing to do if it has already been allocated.
|
||||||
}
|
} else if (gIR->func()->retArg && gIR->func()->decl->nrvo_can &&
|
||||||
/* Named Return Value Optimization (NRVO):
|
|
||||||
T f(){
|
|
||||||
T ret; // &ret == hidden pointer
|
|
||||||
ret = ...
|
|
||||||
return ret; // NRVO.
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
else if (gIR->func()->retArg && gIR->func()->decl->nrvo_can &&
|
|
||||||
gIR->func()->decl->nrvo_var == vd) {
|
gIR->func()->decl->nrvo_var == vd) {
|
||||||
|
// Named Return Value Optimization (NRVO):
|
||||||
|
// T f() {
|
||||||
|
// T ret; // &ret == hidden pointer
|
||||||
|
// ret = ...
|
||||||
|
// return ret; // NRVO.
|
||||||
|
// }
|
||||||
assert(!isSpecialRefVar(vd) && "Can this happen?");
|
assert(!isSpecialRefVar(vd) && "Can this happen?");
|
||||||
IrLocal *irLocal = getIrLocal(vd, true);
|
getIrLocal(vd, true)->value = gIR->func()->retArg;
|
||||||
irLocal->value = gIR->func()->retArg;
|
|
||||||
}
|
}
|
||||||
// normal stack variable, allocate storage on the stack if it has not already
|
|
||||||
// been done
|
|
||||||
else {
|
else {
|
||||||
|
// normal stack variable, allocate storage on the stack if it has not
|
||||||
|
// already been done
|
||||||
IrLocal *irLocal = getIrLocal(vd, true);
|
IrLocal *irLocal = getIrLocal(vd, true);
|
||||||
|
|
||||||
Type *type = isSpecialRefVar(vd) ? vd->type->pointerTo() : vd->type;
|
Type *type = isSpecialRefVar(vd) ? vd->type->pointerTo() : vd->type;
|
||||||
|
@ -967,7 +965,6 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
|
||||||
IF_LOG Logger::print("DtoDeclarationExp: %s\n", declaration->toChars());
|
IF_LOG Logger::print("DtoDeclarationExp: %s\n", declaration->toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
// variable declaration
|
|
||||||
if (VarDeclaration *vd = declaration->isVarDeclaration()) {
|
if (VarDeclaration *vd = declaration->isVarDeclaration()) {
|
||||||
Logger::println("VarDeclaration");
|
Logger::println("VarDeclaration");
|
||||||
|
|
||||||
|
@ -991,23 +988,17 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
|
||||||
}
|
}
|
||||||
return makeVarDValue(vd->type, vd);
|
return makeVarDValue(vd->type, vd);
|
||||||
}
|
}
|
||||||
// struct declaration
|
|
||||||
if (StructDeclaration *s = declaration->isStructDeclaration()) {
|
if (StructDeclaration *s = declaration->isStructDeclaration()) {
|
||||||
Logger::println("StructDeclaration");
|
Logger::println("StructDeclaration");
|
||||||
Declaration_codegen(s);
|
Declaration_codegen(s);
|
||||||
}
|
} else if (FuncDeclaration *f = declaration->isFuncDeclaration()) {
|
||||||
// function declaration
|
|
||||||
else if (FuncDeclaration *f = declaration->isFuncDeclaration()) {
|
|
||||||
Logger::println("FuncDeclaration");
|
Logger::println("FuncDeclaration");
|
||||||
Declaration_codegen(f);
|
Declaration_codegen(f);
|
||||||
}
|
} else if (ClassDeclaration *e = declaration->isClassDeclaration()) {
|
||||||
// class
|
|
||||||
else if (ClassDeclaration *e = declaration->isClassDeclaration()) {
|
|
||||||
Logger::println("ClassDeclaration");
|
Logger::println("ClassDeclaration");
|
||||||
Declaration_codegen(e);
|
Declaration_codegen(e);
|
||||||
}
|
} else if (AttribDeclaration *a = declaration->isAttribDeclaration()) {
|
||||||
// attribute declaration
|
|
||||||
else if (AttribDeclaration *a = declaration->isAttribDeclaration()) {
|
|
||||||
Logger::println("AttribDeclaration");
|
Logger::println("AttribDeclaration");
|
||||||
// choose the right set in case this is a conditional declaration
|
// choose the right set in case this is a conditional declaration
|
||||||
Dsymbols *d = a->include(nullptr, nullptr);
|
Dsymbols *d = a->include(nullptr, nullptr);
|
||||||
|
@ -1016,17 +1007,13 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
|
||||||
DtoDeclarationExp((*d)[i]);
|
DtoDeclarationExp((*d)[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (TemplateMixin *m = declaration->isTemplateMixin()) {
|
||||||
// mixin declaration
|
|
||||||
else if (TemplateMixin *m = declaration->isTemplateMixin()) {
|
|
||||||
Logger::println("TemplateMixin");
|
Logger::println("TemplateMixin");
|
||||||
for (unsigned i = 0; i < m->members->dim; ++i) {
|
for (unsigned i = 0; i < m->members->dim; ++i) {
|
||||||
Dsymbol *mdsym = static_cast<Dsymbol *>(m->members->data[i]);
|
Dsymbol *mdsym = static_cast<Dsymbol *>(m->members->data[i]);
|
||||||
DtoDeclarationExp(mdsym);
|
DtoDeclarationExp(mdsym);
|
||||||
}
|
}
|
||||||
}
|
} else if (TupleDeclaration *tupled = declaration->isTupleDeclaration()) {
|
||||||
// tuple declaration
|
|
||||||
else if (TupleDeclaration *tupled = declaration->isTupleDeclaration()) {
|
|
||||||
Logger::println("TupleDeclaration");
|
Logger::println("TupleDeclaration");
|
||||||
assert(tupled->isexp && "Non-expression tuple decls not handled yet.");
|
assert(tupled->isexp && "Non-expression tuple decls not handled yet.");
|
||||||
assert(tupled->objects);
|
assert(tupled->objects);
|
||||||
|
|
14
gen/toir.cpp
14
gen/toir.cpp
|
@ -1304,25 +1304,20 @@ public:
|
||||||
e->type->toChars());
|
e->type->toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
// this is the new slicing code, it's different in that a full slice will no
|
|
||||||
// longer retain the original pointer.
|
|
||||||
// but this was broken if there *was* no original pointer, ie. a slice of a
|
|
||||||
// slice...
|
|
||||||
// now all slices have *both* the 'len' and 'ptr' fields set to != null.
|
|
||||||
|
|
||||||
// value being sliced
|
// value being sliced
|
||||||
LLValue *elen = nullptr;
|
LLValue *elen = nullptr;
|
||||||
LLValue *eptr;
|
LLValue *eptr;
|
||||||
DValue *v = toElem(e->e1);
|
DValue *v = toElem(e->e1);
|
||||||
|
|
||||||
// handle pointer slicing
|
|
||||||
Type *etype = e->e1->type->toBasetype();
|
Type *etype = e->e1->type->toBasetype();
|
||||||
if (etype->ty == Tpointer) {
|
if (etype->ty == Tpointer) {
|
||||||
|
// pointer slicing
|
||||||
assert(e->lwr);
|
assert(e->lwr);
|
||||||
eptr = v->getRVal();
|
eptr = v->getRVal();
|
||||||
}
|
}
|
||||||
// array slice
|
|
||||||
else {
|
else {
|
||||||
|
// array slice
|
||||||
eptr = DtoArrayPtr(v);
|
eptr = DtoArrayPtr(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1383,8 +1378,7 @@ public:
|
||||||
// no bounds or full slice -> just convert to slice
|
// no bounds or full slice -> just convert to slice
|
||||||
else {
|
else {
|
||||||
assert(e->e1->type->toBasetype()->ty != Tpointer);
|
assert(e->e1->type->toBasetype()->ty != Tpointer);
|
||||||
// if the sliceee is a static array, we use the length of that as DMD
|
// if the slicee is a static array, we use the length of that as DMD seems
|
||||||
// seems
|
|
||||||
// to give contrary inconsistent sizesin some multidimensional static
|
// to give contrary inconsistent sizesin some multidimensional static
|
||||||
// array cases.
|
// array cases.
|
||||||
// (namely default initialization, int[16][16] arr; -> int[256] arr = 0;)
|
// (namely default initialization, int[16][16] arr; -> int[256] arr = 0;)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue