Mercurial > projects > ddmd
comparison dmd/ThrowStatement.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | a8b50ff7f201 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
1 module dmd.ThrowStatement; | |
2 | |
3 import dmd.Statement; | |
4 import dmd.Expression; | |
5 import dmd.Loc; | |
6 import dmd.IRState; | |
7 import dmd.InlineScanState; | |
8 import dmd.HdrGenState; | |
9 import dmd.OutBuffer; | |
10 import dmd.Scope; | |
11 import dmd.Expression; | |
12 import dmd.FuncDeclaration; | |
13 import dmd.BE; | |
14 | |
15 import dmd.backend.Util; | |
16 import dmd.backend.Blockx; | |
17 import dmd.backend.elem; | |
18 import dmd.backend.RTLSYM; | |
19 import dmd.backend.OPER; | |
20 import dmd.backend.TYM; | |
21 | |
22 class ThrowStatement : Statement | |
23 { | |
24 Expression exp; | |
25 | |
26 this(Loc loc, Expression exp) | |
27 { | |
28 super(loc); | |
29 this.exp = exp; | |
30 } | |
31 | |
32 Statement syntaxCopy() | |
33 { | |
34 assert(false); | |
35 } | |
36 | |
37 Statement semantic(Scope sc) | |
38 { | |
39 //printf("ThrowStatement::semantic()\n"); | |
40 | |
41 FuncDeclaration fd = sc.parent.isFuncDeclaration(); | |
42 fd.hasReturnExp |= 2; | |
43 | |
44 if (sc.incontract) | |
45 error("Throw statements cannot be in contracts"); | |
46 exp = exp.semantic(sc); | |
47 exp = resolveProperties(sc, exp); | |
48 if (!exp.type.toBasetype().isClassHandle()) | |
49 error("can only throw class objects, not type %s", exp.type.toChars()); | |
50 return this; | |
51 } | |
52 | |
53 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
54 { | |
55 assert(false); | |
56 } | |
57 | |
58 BE blockExit() | |
59 { | |
60 return BE.BEthrow; // obviously | |
61 } | |
62 | |
63 Statement inlineScan(InlineScanState* iss) | |
64 { | |
65 if (exp) | |
66 exp = exp.inlineScan(iss); | |
67 return this; | |
68 } | |
69 | |
70 void toIR(IRState* irs) | |
71 { | |
72 // throw(exp) | |
73 | |
74 Blockx *blx = irs.blx; | |
75 | |
76 incUsage(irs, loc); | |
77 elem *e = exp.toElem(irs); | |
78 static if (false) { | |
79 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_LTHROW]),e); | |
80 } else { | |
81 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_THROW]),e); | |
82 } | |
83 block_appendexp(blx.curblock, e); | |
84 } | |
85 } |