comparison dmd/constfold.c @ 1587:def7a1d494fd

Merge DMD 1.051
author Christian Kamm <kamm incasoftware de>
date Fri, 06 Nov 2009 23:58:01 +0100
parents 8026319762be
children fb2e6707ad17
comparison
equal deleted inserted replaced
1586:7f728c52e63c 1587:def7a1d494fd
68 { 68 {
69 return 1; 69 return 1;
70 } 70 }
71 71
72 int ComplexExp::isConst() 72 int ComplexExp::isConst()
73 {
74 return 1;
75 }
76
77 int NullExp::isConst()
73 { 78 {
74 return 1; 79 return 1;
75 } 80 }
76 81
77 int SymOffExp::isConst() 82 int SymOffExp::isConst()
843 } 848 }
844 else if (e1->type->iscomplex()) 849 else if (e1->type->iscomplex())
845 { 850 {
846 cmp = e1->toComplex() == e2->toComplex(); 851 cmp = e1->toComplex() == e2->toComplex();
847 } 852 }
848 else if (e1->type->isintegral()) 853 else if (e1->type->isintegral() || e1->type->toBasetype()->ty == Tpointer)
849 { 854 {
850 cmp = (e1->toInteger() == e2->toInteger()); 855 cmp = (e1->toInteger() == e2->toInteger());
851 } 856 }
852 else 857 else
853 return EXP_CANT_INTERPRET; 858 return EXP_CANT_INTERPRET;
860 Expression *Identity(enum TOK op, Type *type, Expression *e1, Expression *e2) 865 Expression *Identity(enum TOK op, Type *type, Expression *e1, Expression *e2)
861 { Expression *e; 866 { Expression *e;
862 Loc loc = e1->loc; 867 Loc loc = e1->loc;
863 int cmp; 868 int cmp;
864 869
865 if (e1->op == TOKnull && e2->op == TOKnull) 870 if (e1->op == TOKnull)
866 { 871 {
867 cmp = 1; 872 cmp = (e2->op == TOKnull);
873 }
874 else if (e2->op == TOKnull)
875 {
876 cmp = 0;
868 } 877 }
869 else if (e1->op == TOKsymoff && e2->op == TOKsymoff) 878 else if (e1->op == TOKsymoff && e2->op == TOKsymoff)
870 { 879 {
871 SymOffExp *es1 = (SymOffExp *)e1; 880 SymOffExp *es1 = (SymOffExp *)e1;
872 SymOffExp *es2 = (SymOffExp *)e2; 881 SymOffExp *es2 = (SymOffExp *)e2;
1044 //printf("e1->type = %s\n", e1->type->toChars()); 1053 //printf("e1->type = %s\n", e1->type->toChars());
1045 if (type->equals(e1->type) && to->equals(type)) 1054 if (type->equals(e1->type) && to->equals(type))
1046 return e1; 1055 return e1;
1047 1056
1048 Type *tb = to->toBasetype(); 1057 Type *tb = to->toBasetype();
1049 Type *typeb = type->toBasetype(); 1058
1050 1059 /* Allow casting from one string type to another
1051 // LDC: ported from D2 to allow char[] ~ char[n] arguments in CTFE 1060 */
1052 if (e1->op == TOKstring) 1061 if (e1->op == TOKstring)
1053 { 1062 {
1063 Type *typeb = type->toBasetype();
1054 if (tb->ty == Tarray && typeb->ty == Tarray && 1064 if (tb->ty == Tarray && typeb->ty == Tarray &&
1055 tb->nextOf()->size() == typeb->nextOf()->size()) 1065 tb->nextOf()->size() == typeb->nextOf()->size())
1056 { 1066 {
1057 return expType(to, e1); 1067 return expType(to, e1);
1058 } 1068 }
1067 { 1077 {
1068 if (e1->type->isfloating()) 1078 if (e1->type->isfloating())
1069 { dinteger_t result; 1079 { dinteger_t result;
1070 real_t r = e1->toReal(); 1080 real_t r = e1->toReal();
1071 1081
1072 switch (typeb->ty) 1082 switch (type->toBasetype()->ty)
1073 { 1083 {
1074 case Tint8: result = (d_int8)r; break; 1084 case Tint8: result = (d_int8)r; break;
1075 case Tchar: 1085 case Tchar:
1076 case Tuns8: result = (d_uns8)r; break; 1086 case Tuns8: result = (d_uns8)r; break;
1077 case Tint16: result = (d_int16)r; break; 1087 case Tint16: result = (d_int16)r; break;