annotate dmd/AddAssignExp.d @ 146:af7e5ebef6ad

redundant extern(C)
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Tue, 14 Sep 2010 23:34:50 +0100
parents 60bb0fe4563e
children e3afd1303184
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 class AddAssignExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 super(loc, TOK.TOKaddass, AddAssignExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
36 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 BinExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 Type tb1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 Type tb2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
53 if (e1.op == TOKarraylength)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
54 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
55 e = ArrayLengthExp.rewriteOpAssign(this);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
56 e = e.semantic(sc);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
57 return e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
58 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
59
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (e1.op == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 return arrayOp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 e1 = e1.modifiableLvalue(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 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
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 typeCombine(sc);
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 e1.checkScalar();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 e1.checkNoBool();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 if (tb1.ty == TY.Tpointer && tb2.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 e = scaleFactor(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 else if (tb1.ty == TY.Tbit || tb1.ty == TY.Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 // Need to rethink this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (e1.op != TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 // Rewrite e1+=e2 to (v=&e1),*v=*v+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 VarDeclaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 Expression ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 Identifier id = Lexer.uniqueId("__name");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 v = new VarDeclaration(loc, tb1.pointerTo(), id, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 v.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (!sc.insert(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 v.parent = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 ea = new AddrExp(loc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 ea = new AssignExp(loc, new VarExp(loc, v), ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 ex = new VarExp(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 ex = new PtrExp(loc, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 e = new AddExp(loc, ex, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e = new AssignExp(loc, ex.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 e = new CommaExp(loc, ea, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 // Rewrite e1+=e2 to e1=e1+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 // BUG: doesn't account for side effects in e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 // BUG: other assignment operators for bits aren't handled at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 e = new AddExp(loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 e = new AssignExp(loc, e1.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 // Rewrite e1+=e2 to e1=e1+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 // BUG: doesn't account for side effects in e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 // BUG: other assignment operators for bits aren't handled at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 e = new AddExp(loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 e = new AssignExp(loc, e1.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 e1.checkArithmetic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 e2.checkArithmetic();
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
139 checkComplexAddAssign();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (type.isreal() || type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 assert(global.errors || e2.type.isfloating());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 e2 = e2.castTo(sc, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
152 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 {
117
fe941d774f4a + ctfe of assign operations
Trass3r
parents: 114
diff changeset
154 return interpretAssignCommon(istate, &Add);
0
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 void buildArrayIdent(OutBuffer buf, Expressions arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
159 AssignExp_buildArrayIdent(buf, arguments, "Add");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
162 override Expression buildArrayLoop(Parameters fparams)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 117
diff changeset
164 return AssignExp_buildArrayLoop!(typeof(this))(fparams);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
167 override Identifier opId() /* For operator overloading */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 return Id.addass;
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 elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 //printf("AddAssignExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 elem *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 Type tb1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 Type tb2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 error("Array operations not implemented");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 e = toElemBin(irs, OPER.OPaddass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
188 }