72
|
1 module dmd.ArrayLengthExp;
|
|
2
|
114
|
3 import dmd.common;
|
72
|
4 import dmd.Expression;
|
|
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.HdrGenState;
|
0
|
13 import dmd.TOK;
|
|
14 import dmd.Type;
|
|
15 import dmd.WANT;
|
|
16
|
|
17 import dmd.expression.ArrayLength;
|
|
18
|
|
19 import dmd.backend.Util;
|
72
|
20 import dmd.backend.OPER;
|
|
21
|
0
|
22 class ArrayLengthExp : UnaExp
|
|
23 {
|
|
24 this(Loc loc, Expression e1)
|
|
25 {
|
|
26 super(loc, TOK.TOKarraylength, ArrayLengthExp.sizeof, e1);
|
|
27 }
|
|
28
|
72
|
29 override Expression semantic(Scope sc)
|
0
|
30 {
|
|
31 Expression e;
|
|
32
|
|
33 version (LOGSEMANTIC) {
|
|
34 printf("ArrayLengthExp::semantic('%s')\n", toChars());
|
|
35 }
|
|
36 if (!type)
|
|
37 {
|
|
38 UnaExp.semantic(sc);
|
|
39 e1 = resolveProperties(sc, e1);
|
|
40
|
|
41 type = Type.tsize_t;
|
|
42 }
|
|
43 return this;
|
|
44 }
|
|
45
|
72
|
46 override Expression optimize(int result)
|
0
|
47 {
|
|
48 //printf("ArrayLengthExp::optimize(result = %d) %s\n", result, toChars());
|
|
49 e1 = e1.optimize(WANTvalue | (result & WANTinterpret));
|
|
50 Expression e = this;
|
|
51 if (e1.op == TOKstring || e1.op == TOKarrayliteral || e1.op == TOKassocarrayliteral)
|
|
52 {
|
|
53 e = ArrayLength(type, e1);
|
|
54 }
|
|
55 return e;
|
|
56 }
|
|
57
|
72
|
58 override Expression interpret(InterState istate)
|
0
|
59 {
|
|
60 assert(false);
|
|
61 }
|
|
62
|
72
|
63 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
64 {
|
|
65 assert(false);
|
|
66 }
|
|
67
|
72
|
68 override elem* toElem(IRState* irs)
|
0
|
69 {
|
|
70 elem *e = e1.toElem(irs);
|
|
71 e = el_una(OP64_32, type.totym(), e);
|
|
72 el_setLoc(e,loc);
|
|
73 return e;
|
|
74 }
|
|
75 }
|
|
76
|