0
|
1 module dmd.expression.ArrayLength;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Type;
|
|
5 import dmd.Expression;
|
|
6 import dmd.StringExp;
|
|
7 import dmd.IntegerExp;
|
|
8 import dmd.ArrayLiteralExp;
|
|
9 import dmd.Loc;
|
|
10 import dmd.TOK;
|
|
11 import dmd.AssocArrayLiteralExp;
|
|
12 import dmd.GlobalExpressions;
|
|
13
|
|
14 Expression ArrayLength(Type type, Expression e1)
|
|
15 {
|
|
16 Expression e;
|
|
17 Loc loc = e1.loc;
|
|
18
|
|
19 if (e1.op == TOKstring)
|
|
20 {
|
|
21 StringExp es1 = cast(StringExp)e1;
|
|
22 e = new IntegerExp(loc, es1.len, type);
|
|
23 }
|
|
24 else if (e1.op == TOKarrayliteral)
|
|
25 {
|
|
26 ArrayLiteralExp ale = cast(ArrayLiteralExp)e1;
|
|
27 size_t dim = ale.elements ? ale.elements.dim : 0;
|
|
28 e = new IntegerExp(loc, dim, type);
|
|
29 }
|
|
30 else if (e1.op == TOKassocarrayliteral)
|
|
31 {
|
|
32 AssocArrayLiteralExp ale = cast(AssocArrayLiteralExp)e1;
|
|
33 size_t dim = ale.keys.dim;
|
|
34 e = new IntegerExp(loc, dim, type);
|
|
35 }
|
|
36 else
|
|
37 e = EXP_CANT_INTERPRET;
|
|
38
|
|
39 return e;
|
|
40 } |