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