Mercurial > projects > ddmd
annotate dmd/ThrowStatement.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | e28b18c23469 |
children | af724d3510d7 |
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 | |
23 class ThrowStatement : Statement | |
24 { | |
25 Expression exp; | |
26 | |
27 this(Loc loc, Expression exp) | |
28 { | |
29 super(loc); | |
30 this.exp = exp; | |
31 } | |
32 | |
72 | 33 override Statement syntaxCopy() |
0 | 34 { |
53 | 35 ThrowStatement s = new ThrowStatement(loc, exp.syntaxCopy()); |
36 return s; | |
0 | 37 } |
38 | |
72 | 39 override Statement semantic(Scope sc) |
0 | 40 { |
41 //printf("ThrowStatement::semantic()\n"); | |
42 | |
43 FuncDeclaration fd = sc.parent.isFuncDeclaration(); | |
44 fd.hasReturnExp |= 2; | |
45 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
46 version(DMDV1) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
47 // See bugzilla 3388. Should this be or not? |
0 | 48 if (sc.incontract) |
49 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
|
50 } |
0 | 51 exp = exp.semantic(sc); |
52 exp = resolveProperties(sc, exp); | |
53 if (!exp.type.toBasetype().isClassHandle()) | |
54 error("can only throw class objects, not type %s", exp.type.toChars()); | |
55 return this; | |
56 } | |
57 | |
72 | 58 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 59 { |
60 assert(false); | |
61 } | |
62 | |
72 | 63 override BE blockExit() |
0 | 64 { |
65 return BE.BEthrow; // obviously | |
66 } | |
67 | |
72 | 68 override Statement inlineScan(InlineScanState* iss) |
0 | 69 { |
70 if (exp) | |
71 exp = exp.inlineScan(iss); | |
72 return this; | |
73 } | |
74 | |
72 | 75 override void toIR(IRState* irs) |
0 | 76 { |
77 // throw(exp) | |
78 | |
79 Blockx *blx = irs.blx; | |
80 | |
81 incUsage(irs, loc); | |
82 elem *e = exp.toElem(irs); | |
83 static if (false) { | |
84 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_LTHROW]),e); | |
85 } else { | |
86 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_THROW]),e); | |
87 } | |
88 block_appendexp(blx.curblock, e); | |
89 } | |
72 | 90 } |