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