0
|
1 module dmd.NegExp;
|
|
2
|
|
3 import dmd.Expression;
|
|
4 import dmd.Identifier;
|
|
5 import dmd.backend.elem;
|
|
6 import dmd.UnaExp;
|
|
7 import dmd.InterState;
|
|
8 import dmd.OutBuffer;
|
|
9 import dmd.Loc;
|
|
10 import dmd.Scope;
|
|
11 import dmd.IRState;
|
|
12 import dmd.ArrayTypes;
|
|
13 import dmd.TOK;
|
|
14
|
|
15 import dmd.expression.Neg;
|
|
16
|
|
17 import dmd.backend.Util;
|
|
18 import dmd.backend.OPER;
|
|
19
|
|
20 class NegExp : UnaExp
|
|
21 {
|
|
22 this(Loc loc, Expression e)
|
|
23 {
|
|
24 super(loc, TOKneg, NegExp.sizeof, e);
|
|
25 }
|
|
26
|
|
27 Expression semantic(Scope sc)
|
|
28 {
|
|
29 Expression e;
|
|
30
|
|
31 version (LOGSEMANTIC) {
|
|
32 printf("NegExp::semantic('%s')\n", toChars());
|
|
33 }
|
|
34 if (!type)
|
|
35 {
|
|
36 UnaExp.semantic(sc);
|
|
37 e1 = resolveProperties(sc, e1);
|
|
38 e = op_overload(sc);
|
|
39 if (e)
|
|
40 return e;
|
|
41
|
|
42 e1.checkNoBool();
|
|
43 if (e1.op != TOKslice)
|
|
44 e1.checkArithmetic();
|
|
45
|
|
46 type = e1.type;
|
|
47 }
|
|
48 return this;
|
|
49 }
|
|
50
|
|
51 Expression optimize(int result)
|
|
52 {
|
|
53 Expression e;
|
|
54
|
|
55 e1 = e1.optimize(result);
|
|
56 if (e1.isConst() == 1)
|
|
57 {
|
|
58 e = Neg(type, e1);
|
|
59 }
|
|
60 else
|
|
61 e = this;
|
|
62
|
|
63 return e;
|
|
64 }
|
|
65
|
|
66 Expression interpret(InterState* istate)
|
|
67 {
|
|
68 assert(false);
|
|
69 }
|
|
70
|
|
71 void buildArrayIdent(OutBuffer buf, Expressions arguments)
|
|
72 {
|
|
73 assert(false);
|
|
74 }
|
|
75
|
|
76 Expression buildArrayLoop(Arguments fparams)
|
|
77 {
|
|
78 assert(false);
|
|
79 }
|
|
80
|
|
81 Identifier opId()
|
|
82 {
|
|
83 assert(false);
|
|
84 }
|
|
85
|
|
86 elem* toElem(IRState* irs)
|
|
87 {
|
|
88 elem *e = el_una(OPneg, type.totym(), e1.toElem(irs));
|
|
89 el_setLoc(e,loc);
|
|
90 return e;
|
|
91 }
|
|
92 }
|
|
93
|