Mercurial > projects > ddmd
annotate dmd/ThrowStatement.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 |
rev | line source |
---|---|
0 | 1 module dmd.ThrowStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Statement; |
5 import dmd.Expression; | |
6 import dmd.Loc; | |
7 import dmd.IRState; | |
8 import dmd.InlineScanState; | |
9 import dmd.HdrGenState; | |
10 import dmd.OutBuffer; | |
11 import dmd.Scope; | |
12 import dmd.Expression; | |
13 import dmd.FuncDeclaration; | |
14 import dmd.BE; | |
15 | |
16 import dmd.backend.Util; | |
17 import dmd.backend.Blockx; | |
18 import dmd.backend.elem; | |
19 import dmd.backend.RTLSYM; | |
20 import dmd.backend.OPER; | |
21 import dmd.backend.TYM; | |
22 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 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
|
24 |
0 | 25 class ThrowStatement : Statement |
26 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 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
|
28 |
0 | 29 Expression exp; |
30 | |
31 this(Loc loc, Expression exp) | |
32 { | |
178 | 33 register(); |
0 | 34 super(loc); |
35 this.exp = exp; | |
36 } | |
37 | |
72 | 38 override Statement syntaxCopy() |
0 | 39 { |
53 | 40 ThrowStatement s = new ThrowStatement(loc, exp.syntaxCopy()); |
41 return s; | |
0 | 42 } |
43 | |
72 | 44 override Statement semantic(Scope sc) |
0 | 45 { |
46 //printf("ThrowStatement::semantic()\n"); | |
47 | |
48 FuncDeclaration fd = sc.parent.isFuncDeclaration(); | |
49 fd.hasReturnExp |= 2; | |
50 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
51 version(DMDV1) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
52 // See bugzilla 3388. Should this be or not? |
0 | 53 if (sc.incontract) |
54 error("Throw statements cannot be in contracts"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
55 } |
0 | 56 exp = exp.semantic(sc); |
57 exp = resolveProperties(sc, exp); | |
58 if (!exp.type.toBasetype().isClassHandle()) | |
59 error("can only throw class objects, not type %s", exp.type.toChars()); | |
60 return this; | |
61 } | |
62 | |
72 | 63 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 64 { |
174 | 65 buf.printf("throw "); |
66 exp.toCBuffer(buf, hgs); | |
67 buf.writeByte(';'); | |
68 buf.writenl(); | |
0 | 69 } |
70 | |
72 | 71 override BE blockExit() |
0 | 72 { |
73 return BE.BEthrow; // obviously | |
74 } | |
75 | |
72 | 76 override Statement inlineScan(InlineScanState* iss) |
0 | 77 { |
78 if (exp) | |
79 exp = exp.inlineScan(iss); | |
80 return this; | |
81 } | |
82 | |
72 | 83 override void toIR(IRState* irs) |
0 | 84 { |
85 // throw(exp) | |
86 | |
87 Blockx *blx = irs.blx; | |
88 | |
89 incUsage(irs, loc); | |
90 elem *e = exp.toElem(irs); | |
91 static if (false) { | |
92 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_LTHROW]),e); | |
93 } else { | |
94 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_THROW]),e); | |
95 } | |
96 block_appendexp(blx.curblock, e); | |
97 } | |
72 | 98 } |