Mercurial > projects > ddmd
annotate dmd/StaticIfCondition.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
14 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
15 |
0 | 16 class StaticIfCondition : Condition |
17 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
18 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
19 |
0 | 20 Expression exp; |
21 | |
22 this(Loc loc, Expression exp) | |
23 { | |
178 | 24 register(); |
0 | 25 super(loc); |
26 this.exp = exp; | |
27 } | |
28 | |
72 | 29 override Condition syntaxCopy() |
0 | 30 { |
72 | 31 return new StaticIfCondition(loc, exp.syntaxCopy()); |
0 | 32 } |
33 | |
72 | 34 override bool include(Scope sc, ScopeDsymbol s) |
0 | 35 { |
36 static if (false) { | |
37 printf("StaticIfCondition.include(sc = %p, s = %p)\n", sc, s); | |
38 if (s) | |
39 { | |
40 printf("\ts = '%s', kind = %s\n", s.toChars(), s.kind()); | |
41 } | |
42 } | |
43 if (inc == 0) | |
44 { | |
45 if (!sc) | |
46 { | |
47 error(loc, "static if conditional cannot be at global scope"); | |
48 inc = 2; | |
49 return 0; | |
50 } | |
51 | |
52 sc = sc.push(sc.scopesym); | |
53 sc.sd = s; // s gets any addMember() | |
54 sc.flags |= SCOPE.SCOPEstaticif; | |
55 Expression e = exp.semantic(sc); | |
56 sc.pop(); | |
57 e = e.optimize(WANTvalue | WANTinterpret); | |
58 if (e.isBool(true)) | |
59 inc = 1; | |
60 else if (e.isBool(false)) | |
61 inc = 2; | |
62 else | |
63 { | |
64 e.error("expression %s is not constant or does not evaluate to a bool", e.toChars()); | |
65 inc = 2; | |
66 } | |
67 } | |
68 return (inc == 1); | |
69 } | |
70 | |
72 | 71 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 72 { |
73 assert(false); | |
74 } | |
75 } | |
76 |