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