Mercurial > projects > ddmd
comparison dmd/TypeSArray.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 | f23312cb6f2e |
children | 4290d870944a |
comparison
equal
deleted
inserted
replaced
50:adf6f7f216ea | 51:b7d29f613539 |
---|---|
1 module dmd.TypeSArray; | 1 module dmd.TypeSArray; |
2 | 2 |
3 import dmd.TypeArray; | 3 import dmd.TypeArray; |
4 import dmd.TypeAArray; | |
4 import dmd.MOD; | 5 import dmd.MOD; |
5 import dmd.Argument; | 6 import dmd.Argument; |
7 import dmd.TypeIdentifier; | |
8 import dmd.TemplateParameter; | |
9 import dmd.TemplateValueParameter; | |
6 import dmd.TypeStruct; | 10 import dmd.TypeStruct; |
7 import dmd.TypeTuple; | 11 import dmd.TypeTuple; |
8 import dmd.VarExp; | 12 import dmd.VarExp; |
9 import dmd.IntegerExp; | 13 import dmd.IntegerExp; |
10 import dmd.Expression; | 14 import dmd.Expression; |
474 return pdt; | 478 return pdt; |
475 } | 479 } |
476 | 480 |
477 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | 481 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
478 { | 482 { |
479 assert(false); | 483 static if (false) { |
484 printf("TypeSArray.deduceType()\n"); | |
485 printf("\tthis = %d, ", ty); print(); | |
486 printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
487 } | |
488 | |
489 // Extra check that array dimensions must match | |
490 if (tparam) | |
491 { | |
492 if (tparam.ty == Tsarray) | |
493 { | |
494 TypeSArray tp = cast(TypeSArray)tparam; | |
495 | |
496 if (tp.dim.op == TOKvar && (cast(VarExp)tp.dim).var.storage_class & STCtemplateparameter) | |
497 { | |
498 int i = templateIdentifierLookup((cast(VarExp)tp.dim).var.ident, parameters); | |
499 // This code matches code in TypeInstance.deduceType() | |
500 if (i == -1) | |
501 goto Lnomatch; | |
502 TemplateParameter tp2 = cast(TemplateParameter)parameters.data[i]; | |
503 TemplateValueParameter tvp = tp2.isTemplateValueParameter(); | |
504 if (!tvp) | |
505 goto Lnomatch; | |
506 Expression e = cast(Expression)dedtypes.data[i]; | |
507 if (e) | |
508 { | |
509 if (!dim.equals(e)) | |
510 goto Lnomatch; | |
511 } | |
512 else | |
513 { | |
514 Type vt = tvp.valType.semantic(Loc(0), sc); | |
515 MATCH m = cast(MATCH)dim.implicitConvTo(vt); | |
516 if (!m) | |
517 goto Lnomatch; | |
518 dedtypes.data[i] = cast(void*)dim; | |
519 } | |
520 } | |
521 else if (dim.toInteger() != tp.dim.toInteger()) | |
522 return MATCHnomatch; | |
523 } | |
524 else if (tparam.ty == Taarray) | |
525 { | |
526 TypeAArray tp = cast(TypeAArray)tparam; | |
527 if (tp.index.ty == Tident) | |
528 { | |
529 TypeIdentifier tident = cast(TypeIdentifier)tp.index; | |
530 | |
531 if (tident.idents.dim == 0) | |
532 { | |
533 Identifier id = tident.ident; | |
534 | |
535 for (size_t i = 0; i < parameters.dim; i++) | |
536 { | |
537 TemplateParameter tp2 = cast(TemplateParameter)parameters.data[i]; | |
538 | |
539 if (tp2.ident.equals(id)) | |
540 { | |
541 // Found the corresponding template parameter | |
542 TemplateValueParameter tvp = tp2.isTemplateValueParameter(); | |
543 if (!tvp || !tvp.valType.isintegral()) | |
544 goto Lnomatch; | |
545 | |
546 if (dedtypes.data[i]) | |
547 { | |
548 if (!dim.equals(cast(Object)dedtypes.data[i])) | |
549 goto Lnomatch; | |
550 } | |
551 else | |
552 { dedtypes.data[i] = cast(void*)dim; | |
553 } | |
554 return next.deduceType(sc, tparam.nextOf(), parameters, dedtypes); | |
555 } | |
556 } | |
557 } | |
558 } | |
559 } | |
560 else if (tparam.ty == Tarray) | |
561 { | |
562 MATCH m; | |
563 | |
564 m = next.deduceType(sc, tparam.nextOf(), parameters, dedtypes); | |
565 if (m == MATCHexact) | |
566 m = MATCHconvert; | |
567 return m; | |
568 } | |
569 } | |
570 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
571 | |
572 Lnomatch: | |
573 return MATCHnomatch; | |
480 } | 574 } |
481 | 575 |
482 TypeInfoDeclaration getTypeInfoDeclaration() | 576 TypeInfoDeclaration getTypeInfoDeclaration() |
483 { | 577 { |
484 assert(false); | 578 assert(false); |