comparison dmd/CatExp.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children e8a741997ccf
comparison
equal deleted inserted replaced
129:010eb8f0e18d 130:60bb0fe4563e
12 import dmd.Type; 12 import dmd.Type;
13 import dmd.TY; 13 import dmd.TY;
14 import dmd.MATCH; 14 import dmd.MATCH;
15 import dmd.ArrayLiteralExp; 15 import dmd.ArrayLiteralExp;
16 import dmd.StringExp; 16 import dmd.StringExp;
17 import dmd.ErrorExp;
17 import dmd.WANT; 18 import dmd.WANT;
18 import dmd.Id; 19 import dmd.Id;
19 import dmd.GlobalExpressions; 20 import dmd.GlobalExpressions;
20 21
21 import dmd.backend.elem; 22 import dmd.backend.elem;
57 58
58 static if (false) { 59 static if (false) {
59 e1.type.print(); 60 e1.type.print();
60 e2.type.print(); 61 e2.type.print();
61 } 62 }
63 Type tb1next = tb1.nextOf();
64 Type tb2next = tb2.nextOf();
65
62 if ((tb1.ty == Tsarray || tb1.ty == Tarray) && 66 if ((tb1.ty == Tsarray || tb1.ty == Tarray) &&
63 e2.type.implicitConvTo(tb1.nextOf()) >= MATCHconst) 67 e2.implicitConvTo(tb1next) >= MATCHconvert)
64 { 68 {
65 type = tb1.nextOf().arrayOf(); 69 e2 = e2.implicitCastTo(sc, tb1next);
66 if (tb2.ty == Tarray) 70 if (tb2.ty == Tarray)
67 { 71 {
68 // Make e2 into [e2] 72 // Make e2 into [e2]
69 e2 = new ArrayLiteralExp(e2.loc, e2); 73 e2 = new ArrayLiteralExp(e2.loc, e2);
70 e2.type = type; 74 e2.type = type;
71 } 75 }
72 return this; 76 return this;
73 } 77 }
74 else if ((tb2.ty == Tsarray || tb2.ty == Tarray) && 78 else if ((tb2.ty == Tsarray || tb2.ty == Tarray) &&
75 e1.type.implicitConvTo(tb2.nextOf()) >= MATCHconst) 79 e1.implicitConvTo(tb2next) >= MATCHconvert)
76 { 80 {
77 type = tb2.nextOf().arrayOf(); 81 e1 = e1.implicitCastTo(sc, tb2next);
78 if (tb1.ty == Tarray) 82 if (tb1.ty == Tarray)
79 { 83 {
80 // Make e1 into [e1] 84 // Make e1 into [e1]
81 e1 = new ArrayLiteralExp(e1.loc, e1); 85 e1 = new ArrayLiteralExp(e1.loc, e1);
82 e1.type = type; 86 e1.type = type;
84 return this; 88 return this;
85 } 89 }
86 90
87 if ((tb1.ty == Tsarray || tb1.ty == Tarray) && 91 if ((tb1.ty == Tsarray || tb1.ty == Tarray) &&
88 (tb2.ty == Tsarray || tb2.ty == Tarray) && 92 (tb2.ty == Tsarray || tb2.ty == Tarray) &&
89 (tb1.nextOf().mod || tb2.nextOf().mod) && 93 (tb1next.mod || tb2next.mod) &&
90 (tb1.nextOf().mod != tb2.nextOf().mod) 94 (tb1next.mod != tb2next.mod)
91 ) 95 )
92 { 96 {
93 Type t1 = tb1.nextOf().mutableOf().constOf().arrayOf(); 97 Type t1 = tb1next.mutableOf().constOf().arrayOf();
94 Type t2 = tb2.nextOf().mutableOf().constOf().arrayOf(); 98 Type t2 = tb2next.mutableOf().constOf().arrayOf();
95 if (e1.op == TOKstring && !(cast(StringExp)e1).committed) 99 if (e1.op == TOKstring && !(cast(StringExp)e1).committed)
96 e1.type = t1; 100 e1.type = t1;
97 else 101 else
98 e1 = e1.castTo(sc, t1); 102 e1 = e1.castTo(sc, t1);
99 if (e2.op == TOKstring && !(cast(StringExp)e2).committed) 103 if (e2.op == TOKstring && !(cast(StringExp)e2).committed)
106 type = type.toHeadMutable(); 110 type = type.toHeadMutable();
107 111
108 Type tb = type.toBasetype(); 112 Type tb = type.toBasetype();
109 if (tb.ty == Tsarray) 113 if (tb.ty == Tsarray)
110 type = tb.nextOf().arrayOf(); 114 type = tb.nextOf().arrayOf();
111 if (type.ty == Tarray && tb1.nextOf() && tb2.nextOf() && 115 if (type.ty == Tarray && tb1next && tb2next &&
112 tb1.nextOf().mod != tb2.nextOf().mod) 116 tb1next.mod != tb2next.mod)
113 { 117 {
114 type = type.nextOf().toHeadMutable().arrayOf(); 118 type = type.nextOf().toHeadMutable().arrayOf();
115 } 119 }
116 static if (false) { 120 static if (false) {
117 e1.type.print(); 121 e1.type.print();
131 else 135 else
132 { 136 {
133 //printf("(%s) ~ (%s)\n", e1.toChars(), e2.toChars()); 137 //printf("(%s) ~ (%s)\n", e1.toChars(), e2.toChars());
134 error("Can only concatenate arrays, not (%s ~ %s)", 138 error("Can only concatenate arrays, not (%s ~ %s)",
135 e1.type.toChars(), e2.type.toChars()); 139 e1.type.toChars(), e2.type.toChars());
136 type = Type.tint32; 140 return new ErrorExp();
137 e = this;
138 } 141 }
139 e.type = e.type.semantic(loc, sc); 142 e.type = e.type.semantic(loc, sc);
140 return e; 143 return e;
141 } 144 }
142 return this; 145 return this;