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