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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
1 module dmd.StaticIfCondition;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
5 import dmd.ScopeDsymbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
6 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
7 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
8 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
9 import dmd.Condition;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.WANT;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
12 import dmd.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 class StaticIfCondition : Condition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
24 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
29 override Condition syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
31 return new StaticIfCondition(loc, exp.syntaxCopy());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
34 override bool include(Scope sc, ScopeDsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 printf("StaticIfCondition.include(sc = %p, s = %p)\n", sc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 printf("\ts = '%s', kind = %s\n", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 if (inc == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 if (!sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 error(loc, "static if conditional cannot be at global scope");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 sc = sc.push(sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 sc.sd = s; // s gets any addMember()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 sc.flags |= SCOPE.SCOPEstaticif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 Expression e = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 e = e.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 if (e.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 inc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 else if (e.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 e.error("expression %s is not constant or does not evaluate to a bool", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return (inc == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
71 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76