Mercurial > projects > ldc
comparison dmd/constfold.c @ 35:3cfcb944304e trunk
[svn r39] * Updated to DMD 1.022 with the exception of:
Bugzilla 278: dmd.conf search path doesn't work
This fix was causing crashes for me :/ So for it's the old behaviour
author | lindquist |
---|---|
date | Tue, 09 Oct 2007 06:21:30 +0200 |
parents | 788401029ecf |
children | 2b72433d5c8c |
comparison
equal
deleted
inserted
replaced
34:4648206ca213 | 35:3cfcb944304e |
---|---|
731 if (cmp == 0) | 731 if (cmp == 0) |
732 break; | 732 break; |
733 } | 733 } |
734 } | 734 } |
735 } | 735 } |
736 else if (e1->op == TOKarrayliteral && e2->op == TOKstring) | |
737 { // Swap operands and use common code | |
738 Expression *e = e1; | |
739 e1 = e2; | |
740 e2 = e; | |
741 goto Lsa; | |
742 } | |
743 else if (e1->op == TOKstring && e2->op == TOKarrayliteral) | |
744 { | |
745 Lsa: | |
746 StringExp *es1 = (StringExp *)e1; | |
747 ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; | |
748 size_t dim1 = es1->len; | |
749 size_t dim2 = es2->elements ? es2->elements->dim : 0; | |
750 if (dim1 != dim2) | |
751 cmp = 0; | |
752 else | |
753 { | |
754 for (size_t i = 0; i < dim1; i++) | |
755 { | |
756 uinteger_t c = es1->charAt(i); | |
757 Expression *ee2 = (Expression *)es2->elements->data[i]; | |
758 if (ee2->isConst() != 1) | |
759 return EXP_CANT_INTERPRET; | |
760 cmp = (c == ee2->toInteger()); | |
761 if (cmp == 0) | |
762 break; | |
763 } | |
764 } | |
765 } | |
736 else if (e1->op == TOKstructliteral && e2->op == TOKstructliteral) | 766 else if (e1->op == TOKstructliteral && e2->op == TOKstructliteral) |
737 { StructLiteralExp *es1 = (StructLiteralExp *)e1; | 767 { StructLiteralExp *es1 = (StructLiteralExp *)e1; |
738 StructLiteralExp *es2 = (StructLiteralExp *)e2; | 768 StructLiteralExp *es2 = (StructLiteralExp *)e2; |
739 | 769 |
740 if (es1->sd != es2->sd) | 770 if (es1->sd != es2->sd) |
1130 uinteger_t i = e2->toInteger(); | 1160 uinteger_t i = e2->toInteger(); |
1131 | 1161 |
1132 if (i >= es1->len) | 1162 if (i >= es1->len) |
1133 e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); | 1163 e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); |
1134 else | 1164 else |
1135 { integer_t value; | 1165 { unsigned value = es1->charAt(i); |
1136 | |
1137 switch (es1->sz) | |
1138 { | |
1139 case 1: | |
1140 value = ((unsigned char *)es1->string)[i]; | |
1141 break; | |
1142 | |
1143 case 2: | |
1144 value = ((unsigned short *)es1->string)[i]; | |
1145 break; | |
1146 | |
1147 case 4: | |
1148 value = ((unsigned int *)es1->string)[i]; | |
1149 break; | |
1150 | |
1151 default: | |
1152 assert(0); | |
1153 break; | |
1154 } | |
1155 e = new IntegerExp(loc, value, type); | 1166 e = new IntegerExp(loc, value, type); |
1156 } | 1167 } |
1157 } | 1168 } |
1158 else if (e1->type->toBasetype()->ty == Tsarray && e2->op == TOKint64) | 1169 else if (e1->type->toBasetype()->ty == Tsarray && e2->op == TOKint64) |
1159 { TypeSArray *tsa = (TypeSArray *)e1->type->toBasetype(); | 1170 { TypeSArray *tsa = (TypeSArray *)e1->type->toBasetype(); |