0
|
1 module dmd.CatAssignExp;
|
|
2
|
|
3 import dmd.BinExp;
|
|
4 import dmd.Loc;
|
|
5 import dmd.Expression;
|
|
6 import dmd.Scope;
|
|
7 import dmd.InterState;
|
|
8 import dmd.SliceExp;
|
|
9 import dmd.Identifier;
|
|
10 import dmd.IRState;
|
|
11 import dmd.TOK;
|
|
12 import dmd.TY;
|
|
13 import dmd.Id;
|
|
14 import dmd.Type;
|
|
15 import dmd.backend.elem;
|
|
16 import dmd.backend.RTLSYM;
|
|
17 import dmd.backend.Util;
|
|
18 import dmd.backend.OPER;
|
|
19 import dmd.backend.TYM;
|
|
20 import dmd.backend.mTY;
|
|
21
|
|
22 import dmd.expression.Util;
|
|
23
|
|
24 class CatAssignExp : BinExp
|
|
25 {
|
|
26 this(Loc loc, Expression e1, Expression e2)
|
|
27 {
|
|
28 super(loc, TOK.TOKcatass, CatAssignExp.sizeof, e1, e2);
|
|
29 }
|
|
30
|
72
|
31 override Expression semantic(Scope sc)
|
0
|
32 {
|
|
33 Expression e;
|
|
34
|
|
35 BinExp.semantic(sc);
|
|
36 e2 = resolveProperties(sc, e2);
|
|
37
|
|
38 e = op_overload(sc);
|
|
39 if (e)
|
|
40 return e;
|
|
41
|
|
42 if (e1.op == TOKslice)
|
|
43 {
|
|
44 SliceExp se = cast(SliceExp)e1;
|
|
45
|
|
46 if (se.e1.type.toBasetype().ty == Tsarray)
|
|
47 error("cannot append to static array %s", se.e1.type.toChars());
|
|
48 }
|
|
49
|
|
50 e1 = e1.modifiableLvalue(sc, e1);
|
|
51
|
|
52 Type tb1 = e1.type.toBasetype();
|
|
53 Type tb2 = e2.type.toBasetype();
|
|
54
|
|
55 e2.rvalue();
|
|
56
|
|
57 if ((tb1.ty == Tarray) &&
|
|
58 (tb2.ty == Tarray || tb2.ty == Tsarray) &&
|
|
59 (e2.implicitConvTo(e1.type) ||
|
|
60 tb2.nextOf().implicitConvTo(tb1.nextOf()))
|
|
61 )
|
|
62 { // Append array
|
|
63 e2 = e2.castTo(sc, e1.type);
|
|
64 type = e1.type;
|
|
65 e = this;
|
|
66 }
|
|
67 else if ((tb1.ty == Tarray) &&
|
|
68 e2.implicitConvTo(tb1.nextOf())
|
|
69 )
|
|
70 { // Append element
|
|
71 e2 = e2.castTo(sc, tb1.nextOf());
|
|
72 type = e1.type;
|
|
73 e = this;
|
|
74 }
|
|
75 else
|
|
76 {
|
|
77 error("cannot append type %s to type %s", tb2.toChars(), tb1.toChars());
|
|
78 type = Type.tint32;
|
|
79 e = this;
|
|
80 }
|
|
81 return e;
|
|
82 }
|
|
83
|
72
|
84 override Expression interpret(InterState istate)
|
0
|
85 {
|
|
86 assert(false);
|
|
87 }
|
|
88
|
72
|
89 override Identifier opId() /* For operator overloading */
|
0
|
90 {
|
|
91 return Id.catass;
|
|
92 }
|
|
93
|
72
|
94 override elem* toElem(IRState* irs)
|
0
|
95 {
|
|
96 //printf("CatAssignExp.toElem('%s')\n", toChars());
|
|
97 elem* e;
|
|
98 Type tb1 = e1.type.toBasetype();
|
|
99 Type tb2 = e2.type.toBasetype();
|
|
100
|
|
101 if (tb1.ty == Tarray || tb2.ty == Tsarray)
|
|
102 { elem* e1;
|
|
103 elem* e2;
|
|
104 elem* ep;
|
|
105
|
|
106 e1 = this.e1.toElem(irs);
|
|
107 e1 = el_una(OPaddr, TYnptr, e1);
|
|
108
|
|
109 e2 = this.e2.toElem(irs);
|
|
110 if (tybasic(e2.Ety) == TYstruct)
|
|
111 {
|
|
112 e2 = el_una(OPstrpar, TYstruct, e2);
|
|
113 e2.Enumbytes = e2.E1.Enumbytes;
|
|
114 assert(e2.Enumbytes);
|
|
115 }
|
|
116
|
|
117 Type tb1n = tb1.nextOf().toBasetype();
|
|
118 if ((tb2.ty == Tarray || tb2.ty == Tsarray) &&
|
|
119 tb1n.equals(tb2.nextOf().toBasetype()))
|
|
120 { // Append array
|
|
121 static if (true) {
|
|
122 ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null);
|
|
123 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep);
|
|
124 } else {
|
|
125 ep = el_params(el_long(TYint, tb1n.size()), e2, e1, null);
|
|
126 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep);
|
|
127 }
|
|
128 }
|
|
129 else
|
|
130 { // Append element
|
|
131 static if (true) {
|
|
132 ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null);
|
|
133 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep);
|
|
134 } else {
|
|
135 ep = el_params(e2, el_long(TYint, tb1n.size()), e1, null);
|
|
136 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep);
|
|
137 }
|
|
138 }
|
|
139 el_setLoc(e,loc);
|
|
140 }
|
|
141 else
|
|
142 assert(0);
|
|
143
|
|
144 return e;
|
|
145 }
|
72
|
146 }
|