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