Mercurial > projects > ddmd
comparison dmd/TemplateDeclaration.d @ 51:b7d29f613539
StaticAssertStatement.syntaxCopy
IfStatement.syntaxCopy
CompoundDeclarationStatement.syntaxCopy
VoidInitializer.syntaxCopy
TypeAArray.syntaxCopy
TypeTypeof.syntaxCopy
TypeAArray.resolve
TypeSArray.deduceType
TypeAArray.deduceType
TypeAArray.implicitConvTo
TemplateDeclaration.leastAsSpecialized
TemplateTypeParameter.dummyArg
TypeIdentifier.deduceType
TemplateTypeParameter.syntaxCopy
Lexer.hexStringConstant
Lexer.delimitedStringConstant
GotoDefaultStatement.ctor
CaseRangeStatement.ctor
Type.castMod
StorageClassDeclaration.syntaxCopy
TemplateDeclaration.syntaxCopy
author | korDen |
---|---|
date | Sat, 21 Aug 2010 11:17:42 +0400 |
parents | adf6f7f216ea |
children | cab4c37afb89 |
comparison
equal
deleted
inserted
replaced
50:adf6f7f216ea | 51:b7d29f613539 |
---|---|
149 instances = new Array(); | 149 instances = new Array(); |
150 } | 150 } |
151 | 151 |
152 Dsymbol syntaxCopy(Dsymbol) | 152 Dsymbol syntaxCopy(Dsymbol) |
153 { | 153 { |
154 assert(false); | 154 //printf("TemplateDeclaration.syntaxCopy()\n"); |
155 TemplateDeclaration td; | |
156 TemplateParameters p; | |
157 Array d; | |
158 | |
159 p = null; | |
160 if (parameters) | |
161 { | |
162 p = new TemplateParameters(); | |
163 p.setDim(parameters.dim); | |
164 for (int i = 0; i < p.dim; i++) | |
165 { | |
166 TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; | |
167 p.data[i] = cast(void*)tp.syntaxCopy(); | |
168 } | |
169 } | |
170 | |
171 Expression e = null; | |
172 if (constraint) | |
173 e = constraint.syntaxCopy(); | |
174 d = Dsymbol.arraySyntaxCopy(members); | |
175 td = new TemplateDeclaration(loc, ident, p, e, d); | |
176 return td; | |
155 } | 177 } |
156 | 178 |
157 void semantic(Scope sc) | 179 void semantic(Scope sc) |
158 { | 180 { |
159 version (LOG) { | 181 version (LOG) { |
512 printf("-TemplateDeclaration.matchWithInstance(this = %p, ti = %p) = %d\n", this, ti, m); | 534 printf("-TemplateDeclaration.matchWithInstance(this = %p, ti = %p) = %d\n", this, ti, m); |
513 } | 535 } |
514 return m; | 536 return m; |
515 } | 537 } |
516 | 538 |
539 /******************************************** | |
540 * Determine partial specialization order of 'this' vs td2. | |
541 * Returns: | |
542 * match this is at least as specialized as td2 | |
543 * 0 td2 is more specialized than this | |
544 */ | |
517 MATCH leastAsSpecialized(TemplateDeclaration td2) | 545 MATCH leastAsSpecialized(TemplateDeclaration td2) |
518 { | 546 { |
519 assert(false); | 547 /* This works by taking the template parameters to this template |
548 * declaration and feeding them to td2 as if it were a template | |
549 * instance. | |
550 * If it works, then this template is at least as specialized | |
551 * as td2. | |
552 */ | |
553 | |
554 scope TemplateInstance ti = new TemplateInstance(Loc(0), ident); // create dummy template instance | |
555 scope Objects dedtypes = new Objects(); | |
556 | |
557 version (LOG_LEASTAS) { | |
558 printf("%s.leastAsSpecialized(%s)\n", toChars(), td2.toChars()); | |
559 } | |
560 | |
561 // Set type arguments to dummy template instance to be types | |
562 // generated from the parameters to this template declaration | |
563 ti.tiargs = new Objects(); | |
564 ti.tiargs.setDim(parameters.dim); | |
565 for (int i = 0; i < ti.tiargs.dim; i++) | |
566 { | |
567 TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; | |
568 | |
569 void* p = tp.dummyArg(); | |
570 if (p) | |
571 ti.tiargs.data[i] = p; | |
572 else | |
573 ti.tiargs.setDim(i); | |
574 } | |
575 | |
576 // Temporary Array to hold deduced types | |
577 //dedtypes.setDim(parameters.dim); | |
578 dedtypes.setDim(td2.parameters.dim); | |
579 | |
580 // Attempt a type deduction | |
581 MATCH m = td2.matchWithInstance(ti, dedtypes, 1); | |
582 if (m) | |
583 { | |
584 /* A non-variadic template is more specialized than a | |
585 * variadic one. | |
586 */ | |
587 if (isVariadic() && !td2.isVariadic()) | |
588 goto L1; | |
589 | |
590 version (LOG_LEASTAS) { | |
591 printf(" matches %d, so is least as specialized\n", m); | |
592 } | |
593 return m; | |
594 } | |
595 L1: | |
596 version (LOG_LEASTAS) { | |
597 printf(" doesn't match, so is not as specialized\n"); | |
598 } | |
599 return MATCHnomatch; | |
520 } | 600 } |
521 | 601 |
522 /************************************************* | 602 /************************************************* |
523 * Match function arguments against a specific template function. | 603 * Match function arguments against a specific template function. |
524 * Input: | 604 * Input: |