annotate dmd/DoStatement.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 a43c65469219
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.DoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 class DoStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 Expression condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this(Loc loc, Statement b, Expression c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 body_ = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 condition = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
33 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 DoStatement s = new DoStatement(loc, body_ ? body_.syntaxCopy() : null, condition.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
39 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 sc.noctor++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 body_ = body_.semanticScope(sc, this, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 sc.noctor--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 condition = condition.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 condition = resolveProperties(sc, condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 condition = condition.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 condition = condition.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
54 override bool hasBreak()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
59 override bool hasContinue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
64 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return body_ ? body_.usesEH() : false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
69 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 BE result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 result = body_.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 if (result == BE.BEbreak)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (result & BE.BEcontinue)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 result = BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 if (result & BE.BEfallthru)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if (condition.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (!(result & BE.BEbreak) && condition.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 result &= ~BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 result &= ~(BE.BEbreak | BE.BEcontinue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
96 override bool comeFrom()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
101 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
106 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
111 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 body_ = body_ ? body_.inlineScan(iss) : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 condition = condition.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
118 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 Blockx *blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 IRState mystate = IRState(irs,this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 mystate.breakBlock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 mystate.contBlock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 block* bpre = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 block_next(blx, BCgoto, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 list_append(&bpre.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 list_append(&mystate.contBlock.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 list_append(&mystate.contBlock.Bsucc, mystate.breakBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 body_.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 list_append(&blx.curblock.Bsucc, mystate.contBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 block_next(blx, BCgoto, mystate.contBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 incUsage(irs, condition.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 block_appendexp(mystate.contBlock, condition.toElem(&mystate));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 block_next(blx, BCiftrue, mystate.breakBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
142 }