comparison gen/toir.cpp @ 1137:45d73f0a9b43

Automated merge with http://hg.dsource.org/projects/ldc
author Christian Kamm <kamm incasoftware de>
date Tue, 24 Mar 2009 14:34:16 +0100
parents 9d308feaec27
children f99a3b393c03
comparison
equal deleted inserted replaced
1135:8ebbad15fc99 1137:45d73f0a9b43
1102 } 1102 }
1103 } 1103 }
1104 LLValue* vthis = l->getRVal(); 1104 LLValue* vthis = l->getRVal();
1105 if (!vthis2) vthis2 = vthis; 1105 if (!vthis2) vthis2 = vthis;
1106 1106
1107 // super call 1107 //
1108 if (e1->op == TOKsuper) { 1108 // decide whether this function needs to be looked up in the vtable
1109 //
1110 bool vtbllookup = fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual());
1111
1112 // even virtual functions are looked up directly if super or DotTypeExp
1113 // are used, thus we need to walk through the this expression and check
1114 Expression* e = e1;
1115 while (e && vtbllookup) {
1116 if (e->op == TOKsuper || e->op == TOKdottype)
1117 vtbllookup = false;
1118 else if (e->op == TOKcast)
1119 e = ((CastExp*)e)->e1;
1120 else
1121 break;
1122 }
1123
1124 //
1125 // look up function
1126 //
1127 if (!vtbllookup) {
1109 DtoForceDeclareDsymbol(fdecl); 1128 DtoForceDeclareDsymbol(fdecl);
1110 funcval = fdecl->ir.irFunc->func; 1129 funcval = fdecl->ir.irFunc->func;
1111 assert(funcval); 1130 assert(funcval);
1112 } 1131 }
1113 // normal virtual call 1132 else {
1114 else if (fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual())) {
1115 assert(fdecl->vtblIndex > 0); 1133 assert(fdecl->vtblIndex > 0);
1116 assert(e1type->ty == Tclass); 1134 assert(e1type->ty == Tclass);
1117 1135
1118 LLValue* zero = DtoConstUint(0); 1136 LLValue* zero = DtoConstUint(0);
1119 size_t vtblidx = fdecl->vtblIndex; 1137 size_t vtblidx = fdecl->vtblIndex;
1129 1147
1130 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); 1148 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type)));
1131 if (Logger::enabled()) 1149 if (Logger::enabled())
1132 Logger::cout() << "funcval casted: " << *funcval << '\n'; 1150 Logger::cout() << "funcval casted: " << *funcval << '\n';
1133 } 1151 }
1134 // static call 1152
1135 else {
1136 DtoForceDeclareDsymbol(fdecl);
1137 funcval = fdecl->ir.irFunc->func;
1138 assert(funcval);
1139 }
1140 return new DFuncValue(fdecl, funcval, vthis2); 1153 return new DFuncValue(fdecl, funcval, vthis2);
1141 } 1154 }
1142 else { 1155 else {
1143 printf("unsupported dotvarexp: %s\n", var->toChars()); 1156 printf("unsupported dotvarexp: %s\n", var->toChars());
1144 } 1157 }