Mercurial > projects > ddmd
annotate dmd/AddExp.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
72 | 1 module dmd.AddExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.backend.elem; | |
7 import dmd.InterState; | |
8 import dmd.OutBuffer; | |
9 import dmd.Loc; | |
10 import dmd.Id; | |
11 import dmd.Scope; | |
12 import dmd.IRState; | |
13 import dmd.ArrayTypes; | |
14 import dmd.BinExp; | |
15 import dmd.Type; | |
16 import dmd.TOK; | |
17 import dmd.TY; | |
18 | |
19 import dmd.expression.Add; | |
20 import dmd.backend.Util; | |
21 import dmd.backend.OPER; | |
22 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 |
0 | 25 class AddExp : BinExp |
26 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 |
0 | 29 this(Loc loc, Expression e1, Expression e2) |
30 { | |
178 | 31 register(); |
0 | 32 super(loc, TOK.TOKadd, AddExp.sizeof, e1, e2); |
33 } | |
34 | |
72 | 35 override Expression semantic(Scope sc) |
0 | 36 { |
72 | 37 Expression e; |
38 | |
39 version (LOGSEMANTIC) { | |
40 printf("AddExp.semantic('%s')\n", toChars()); | |
41 } | |
42 if (!type) | |
43 { | |
44 BinExp.semanticp(sc); | |
45 | |
46 e = op_overload(sc); | |
47 if (e) | |
48 return e; | |
49 | |
50 Type tb1 = e1.type.toBasetype(); | |
51 Type tb2 = e2.type.toBasetype(); | |
52 | |
53 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && | |
54 (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray) && | |
55 tb1.nextOf().equals(tb2.nextOf()) | |
56 ) | |
57 { | |
58 type = e1.type; | |
59 e = this; | |
60 } | |
61 else if (tb1.ty == TY.Tpointer && e2.type.isintegral() || | |
62 tb2.ty == TY.Tpointer && e1.type.isintegral()) | |
63 e = scaleFactor(sc); | |
64 else if (tb1.ty == TY.Tpointer && tb2.ty == TY.Tpointer) | |
65 { | |
66 incompatibleTypes(); | |
67 type = e1.type; | |
68 e = this; | |
69 } | |
70 else | |
71 { | |
72 typeCombine(sc); | |
73 if ((e1.type.isreal() && e2.type.isimaginary()) || | |
74 (e1.type.isimaginary() && e2.type.isreal())) | |
75 { | |
76 switch (type.toBasetype().ty) | |
77 { | |
78 case TY.Tfloat32: | |
79 case TY.Timaginary32: | |
80 type = Type.tcomplex32; | |
81 break; | |
82 | |
83 case TY.Tfloat64: | |
84 case TY.Timaginary64: | |
85 type = Type.tcomplex64; | |
86 break; | |
87 | |
88 case TY.Tfloat80: | |
89 case TY.Timaginary80: | |
90 type = Type.tcomplex80; | |
91 break; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
130
diff
changeset
|
92 default: |
72 | 93 } |
94 } | |
95 e = this; | |
96 } | |
97 return e; | |
98 } | |
0 | 99 return this; |
100 } | |
101 | |
72 | 102 override Expression optimize(int result) |
0 | 103 { |
72 | 104 Expression e; |
105 | |
106 //printf("AddExp::optimize(%s)\n", toChars()); | |
107 e1 = e1.optimize(result); | |
108 e2 = e2.optimize(result); | |
109 if (e1.isConst() && e2.isConst()) | |
110 { | |
111 if (e1.op == TOK.TOKsymoff && e2.op == TOK.TOKsymoff) | |
112 return this; | |
113 e = Add(type, e1, e2); | |
114 } | |
115 else | |
116 e = this; | |
117 | |
0 | 118 return e; |
119 } | |
120 | |
72 | 121 override Expression interpret(InterState istate) |
0 | 122 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
123 return interpretCommon(istate, &Add); |
0 | 124 } |
125 | |
72 | 126 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 127 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
128 Exp_buildArrayIdent(buf, arguments, "Add"); |
0 | 129 } |
130 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
131 override Expression buildArrayLoop(Parameters fparams) |
0 | 132 { |
123 | 133 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 134 } |
135 | |
72 | 136 override bool isCommutative() |
0 | 137 { |
138 return true; | |
139 } | |
140 | |
72 | 141 override Identifier opId() |
0 | 142 { |
143 return Id.add; | |
144 } | |
145 | |
72 | 146 override Identifier opId_r() |
0 | 147 { |
148 return Id.add_r; | |
149 } | |
150 | |
72 | 151 override elem* toElem(IRState* irs) |
0 | 152 { |
72 | 153 elem *e; |
154 Type tb1 = e1.type.toBasetype(); | |
155 Type tb2 = e2.type.toBasetype(); | |
156 | |
157 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray)) | |
158 { | |
159 error("Array operation %s not implemented", toChars()); | |
160 e = el_long(type.totym(), 0); // error recovery | |
161 } | |
162 else | |
163 e = toElemBin(irs, OPER.OPadd); | |
164 | |
0 | 165 return e; |
166 } | |
167 } | |
168 |