annotate dmd/AddAssignExp.d @ 73:ef02e2e203c2

Updating to dmd2.033
author korDen
date Sat, 28 Aug 2010 19:42:41 +0400
parents 2e2a5c3f943a
children e28b18c23469
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.InterState;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
8 import dmd.Argument;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
9 import dmd.STC;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.AddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class AddAssignExp : 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.TOKaddass, AddAssignExp.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 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 BinExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 Type tb1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Type tb2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 if (e1.op == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 return arrayOp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 e1 = e1.modifiableLvalue(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 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
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 e1.checkScalar();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 e1.checkNoBool();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 if (tb1.ty == TY.Tpointer && tb2.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 e = scaleFactor(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 else if (tb1.ty == TY.Tbit || tb1.ty == TY.Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 // Need to rethink this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 if (e1.op != TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 // Rewrite e1+=e2 to (v=&e1),*v=*v+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 VarDeclaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Expression ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Identifier id = Lexer.uniqueId("__name");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 v = new VarDeclaration(loc, tb1.pointerTo(), id, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 v.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (!sc.insert(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 v.parent = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 ea = new AddrExp(loc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 ea = new AssignExp(loc, new VarExp(loc, v), ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 ex = new VarExp(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 ex = new PtrExp(loc, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 e = new AddExp(loc, ex, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 e = new AssignExp(loc, ex.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e = new CommaExp(loc, ea, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 // Rewrite e1+=e2 to e1=e1+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 // BUG: doesn't account for side effects in e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 // BUG: other assignment operators for bits aren't handled at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 e = new AddExp(loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 e = new AssignExp(loc, e1.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 // Rewrite e1+=e2 to e1=e1+e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 // BUG: doesn't account for side effects in e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 // BUG: other assignment operators for bits aren't handled at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 e = new AddExp(loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 e = new CastExp(loc, e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 e = new AssignExp(loc, e1.syntaxCopy(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 e = e.semantic(sc);
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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 e1.checkArithmetic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 e2.checkArithmetic();
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
129 checkComplexAddAssign();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (type.isreal() || type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 assert(global.errors || e2.type.isfloating());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 e2 = e2.castTo(sc, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
142 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
147 override void buildArrayIdent(OutBuffer buf, Expressions arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
149 AssignExp_buildArrayIdent(buf, arguments, "Add");
0
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 buildArrayLoop(Arguments fparams)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
154 /* Evaluate assign expressions right to left
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
155 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
156 Expression ex2 = e2.buildArrayLoop(fparams);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
157 Expression ex1 = e1.buildArrayLoop(fparams);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
158 Argument param = cast(Argument)fparams.data[0];
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
159 param.storageClass = STCundefined;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
160 Expression e = new AddAssignExp(Loc(0), ex1, ex2);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
161 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
164 override Identifier opId() /* For operator overloading */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 return Id.addass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
169 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 //printf("AddAssignExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 elem *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 Type tb1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 Type tb2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 error("Array operations not implemented");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 e = toElemBin(irs, OPER.OPaddass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
185 }