annotate dmd/AddAssignExp.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.AddAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 73
diff changeset
3 import dmd.common;
117
fe941d774f4a + ctfe of assign operations
Trass3r
parents: 114
diff changeset
4 import dmd.expression.Add;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.InterState;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
10 import dmd.Parameter;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
11 import dmd.STC;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.AddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Id;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
24 import dmd.ArrayLengthExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
29 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
30
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 class AddAssignExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
33 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
34
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 130
diff changeset
37 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 super(loc, TOK.TOKaddass, AddAssignExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
41 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 BinExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 Type tb1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 Type tb2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
58 if (e1.op == TOKarraylength)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
59 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
60 e = ArrayLengthExp.rewriteOpAssign(this);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
61 e = e.semantic(sc);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
62 return e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
63 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
64
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 if (e1.op == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 return arrayOp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 e1 = e1.modifiableLvalue(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray) && tb1.nextOf().equals(tb2.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 e1.checkScalar();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 e1.checkNoBool();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if (tb1.ty == TY.Tpointer && tb2.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 e = scaleFactor(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 else if (tb1.ty == TY.Tbit || tb1.ty == TY.Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 // Need to rethink this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if (e1.op != TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 // Rewrite e1+=e2 to (v=&e1),*v=*v+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 VarDeclaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 Expression ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 Identifier id = Lexer.uniqueId("__name");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 v = new VarDeclaration(loc, tb1.pointerTo(), id, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 v.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (!sc.insert(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 v.parent = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 ea = new AddrExp(loc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 ea = new AssignExp(loc, new VarExp(loc, v), ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 ex = new VarExp(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 ex = new PtrExp(loc, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 e = new AddExp(loc, ex, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 e = new AssignExp(loc, ex.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 e = new CommaExp(loc, ea, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 // Rewrite e1+=e2 to e1=e1+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 // BUG: doesn't account for side effects in e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 // BUG: other assignment operators for bits aren't handled at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 e = new AddExp(loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 e = new AssignExp(loc, e1.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 // Rewrite e1+=e2 to e1=e1+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 // BUG: doesn't account for side effects in e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 // BUG: other assignment operators for bits aren't handled at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 e = new AddExp(loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 e = new AssignExp(loc, e1.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 e1.checkArithmetic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 e2.checkArithmetic();
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
144 checkComplexAddAssign();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 if (type.isreal() || type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 assert(global.errors || e2.type.isfloating());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 e2 = e2.castTo(sc, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
157 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
117
fe941d774f4a + ctfe of assign operations
Trass3r
parents: 114
diff changeset
159 return interpretAssignCommon(istate, &Add);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
162 override void buildArrayIdent(OutBuffer buf, Expressions arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
164 AssignExp_buildArrayIdent(buf, arguments, "Add");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
167 override Expression buildArrayLoop(Parameters fparams)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 117
diff changeset
169 return AssignExp_buildArrayLoop!(typeof(this))(fparams);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
172 override Identifier opId() /* For operator overloading */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 return Id.addass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
177 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 //printf("AddAssignExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 elem *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 Type tb1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 Type tb2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 error("Array operations not implemented");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 e = toElemBin(irs, OPER.OPaddass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
193 }