Mercurial > projects > ddmd
annotate dmd/NegExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 9e39c7de8438 |
children | e3afd1303184 |
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 | |
0 | 22 class NegExp : UnaExp |
23 { | |
24 this(Loc loc, Expression e) | |
25 { | |
26 super(loc, TOKneg, NegExp.sizeof, e); | |
27 } | |
28 | |
72 | 29 override Expression semantic(Scope sc) |
0 | 30 { |
31 Expression e; | |
32 | |
33 version (LOGSEMANTIC) { | |
34 printf("NegExp::semantic('%s')\n", toChars()); | |
35 } | |
36 if (!type) | |
37 { | |
38 UnaExp.semantic(sc); | |
39 e1 = resolveProperties(sc, e1); | |
40 e = op_overload(sc); | |
41 if (e) | |
42 return e; | |
43 | |
44 e1.checkNoBool(); | |
109 | 45 if (!e1.isArrayOperand()) |
0 | 46 e1.checkArithmetic(); |
47 | |
48 type = e1.type; | |
49 } | |
50 return this; | |
51 } | |
52 | |
72 | 53 override Expression optimize(int result) |
0 | 54 { |
55 Expression e; | |
56 | |
57 e1 = e1.optimize(result); | |
58 if (e1.isConst() == 1) | |
59 { | |
60 e = Neg(type, e1); | |
61 } | |
62 else | |
63 e = this; | |
64 | |
65 return e; | |
66 } | |
67 | |
72 | 68 override Expression interpret(InterState istate) |
0 | 69 { |
70 assert(false); | |
71 } | |
72 | |
72 | 73 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 74 { |
123 | 75 e1.buildArrayIdent(buf, arguments); |
76 buf.writestring("Neg"); | |
0 | 77 } |
78 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
79 override Expression buildArrayLoop(Parameters fparams) |
0 | 80 { |
123 | 81 Expression ex1 = e1.buildArrayLoop(fparams); |
82 Expression e = new NegExp(Loc(0), ex1); | |
83 return e; | |
0 | 84 } |
85 | |
72 | 86 override Identifier opId() |
0 | 87 { |
63 | 88 return Id.neg; |
0 | 89 } |
90 | |
72 | 91 override elem* toElem(IRState* irs) |
0 | 92 { |
93 elem *e = el_una(OPneg, type.totym(), e1.toElem(irs)); | |
94 el_setLoc(e,loc); | |
95 return e; | |
96 } | |
97 } | |
98 |