Mercurial > projects > ddmd
annotate dmd/VolatileStatement.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | af724d3510d7 |
children | b0d41ff5e0df |
rev | line source |
---|---|
0 | 1 module dmd.VolatileStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Statement; |
5 import dmd.ArrayTypes; | |
6 import dmd.Scope; | |
7 import dmd.Loc; | |
8 import dmd.OutBuffer; | |
9 import dmd.HdrGenState; | |
10 import dmd.InlineScanState; | |
11 import dmd.IRState; | |
12 import dmd.BE; | |
13 | |
14 import dmd.backend.block; | |
15 import dmd.backend.Blockx; | |
16 import dmd.backend.Util; | |
17 import dmd.backend.BC; | |
140 | 18 import dmd.backend.elem; |
19 import dmd.backend.OPER; | |
20 import dmd.backend.mTY; | |
0 | 21 //import dmd.backend.BFL; |
22 | |
23 class VolatileStatement : Statement | |
24 { | |
25 Statement statement; | |
26 | |
27 this(Loc loc, Statement statement) | |
28 { | |
178 | 29 register(); |
0 | 30 super(loc); |
31 this.statement = statement; | |
32 } | |
33 | |
72 | 34 override Statement syntaxCopy() |
0 | 35 { |
36 assert(false); | |
37 } | |
38 | |
72 | 39 override Statement semantic(Scope sc) |
0 | 40 { |
41 if (statement) | |
42 statement = statement.semantic(sc); | |
43 return this; | |
44 } | |
45 | |
72 | 46 override Statements flatten(Scope sc) |
0 | 47 { |
48 Statements a = statement ? statement.flatten(sc) : null; | |
49 if (a) | |
50 { | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
51 foreach (ref Statement s; a) |
0 | 52 { |
53 s = new VolatileStatement(loc, s); | |
54 } | |
55 } | |
56 | |
57 return a; | |
58 } | |
59 | |
72 | 60 override BE blockExit() |
0 | 61 { |
62 return statement ? statement.blockExit() : BE.BEfallthru; | |
63 } | |
64 | |
72 | 65 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 66 { |
174 | 67 buf.writestring("volatile"); |
68 if (statement) | |
69 { | |
70 if (statement.isScopeStatement()) | |
71 buf.writenl(); | |
72 else | |
73 buf.writebyte(' '); | |
74 statement.toCBuffer(buf, hgs); | |
75 } | |
0 | 76 } |
77 | |
72 | 78 override Statement inlineScan(InlineScanState* iss) |
0 | 79 { |
80 if (statement) | |
81 statement = statement.inlineScan(iss); | |
82 return this; | |
83 } | |
84 | |
140 | 85 static void el_setVolatile(elem* e) |
86 { | |
87 while (1) | |
88 { | |
89 e.Ety |= mTYvolatile; | |
90 if (OTunary(e.Eoper)) | |
91 e = e.E1; | |
92 else if (OTbinary(e.Eoper)) | |
93 { | |
94 el_setVolatile(e.E2); | |
95 e = e.E1; | |
96 } | |
97 else | |
98 break; | |
99 } | |
100 } | |
101 | |
72 | 102 override void toIR(IRState* irs) |
0 | 103 { |
104 block* b; | |
105 | |
106 if (statement) | |
107 { | |
108 Blockx* blx = irs.blx; | |
109 | |
110 block_goto(blx, BCgoto, null); | |
111 b = blx.curblock; | |
112 | |
113 statement.toIR(irs); | |
114 | |
115 block_goto(blx, BCgoto, null); | |
116 | |
117 // Mark the blocks generated as volatile | |
118 for (; b != blx.curblock; b = b.Bnext) | |
119 { | |
120 b.Bflags |= BFL.BFLvolatile; | |
121 if (b.Belem) | |
122 el_setVolatile(b.Belem); | |
123 } | |
124 } | |
125 } | |
72 | 126 } |