annotate dmd/BinExp.d @ 56:51605de93870

TupleExp.optimize UnrolledLoopStatement.ctor UnrolledLoopStatement.semantic UnrolledLoopStatement.blockExit OrOrExp.checkSideEffect FuncExp.syntaxCopy FuncLiteralDeclaration.syntaxCopy WhileStatement.hasBreak StructInitializer.toExpression StructLiteralExp.ctor StructLiteralExp.optimize BinExp.commonSemanticAssign ModAssignExp.opId Argument.isLazyArray CommaExp.implicitConvTo CommaExp.castTo TypeClass.isBaseOf createTypeInfoArray TypeTuple.getTypeInfoDeclaration TypeInfoTupleDeclaration.ctor TypeNext.constConv XorExp.implicitConvTo TemplateParameter.isTemplateValueParameter
author korDen
date Sat, 21 Aug 2010 14:16:53 +0400
parents 832f71e6f96c
children a8740d0dbea4
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.declaration.Match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.MulExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.PREC;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
34 import dmd.StringValue;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
35 import dmd.StringTable;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
36 import dmd.Argument;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
37 import dmd.Statement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
38 import dmd.ForeachRangeStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
39 import dmd.ArrayLengthExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
40 import dmd.IdentifierExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
41 import dmd.ExpStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
42 import dmd.CompoundStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
43 import dmd.TypeFunction;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
44 import dmd.LINK;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
45 import dmd.Lexer;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
46 import dmd.ReturnStatement;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
47 import dmd.Id;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
48 import dmd.STC;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
49 import dmd.PROT;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
50 import dmd.VarExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
51 import dmd.CallExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
58 import dmd.backend.iasm : binary;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
59
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import std.stdio : writef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 * Combine types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 * *pt merged type, if *pt is not null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 * *pe1 rewritten e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 * *pe2 rewritten e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 * !=0 success
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 * 0 failed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
73 /**************************************
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
74 * 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
75 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
76
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
77 __gshared StringTable arrayfuncs;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
78
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 int typeMerge(Scope sc, Expression e, Type* pt, Expression* pe1, Expression* pe2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 //printf("typeMerge() %s op %s\n", (*pe1).toChars(), (*pe2).toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Expression e1 = (*pe1).integralPromotions(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 Expression e2 = (*pe2).integralPromotions(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 Type t1 = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 Type t2 = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 assert(t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 Type t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 //if (t1) printf("\tt1 = %s\n", t1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 //if (t2) printf("\tt2 = %s\n", t2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (!t2) writef("\te2 = '%s'\n", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 assert(t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 Type t1b = t1.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 Type t2b = t2.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 TY ty = cast(TY)Type.impcnvResult[t1b.ty][t2b.ty];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (ty != TY.Terror)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 TY ty1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 TY ty2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 ty1 = cast(TY)Type.impcnvType1[t1b.ty][t2b.ty];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 ty2 = cast(TY)Type.impcnvType2[t1b.ty][t2b.ty];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (t1b.ty == ty1) // if no promotions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (t1 == t2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (t1b == t2b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 t = t1b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 t = Type.basic[ty];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 t1 = Type.basic[ty1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 t2 = Type.basic[ty2];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 e1 = e1.castTo(sc, t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 e2 = e2.castTo(sc, t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 //printf("after typeCombine():\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 t1 = t1b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 t2 = t2b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 Lagain:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (t1 == t2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 else if (t1.ty == TY.Tpointer && t2.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 // Bring pointers to compatible type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 Type t1n = t1.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 Type t2n = t2.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 if (t1n == t2n) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 } else if (t1n.ty == TY.Tvoid) {// pointers to void are always compatible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 t = t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 } else if (t2n.ty == TY.Tvoid) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 } else if (t1n.mod != t2n.mod) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 t1 = t1n.mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 t2 = t2n.mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 } else if (t1n.ty == TY.Tclass && t2n.ty == TY.Tclass) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 ClassDeclaration cd1 = t1n.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 ClassDeclaration cd2 = t2n.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 int offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (cd1.isBaseOf(cd2, &offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 else if (cd2.isBaseOf(cd1, &offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 t = t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 if (offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 e1 = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 e2.op == TOK.TOKnull && t2.ty == TY.Tpointer && t2.nextOf().ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 { /* (T[n] op void*)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 * (T[] op void*)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 goto Lx1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 else if ((t2.ty == TY.Tsarray || t2.ty == TY.Tarray) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 e1.op == TOK.TOKnull && t1.ty == TY.Tpointer && t1.nextOf().ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 { /* (void* op T[n])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 * (void* op T[])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 goto Lx2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray) && t1.implicitConvTo(t2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 goto Lt2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 else if ((t2.ty == TY.Tsarray || t2.ty == TY.Tarray) && t2.implicitConvTo(t1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 goto Lt1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 /* If one is mutable and the other invariant, then retry
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 * with both of them as const
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray || t1.ty == TY.Tpointer) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 (t2.ty == TY.Tsarray || t2.ty == TY.Tarray || t2.ty == TY.Tpointer) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 t1.nextOf().mod != t2.nextOf().mod
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 if (t1.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 t1 = t1.nextOf().mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 t1 = t1.nextOf().mutableOf().constOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 if (t2.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 t2 = t2.nextOf().mutableOf().constOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 t2 = t2.nextOf().mutableOf().constOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 else if (t1.ty == TY.Tclass || t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 int i1 = e2.implicitConvTo(t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 int i2 = e1.implicitConvTo(t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 if (i1 && i2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 // We have the case of class vs. void*, so pick class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 if (t1.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 i1 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 else if (t2.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 i2 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 if (i2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 goto Lt2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 else if (i1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 goto Lt1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 else if (t1.ty == TY.Tclass && t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 TypeClass tc1 = cast(TypeClass)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 TypeClass tc2 = cast(TypeClass)t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 /* Pick 'tightest' type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 ClassDeclaration cd1 = tc1.sym.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 ClassDeclaration cd2 = tc2.sym.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 if (cd1 && cd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 { t1 = cd1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 t2 = cd2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 else if (cd1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 t1 = cd1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 else if (cd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 t2 = cd2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 else if (t1.ty == TY.Tstruct && t2.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if ((cast(TypeStruct)t1).sym != (cast(TypeStruct)t2).sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 goto Lincompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 else if ((e1.op == TOK.TOKstring || e1.op == TOK.TOKnull) && e1.implicitConvTo(t2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 goto Lt2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 else if ((e2.op == TOK.TOKstring || e2.op == TOK.TOKnull) && e2.implicitConvTo(t1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 goto Lt1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 else if (t1.ty == TY.Tsarray && t2.ty == TY.Tsarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 e2.implicitConvTo(t1.nextOf().arrayOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 Lx1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 t = t1.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 e1 = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 else if (t1.ty == TY.Tsarray && t2.ty == TY.Tsarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 e1.implicitConvTo(t2.nextOf().arrayOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 Lx2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 t = t2.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 e1 = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 else if (t1.isintegral() && t2.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 else if (e1.op == TOK.TOKslice && t1.ty == TY.Tarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 e2.implicitConvTo(t1.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 { // T[] op T
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 e2 = e2.castTo(sc, t1.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 t = t1.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 else if (e2.op == TOK.TOKslice && t2.ty == TY.Tarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 e1.implicitConvTo(t2.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 { // T op T[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 e1 = e1.castTo(sc, t2.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 t = t2.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 //printf("test %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 e1 = e1.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 if (e && e.isCommutative() && e1.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 { /* Swap operands to minimize number of functions generated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 //printf("swap %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 Expression tmp = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 e1 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 e2 = tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 Lincompatible:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 Lret:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 if (!*pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 *pe1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 *pe2 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 printf("-typeMerge() %s op %s\n", e1.toChars(), e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 if (e1.type) printf("\tt1 = %s\n", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 if (e2.type) printf("\tt2 = %s\n", e2.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 printf("\ttype = %s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 Lt1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 e2 = e2.castTo(sc, t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 t = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 Lt2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 e1 = e1.castTo(sc, t2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 t = t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 class BinExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 Expression e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 this(Loc loc, TOK op, int size, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 super(loc, op, size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 this.e1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 this.e2 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 Expression syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 BinExp e = cast(BinExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 e.type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 e.e1 = e.e1.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 e.e2 = e.e2.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 printf("BinExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 if (!e1.type && !(op == TOK.TOKassign && e1.op == TOK.TOKdottd)) // a.template = e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 error("%s has no value", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 e1.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 if (!e2.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 error("%s has no value", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 e2.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 Expression semanticp(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 printf("BinExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (!e1.type &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 !(op == TOK.TOKassign && e1.op == TOK.TOKdottd)) // a.template = e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 error("%s has no value", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 e1.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 if (!e2.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 error("%s has no value", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 e2.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
426 /***************************
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
427 * Common semantic routine for some xxxAssignExp's.
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
428 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 Expression commonSemanticAssign(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 {
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
431 Expression e;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
432
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
433 if (!type)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
434 {
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
435 BinExp.semantic(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
436 e2 = resolveProperties(sc, e2);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
437
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
438 e = op_overload(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
439 if (e)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
440 return e;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
441
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
442 if (e1.op == TOKslice)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
443 {
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
444 // T[] op= ...
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
445 typeCombine(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
446 type = e1.type;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
447 return arrayOp(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
448 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
449
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
450 e1 = e1.modifiableLvalue(sc, e1);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
451 e1.checkScalar();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
452 type = e1.type;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
453 if (type.toBasetype().ty == Tbool)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
454 {
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
455 error("operator not allowed on bool expression %s", toChars());
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
456 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
457 typeCombine(sc);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
458 e1.checkArithmetic();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
459 e2.checkArithmetic();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
460
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
461 if (op == TOKmodass && e2.type.iscomplex())
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
462 { error("cannot perform modulo complex arithmetic");
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
463 return new ErrorExp();
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
464 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
465 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
466 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 Expression commonSemanticAssignIntegral(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 BinExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 if (e1.op == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 { // T[] op= ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 return arrayOp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 e1 = e1.modifiableLvalue(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 e1.checkScalar();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 if (type.toBasetype().ty == TY.Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 e2 = e2.implicitCastTo(sc, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 e1.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 e2.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 bool checkSideEffect(int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 switch (op) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 case TOK.TOKassign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 case TOK.TOKconstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 case TOK.TOKblit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 case TOK.TOKaddass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 case TOK.TOKminass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 case TOK.TOKcatass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 case TOK.TOKmulass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 case TOK.TOKdivass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 case TOK.TOKmodass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 case TOK.TOKshlass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 case TOK.TOKshrass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 case TOK.TOKushrass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 case TOK.TOKandass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 case TOK.TOKorass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 case TOK.TOKxorass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 case TOK.TOKremove:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 return Expression.checkSideEffect(flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 expToCBuffer(buf, hgs, e1, precedence[op]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 buf.writeByte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 buf.writestring(Token.toChars(op));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 buf.writeByte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 expToCBuffer(buf, hgs, e2, cast(PREC)(precedence[op] + 1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 * Scale addition/subtraction to/from pointer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 Expression scaleFactor(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 ulong stride;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 Type t1b = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 Type t2b = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 if (t1b.ty == Tpointer && t2b.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 // Need to adjust operator by the stride
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 // Replace (ptr + int) with (ptr + (int * stride))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 Type t = Type.tptrdiff_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 stride = t1b.nextOf().size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 if (!t.equals(t2b))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 e2 = e2.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 e2 = new MulExp(loc, e2, new IntegerExp(Loc(0), stride, t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 e2.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 else if (t2b.ty == Tpointer && t1b.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 // Need to adjust operator by the stride
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 // Replace (int + ptr) with (ptr + (int * stride))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 Type t = Type.tptrdiff_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 stride = t2b.nextOf().size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 if (!t.equals(t1b))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 e = e1.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 e = new MulExp(loc, e, new IntegerExp(Loc(0), stride, t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 type = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 e1 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 e2 = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 * Bring leaves to common type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 Expression typeCombine(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 if (op == TOK.TOKmin || op == TOK.TOKadd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 if (t2.ty == TY.Tstruct && (cast(TypeStruct)t1).sym is (cast(TypeStruct)t2).sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 else if (t1.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 if (t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 if (!typeMerge(sc, this, &type, &e1, &e2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 incompatibleTypes();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 e1 = new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 e2 = new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 Expression optimize(int result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 //printf("BinExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 if (op != TOK.TOKconstruct && op != TOK.TOKblit) // don't replace const variable with its initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 if (op == TOK.TOKshlass || op == TOK.TOKshrass || op == TOK.TOKushrass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 if (e2.isConst() == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 long i2 = e2.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 ulong sz = e1.type.size() * 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 if (i2 < 0 || i2 > sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 error("shift assign by %jd is outside the range 0..%zu", i2, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 e2 = new IntegerExp(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 bool isunsigned()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 void incompatibleTypes()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 e1.toChars(), Token.toChars(op), e2.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 e1.type.toChars(), e2.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 void dump(int indent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 void scanForNestedRef(Scope *sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 Expression interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 Expression interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 Expression interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 bool canThrow()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 return e1.canThrow() || e2.canThrow();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
687 /***********************************
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
688 * Construct the array operation expression.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
689 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 Expression arrayOp(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
692 //printf("BinExp.arrayOp() %s\n", toChars());
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
693 Expressions arguments = new Expressions();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
694
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
695 /* 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
696 * 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
697 * 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
698 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
699 scope OutBuffer buf = new OutBuffer();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
700 buf.writestring("_array");
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
701 buildArrayIdent(buf, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
702 buf.writeByte('_');
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
703
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
704 /* Append deco of array element type
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
705 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
706 version (DMDV2) {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
707 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
708 } else {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
709 buf.writestring(type.toBasetype().nextOf().toBasetype().deco);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
710 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
711
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
712 size_t namelen = buf.offset;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
713 buf.writeByte(0);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
714 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
715
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
716 /* Look up name in hash table
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
717 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
718 if (arrayfuncs is null) arrayfuncs = new StringTable(); /// HACK!
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
719
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
720 StringValue* sv = arrayfuncs.update(name[0..namelen]);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
721 FuncDeclaration fd = cast(FuncDeclaration)sv.ptrvalue;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
722 if (!fd)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
723 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
724 /* 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
725 * 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
726 * 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
727 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
728 static const(char)*[] libArrayopFuncs =
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
729 [
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
730 "_arrayExpSliceAddass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
731 "_arrayExpSliceAddass_d", // T[]+=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
732 "_arrayExpSliceAddass_f", // T[]+=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
733 "_arrayExpSliceAddass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
734 "_arrayExpSliceAddass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
735 "_arrayExpSliceAddass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
736 "_arrayExpSliceAddass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
737 "_arrayExpSliceAddass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
738 "_arrayExpSliceAddass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
739 "_arrayExpSliceAddass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
740 "_arrayExpSliceAddass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
741
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
742 "_arrayExpSliceDivass_d", // T[]/=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
743 "_arrayExpSliceDivass_f", // T[]/=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
744
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
745 "_arrayExpSliceMinSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
746 "_arrayExpSliceMinSliceAssign_d", // T[]=T-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
747 "_arrayExpSliceMinSliceAssign_f", // T[]=T-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
748 "_arrayExpSliceMinSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
749 "_arrayExpSliceMinSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
750 "_arrayExpSliceMinSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
751 "_arrayExpSliceMinSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
752 "_arrayExpSliceMinSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
753 "_arrayExpSliceMinSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
754 "_arrayExpSliceMinSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
755 "_arrayExpSliceMinSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
756
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
757 "_arrayExpSliceMinass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
758 "_arrayExpSliceMinass_d", // T[]-=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
759 "_arrayExpSliceMinass_f", // T[]-=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
760 "_arrayExpSliceMinass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
761 "_arrayExpSliceMinass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
762 "_arrayExpSliceMinass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
763 "_arrayExpSliceMinass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
764 "_arrayExpSliceMinass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
765 "_arrayExpSliceMinass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
766 "_arrayExpSliceMinass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
767 "_arrayExpSliceMinass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
768
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
769 "_arrayExpSliceMulass_d", // T[]*=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
770 "_arrayExpSliceMulass_f", // T[]*=T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
771 "_arrayExpSliceMulass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
772 "_arrayExpSliceMulass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
773 "_arrayExpSliceMulass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
774 "_arrayExpSliceMulass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
775 "_arrayExpSliceMulass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
776 "_arrayExpSliceMulass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
777
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
778 "_arraySliceExpAddSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
779 "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
780 "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
781 "_arraySliceExpAddSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
782 "_arraySliceExpAddSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
783 "_arraySliceExpAddSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
784 "_arraySliceExpAddSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
785 "_arraySliceExpAddSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
786 "_arraySliceExpAddSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
787 "_arraySliceExpAddSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
788 "_arraySliceExpAddSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
789
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
790 "_arraySliceExpDivSliceAssign_d", // T[]=T[]/T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
791 "_arraySliceExpDivSliceAssign_f", // T[]=T[]/T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
792
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
793 "_arraySliceExpMinSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
794 "_arraySliceExpMinSliceAssign_d", // T[]=T[]-T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
795 "_arraySliceExpMinSliceAssign_f", // T[]=T[]-T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
796 "_arraySliceExpMinSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
797 "_arraySliceExpMinSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
798 "_arraySliceExpMinSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
799 "_arraySliceExpMinSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
800 "_arraySliceExpMinSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
801 "_arraySliceExpMinSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
802 "_arraySliceExpMinSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
803 "_arraySliceExpMinSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
804
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
805 "_arraySliceExpMulSliceAddass_d", // T[] += T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
806 "_arraySliceExpMulSliceAddass_f",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
807 "_arraySliceExpMulSliceAddass_r",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
808
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
809 "_arraySliceExpMulSliceAssign_d", // T[]=T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
810 "_arraySliceExpMulSliceAssign_f", // T[]=T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
811 "_arraySliceExpMulSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
812 "_arraySliceExpMulSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
813 "_arraySliceExpMulSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
814 "_arraySliceExpMulSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
815 "_arraySliceExpMulSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
816 "_arraySliceExpMulSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
817
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
818 "_arraySliceExpMulSliceMinass_d", // T[] -= T[]*T
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
819 "_arraySliceExpMulSliceMinass_f",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
820 "_arraySliceExpMulSliceMinass_r",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
821
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
822 "_arraySliceSliceAddSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
823 "_arraySliceSliceAddSliceAssign_d", // T[]=T[]+T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
824 "_arraySliceSliceAddSliceAssign_f", // T[]=T[]+T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
825 "_arraySliceSliceAddSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
826 "_arraySliceSliceAddSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
827 "_arraySliceSliceAddSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
828 "_arraySliceSliceAddSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
829 "_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
830 "_arraySliceSliceAddSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
831 "_arraySliceSliceAddSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
832 "_arraySliceSliceAddSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
833 "_arraySliceSliceAddSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
834
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
835 "_arraySliceSliceAddass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
836 "_arraySliceSliceAddass_d", // T[]+=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
837 "_arraySliceSliceAddass_f", // T[]+=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
838 "_arraySliceSliceAddass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
839 "_arraySliceSliceAddass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
840 "_arraySliceSliceAddass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
841 "_arraySliceSliceAddass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
842 "_arraySliceSliceAddass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
843 "_arraySliceSliceAddass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
844 "_arraySliceSliceAddass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
845 "_arraySliceSliceAddass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
846
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
847 "_arraySliceSliceMinSliceAssign_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
848 "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
849 "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
850 "_arraySliceSliceMinSliceAssign_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
851 "_arraySliceSliceMinSliceAssign_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
852 "_arraySliceSliceMinSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
853 "_arraySliceSliceMinSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
854 "_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
855 "_arraySliceSliceMinSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
856 "_arraySliceSliceMinSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
857 "_arraySliceSliceMinSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
858 "_arraySliceSliceMinSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
859
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
860 "_arraySliceSliceMinass_a",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
861 "_arraySliceSliceMinass_d", // T[]-=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
862 "_arraySliceSliceMinass_f", // T[]-=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
863 "_arraySliceSliceMinass_g",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
864 "_arraySliceSliceMinass_h",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
865 "_arraySliceSliceMinass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
866 "_arraySliceSliceMinass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
867 "_arraySliceSliceMinass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
868 "_arraySliceSliceMinass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
869 "_arraySliceSliceMinass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
870 "_arraySliceSliceMinass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
871
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
872 "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
873 "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
874 "_arraySliceSliceMulSliceAssign_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
875 "_arraySliceSliceMulSliceAssign_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
876 "_arraySliceSliceMulSliceAssign_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
877 "_arraySliceSliceMulSliceAssign_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
878 "_arraySliceSliceMulSliceAssign_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
879 "_arraySliceSliceMulSliceAssign_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
880
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
881 "_arraySliceSliceMulass_d", // T[]*=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
882 "_arraySliceSliceMulass_f", // T[]*=T[]
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
883 "_arraySliceSliceMulass_i",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
884 "_arraySliceSliceMulass_k",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
885 "_arraySliceSliceMulass_s",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
886 "_arraySliceSliceMulass_t",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
887 "_arraySliceSliceMulass_u",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
888 "_arraySliceSliceMulass_w",
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
889 ];
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
890
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
891 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
892 if (i == -1)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
893 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
894 debug { // Make sure our array is alphabetized
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
895 for (i = 0; i < libArrayopFuncs.length; i++)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
896 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
897 if (strcmp(name, libArrayopFuncs[i]) == 0)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
898 assert(false);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
899 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
900 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
901 /* Not in library, so generate it.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
902 * Construct the function body:
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
903 * 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
904 * loopbody;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
905 * return p;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
906 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
907
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
908 Arguments fparams = new Arguments();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
909 Expression loopbody = buildArrayLoop(fparams);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
910 Argument p = cast(Argument)fparams.data[0 /*fparams.dim - 1*/];
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
911 version (DMDV1) {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
912 // 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
913 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
914 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
915 Statement s1 = new ForStatement(0,
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
916 new DeclarationStatement(0, d),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
917 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
918 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
919 new ExpStatement(0, loopbody));
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
920 } else {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
921 // foreach (i; 0 .. p.length)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
922 Statement s1 = new ForeachRangeStatement(Loc(0), TOKforeach,
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
923 new Argument(STC.STCundefined, null, Id.p, null),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
924 new IntegerExp(Loc(0), 0, Type.tint32),
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
925 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
926 new ExpStatement(Loc(0), loopbody));
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
927 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
928 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
929 //printf("s2: %s\n", s2.toChars());
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
930 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
931
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
932 /* Construct the function
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
933 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
934 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
935 //printf("ftype: %s\n", ftype.toChars());
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
936 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
937 fd.fbody = fbody;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
938 fd.protection = PROT.PROTpublic;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
939 fd.linkage = LINKc;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
940
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
941 sc.module_.importedFrom.members.push(cast(void*)fd);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
942
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
943 sc = sc.push();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
944 sc.parent = sc.module_.importedFrom;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
945 sc.stc = STCundefined;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
946 sc.linkage = LINKc;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
947 fd.semantic(sc);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
948 sc.pop();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
949 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
950 else
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
951 { /* In library, refer to it.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
952 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
953 fd = FuncDeclaration.genCfunc(type, name[0..namelen]);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
954 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
955 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
956 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
957
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
958 /* Call the function fd(arguments)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
959 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
960 Expression ec = new VarExp(Loc(0), fd);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
961 Expression e = new CallExp(loc, ec, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
962 e.type = type;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
963 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 return 1 + e1.inlineCost(ics) + e2.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 BinExp be = cast(BinExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 be.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 be.e2 = e2.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 return be;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 Expression inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 e2 = e2.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 Expression op_overload(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 //printf("BinExp.op_overload() (%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 Identifier id = opId();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 Identifier id_r = opId_r();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 Match m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 scope Expressions args1 = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 scope Expressions args2 = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 int argsset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 AggregateDeclaration ad1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 if (t1.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 ad1 = (cast(TypeClass)t1).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 else if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 ad1 = (cast(TypeStruct)t1).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 ad1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 AggregateDeclaration ad2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 if (t2.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 ad2 = (cast(TypeClass)t2).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 else if (t2.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 ad2 = (cast(TypeStruct)t2).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 ad2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 Dsymbol s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 Dsymbol s_r = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 FuncDeclaration fd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 TemplateDeclaration td = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 if (ad1 && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 s = search_function(ad1, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 if (ad2 && id_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 s_r = search_function(ad2, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 if (s || s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 /* Try:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 * a.opfunc(b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 * b.opfunc_r(a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 * and see which is better.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 FuncDeclaration lastf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 args1.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 args1.data[0] = cast(void*) e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 args2.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 args2.data[0] = cast(void*) e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 argsset = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 ///memset(&m, 0, sizeof(m));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 m.last = MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 overloadResolveX(&m, fd, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 templateResolve(&m, td, sc, loc, null, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 lastf = m.lastf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 if (s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 fd = s_r.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 overloadResolveX(&m, fd, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 td = s_r.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 templateResolve(&m, td, sc, loc, null, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 if (m.count > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 // Error, ambiguous
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 error("overloads %s and %s both match argument list for %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 m.lastf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 m.nextf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 m.lastf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 else if (m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 m.lastf = m.anyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 if (op == TOK.TOKplusplus || op == TOK.TOKminusminus)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 // Kludge because operator overloading regards e++ and e--
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 // as unary, but it's implemented as a binary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 // Rewrite (e1 ++ e2) as e1.postinc()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 // Rewrite (e1 -- e2) as e1.postdec()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 e = build_overload(loc, sc, e1, null, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 else if (lastf && m.lastf == lastf || m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 // Rewrite (e1 op e2) as e1.opfunc(e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 e = build_overload(loc, sc, e1, e2, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 // Rewrite (e1 op e2) as e2.opfunc_r(e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 e = build_overload(loc, sc, e2, e1, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 if (isCommutative())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 s_r = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 if (ad1 && id_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 s_r = search_function(ad1, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 if (ad2 && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 s = search_function(ad2, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 if (s || s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 /* Try:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 * a.opfunc_r(b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 * b.opfunc(a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 * and see which is better.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 if (!argsset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 args1.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 args1.data[0] = cast(void*) e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 args2.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 args2.data[0] = cast(void*) e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 ///memset(&m, 0, sizeof(m));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 m.last = MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 if (s_r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 fd = s_r.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 overloadResolveX(&m, fd, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 { td = s_r.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 templateResolve(&m, td, sc, loc, null, null, args2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 FuncDeclaration lastf = m.lastf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 overloadResolveX(&m, fd, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 { td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 templateResolve(&m, td, sc, loc, null, null, args1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 if (m.count > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 // Error, ambiguous
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 error("overloads %s and %s both match argument list for %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171 m.lastf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 m.nextf.type.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 m.lastf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 else if (m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 m.lastf = m.anyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 if (lastf && m.lastf == lastf || id_r && m.last == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 // Rewrite (e1 op e2) as e1.opfunc_r(e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 e = build_overload(loc, sc, e1, e2, id_r);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 // Rewrite (e1 op e2) as e2.opfunc(e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 e = build_overload(loc, sc, e2, e1, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 // When reversing operands of comparison operators,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 // need to reverse the sense of the op
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 case TOK.TOKlt: op = TOK.TOKgt; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 case TOK.TOKgt: op = TOK.TOKlt; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 case TOK.TOKle: op = TOK.TOKge; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 case TOK.TOKge: op = TOK.TOKle; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 // Floating point compares
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 case TOK.TOKule: op = TOK.TOKuge; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 case TOK.TOKul: op = TOK.TOKug; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 case TOK.TOKuge: op = TOK.TOKule; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 case TOK.TOKug: op = TOK.TOKul; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 // These are symmetric
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 case TOK.TOKunord:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 case TOK.TOKlg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 case TOK.TOKleg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 case TOK.TOKue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 // Try alias this on first operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 if (ad1 && ad1.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 /* Rewrite (e1 op e2) as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 * (e1.aliasthis op e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 Expression e1 = new DotIdExp(loc, this.e1, ad1.aliasthis.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 Expression e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 (cast(BinExp)e).e1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 // Try alias this on second operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 if (ad2 && ad2.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 /* Rewrite (e1 op e2) as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 * (e1 op e2.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 Expression e2 = new DotIdExp(loc, this.e2, ad2.aliasthis.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 Expression e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 (cast(BinExp)e).e2 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 elem* toElemBin(IRState* irs, int op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 //printf("toElemBin() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 tym_t tym = type.totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 elem* el = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 elem* er = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 elem* e = el_bin(op,tym,el,er);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 }
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1258
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1259 final void Exp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1260 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1261 /* Evaluate assign expressions left to right
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1262 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1263 e1.buildArrayIdent(buf, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1264 e2.buildArrayIdent(buf, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1265 buf.writestring(Str);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1266 }
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1267
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1268 final void AssignExp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1269 {
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1270 /* Evaluate assign expressions right to left
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1271 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1272 e2.buildArrayIdent(buf, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1273 e1.buildArrayIdent(buf, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1274 buf.writestring(Str);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1275 buf.writestring("ass");
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
1276 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 }