@@ -947,8 +947,9 @@ class ToElemVisitor : public Visitor {
947
947
// Logger::println("FuncDeclaration");
948
948
FuncDeclaration *fd = fv->func ;
949
949
assert (fd);
950
- result =
951
- fv->type == e->type ? fv : new DFuncValue (e->type , fd, fv->funcPtr );
950
+ result = fv->type == e->type
951
+ ? fv
952
+ : new DFuncValue (e->type , fd, fv->funcPtr , fv->vthis );
952
953
return ;
953
954
}
954
955
if (v->isIm ()) {
@@ -986,9 +987,10 @@ class ToElemVisitor : public Visitor {
986
987
if (e->type ->toBasetype ()->ty == TY::Tfunction) {
987
988
DValue *dv = toElem (e->e1 );
988
989
if (DFuncValue *dfv = dv->isFunc ()) {
989
- result = dfv->type == e->type
990
- ? dfv
991
- : new DFuncValue (e->type , dfv->func , dfv->funcPtr );
990
+ result =
991
+ dfv->type == e->type
992
+ ? dfv
993
+ : new DFuncValue (e->type , dfv->func , dfv->funcPtr , dfv->vthis );
992
994
} else {
993
995
// FIXME: should not reach this
994
996
result = new DImValue (e->type , DtoRVal (dv));
@@ -1955,9 +1957,11 @@ class ToElemVisitor : public Visitor {
1955
1957
DValue *u = toElem (e->e1 );
1956
1958
LLValue *contextptr;
1957
1959
if (DFuncValue *f = u->isFunc ()) {
1958
- assert (f->func );
1959
- // FIXME: use f->vthis
1960
- contextptr = DtoNestedContext (e->loc , f->func );
1960
+ contextptr = f->vthis ;
1961
+ if (!contextptr) {
1962
+ assert (f->func );
1963
+ contextptr = DtoNestedContext (e->loc , f->func );
1964
+ }
1961
1965
} else {
1962
1966
contextptr = (DtoIsInMemoryOnly (u->type ) ? DtoLVal (u) : DtoRVal (u));
1963
1967
}
@@ -1993,9 +1997,7 @@ class ToElemVisitor : public Visitor {
1993
1997
fptr = DtoCallee (e->func );
1994
1998
}
1995
1999
1996
- // FIXME: use DFuncValue
1997
- result = new DImValue (
1998
- e->type , DtoAggrPair (DtoType (e->type ), contextptr, fptr, " .dg" ));
2000
+ result = new DFuncValue (e->type , e->func , fptr, contextptr);
1999
2001
}
2000
2002
2001
2003
// ////////////////////////////////////////////////////////////////////////////
@@ -2286,11 +2288,11 @@ class ToElemVisitor : public Visitor {
2286
2288
genFuncLiteral (fd, e);
2287
2289
LLFunction *callee = DtoCallee (fd, false );
2288
2290
2289
- if (fd-> isNested ()) { // FIXME: if e->type->toBasetype() is a Tdelegate?
2291
+ if (e->type ->toBasetype ()-> ty == TY:: Tdelegate) {
2290
2292
LLValue *cval = DtoNestedContext (e->loc , fd);
2291
- // FIXME: use DFuncValue
2292
- result = new DImValue (e->type , DtoAggrPair (cval, callee, " .func" ));
2293
+ result = new DFuncValue (e->type , fd, callee, cval);
2293
2294
} else {
2295
+ assert (!fd->isNested ());
2294
2296
result = new DFuncValue (e->type , fd, callee);
2295
2297
}
2296
2298
}
0 commit comments