annotate dmd/StaticIfCondition.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children e3afd1303184
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
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 class StaticIfCondition : Condition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
24 override Condition syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
26 return new StaticIfCondition(loc, exp.syntaxCopy());
0
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 bool include(Scope sc, ScopeDsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 printf("StaticIfCondition.include(sc = %p, s = %p)\n", sc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 printf("\ts = '%s', kind = %s\n", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 if (inc == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 if (!sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 error(loc, "static if conditional cannot be at global scope");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 sc = sc.push(sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 sc.sd = s; // s gets any addMember()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 sc.flags |= SCOPE.SCOPEstaticif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 Expression e = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 e = e.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (e.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 inc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 else if (e.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 e.error("expression %s is not constant or does not evaluate to a bool", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 return (inc == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
66 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71