Mercurial > projects > ddmd
annotate dmd/ConditionalStatement.d @ 168:ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
author | korDen |
---|---|
date | Thu, 30 Sep 2010 12:57:13 +0400 |
parents | c77e9f4f1793 |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.ConditionalStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Statement; |
5 import dmd.Condition; | |
6 import dmd.Loc; | |
7 import dmd.OutBuffer; | |
8 import dmd.Scope; | |
9 import dmd.HdrGenState; | |
10 import dmd.ArrayTypes; | |
11 import dmd.BE; | |
12 | |
13 class ConditionalStatement : Statement | |
14 { | |
15 Condition condition; | |
16 Statement ifbody; | |
17 Statement elsebody; | |
18 | |
19 this(Loc loc, Condition condition, Statement ifbody, Statement elsebody) | |
20 { | |
21 super(loc); | |
22 this.condition = condition; | |
23 this.ifbody = ifbody; | |
24 this.elsebody = elsebody; | |
25 } | |
26 | |
72 | 27 override Statement syntaxCopy() |
0 | 28 { |
49 | 29 Statement e = null; |
30 if (elsebody) | |
31 e = elsebody.syntaxCopy(); | |
32 ConditionalStatement s = new ConditionalStatement(loc, condition.syntaxCopy(), ifbody.syntaxCopy(), e); | |
33 return s; | |
0 | 34 } |
35 | |
72 | 36 override Statement semantic(Scope sc) |
0 | 37 { |
64 | 38 //printf("ConditionalStatement.semantic()\n"); |
39 | |
40 // If we can short-circuit evaluate the if statement, don't do the | |
41 // semantic analysis of the skipped code. | |
42 // This feature allows a limited form of conditional compilation. | |
43 if (condition.include(sc, null)) | |
44 { | |
45 ifbody = ifbody.semantic(sc); | |
46 return ifbody; | |
47 } | |
48 else | |
49 { | |
50 if (elsebody) | |
51 elsebody = elsebody.semantic(sc); | |
52 return elsebody; | |
53 } | |
0 | 54 } |
55 | |
72 | 56 override Statements flatten(Scope sc) |
0 | 57 { |
58 Statement s; | |
59 | |
60 if (condition.include(sc, null)) | |
61 s = ifbody; | |
62 else | |
63 s = elsebody; | |
64 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
65 auto a = new Statements(); |
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
66 a.push(s); |
0 | 67 |
68 return a; | |
69 } | |
70 | |
72 | 71 override bool usesEH() |
0 | 72 { |
73 assert(false); | |
74 } | |
75 | |
72 | 76 override BE blockExit() |
0 | 77 { |
78 assert(false); | |
79 } | |
80 | |
72 | 81 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 82 { |
83 assert(false); | |
84 } | |
72 | 85 } |