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