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