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