Mercurial > projects > ddmd
comparison dmd/TemplateDeclaration.d @ 50:adf6f7f216ea
CondExp.toCBuffer
IsExp.toCBuffer
TemplateValueParameter.toCBuffer
Dsymbol.search
TemplateDeclaration.overloadInsert bug fixed
author | korDen |
---|---|
date | Sat, 21 Aug 2010 10:38:26 +0400 |
parents | 0aa7d1437ada |
children | b7d29f613539 |
comparison
equal
deleted
inserted
replaced
49:0aa7d1437ada | 50:adf6f7f216ea |
---|---|
250 * Overload existing TemplateDeclaration 'this' with the new one 's'. | 250 * Overload existing TemplateDeclaration 'this' with the new one 's'. |
251 * Return !=0 if successful; i.e. no conflict. | 251 * Return !=0 if successful; i.e. no conflict. |
252 */ | 252 */ |
253 bool overloadInsert(Dsymbol s) | 253 bool overloadInsert(Dsymbol s) |
254 { | 254 { |
255 TemplateDeclaration *pf; | |
255 TemplateDeclaration f; | 256 TemplateDeclaration f; |
256 | 257 |
257 version (LOG) { | 258 version (LOG) { |
258 printf("TemplateDeclaration.overloadInsert('%s')\n", s.toChars()); | 259 printf("TemplateDeclaration.overloadInsert('%.*s')\n", s.toChars()); |
259 } | 260 } |
260 f = s.isTemplateDeclaration(); | 261 f = s.isTemplateDeclaration(); |
261 if (!f) | 262 if (!f) |
262 return false; | 263 return false; |
263 | 264 |
264 for (TemplateDeclaration f2 = this; f2; f2 = f2.overnext) | 265 TemplateDeclaration pthis = this; |
265 { | 266 for (pf = &pthis; *pf; pf = &(*pf).overnext) |
266 static if (false) { | 267 { |
267 // Conflict if TemplateParameter's match | 268 static if (false) { |
268 // Will get caught anyway later with TemplateInstance, but | 269 // Conflict if TemplateParameter's match |
269 // should check it now. | 270 // Will get caught anyway later with TemplateInstance, but |
270 if (f.parameters.dim != f2.parameters.dim) | 271 // should check it now. |
271 goto Lcontinue; | 272 if (f.parameters.dim != f2.parameters.dim) |
272 | |
273 for (int i = 0; i < f.parameters.dim; i++) | |
274 { | |
275 TemplateParameter p1 = cast(TemplateParameter)f.parameters.data[i]; | |
276 TemplateParameter p2 = cast(TemplateParameter)f2.parameters.data[i]; | |
277 | |
278 if (!p1.overloadMatch(p2)) | |
279 goto Lcontinue; | 273 goto Lcontinue; |
280 } | 274 |
281 | 275 for (int i = 0; i < f.parameters.dim; i++) |
282 version (LOG) { | 276 { |
283 printf("\tfalse: conflict\n"); | 277 TemplateParameter p1 = cast(TemplateParameter)f.parameters.data[i]; |
284 } | 278 TemplateParameter p2 = cast(TemplateParameter)f2.parameters.data[i]; |
285 return false; | 279 |
286 | 280 if (!p1.overloadMatch(p2)) |
287 Lcontinue: | 281 goto Lcontinue; |
282 } | |
283 | |
284 version (LOG) { | |
285 printf("\tfalse: conflict\n"); | |
286 } | |
287 return false; | |
288 | |
289 Lcontinue: | |
288 ; | 290 ; |
289 } | 291 } |
290 } | 292 } |
291 | 293 |
292 f.overroot = this; | 294 f.overroot = this; |
293 ///*pf = f; | 295 *pf = f; |
294 version (LOG) { | 296 version (LOG) { |
295 printf("\ttrue: no conflict\n"); | 297 printf("\ttrue: no conflict\n"); |
296 } | 298 } |
299 | |
297 return true; | 300 return true; |
298 } | 301 } |
299 | 302 |
300 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | 303 void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
301 { | 304 { |
302 assert(false); | 305 assert(false); |
303 } | 306 } |
304 | 307 |
305 string kind() | 308 string kind() |
306 { | 309 { |
307 assert(false); | 310 return (onemember && onemember.isAggregateDeclaration()) |
311 ? onemember.kind() | |
312 : "template"; | |
308 } | 313 } |
309 | 314 |
310 string toChars() | 315 string toChars() |
311 { | 316 { |
312 OutBuffer buf = new OutBuffer(); | 317 OutBuffer buf = new OutBuffer(); |
337 | 342 |
338 void emitComment(Scope sc) | 343 void emitComment(Scope sc) |
339 { | 344 { |
340 assert(false); | 345 assert(false); |
341 } | 346 } |
342 | 347 |
343 // void toDocBuffer(OutBuffer *buf); | 348 // void toDocBuffer(OutBuffer *buf); |
344 | 349 |
345 /*************************************** | 350 /*************************************** |
346 * Given that ti is an instance of this TemplateDeclaration, | 351 * Given that ti is an instance of this TemplateDeclaration, |
347 * deduce the types of the parameters to this, and store | 352 * deduce the types of the parameters to this, and store |
357 { | 362 { |
358 MATCH m; | 363 MATCH m; |
359 int dedtypes_dim = dedtypes.dim; | 364 int dedtypes_dim = dedtypes.dim; |
360 | 365 |
361 version (LOGM) { | 366 version (LOGM) { |
362 printf("\n+TemplateDeclaration.matchWithInstance(this = %s, ti = %s, flag = %d)\n", toChars(), ti.toChars(), flag); | 367 printf("\n+TemplateDeclaration.matchWithInstance(this = %.*s, ti = %.*s, flag = %d)\n", toChars(), ti.toChars(), flag); |
363 } | 368 } |
364 | 369 |
365 static if (false) { | 370 static if (false) { |
366 printf("dedtypes.dim = %d, parameters.dim = %d\n", dedtypes_dim, parameters.dim); | 371 printf("dedtypes.dim = %d, parameters.dim = %d\n", dedtypes_dim, parameters.dim); |
367 if (ti.tiargs.dim) | 372 if (ti.tiargs.dim) |
374 | 379 |
375 // If more arguments than parameters, no match | 380 // If more arguments than parameters, no match |
376 if (ti.tiargs.dim > parameters_dim && !variadic) | 381 if (ti.tiargs.dim > parameters_dim && !variadic) |
377 { | 382 { |
378 version (LOGM) { | 383 version (LOGM) { |
379 printf(" no match: more arguments than parameters\n"); | 384 printf(" no match: more arguments than parameters\n"); |
380 } | 385 } |
381 return MATCHnomatch; | 386 return MATCHnomatch; |
382 } | 387 } |
383 | 388 |
384 assert(dedtypes_dim == parameters_dim); | 389 assert(dedtypes_dim == parameters_dim); |
385 assert(dedtypes_dim >= ti.tiargs.dim || variadic); | 390 assert(dedtypes_dim >= ti.tiargs.dim || variadic); |
386 | 391 |