Mercurial > projects > ddmd
annotate dmd/CatAssignExp.d @ 137:09c858522d55
merge
author | Trass3r |
---|---|
date | Mon, 13 Sep 2010 23:29:00 +0200 |
parents | 60bb0fe4563e |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.CatAssignExp; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.BinExp; |
5 import dmd.Loc; | |
6 import dmd.Expression; | |
7 import dmd.Scope; | |
8 import dmd.InterState; | |
9 import dmd.SliceExp; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
10 import dmd.ErrorExp; |
0 | 11 import dmd.Identifier; |
12 import dmd.IRState; | |
13 import dmd.TOK; | |
14 import dmd.TY; | |
15 import dmd.Id; | |
16 import dmd.Type; | |
17 import dmd.backend.elem; | |
18 import dmd.backend.RTLSYM; | |
19 import dmd.backend.Util; | |
20 import dmd.backend.OPER; | |
21 import dmd.backend.TYM; | |
22 import dmd.backend.mTY; | |
23 | |
117 | 24 import dmd.expression.Cat; |
0 | 25 import dmd.expression.Util; |
26 | |
27 class CatAssignExp : BinExp | |
28 { | |
29 this(Loc loc, Expression e1, Expression e2) | |
30 { | |
31 super(loc, TOK.TOKcatass, CatAssignExp.sizeof, e1, e2); | |
32 } | |
33 | |
72 | 34 override Expression semantic(Scope sc) |
0 | 35 { |
36 Expression e; | |
37 | |
38 BinExp.semantic(sc); | |
39 e2 = resolveProperties(sc, e2); | |
40 | |
41 e = op_overload(sc); | |
42 if (e) | |
43 return e; | |
44 | |
45 if (e1.op == TOKslice) | |
46 { | |
47 SliceExp se = cast(SliceExp)e1; | |
48 | |
49 if (se.e1.type.toBasetype().ty == Tsarray) | |
50 error("cannot append to static array %s", se.e1.type.toChars()); | |
51 } | |
52 | |
53 e1 = e1.modifiableLvalue(sc, e1); | |
54 | |
55 Type tb1 = e1.type.toBasetype(); | |
56 Type tb2 = e2.type.toBasetype(); | |
57 | |
58 e2.rvalue(); | |
59 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
60 Type tb1next = tb1.nextOf(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
61 |
0 | 62 if ((tb1.ty == Tarray) && |
63 (tb2.ty == Tarray || tb2.ty == Tsarray) && | |
64 (e2.implicitConvTo(e1.type) || | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
65 //version(DMDV2) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
66 tb2.nextOf().implicitConvTo(tb1next) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
67 //} |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
68 ) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
69 |
0 | 70 ) |
71 { // Append array | |
72 e2 = e2.castTo(sc, e1.type); | |
73 type = e1.type; | |
74 e = this; | |
75 } | |
76 else if ((tb1.ty == Tarray) && | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
77 e2.implicitConvTo(tb1next) |
0 | 78 ) |
79 { // Append element | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
80 e2 = e2.castTo(sc, tb1next); |
0 | 81 type = e1.type; |
82 e = this; | |
83 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
84 else if (tb1.ty == Tarray && |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
85 (tb1next.ty == Tchar || tb1next.ty == Twchar) && |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
86 e2.implicitConvTo(Type.tdchar) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
87 ) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
88 { // Append dchar to char[] or wchar[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
89 e2 = e2.castTo(sc, Type.tdchar); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
90 type = e1.type; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
91 e = this; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
92 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
93 /* Do not allow appending wchar to char[] because if wchar happens |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
94 * to be a surrogate pair, nothing good can result. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
95 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
96 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
97 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
98 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
99 error("cannot append type %s to type %s", tb2.toChars(), tb1.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
100 e = new ErrorExp(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
101 } |
0 | 102 return e; |
103 } | |
104 | |
72 | 105 override Expression interpret(InterState istate) |
0 | 106 { |
117 | 107 return interpretAssignCommon(istate, &Cat); |
0 | 108 } |
109 | |
72 | 110 override Identifier opId() /* For operator overloading */ |
0 | 111 { |
112 return Id.catass; | |
113 } | |
114 | |
72 | 115 override elem* toElem(IRState* irs) |
0 | 116 { |
117 //printf("CatAssignExp.toElem('%s')\n", toChars()); | |
118 elem* e; | |
119 Type tb1 = e1.type.toBasetype(); | |
120 Type tb2 = e2.type.toBasetype(); | |
121 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
122 if (tb1.ty == Tarray && tb2.ty == Tdchar && |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
123 (tb1.nextOf().ty == Tchar || tb1.nextOf().ty == Twchar)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
124 { // Append dchar to char[] or wchar[] |
0 | 125 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
126 auto e1 = this.e1.toElem(irs); |
0 | 127 e1 = el_una(OPaddr, TYnptr, e1); |
128 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
129 auto e2 = this.e2.toElem(irs); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
130 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
131 auto ep = el_params(e2, e1, null); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
132 int rtl = (tb1.nextOf().ty == Tchar) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
133 ? RTLSYM_ARRAYAPPENDCD |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
134 : RTLSYM_ARRAYAPPENDWD; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
135 e = el_bin(OPcall, TYdarray, el_var(rtlsym[rtl]), ep); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
136 el_setLoc(e,loc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
137 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
138 else if (tb1.ty == Tarray || tb2.ty == Tsarray) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
139 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
140 auto e1 = this.e1.toElem(irs); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
141 e1 = el_una(OPaddr, TYnptr, e1); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
142 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
143 auto e2 = this.e2.toElem(irs); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
144 |
108
6da99741178e
e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents:
72
diff
changeset
|
145 if (tybasic(e2.Ety) == TYstruct || tybasic(e2.Ety) == TYarray) |
0 | 146 { |
147 e2 = el_una(OPstrpar, TYstruct, e2); | |
148 e2.Enumbytes = e2.E1.Enumbytes; | |
149 assert(e2.Enumbytes); | |
150 } | |
151 | |
152 Type tb1n = tb1.nextOf().toBasetype(); | |
153 if ((tb2.ty == Tarray || tb2.ty == Tsarray) && | |
154 tb1n.equals(tb2.nextOf().toBasetype())) | |
155 { // Append array | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
156 auto ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); |
0 | 157 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); |
158 } | |
159 else | |
160 { // Append element | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
161 auto ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); |
0 | 162 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); |
163 } | |
164 el_setLoc(e,loc); | |
165 } | |
166 else | |
167 assert(0); | |
168 | |
169 return e; | |
170 } | |
72 | 171 } |