Mercurial > projects > ddmd
annotate dmd/NegExp.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
72 | 1 module dmd.NegExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.backend.elem; | |
7 import dmd.UnaExp; | |
8 import dmd.InterState; | |
9 import dmd.OutBuffer; | |
10 import dmd.Loc; | |
11 import dmd.Scope; | |
12 import dmd.IRState; | |
13 import dmd.ArrayTypes; | |
14 import dmd.TOK; | |
63 | 15 import dmd.Id; |
0 | 16 |
17 import dmd.expression.Neg; | |
18 | |
19 import dmd.backend.Util; | |
72 | 20 import dmd.backend.OPER; |
21 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
22 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
|
23 |
0 | 24 class NegExp : UnaExp |
25 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 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
|
27 |
0 | 28 this(Loc loc, Expression e) |
29 { | |
178 | 30 register(); |
0 | 31 super(loc, TOKneg, NegExp.sizeof, e); |
32 } | |
33 | |
72 | 34 override Expression semantic(Scope sc) |
0 | 35 { |
36 Expression e; | |
37 | |
38 version (LOGSEMANTIC) { | |
39 printf("NegExp::semantic('%s')\n", toChars()); | |
40 } | |
41 if (!type) | |
42 { | |
43 UnaExp.semantic(sc); | |
44 e1 = resolveProperties(sc, e1); | |
45 e = op_overload(sc); | |
46 if (e) | |
47 return e; | |
48 | |
49 e1.checkNoBool(); | |
109 | 50 if (!e1.isArrayOperand()) |
0 | 51 e1.checkArithmetic(); |
52 | |
53 type = e1.type; | |
54 } | |
55 return this; | |
56 } | |
57 | |
72 | 58 override Expression optimize(int result) |
0 | 59 { |
60 Expression e; | |
61 | |
62 e1 = e1.optimize(result); | |
63 if (e1.isConst() == 1) | |
64 { | |
65 e = Neg(type, e1); | |
66 } | |
67 else | |
68 e = this; | |
69 | |
70 return e; | |
71 } | |
72 | |
72 | 73 override Expression interpret(InterState istate) |
0 | 74 { |
75 assert(false); | |
76 } | |
77 | |
72 | 78 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 79 { |
123 | 80 e1.buildArrayIdent(buf, arguments); |
81 buf.writestring("Neg"); | |
0 | 82 } |
83 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
84 override Expression buildArrayLoop(Parameters fparams) |
0 | 85 { |
123 | 86 Expression ex1 = e1.buildArrayLoop(fparams); |
87 Expression e = new NegExp(Loc(0), ex1); | |
88 return e; | |
0 | 89 } |
90 | |
72 | 91 override Identifier opId() |
0 | 92 { |
63 | 93 return Id.neg; |
0 | 94 } |
95 | |
72 | 96 override elem* toElem(IRState* irs) |
0 | 97 { |
98 elem *e = el_una(OPneg, type.totym(), e1.toElem(irs)); | |
99 el_setLoc(e,loc); | |
100 return e; | |
101 } | |
102 } | |
103 |