annotate dmd/StaticIfCondition.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 1628b221808d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.StaticIfCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 class StaticIfCondition : Condition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 Condition syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 bool include(Scope sc, ScopeDsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 printf("StaticIfCondition.include(sc = %p, s = %p)\n", sc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 printf("\ts = '%s', kind = %s\n", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 if (inc == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 if (!sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 error(loc, "static if conditional cannot be at global scope");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 sc = sc.push(sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 sc.sd = s; // s gets any addMember()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 sc.flags |= SCOPE.SCOPEstaticif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Expression e = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 e = e.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (e.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 inc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 else if (e.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 e.error("expression %s is not constant or does not evaluate to a bool", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 return (inc == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70