Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
0 | 1 module dmd.AddAssignExp; |
2 | |
3 import dmd.BinExp; | |
4 import dmd.Loc; | |
5 import dmd.Expression; | |
6 import dmd.Scope; | |
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 | 10 import dmd.OutBuffer; |
11 import dmd.ArrayTypes; | |
12 import dmd.Identifier; | |
13 import dmd.IRState; | |
14 import dmd.TOK; | |
15 import dmd.Type; | |
16 import dmd.TY; | |
17 import dmd.AddExp; | |
18 import dmd.CastExp; | |
19 import dmd.AssignExp; | |
20 import dmd.Global; | |
21 import dmd.Id; | |
22 | |
23 import dmd.backend.OPER; | |
24 import dmd.backend.elem; | |
25 | |
26 class AddAssignExp : BinExp | |
27 { | |
28 this(Loc loc, Expression e1, Expression e2) | |
29 { | |
30 super(loc, TOK.TOKaddass, AddAssignExp.sizeof, e1, e2); | |
31 } | |
32 | |
72 | 33 override Expression semantic(Scope sc) |
0 | 34 { |
35 Expression e; | |
36 | |
37 if (type) | |
38 return this; | |
39 | |
40 BinExp.semantic(sc); | |
41 e2 = resolveProperties(sc, e2); | |
42 | |
43 e = op_overload(sc); | |
44 if (e) | |
45 return e; | |
46 | |
47 Type tb1 = e1.type.toBasetype(); | |
48 Type tb2 = e2.type.toBasetype(); | |
49 | |
50 if (e1.op == TOK.TOKslice) | |
51 { | |
52 typeCombine(sc); | |
53 type = e1.type; | |
54 return arrayOp(sc); | |
55 } | |
56 else | |
57 { | |
58 e1 = e1.modifiableLvalue(sc, e1); | |
59 } | |
60 | |
61 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray) && tb1.nextOf().equals(tb2.nextOf())) | |
62 { | |
63 type = e1.type; | |
64 typeCombine(sc); | |
65 e = this; | |
66 } | |
67 else | |
68 { | |
69 e1.checkScalar(); | |
70 e1.checkNoBool(); | |
71 if (tb1.ty == TY.Tpointer && tb2.isintegral()) | |
72 e = scaleFactor(sc); | |
73 else if (tb1.ty == TY.Tbit || tb1.ty == TY.Tbool) | |
74 { | |
75 static if (false) { | |
76 // Need to rethink this | |
77 if (e1.op != TOK.TOKvar) | |
78 { | |
79 // Rewrite e1+=e2 to (v=&e1),*v=*v+e2 | |
80 VarDeclaration v; | |
81 Expression ea; | |
82 Expression ex; | |
83 | |
84 Identifier id = Lexer.uniqueId("__name"); | |
85 | |
86 v = new VarDeclaration(loc, tb1.pointerTo(), id, null); | |
87 v.semantic(sc); | |
88 if (!sc.insert(v)) | |
89 assert(0); | |
90 | |
91 v.parent = sc.func; | |
92 | |
93 ea = new AddrExp(loc, e1); | |
94 ea = new AssignExp(loc, new VarExp(loc, v), ea); | |
95 | |
96 ex = new VarExp(loc, v); | |
97 ex = new PtrExp(loc, ex); | |
98 e = new AddExp(loc, ex, e2); | |
99 e = new CastExp(loc, e, e1.type); | |
100 e = new AssignExp(loc, ex.syntaxCopy(), e); | |
101 | |
102 e = new CommaExp(loc, ea, e); | |
103 } | |
104 else | |
105 { | |
106 // Rewrite e1+=e2 to e1=e1+e2 | |
107 // BUG: doesn't account for side effects in e1 | |
108 // BUG: other assignment operators for bits aren't handled at all | |
109 e = new AddExp(loc, e1, e2); | |
110 e = new CastExp(loc, e, e1.type); | |
111 e = new AssignExp(loc, e1.syntaxCopy(), e); | |
112 } | |
113 } else { | |
114 // Rewrite e1+=e2 to e1=e1+e2 | |
115 // BUG: doesn't account for side effects in e1 | |
116 // BUG: other assignment operators for bits aren't handled at all | |
117 e = new AddExp(loc, e1, e2); | |
118 e = new CastExp(loc, e, e1.type); | |
119 e = new AssignExp(loc, e1.syntaxCopy(), e); | |
120 } | |
121 e = e.semantic(sc); | |
122 } | |
123 else | |
124 { | |
125 type = e1.type; | |
126 typeCombine(sc); | |
127 e1.checkArithmetic(); | |
128 e2.checkArithmetic(); | |
73 | 129 checkComplexAddAssign(); |
0 | 130 |
131 if (type.isreal() || type.isimaginary()) | |
132 { | |
133 assert(global.errors || e2.type.isfloating()); | |
134 e2 = e2.castTo(sc, e1.type); | |
135 } | |
136 e = this; | |
137 } | |
138 } | |
139 return e; | |
140 } | |
141 | |
72 | 142 override Expression interpret(InterState istate) |
0 | 143 { |
144 assert(false); | |
145 } | |
146 | |
72 | 147 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 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 | 150 } |
151 | |
72 | 152 override Expression buildArrayLoop(Arguments fparams) |
0 | 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 | 162 } |
163 | |
72 | 164 override Identifier opId() /* For operator overloading */ |
0 | 165 { |
166 return Id.addass; | |
167 } | |
168 | |
72 | 169 override elem* toElem(IRState* irs) |
0 | 170 { |
171 //printf("AddAssignExp::toElem() %s\n", toChars()); | |
172 elem *e; | |
173 Type tb1 = e1.type.toBasetype(); | |
174 Type tb2 = e2.type.toBasetype(); | |
175 | |
176 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray)) | |
177 { | |
178 error("Array operations not implemented"); | |
179 } | |
180 else | |
181 e = toElemBin(irs, OPER.OPaddass); | |
182 | |
183 return e; | |
184 } | |
72 | 185 } |