annotate dmd/ThrowStatement.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents 60bb0fe4563e
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ThrowStatement;
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.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.InlineScanState;
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.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 class ThrowStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this.exp = exp;
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: 53
diff changeset
33 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 0
diff changeset
35 ThrowStatement s = new ThrowStatement(loc, exp.syntaxCopy());
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 0
diff changeset
36 return s;
0
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: 53
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 //printf("ThrowStatement::semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 fd.hasReturnExp |= 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 if (sc.incontract)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 exp = resolveProperties(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (!exp.type.toBasetype().isClassHandle())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 error("can only throw class objects, not type %s", exp.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
58 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
60 buf.printf("throw ");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
61 exp.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
62 buf.writeByte(';');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
63 buf.writenl();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
66 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return BE.BEthrow; // obviously
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
71 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 exp = exp.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
78 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 // throw(exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Blockx *blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 elem *e = exp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_LTHROW]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_THROW]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 block_appendexp(blx.curblock, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
93 }