annotate dmd/BinExp.d @ 176:fa9a71a9f5a8

Moved all the mutable globals to Global
author korDen
date Sun, 10 Oct 2010 05:22:45 +0400
parents 94b6033c07f3
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.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 98
diff changeset
3 import dmd.common;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
4 import dmd.SliceExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
5 import dmd.IndexExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
6 import dmd.StructDeclaration;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
7 import dmd.expression.ArrayLength;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
8 import dmd.expression.Equal;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
9 import dmd.expression.Index;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
10 import dmd.ArrayLiteralExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
11 import dmd.AssocArrayLiteralExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
12 import dmd.StringExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
13 import dmd.TypeSArray;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
14 import dmd.PtrExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
15 import dmd.SymOffExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
16 import dmd.Declaration;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
17 import dmd.StructLiteralExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Expression;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
19 import dmd.interpret.Util;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
20 import dmd.GlobalExpressions;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
21 import dmd.Global;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
22 import dmd.Cast;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
23 import dmd.CastExp;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
24 import dmd.VarDeclaration;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
25 import dmd.DotVarExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.declaration.Match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.MulExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.PREC;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
56 import dmd.StringValue;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
57 import dmd.StringTable;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
58 import dmd.Parameter;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
59 import dmd.Statement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
60 import dmd.ForeachRangeStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
61 import dmd.ArrayLengthExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
62 import dmd.IdentifierExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
63 import dmd.ExpStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
64 import dmd.CompoundStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
65 import dmd.TypeFunction;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
66 import dmd.LINK;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
67 import dmd.Lexer;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
68 import dmd.ReturnStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
69 import dmd.Id;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
70 import dmd.STC;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
71 import dmd.PROT;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
72 import dmd.VarExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
73 import dmd.CallExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
80 import dmd.backend.iasm : binary;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
81
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
82 import std.exception : assumeUnique;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
83 import core.stdc.stdlib : calloc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 import std.stdio : writef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 * Combine types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 * *pt merged type, if *pt is not null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 * *pe1 rewritten e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 * *pe2 rewritten e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 * !=0 success
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 * 0 failed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
97 /**************************************
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
98 * Hash table of array op functions already generated or known about.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
99 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
100
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 int typeMerge(Scope sc, Expression e, Type* pt, Expression* pe1, Expression* pe2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
60
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 56
diff changeset
103 //printf("typeMerge() %.*s op %.*s\n", (*pe1).toChars(), (*pe2).toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Expression e1 = (*pe1).integralPromotions(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 Expression e2 = (*pe2).integralPromotions(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Type t1 = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 Type t2 = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 assert(t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 Type t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 //if (t1) printf("\tt1 = %s\n", t1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 //if (t2) printf("\tt2 = %s\n", t2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (!t2) writef("\te2 = '%s'\n", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 assert(t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 Type t1b = t1.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 Type t2b = t2.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 TY ty = cast(TY)Type.impcnvResult[t1b.ty][t2b.ty];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if (ty != TY.Terror)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
127 auto ty1 = cast(TY)Type.impcnvType1[t1b.ty][t2b.ty];
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
128 auto ty2 = cast(TY)Type.impcnvType2[t1b.ty][t2b.ty];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 if (t1b.ty == ty1) // if no promotions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (t1 == t2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (t1b == t2b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 t = t1b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 t = Type.basic[ty];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 t1 = Type.basic[ty1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 t2 = Type.basic[ty2];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 e1 = e1.castTo(sc, t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 e2 = e2.castTo(sc, t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 //printf("after typeCombine():\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 t1 = t1b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 t2 = t2b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 Lagain:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 if (t1 == t2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 else if (t1.ty == TY.Tpointer && t2.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 // Bring pointers to compatible type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 Type t1n = t1.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 Type t2n = t2.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 if (t1n == t2n) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 } else if (t1n.ty == TY.Tvoid) {// pointers to void are always compatible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 t = t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 } else if (t2n.ty == TY.Tvoid) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 } else if (t1n.mod != t2n.mod) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 t1 = t1n.mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 t2 = t2n.mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 } else if (t1n.ty == TY.Tclass && t2n.ty == TY.Tclass) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 ClassDeclaration cd1 = t1n.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 ClassDeclaration cd2 = t2n.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 int offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 if (cd1.isBaseOf(cd2, &offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 else if (cd2.isBaseOf(cd1, &offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 t = t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 e1 = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray) &&
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
205 (e2.op == TOK.TOKnull && t2.ty == TY.Tpointer && t2.nextOf().ty == TY.Tvoid ||
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
206 e2.op == TOK.TOKarrayliteral && t2.ty == TY.Tsarray && t2.nextOf().ty == TY.Tvoid && (cast(TypeSArray)t2).dim.toInteger() == 0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
207 )
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
208 { /* (T[n] op void*) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
209 * (T[] op void*) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
210 * (T[n] op void[0]) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
211 * (T[] op void[0]) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
212 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 goto Lx1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 else if ((t2.ty == TY.Tsarray || t2.ty == TY.Tarray) &&
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
216 (e1.op == TOK.TOKnull && t1.ty == TY.Tpointer && t1.nextOf().ty == TY.Tvoid ||
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
217 e1.op == TOK.TOKarrayliteral && t1.ty == TY.Tsarray && t1.nextOf().ty == TY.Tvoid && (cast(TypeSArray)t1).dim.toInteger() == 0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
218 )
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
219 { /* (void* op T[n]) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
220 * (void* op T[]) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
221 * (void[0] op T[n]) => T[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
222 * (void[0] op T[]) => T[]
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 goto Lx2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray) && t1.implicitConvTo(t2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 goto Lt2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 else if ((t2.ty == TY.Tsarray || t2.ty == TY.Tarray) && t2.implicitConvTo(t1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 goto Lt1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 /* If one is mutable and the other invariant, then retry
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 * with both of them as const
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray || t1.ty == TY.Tpointer) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 (t2.ty == TY.Tsarray || t2.ty == TY.Tarray || t2.ty == TY.Tpointer) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 t1.nextOf().mod != t2.nextOf().mod
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 if (t1.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 t1 = t1.nextOf().mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 t1 = t1.nextOf().mutableOf().constOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 if (t2.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 t2 = t2.nextOf().mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 t2 = t2.nextOf().mutableOf().constOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 else if (t1.ty == TY.Tclass || t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 int i1 = e2.implicitConvTo(t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 int i2 = e1.implicitConvTo(t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 if (i1 && i2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 // We have the case of class vs. void*, so pick class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (t1.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 i1 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 else if (t2.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 i2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 if (i2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 goto Lt2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 else if (i1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 goto Lt1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 else if (t1.ty == TY.Tclass && t2.ty == TY.Tclass)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
279 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 TypeClass tc1 = cast(TypeClass)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 TypeClass tc2 = cast(TypeClass)t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 /* Pick 'tightest' type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 ClassDeclaration cd1 = tc1.sym.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 ClassDeclaration cd2 = tc2.sym.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 if (cd1 && cd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 { t1 = cd1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 t2 = cd2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 else if (cd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 t1 = cd1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 else if (cd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 t2 = cd2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 else if (t1.ty == TY.Tstruct && t2.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if ((cast(TypeStruct)t1).sym != (cast(TypeStruct)t2).sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 else if ((e1.op == TOK.TOKstring || e1.op == TOK.TOKnull) && e1.implicitConvTo(t2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 goto Lt2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 else if ((e2.op == TOK.TOKstring || e2.op == TOK.TOKnull) && e2.implicitConvTo(t1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 goto Lt1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 else if (t1.ty == TY.Tsarray && t2.ty == TY.Tsarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 e2.implicitConvTo(t1.nextOf().arrayOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 Lx1:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
320 t = t1.nextOf().arrayOf(); // T[]
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 e1 = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 else if (t1.ty == TY.Tsarray && t2.ty == TY.Tsarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 e1.implicitConvTo(t2.nextOf().arrayOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 Lx2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 t = t2.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 e1 = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 else if (t1.isintegral() && t2.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
98
5c859d5fbe27 and more
Trass3r
parents: 90
diff changeset
336 else if (e1.isArrayOperand() && t1.ty == TY.Tarray &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 e2.implicitConvTo(t1.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 { // T[] op T
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 e2 = e2.castTo(sc, t1.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 t = t1.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 }
98
5c859d5fbe27 and more
Trass3r
parents: 90
diff changeset
342 else if (e2.isArrayOperand() && t2.ty == TY.Tarray &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 e1.implicitConvTo(t2.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 { // T op T[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 e1 = e1.castTo(sc, t2.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 t = t2.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 //printf("test %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 e1 = e1.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 if (e && e.isCommutative() && e1.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 { /* Swap operands to minimize number of functions generated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 //printf("swap %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 Expression tmp = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 e1 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 e2 = tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 Lincompatible:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 Lret:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 if (!*pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 *pe1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 *pe2 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 printf("-typeMerge() %s op %s\n", e1.toChars(), e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 if (e1.type) printf("\tt1 = %s\n", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 if (e2.type) printf("\tt2 = %s\n", e2.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 printf("\ttype = %s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 Lt1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 e2 = e2.castTo(sc, t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 Lt2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 e1 = e1.castTo(sc, t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 t = t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 class BinExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 Expression e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 this(Loc loc, TOK op, int size, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 super(loc, op, size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 this.e1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 this.e2 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
401
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
402 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 BinExp e = cast(BinExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 e.type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 e.e1 = e.e1.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 e.e2 = e.e2.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
412 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 version (LOGSEMANTIC) {
60
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 56
diff changeset
415 printf("BinExp.semantic('%.*s')\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 if (!e1.type && !(op == TOK.TOKassign && e1.op == TOK.TOKdottd)) // a.template = e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 error("%s has no value", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 e1.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 if (!e2.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 error("%s has no value", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 e2.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
431
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 Expression semanticp(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 {
60
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 56
diff changeset
434 BinExp.semantic(sc);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
435
60
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 56
diff changeset
436 e1 = resolveProperties(sc, e1);
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 56
diff changeset
437 e2 = resolveProperties(sc, e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
440
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
441 /***************************
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
442 * Common semantic routine for some xxxAssignExp's.
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
443 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 Expression commonSemanticAssign(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 {
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
446 Expression e;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
447
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
448 if (!type)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
449 {
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
450 BinExp.semantic(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
451 e2 = resolveProperties(sc, e2);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
452
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
453 e = op_overload(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
454 if (e)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
455 return e;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
456
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
457 if (e1.op == TOK.TOKarraylength)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
458 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
459 e = ArrayLengthExp.rewriteOpAssign(this);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
460 e = e.semantic(sc);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
461 return e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
462 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
463
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
464 if (e1.op == TOKslice)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
465 {
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
466 // T[] op= ...
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
467 typeCombine(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
468 type = e1.type;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
469 return arrayOp(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
470 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
471
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
472 e1 = e1.modifiableLvalue(sc, e1);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
473 e1.checkScalar();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
474 type = e1.type;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
475 if (type.toBasetype().ty == Tbool)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
476 {
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
477 error("operator not allowed on bool expression %s", toChars());
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
478 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
479 typeCombine(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
480 e1.checkArithmetic();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
481 e2.checkArithmetic();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
482
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
483 if (op == TOKmodass && e2.type.iscomplex())
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
484 { error("cannot perform modulo complex arithmetic");
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
485 return new ErrorExp();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
486 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
487 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
488 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 Expression commonSemanticAssignIntegral(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 BinExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
504 if (e1.op == TOKarraylength)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
505 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
506 e = ArrayLengthExp.rewriteOpAssign(this);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
507 e = e.semantic(sc);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
508 return e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
509 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
510
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 if (e1.op == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 { // T[] op= ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 return arrayOp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 e1 = e1.modifiableLvalue(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 e1.checkScalar();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 if (type.toBasetype().ty == TY.Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 e2 = e2.implicitCastTo(sc, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 e1.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 e2.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
533
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
534 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 switch (op) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 case TOK.TOKassign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 case TOK.TOKconstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 case TOK.TOKblit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 case TOK.TOKaddass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 case TOK.TOKminass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 case TOK.TOKcatass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 case TOK.TOKmulass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 case TOK.TOKdivass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 case TOK.TOKmodass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 case TOK.TOKshlass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 case TOK.TOKshrass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 case TOK.TOKushrass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 case TOK.TOKandass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 case TOK.TOKorass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 case TOK.TOKxorass:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
554 case TOK.TOKpowass:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 case TOK.TOKremove:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 return Expression.checkSideEffect(flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
563
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
564 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 expToCBuffer(buf, hgs, e1, precedence[op]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 buf.writeByte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 buf.writestring(Token.toChars(op));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 buf.writeByte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 expToCBuffer(buf, hgs, e2, cast(PREC)(precedence[op] + 1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 * Scale addition/subtraction to/from pointer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 Expression scaleFactor(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 ulong stride;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 Type t1b = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 Type t2b = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 if (t1b.ty == Tpointer && t2b.isintegral())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
583 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 // Need to adjust operator by the stride
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 // Replace (ptr + int) with (ptr + (int * stride))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 Type t = Type.tptrdiff_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 stride = t1b.nextOf().size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 if (!t.equals(t2b))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 e2 = new MulExp(loc, e2, new IntegerExp(Loc(0), stride, t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 e2.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 else if (t2b.ty == Tpointer && t1b.isintegral())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
596 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 // Need to adjust operator by the stride
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 // Replace (int + ptr) with (ptr + (int * stride))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 Type t = Type.tptrdiff_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 stride = t2b.nextOf().size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 if (!t.equals(t1b))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 e = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 e = new MulExp(loc, e, new IntegerExp(Loc(0), stride, t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 type = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 e1 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 e2 = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
615
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 * Bring leaves to common type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 Expression typeCombine(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 if (op == TOK.TOKmin || op == TOK.TOKadd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 if (t2.ty == TY.Tstruct && (cast(TypeStruct)t1).sym is (cast(TypeStruct)t2).sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 else if (t1.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 if (t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 if (!typeMerge(sc, this, &type, &e1, &e2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 incompatibleTypes();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 e1 = new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 e2 = new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
650 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 //printf("BinExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 if (op != TOK.TOKconstruct && op != TOK.TOKblit) // don't replace const variable with its initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 if (op == TOK.TOKshlass || op == TOK.TOKshrass || op == TOK.TOKushrass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 if (e2.isConst() == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 long i2 = e2.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 ulong sz = e1.type.size() * 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 if (i2 < 0 || i2 > sz)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
665 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 error("shift assign by %jd is outside the range 0..%zu", i2, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 e2 = new IntegerExp(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 bool isunsigned()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 {
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
677 return e1.type.isunsigned() || e2.type.isunsigned();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
679
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 void incompatibleTypes()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 e1.toChars(), Token.toChars(op), e2.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 e1.type.toChars(), e2.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
687 override void dump(int indent)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691
154
14feb7ae01a6 * changed the build system to build a release version if the debug one compiles
trass3r
parents: 135
diff changeset
692 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
694 e1.scanForNestedRef(sc);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
695 e2.scanForNestedRef(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
698 Expression interpretCommon(InterState istate, Expression function(Type, Expression, Expression) fp)
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
699 {
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
700 Expression e;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
701 Expression e1;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
702 Expression e2;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
703
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
704 version(LOG)
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
705 {
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
706 writef("BinExp::interpretCommon() %s\n", toChars());
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
707 }
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
708 e1 = this.e1.interpret(istate);
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
709 if (e1 is EXP_CANT_INTERPRET)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
710 goto Lcant;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
711 if (e1.isConst() != 1)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
712 goto Lcant;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
713
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
714 e2 = this.e2.interpret(istate);
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
715 if (e2 is EXP_CANT_INTERPRET)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
716 goto Lcant;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
717 if (e2.isConst() != 1)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
718 goto Lcant;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
719
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
720 e = fp(type, e1, e2);
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
721 return e;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
722
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
723 Lcant:
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
724 return EXP_CANT_INTERPRET;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
725 }
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
726
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
727 Expression interpretCommon2(InterState istate, Expression function(TOK, Type, Expression, Expression) fp)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 {
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
729 Expression e;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
730 Expression e1;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
731 Expression e2;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
732
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
733 version(LOG)
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
734 {
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
735 writef("BinExp::interpretCommon2() %s\n", toChars());
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
736 }
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
737 e1 = this.e1.interpret(istate);
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
738 if (e1 is EXP_CANT_INTERPRET)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
739 goto Lcant;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
740 if (e1.isConst() != 1 &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
741 e1.op != TOKnull &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
742 e1.op != TOKstring &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
743 e1.op != TOKarrayliteral &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
744 e1.op != TOKstructliteral)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
745 goto Lcant;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
746
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
747 e2 = this.e2.interpret(istate);
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
748 if (e2 is EXP_CANT_INTERPRET)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
749 goto Lcant;
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
750 if (e2.isConst() != 1 &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
751 e2.op != TOKnull &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
752 e2.op != TOKstring &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
753 e2.op != TOKarrayliteral &&
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
754 e2.op != TOKstructliteral)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
755 goto Lcant;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
756
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
757 e = fp(op, type, e1, e2);
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
758 return e;
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
759
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
760 Lcant:
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
761 return EXP_CANT_INTERPRET;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
763
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
764 Expression interpretAssignCommon(InterState istate, Expression function(Type, Expression, Expression) fp, int post = 0)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 {
116
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
766 version (LOG)
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
767 {
352a5164f692 small bugfixes
Trass3r
parents: 115
diff changeset
768 writef("BinExp.interpretAssignCommon() %.*s\n", toChars());
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
769 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
770 Expression e = EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
771 Expression e1 = this.e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
772
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
773 if (fp)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
774 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
775 if (e1.op == TOKcast)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
776 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
777 CastExp ce = cast(CastExp)e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
778 e1 = ce.e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
779 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
780 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
781 if (e1 is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
782 return e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
783 Expression e2 = this.e2.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
784 if (e2 is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
785 return e2;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
786
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
787 // Chase down rebinding of out and ref.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
788 if (e1.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
789 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
790 VarExp ve = cast(VarExp)e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
791 VarDeclaration v = ve.var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
792 if (v && v.value && v.value.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
793 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
794 VarExp ve2 = cast(VarExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
795 if (ve2.var.isSymbolDeclaration())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
796 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
797 // This can happen if v is a struct initialized to
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
798 // 0 using an __initZ SymbolDeclaration from
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
799 // TypeStruct.defaultInit()
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
800 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
801 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
802 e1 = v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
803 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
804 else if (v && v.value && (v.value.op==TOKindex || v.value.op == TOKdotvar))
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
805 {
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
806 // It is no longer a TOKvar, eg when a[4] is passed by ref.
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
807 e1 = v.value;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
808 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
809 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
810
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
811 // To reduce code complexity of handling dotvar expressions,
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
812 // extract the aggregate now.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
813 Expression aggregate;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
814 if (e1.op == TOKdotvar) {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
815 aggregate = (cast(DotVarExp)e1).e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
816 // Get rid of 'this'.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
817 if (aggregate.op == TOKthis && istate.localThis)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
818 aggregate = istate.localThis;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
819 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
820
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
821 /* Assignment to variable of the form:
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
822 * v = e2
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
823 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
824 if (e1.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
825 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
826 VarExp ve = cast(VarExp)e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
827 VarDeclaration v = ve.var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
828 assert(v);
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
829 if (v && !v.isCTFE())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
830 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
831 // Can't modify global or static data
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
832 error("%s cannot be modified at compile time", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
833 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
834 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
835 if (v && v.isCTFE())
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
836 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
837 Expression ev = v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
838 if (fp && !ev)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
839 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
840 error("variable %s is used before initialization", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
841 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
842 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
843 if (fp)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
844 e2 = (*fp)(v.type, ev, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
845 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
846 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
847 /* Look for special case of struct being initialized with 0.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
848 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
849 if (v.type.toBasetype().ty == Tstruct && e2.op == TOKint64)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
850 {
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
851 e2 = v.type.defaultInitLiteral(Loc(0));
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
852 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
853 e2 = Cast(v.type, v.type, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
854 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
855 if (e2 is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
856 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
857
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
858 addVarToInterstate(istate, v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
859 v.value = e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
860 e = Cast(type, type, post ? ev : e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
861 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
862 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
863 else if (e1.op == TOKdotvar && aggregate.op == TOKdotvar)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
864 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
865 // eg v.u.var = e2, v[3].u.var = e2, etc.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
866 error("Nested struct assignment %s is not yet supported in CTFE", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
867 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
868 /* Assignment to struct member of the form:
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
869 * v.var = e2
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
870 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
871 else if (e1.op == TOKdotvar && aggregate.op == TOKvar)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
872 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
873 VarDeclaration v = (cast(VarExp)aggregate).var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
874
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
875 if (!v.isCTFE())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
876 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
877 // Can't modify global or static data
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
878 error("%s cannot be modified at compile time", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
879 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
880 } else {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
881 // Chase down rebinding of out and ref
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
882 if (v.value && v.value.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
883 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
884 VarExp ve2 = cast(VarExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
885 if (ve2.var.isSymbolDeclaration())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
886 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
887 // This can happen if v is a struct initialized to
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
888 // 0 using an __initZ SymbolDeclaration from
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
889 // TypeStruct.defaultInit()
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
890 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
891 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
892 v = ve2.var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
893 assert(v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
894 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
895 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
896 if (fp && !v.value)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
897 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
898 error("variable %s is used before initialization", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
899 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
900 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
901 if (v.value is null && v.init.isVoidInitializer())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
902 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
903 /* Since a void initializer initializes to undefined
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
904 * values, it is valid here to use the default initializer.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
905 * No attempt is made to determine if someone actually relies
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
906 * on the void value - to do that we'd need a VoidExp.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
907 * That's probably a good enhancement idea.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
908 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
909 v.value = v.type.defaultInit(Loc(0));
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
910 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
911 Expression vie = v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
912 if (vie.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
913 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
914 Declaration d = (cast(VarExp)vie).var;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
915 vie = getVarExp(e1.loc, istate, d);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
916 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
917 if (vie.op != TOKstructliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
918 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
919 StructLiteralExp se = cast(StructLiteralExp)vie;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
920 VarDeclaration vf = (cast(DotVarExp)e1).var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
921 if (!vf)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
922 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
923 int fieldi = se.getFieldIndex(type, vf.offset);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
924 if (fieldi == -1)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
925 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
926 Expression ev = se.getField(type, vf.offset);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
927 if (fp)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
928 e2 = (*fp)(type, ev, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
929 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
930 e2 = Cast(type, type, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
931 if (e2 is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
932 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
933
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
934 addVarToInterstate(istate, v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
935
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
936 /* Create new struct literal reflecting updated fieldi
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
937 */
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
938 auto expsx = changeOneElement(se.elements, fieldi, e2);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
939 v.value = new StructLiteralExp(se.loc, se.sd, expsx);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
940 v.value.type = se.type;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
941
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
942 e = Cast(type, type, post ? ev : e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
943 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
944 /* Assignment to struct member of the form:
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
945 * *(symoffexp) = e2
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
946 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
947 else if (e1.op == TOKstar && (cast(PtrExp)e1).e1.op == TOKsymoff)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
948 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
949 SymOffExp soe = cast(SymOffExp)(cast(PtrExp)e1).e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
950 VarDeclaration v = soe.var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
951
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
952 if (!v.isCTFE())
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
953 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
954 error("%s cannot be modified at compile time", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
955 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
956 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
957 if (fp && !v.value)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
958 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
959 error("variable %s is used before initialization", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
960 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
961 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
962 Expression vie = v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
963 if (vie.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
964 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
965 Declaration d = (cast(VarExp)vie).var;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
966 vie = getVarExp(e1.loc, istate, d);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
967 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
968 if (vie.op != TOKstructliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
969 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
970 StructLiteralExp se = cast(StructLiteralExp)vie;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
971 int fieldi = se.getFieldIndex(type, soe.offset);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
972 if (fieldi == -1)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
973 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
974 Expression ev = se.getField(type, soe.offset);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
975 if (fp)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
976 e2 = (*fp)(type, ev, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
977 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
978 e2 = Cast(type, type, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
979 if (e2 is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
980 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
981
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
982 addVarToInterstate(istate, v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
983
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
984 /* Create new struct literal reflecting updated fieldi
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
985 */
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
986 auto expsx = changeOneElement(se.elements, fieldi, e2);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
987 v.value = new StructLiteralExp(se.loc, se.sd, expsx);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
988 v.value.type = se.type;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
989
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
990 e = Cast(type, type, post ? ev : e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
991 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
992 /* Assignment to array element of the form:
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
993 * a[i] = e2
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
994 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
995 else if (e1.op == TOKindex && (cast(IndexExp)e1).e1.op == TOKvar)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
996 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
997 IndexExp ie = cast(IndexExp)e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
998 VarExp ve = cast(VarExp)ie.e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
999 VarDeclaration v = ve.var.isVarDeclaration();
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1000 if (!v || !v.isCTFE())
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1001 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1002 error("%s cannot be modified at compile time", v ? v.toChars(): "void");
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1003 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1004 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1005 if (v.value && v.value.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1006 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1007 VarExp ve2 = cast(VarExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1008 if (ve2.var.isSymbolDeclaration())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1009 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1010 // This can happen if v is a struct initialized to
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1011 // 0 using an __initZ SymbolDeclaration from
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1012 // TypeStruct.defaultInit()
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1013 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1014 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1015 v = ve2.var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1016 assert(v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1017 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1018 if (!v.value)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1019 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1020 if (fp)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1021 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1022 error("variable %s is used before initialization", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1023 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1024 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1025
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1026 Type t = v.type.toBasetype();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1027 if (t.ty == Tsarray)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1028 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1029 /* This array was void initialized. Create a
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1030 * default initializer for it.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1031 * What we should do is fill the array literal with
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1032 * null data, so use-before-initialized can be detected.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1033 * But we're too lazy at the moment to do it, as that
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1034 * involves redoing Index() and whoever calls it.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1035 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1036
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1037 size_t dim = cast(size_t)(cast(TypeSArray)t).dim.toInteger();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1038 v.value = createBlockDuplicatedArrayLiteral(v.type,
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1039 v.type.defaultInit(Loc(0)), dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1040 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1041 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1042 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1043 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1044
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1045 ArrayLiteralExp ae = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1046 AssocArrayLiteralExp aae = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1047 StringExp se = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1048 if (v.value.op == TOKarrayliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1049 ae = cast(ArrayLiteralExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1050 else if (v.value.op == TOKassocarrayliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1051 aae = cast(AssocArrayLiteralExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1052 else if (v.value.op == TOKstring)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1053 se = cast(StringExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1054 else if (v.value.op == TOKnull)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1055 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1056 // This would be a runtime segfault
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1057 error("Cannot index null array %.*s", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1058 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1059 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1060 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1061 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1062
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1063 /* Set the $ variable
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1064 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1065 Expression ee = ArrayLength(Type.tsize_t, v.value);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1066 if (ee !is EXP_CANT_INTERPRET && ie.lengthVar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1067 ie.lengthVar.value = ee;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1068 Expression index = ie.e2.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1069 if (index is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1070 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1071 Expression ev;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1072 if (fp || ae || se) // not for aae, because key might not be there
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1073 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1074 ev = Index(type, v.value, index);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1075 if (ev is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1076 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1077 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1078
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1079 if (fp)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1080 e2 = (*fp)(type, ev, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1081 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1082 e2 = Cast(type, type, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1083 if (e2 is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1084 return e2;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1085
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1086 addVarToInterstate(istate, v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1087 if (ae)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1088 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1089 /* Create new array literal reflecting updated elem
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1090 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1091 int elemi = cast(int)index.toInteger();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1092 auto expsx = changeOneElement(ae.elements, elemi, e2);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1093 v.value = new ArrayLiteralExp(ae.loc, expsx);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1094 v.value.type = ae.type;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1095 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1096 else if (aae)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1097 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1098 /* Create new associative array literal reflecting updated key/value
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1099 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1100 Expressions keysx = aae.keys;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1101 Expressions valuesx = new Expressions();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1102 valuesx.setDim(aae.values.dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1103 int updated = 0;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1104 for (size_t j = valuesx.dim; j; )
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1105 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1106 j--;
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1107 Expression ekey = aae.keys[j];
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1108 Expression ex = Equal(TOKequal, Type.tbool, ekey, index);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1109 if (ex is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1110 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1111 if (ex.isBool(true))
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1112 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1113 valuesx[j] = e2;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1114 updated = 1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1115 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1116 else
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1117 valuesx[j] = aae.values[j];
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1118 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1119 if (!updated)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1120 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1121 // Append index/e2 to keysx[]/valuesx[]
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1122 valuesx.push(e2);
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1123 keysx = keysx.copy();
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1124 keysx.push(index);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1125 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1126 v.value = new AssocArrayLiteralExp(aae.loc, keysx, valuesx);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1127 v.value.type = aae.type;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1128 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1129 else if (se)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1130 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1131 /* Create new string literal reflecting updated elem
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1132 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1133 int elemi = cast(int)index.toInteger();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1134 char* s;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1135 s = cast(char*)calloc(se.len + 1, se.sz);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1136 memcpy(s, se.string_, se.len * se.sz);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1137 dchar value = cast(dchar)e2.toInteger();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1138 switch (se.sz)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1139 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1140 case 1: s[elemi] = cast(char)value; break;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1141 case 2: (cast(wchar*)s)[elemi] = cast(wchar)value; break;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1142 case 4: (cast(dchar*)s)[elemi] = value; break;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1143 default:
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1144 assert(0);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1145 break;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1146 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1147 StringExp se2 = new StringExp(se.loc, assumeUnique(s[0..se.len]));
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1148 se2.committed = se.committed;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1149 se2.postfix = se.postfix;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1150 se2.type = se.type;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1151 v.value = se2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1152 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1153 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1154 assert(0);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1155
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1156 e = Cast(type, type, post ? ev : e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1157 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1158
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1159 /* Assignment to struct element in array, of the form:
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1160 * a[i].var = e2
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1161 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1162 else if (e1.op == TOKdotvar && aggregate.op == TOKindex &&
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1163 (cast(IndexExp)aggregate).e1.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1164 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1165 IndexExp ie = cast(IndexExp)aggregate;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1166 VarExp ve = cast(VarExp)(ie.e1);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1167 VarDeclaration v = ve.var.isVarDeclaration();
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1168 if (!v || !v.isCTFE())
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1169 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1170 error("%s cannot be modified at compile time", v ? v.toChars(): "void");
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1171 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1172 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1173 Type t = ve.type.toBasetype();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1174 ArrayLiteralExp ae = cast(ArrayLiteralExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1175 if (!ae)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1176 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1177 // assignment to one element in an uninitialized (static) array.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1178 // This is quite difficult, because defaultInit() for a struct is a VarExp,
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1179 // not a StructLiteralExp.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1180 Type t2 = v.type.toBasetype();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1181 if (t2.ty != Tsarray)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1182 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1183 error("Cannot index an uninitialized variable");
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1184 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1185 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1186
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1187 Type telem = (cast(TypeSArray)t2).nextOf().toBasetype();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1188 if (telem.ty != Tstruct) { return EXP_CANT_INTERPRET; }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1189
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1190 // Create a default struct literal...
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1191 Expression structinit = telem.defaultInitLiteral(v.loc);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1192
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1193 // ... and use to create a blank array literal
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1194 size_t dim = cast(size_t)(cast(TypeSArray)t2).dim.toInteger();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1195 ae = createBlockDuplicatedArrayLiteral(v.type, structinit, dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1196 v.value = ae;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1197 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1198 if (cast(Expression)(ae.elements) is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1199 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1200 // Note that this would be a runtime segfault
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1201 error("Cannot index null array %s", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1202 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1203 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1204 // Set the $ variable
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1205 Expression ee = ArrayLength(Type.tsize_t, v.value);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1206 if (ee !is EXP_CANT_INTERPRET && ie.lengthVar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1207 ie.lengthVar.value = ee;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1208 // Determine the index, and check that it's OK.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1209 Expression index = ie.e2.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1210 if (index is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1211 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1212
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1213 int elemi = cast(int)index.toInteger();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1214 if (elemi >= ae.elements.dim)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1215 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1216 error("array index %d is out of bounds %s[0..%d]", elemi,
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1217 v.toChars(), ae.elements.dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1218 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1219 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1220 // Get old element
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1221 auto vie = ae.elements[elemi];
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1222 if (vie.op != TOKstructliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1223 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1224
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1225 // Work out which field needs to be changed
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1226 auto se = cast(StructLiteralExp)vie;
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1227 auto vf = (cast(DotVarExp)e1).var.isVarDeclaration();
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1228 if (!vf)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1229 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1230
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1231 int fieldi = se.getFieldIndex(type, vf.offset);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1232 if (fieldi == -1)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1233 return EXP_CANT_INTERPRET;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1234
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1235 Expression ev = se.getField(type, vf.offset);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1236 if (fp)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1237 e2 = (*fp)(type, ev, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1238 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1239 e2 = Cast(type, type, e2);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1240 if (e2 == EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1241 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1242
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1243 // Create new struct literal reflecting updated field
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1244 auto expsx = changeOneElement(se.elements, fieldi, e2);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1245 Expression newstruct = new StructLiteralExp(se.loc, se.sd, expsx);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1246
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1247 // Create new array literal reflecting updated struct elem
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1248 ae.elements = changeOneElement(ae.elements, elemi, newstruct);
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1249 return ae;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1250 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1251 /* Slice assignment, initialization of static arrays
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1252 * a[] = e
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1253 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1254 else if (e1.op == TOKslice && (cast(SliceExp)e1).e1.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1255 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1256 SliceExp sexp = cast(SliceExp)e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1257 VarExp ve = cast(VarExp)(sexp.e1);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1258 VarDeclaration v = ve.var.isVarDeclaration();
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1259 if (!v || !v.isCTFE())
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1260 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1261 error("%s cannot be modified at compile time", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1262 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1263 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1264 // Chase down rebinding of out and ref
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1265 if (v.value && v.value.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1266 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1267 VarExp ve2 = cast(VarExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1268 if (ve2.var.isSymbolDeclaration())
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1269 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1270 // This can happen if v is a struct initialized to
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1271 // 0 using an __initZ SymbolDeclaration from
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1272 // TypeStruct.defaultInit()
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1273 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1274 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1275 v = ve2.var.isVarDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1276 assert(v);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1277 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1278 /* Set the $ variable
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1279 */
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1280 Expression ee = v.value ? ArrayLength(Type.tsize_t, v.value)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1281 : EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1282 if (ee !is EXP_CANT_INTERPRET && sexp.lengthVar)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1283 sexp.lengthVar.value = ee;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1284 Expression upper = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1285 Expression lower = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1286 if (sexp.upr)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1287 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1288 upper = sexp.upr.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1289 if (upper is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1290 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1291 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1292 if (sexp.lwr)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1293 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1294 lower = sexp.lwr.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1295 if (lower is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1296 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1297 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1298 Type t = v.type.toBasetype();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1299 size_t dim;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1300 if (t.ty == Tsarray)
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1301 dim = cast(size_t)(cast(TypeSArray)t).dim.toInteger();
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1302 else if (t.ty == Tarray)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1303 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1304 if (!v.value || v.value.op == TOKnull)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1305 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1306 error("cannot assign to null array %s", v.toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1307 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1308 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1309 if (v.value.op == TOKarrayliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1310 dim = (cast(ArrayLiteralExp)v.value).elements.dim;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1311 else if (v.value.op ==TOKstring)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1312 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1313 error("String slice assignment is not yet supported in CTFE");
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1314 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1315 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1316 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1317 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1318 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1319 error("%s cannot be evaluated at compile time", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1320 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1321 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1322 int upperbound = upper ? cast(int)upper.toInteger() : dim;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1323 int lowerbound = lower ? cast(int)lower.toInteger() : 0;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1324
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1325 ArrayLiteralExp existing;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1326 if ((cast(int)lowerbound < 0) || (upperbound > dim))
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1327 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1328 error("Array bounds [0..%d] exceeded in slice [%d..%d]", dim, lowerbound, upperbound);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1329 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1330 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1331 if (upperbound-lowerbound != dim)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1332 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1333 // Only modifying part of the array. Must create a new array literal.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1334 // If the existing array is uninitialized (this can only happen
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1335 // with static arrays), create it.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1336 if (v.value && v.value.op == TOKarrayliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1337 existing = cast(ArrayLiteralExp)v.value;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1338 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1339 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1340 // this can only happen with static arrays
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1341 existing = createBlockDuplicatedArrayLiteral(v.type, v.type.defaultInit(Loc(0)), dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1342 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1343 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1344
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1345 if (e2.op == TOKarrayliteral)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1346 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1347 // Static array assignment from literal
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1348 ArrayLiteralExp ae = cast(ArrayLiteralExp)e2;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1349 if (ae.elements.dim != (upperbound - lowerbound))
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1350 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1351 error("Array length mismatch assigning [0..%d] to [%d..%d]", ae.elements.dim, lowerbound, upperbound);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1352 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1353 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1354 if (upperbound - lowerbound == dim)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1355 v.value = ae;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1356 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1357 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1358 // value[] = value[0..lower] ~ ae ~ value[upper..$]
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1359 existing.elements = spliceElements(existing.elements, ae.elements, lowerbound);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1360 v.value = existing;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1361 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1362 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1363 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1364 else if (t.nextOf().ty == e2.type.ty)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1365 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1366 // Static array block assignment
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1367 if (upperbound-lowerbound ==dim)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1368 v.value = createBlockDuplicatedArrayLiteral(v.type, e2, dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1369 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1370 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1371 // value[] = value[0..lower] ~ ae ~ value[upper..$]
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1372 existing.elements = spliceElements(existing.elements, createBlockDuplicatedArrayLiteral(v.type, e2, upperbound-lowerbound).elements, lowerbound);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1373 v.value = existing;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1374 }
63
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1375 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1376 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1377 else if (e2.op == TOKstring)
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1378 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1379 StringExp se = cast(StringExp)e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1380 // This is problematic. char[8] should be storing
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1381 // values as a string literal, not
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1382 // as an array literal. Then, for static arrays, we
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1383 // could do modifications
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1384 // in-place, with a dramatic memory and speed improvement.
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1385 error("String slice assignment is not yet supported in CTFE");
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1386 return e2;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1387 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1388 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1389 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1390 error("Slice operation %s cannot be evaluated at compile time", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1391 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1392 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1393 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1394 else
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1395 {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1396 error("%s cannot be evaluated at compile time", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1397 version (DEBUG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1398 dump(0);
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1399 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1400 }
cab4c37afb89 A bunch of implementations
korDen
parents: 60
diff changeset
1401 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 }
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
1403
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
1404 version(DMDV2)
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1405 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 return e1.canThrow() || e2.canThrow();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1409
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1410 // generate an error if this is a nonsensical *=,/=, or %=, eg real *= imaginary
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1411 void checkComplexMulAssign()
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1412 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1413 // Any multiplication by an imaginary or complex number yields a complex result.
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1414 // r *= c, i*=c, r*=i, i*=i are all forbidden operations.
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1415 string opstr = Token.toChars(op);
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1416 if ( e1.type.isreal() && e2.type.iscomplex())
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1417 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1418 error("%s %s %s is undefined. Did you mean %s %s %s.re ?",
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1419 e1.type.toChars(), opstr, e2.type.toChars(),
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1420 e1.type.toChars(), opstr, e2.type.toChars());
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1421 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1422 else if (e1.type.isimaginary() && e2.type.iscomplex())
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1423 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1424 error("%s %s %s is undefined. Did you mean %s %s %s.im ?",
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1425 e1.type.toChars(), opstr, e2.type.toChars(),
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1426 e1.type.toChars(), opstr, e2.type.toChars());
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1427 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1428 else if ((e1.type.isreal() || e1.type.isimaginary()) && e2.type.isimaginary())
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1429 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1430 error("%s %s %s is an undefined operation", e1.type.toChars(),
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1431 opstr, e2.type.toChars());
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1432 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1433 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1434
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1435 // generate an error if this is a nonsensical += or -=, eg real += imaginary
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1436 void checkComplexAddAssign()
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1437 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1438 // Addition or subtraction of a real and an imaginary is a complex result.
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1439 // Thus, r+=i, r+=c, i+=r, i+=c are all forbidden operations.
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1440 if ( (e1.type.isreal() && (e2.type.isimaginary() || e2.type.iscomplex())) ||
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1441 (e1.type.isimaginary() && (e2.type.isreal() || e2.type.iscomplex()))
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1442 )
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1443 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1444 error("%s %s %s is undefined (result is complex)",
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1445 e1.type.toChars(), Token.toChars(op), e2.type.toChars());
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1446 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1447 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1448
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1450 /***********************************
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1451 * Construct the array operation expression.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1452 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 Expression arrayOp(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1455 //printf("BinExp.arrayOp() %s\n", toChars());
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1456
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1457 if (type.toBasetype().nextOf().toBasetype().ty == Tvoid)
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1458 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1459 error("Cannot perform array operations on void[] arrays");
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1460 return new ErrorExp();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
1461 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1462
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
1463 auto arguments = new Expressions();
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1464
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1465 /* The expression to generate an array operation for is mangled
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1466 * into a name to use as the array operation function name.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1467 * Mangle in the operands and operators in RPN order, and type.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1468 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1469 scope OutBuffer buf = new OutBuffer();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1470 buf.writestring("_array");
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1471 buildArrayIdent(buf, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1472 buf.writeByte('_');
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1473
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1474 /* Append deco of array element type
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1475 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1476 version (DMDV2) {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1477 buf.writestring(type.toBasetype().nextOf().toBasetype().mutableOf().deco);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1478 } else {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1479 buf.writestring(type.toBasetype().nextOf().toBasetype().deco);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1480 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1481
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1482 size_t namelen = buf.offset;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1483 buf.writeByte(0);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1484 immutable(char)* name = cast(immutable(char)*)buf.extractData();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1485
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1486 /* Look up name in hash table
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1487 */
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
1488 StringValue* sv = global.arrayfuncs.update(name[0..namelen]);
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1489 FuncDeclaration fd = cast(FuncDeclaration)sv.ptrvalue;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1490 if (!fd)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1491 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1492 /* Some of the array op functions are written as library functions,
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1493 * presumably to optimize them with special CPU vector instructions.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1494 * List those library functions here, in alpha order.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1495 */
175
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
1496 enum const(char)*[] libArrayopFuncs =
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1497 [
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1498 "_arrayExpSliceAddass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1499 "_arrayExpSliceAddass_d", // T[]+=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1500 "_arrayExpSliceAddass_f", // T[]+=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1501 "_arrayExpSliceAddass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1502 "_arrayExpSliceAddass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1503 "_arrayExpSliceAddass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1504 "_arrayExpSliceAddass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1505 "_arrayExpSliceAddass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1506 "_arrayExpSliceAddass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1507 "_arrayExpSliceAddass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1508 "_arrayExpSliceAddass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1509
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1510 "_arrayExpSliceDivass_d", // T[]/=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1511 "_arrayExpSliceDivass_f", // T[]/=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1512
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1513 "_arrayExpSliceMinSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1514 "_arrayExpSliceMinSliceAssign_d", // T[]=T-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1515 "_arrayExpSliceMinSliceAssign_f", // T[]=T-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1516 "_arrayExpSliceMinSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1517 "_arrayExpSliceMinSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1518 "_arrayExpSliceMinSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1519 "_arrayExpSliceMinSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1520 "_arrayExpSliceMinSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1521 "_arrayExpSliceMinSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1522 "_arrayExpSliceMinSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1523 "_arrayExpSliceMinSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1524
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1525 "_arrayExpSliceMinass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1526 "_arrayExpSliceMinass_d", // T[]-=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1527 "_arrayExpSliceMinass_f", // T[]-=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1528 "_arrayExpSliceMinass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1529 "_arrayExpSliceMinass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1530 "_arrayExpSliceMinass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1531 "_arrayExpSliceMinass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1532 "_arrayExpSliceMinass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1533 "_arrayExpSliceMinass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1534 "_arrayExpSliceMinass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1535 "_arrayExpSliceMinass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1536
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1537 "_arrayExpSliceMulass_d", // T[]*=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1538 "_arrayExpSliceMulass_f", // T[]*=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1539 "_arrayExpSliceMulass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1540 "_arrayExpSliceMulass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1541 "_arrayExpSliceMulass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1542 "_arrayExpSliceMulass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1543 "_arrayExpSliceMulass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1544 "_arrayExpSliceMulass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1545
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1546 "_arraySliceExpAddSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1547 "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1548 "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1549 "_arraySliceExpAddSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1550 "_arraySliceExpAddSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1551 "_arraySliceExpAddSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1552 "_arraySliceExpAddSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1553 "_arraySliceExpAddSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1554 "_arraySliceExpAddSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1555 "_arraySliceExpAddSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1556 "_arraySliceExpAddSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1557
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1558 "_arraySliceExpDivSliceAssign_d", // T[]=T[]/T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1559 "_arraySliceExpDivSliceAssign_f", // T[]=T[]/T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1560
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1561 "_arraySliceExpMinSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1562 "_arraySliceExpMinSliceAssign_d", // T[]=T[]-T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1563 "_arraySliceExpMinSliceAssign_f", // T[]=T[]-T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1564 "_arraySliceExpMinSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1565 "_arraySliceExpMinSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1566 "_arraySliceExpMinSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1567 "_arraySliceExpMinSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1568 "_arraySliceExpMinSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1569 "_arraySliceExpMinSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1570 "_arraySliceExpMinSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1571 "_arraySliceExpMinSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1572
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1573 "_arraySliceExpMulSliceAddass_d", // T[] += T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1574 "_arraySliceExpMulSliceAddass_f",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1575 "_arraySliceExpMulSliceAddass_r",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1576
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1577 "_arraySliceExpMulSliceAssign_d", // T[]=T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1578 "_arraySliceExpMulSliceAssign_f", // T[]=T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1579 "_arraySliceExpMulSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1580 "_arraySliceExpMulSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1581 "_arraySliceExpMulSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1582 "_arraySliceExpMulSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1583 "_arraySliceExpMulSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1584 "_arraySliceExpMulSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1585
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1586 "_arraySliceExpMulSliceMinass_d", // T[] -= T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1587 "_arraySliceExpMulSliceMinass_f",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1588 "_arraySliceExpMulSliceMinass_r",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1589
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1590 "_arraySliceSliceAddSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1591 "_arraySliceSliceAddSliceAssign_d", // T[]=T[]+T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1592 "_arraySliceSliceAddSliceAssign_f", // T[]=T[]+T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1593 "_arraySliceSliceAddSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1594 "_arraySliceSliceAddSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1595 "_arraySliceSliceAddSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1596 "_arraySliceSliceAddSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1597 "_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1598 "_arraySliceSliceAddSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1599 "_arraySliceSliceAddSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1600 "_arraySliceSliceAddSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1601 "_arraySliceSliceAddSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1602
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1603 "_arraySliceSliceAddass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1604 "_arraySliceSliceAddass_d", // T[]+=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1605 "_arraySliceSliceAddass_f", // T[]+=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1606 "_arraySliceSliceAddass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1607 "_arraySliceSliceAddass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1608 "_arraySliceSliceAddass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1609 "_arraySliceSliceAddass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1610 "_arraySliceSliceAddass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1611 "_arraySliceSliceAddass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1612 "_arraySliceSliceAddass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1613 "_arraySliceSliceAddass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1614
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1615 "_arraySliceSliceMinSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1616 "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1617 "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1618 "_arraySliceSliceMinSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1619 "_arraySliceSliceMinSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1620 "_arraySliceSliceMinSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1621 "_arraySliceSliceMinSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1622 "_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1623 "_arraySliceSliceMinSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1624 "_arraySliceSliceMinSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1625 "_arraySliceSliceMinSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1626 "_arraySliceSliceMinSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1627
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1628 "_arraySliceSliceMinass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1629 "_arraySliceSliceMinass_d", // T[]-=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1630 "_arraySliceSliceMinass_f", // T[]-=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1631 "_arraySliceSliceMinass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1632 "_arraySliceSliceMinass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1633 "_arraySliceSliceMinass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1634 "_arraySliceSliceMinass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1635 "_arraySliceSliceMinass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1636 "_arraySliceSliceMinass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1637 "_arraySliceSliceMinass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1638 "_arraySliceSliceMinass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1639
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1640 "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1641 "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1642 "_arraySliceSliceMulSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1643 "_arraySliceSliceMulSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1644 "_arraySliceSliceMulSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1645 "_arraySliceSliceMulSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1646 "_arraySliceSliceMulSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1647 "_arraySliceSliceMulSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1648
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1649 "_arraySliceSliceMulass_d", // T[]*=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1650 "_arraySliceSliceMulass_f", // T[]*=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1651 "_arraySliceSliceMulass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1652 "_arraySliceSliceMulass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1653 "_arraySliceSliceMulass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1654 "_arraySliceSliceMulass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1655 "_arraySliceSliceMulass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1656 "_arraySliceSliceMulass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1657 ];
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1658
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1659 int i = binary(name, libArrayopFuncs.ptr, libArrayopFuncs.length);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1660 if (i == -1)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1661 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1662 debug { // Make sure our array is alphabetized
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1663 for (i = 0; i < libArrayopFuncs.length; i++)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1664 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1665 if (strcmp(name, libArrayopFuncs[i]) == 0)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1666 assert(false);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1667 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1668 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1669 /* Not in library, so generate it.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1670 * Construct the function body:
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1671 * foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1672 * loopbody;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1673 * return p;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1674 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1675
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
1676 auto fparams = new Parameters();
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1677 Expression loopbody = buildArrayLoop(fparams);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
1678 auto p = fparams[0 /*fparams.dim - 1*/];
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1679 version (DMDV1) {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1680 // for (size_t i = 0; i < p.length; i++)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1681 Initializer init = new ExpInitializer(0, new IntegerExp(0, 0, Type.tsize_t));
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1682 Dsymbol d = new VarDeclaration(0, Type.tsize_t, Id.p, init);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1683 Statement s1 = new ForStatement(0,
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1684 new DeclarationStatement(0, d),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1685 new CmpExp(TOKlt, 0, new IdentifierExp(0, Id.p), new ArrayLengthExp(0, new IdentifierExp(0, p.ident))),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1686 new PostExp(TOKplusplus, 0, new IdentifierExp(0, Id.p)),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1687 new ExpStatement(0, loopbody));
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1688 } else {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1689 // foreach (i; 0 .. p.length)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1690 Statement s1 = new ForeachRangeStatement(Loc(0), TOKforeach,
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
1691 new Parameter(STC.STCundefined, null, Id.p, null),
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1692 new IntegerExp(Loc(0), 0, Type.tint32),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1693 new ArrayLengthExp(Loc(0), new IdentifierExp(Loc(0), p.ident)),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1694 new ExpStatement(Loc(0), loopbody));
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1695 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1696 Statement s2 = new ReturnStatement(Loc(0), new IdentifierExp(Loc(0), p.ident));
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1697 //printf("s2: %s\n", s2.toChars());
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1698 Statement fbody = new CompoundStatement(Loc(0), s1, s2);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1699
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1700 /* Construct the function
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1701 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1702 TypeFunction ftype = new TypeFunction(fparams, type, 0, LINKc);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1703 //printf("ftype: %s\n", ftype.toChars());
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1704 fd = new FuncDeclaration(Loc(0), Loc(0), Lexer.idPool(name[0..namelen]), STCundefined, ftype);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1705 fd.fbody = fbody;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1706 fd.protection = PROT.PROTpublic;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1707 fd.linkage = LINKc;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1708
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
1709 sc.module_.importedFrom.members.push(fd);
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1710
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1711 sc = sc.push();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1712 sc.parent = sc.module_.importedFrom;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1713 sc.stc = STCundefined;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1714 sc.linkage = LINKc;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1715 fd.semantic(sc);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
1716 fd.semantic2(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
1717 fd.semantic3(sc);
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1718 sc.pop();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1719 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1720 else
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1721 { /* In library, refer to it.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1722 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1723 fd = FuncDeclaration.genCfunc(type, name[0..namelen]);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1724 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1725 sv.ptrvalue = cast(void*)fd; // cache symbol in hash table
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1726 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1727
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1728 /* Call the function fd(arguments)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1729 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1730 Expression ec = new VarExp(Loc(0), fd);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1731 Expression e = new CallExp(loc, ec, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1732 e.type = type;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1733 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1736 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 return 1 + e1.inlineCost(ics) + e2.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1740
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1741 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743 BinExp be = cast(BinExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1744
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 be.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746 be.e2 = e2.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1747 return be;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1748 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1749
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1750 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1752 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1753 e2 = e2.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1754 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1755 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1756
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1757 Expression op_overload(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1758 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1759 //printf("BinExp.op_overload() (%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1761 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1762 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1763 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1764 Identifier id = opId();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1765 Identifier id_r = opId_r();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1767 Match m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1768 scope Expressions args1 = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1769 scope Expressions args2 = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1770 int argsset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1771
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1772 AggregateDeclaration ad1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1773 if (t1.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1774 ad1 = (cast(TypeClass)t1).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1775 else if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1776 ad1 = (cast(TypeStruct)t1).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1777 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1778 ad1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1780 AggregateDeclaration ad2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1781 if (t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1782 ad2 = (cast(TypeClass)t2).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1783 else if (t2.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1784 ad2 = (cast(TypeStruct)t2).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1785 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1786 ad2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788 Dsymbol s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 Dsymbol s_r = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790 FuncDeclaration fd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791 TemplateDeclaration td = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 if (ad1 && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794 s = search_function(ad1, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 if (ad2 && id_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 s_r = search_function(ad2, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801 if (s || s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803 /* Try:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804 * a.opfunc(b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 * b.opfunc_r(a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 * and see which is better.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809 FuncDeclaration lastf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 args1.setDim(1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1812 args1[0] = e1;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 args2.setDim(1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1814 args2[0] = e2;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 argsset = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817 ///memset(&m, 0, sizeof(m));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818 m.last = MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 overloadResolveX(&m, fd, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1828 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829 td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1830 templateResolve(&m, td, sc, loc, null, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1831 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1832 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1833
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1834 lastf = m.lastf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836 if (s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1837 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1838 fd = s_r.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1839 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1840 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1841 overloadResolveX(&m, fd, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1843 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1844 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1845 td = s_r.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1846 templateResolve(&m, td, sc, loc, null, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1849
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1850 if (m.count > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1851 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1852 // Error, ambiguous
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1853 error("overloads %s and %s both match argument list for %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 m.lastf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 m.nextf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1856 m.lastf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1857 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1858 else if (m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1859 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1860 m.lastf = m.anyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1861 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1862
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1863 if (op == TOK.TOKplusplus || op == TOK.TOKminusminus)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1864 // Kludge because operator overloading regards e++ and e--
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1865 // as unary, but it's implemented as a binary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1866 // Rewrite (e1 ++ e2) as e1.postinc()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1867 // Rewrite (e1 -- e2) as e1.postdec()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868 e = build_overload(loc, sc, e1, null, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869 else if (lastf && m.lastf == lastf || m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1870 // Rewrite (e1 op e2) as e1.opfunc(e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 e = build_overload(loc, sc, e1, e2, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1872 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873 // Rewrite (e1 op e2) as e2.opfunc_r(e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1874 e = build_overload(loc, sc, e2, e1, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1875 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1876 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878 if (isCommutative())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1881 s_r = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1882 if (ad1 && id_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1883 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884 s_r = search_function(ad1, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 if (ad2 && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 s = search_function(ad2, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891 if (s || s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 /* Try:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 * a.opfunc_r(b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895 * b.opfunc(a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1896 * and see which is better.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1897 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1898
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899 if (!argsset)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
1900 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901 args1.setDim(1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1902 args1[0] = e1;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903 args2.setDim(1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1904 args2[0] = e2;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1905 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1906
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1907 ///memset(&m, 0, sizeof(m));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1908 m.last = MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1909
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1910 if (s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1911 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1912 fd = s_r.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1913 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1914 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1915 overloadResolveX(&m, fd, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1916 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1917 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1918 { td = s_r.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1919 templateResolve(&m, td, sc, loc, null, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1920 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1921 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1922 FuncDeclaration lastf = m.lastf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1923
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1924 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1925 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1926 fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1927 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1928 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1929 overloadResolveX(&m, fd, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1930 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1931 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1932 { td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1933 templateResolve(&m, td, sc, loc, null, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1934 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1935 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1936
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1937 if (m.count > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1938 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1939 // Error, ambiguous
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1940 error("overloads %s and %s both match argument list for %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1941 m.lastf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1942 m.nextf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1943 m.lastf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1944 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1945 else if (m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1946 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1947 m.lastf = m.anyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1948 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1949
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1950 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1951 if (lastf && m.lastf == lastf || id_r && m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1952 // Rewrite (e1 op e2) as e1.opfunc_r(e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1953 e = build_overload(loc, sc, e1, e2, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1954 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1955 // Rewrite (e1 op e2) as e2.opfunc(e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1956 e = build_overload(loc, sc, e2, e1, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1957
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1958 // When reversing operands of comparison operators,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1959 // need to reverse the sense of the op
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1960 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1961 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 case TOK.TOKlt: op = TOK.TOKgt; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 case TOK.TOKgt: op = TOK.TOKlt; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964 case TOK.TOKle: op = TOK.TOKge; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1965 case TOK.TOKge: op = TOK.TOKle; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1966
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1967 // Floating point compares
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 case TOK.TOKule: op = TOK.TOKuge; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 case TOK.TOKul: op = TOK.TOKug; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970 case TOK.TOKuge: op = TOK.TOKule; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1971 case TOK.TOKug: op = TOK.TOKul; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1972
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1973 // These are symmetric
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1974 case TOK.TOKunord:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 case TOK.TOKlg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 case TOK.TOKleg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1977 case TOK.TOKue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1978 break;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
1979 default:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
1980 break; ///
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1981 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1983 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1984 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1985 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1986
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1987 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1988 // Try alias this on first operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1989 if (ad1 && ad1.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1990 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1991 /* Rewrite (e1 op e2) as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1992 * (e1.aliasthis op e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1993 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1994 Expression e1 = new DotIdExp(loc, this.e1, ad1.aliasthis.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1995 Expression e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1996 (cast(BinExp)e).e1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1997 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1998 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1999 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2001 // Try alias this on second operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2002 if (ad2 && ad2.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2003 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2004 /* Rewrite (e1 op e2) as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2005 * (e1 op e2.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2006 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2007 Expression e2 = new DotIdExp(loc, this.e2, ad2.aliasthis.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2008 Expression e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2009 (cast(BinExp)e).e2 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2010 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2011 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2012 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2013 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2014 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2015 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2016
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2017 elem* toElemBin(IRState* irs, int op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2018 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2019 //printf("toElemBin() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2020
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2021 tym_t tym = type.totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2022
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2023 elem* el = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2024 elem* er = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2025 elem* e = el_bin(op,tym,el,er);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2026 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2027
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2028 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2029 }
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2030 final void AssignExp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2031 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2032 /* Evaluate assign expressions right to left
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2033 */
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2034 e2.buildArrayIdent(buf, arguments);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2035 e1.buildArrayIdent(buf, arguments);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2036 buf.writestring(Str);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2037 buf.writestring("ass");
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2038 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2039
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
2040 final void Exp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2041 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2042 /* Evaluate assign expressions left to right
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2043 */
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2044 e1.buildArrayIdent(buf, arguments);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2045 e2.buildArrayIdent(buf, arguments);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2046 buf.writestring(Str);
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
2047 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2048
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
2049 final Expression AssignExp_buildArrayLoop(AssignExpType)(Parameters fparams)// if (is (AssignExpType : AssignExp))
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2050 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2051 /* Evaluate assign expressions right to left
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2052 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2053 Expression ex2 = e2.buildArrayLoop(fparams);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2054 Expression ex1 = e1.buildArrayLoop(fparams);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
2055 auto param = fparams[0];
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2056 param.storageClass = STCundefined;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2057 Expression e = new AssignExpType(Loc(0), ex1, ex2);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2058 return e;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
2059 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2060
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
2061 final Expression Exp_buildArrayLoop(ExpType)(Parameters fparams) if (is (ExpType : BinExp))
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2062 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2063 /* Evaluate assign expressions left to right
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2064 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2065 Expression ex1 = e1.buildArrayLoop(fparams);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2066 Expression ex2 = e2.buildArrayLoop(fparams);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2067 Expression e = new ExpType(Loc(0), ex1, ex2);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2068 return e;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 116
diff changeset
2069 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 154
diff changeset
2070 }