annotate dmd/expression/ArrayLength.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 10317f0c89a5
children 60bb0fe4563e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.expression.ArrayLength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 0
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.AssocArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 Expression ArrayLength(Type type, Expression e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 Loc loc = e1.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 if (e1.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 StringExp es1 = cast(StringExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 e = new IntegerExp(loc, es1.len, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 else if (e1.op == TOKarrayliteral)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 ArrayLiteralExp ale = cast(ArrayLiteralExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 size_t dim = ale.elements ? ale.elements.dim : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 e = new IntegerExp(loc, dim, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 else if (e1.op == TOKassocarrayliteral)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 AssocArrayLiteralExp ale = cast(AssocArrayLiteralExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 size_t dim = ale.keys.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 e = new IntegerExp(loc, dim, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 e = EXP_CANT_INTERPRET;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }