annotate dmd/Catch.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Catch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 63
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
18 import dmd.TObject;
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
19
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
20 class Catch : TObject
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 Type type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 VarDeclaration var = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 Statement handler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this(Loc loc, Type t, Identifier id, Statement handler)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
30 register();
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 //printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.ident = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.handler = handler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 Catch syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
41 Catch c = new Catch(loc, (type ? type.syntaxCopy() : null), ident, (handler ? handler.syntaxCopy() : null));
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
42 return c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 void semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 ScopeDsymbol sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 //printf("Catch.semantic(%s)\n", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (sc.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 /* This is because the _d_local_unwind() gets the stack munged
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 * up on this. The workaround is to place any try-catches into
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 * a separate function, and call that.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 * To fix, have the compiler automatically convert the finally
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 * body into a nested function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 error(loc, "cannot put catch statement inside finally block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 sym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 sym.parent = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 sc = sc.push(sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 type = new TypeIdentifier(Loc(0), Id.Object_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 if (!type.toBasetype().isClassHandle())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 error("can only catch class objects, not '%s'", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 else if (ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 var = new VarDeclaration(loc, type, ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 var.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 sc.insert(var);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 handler = handler.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 BE blockExit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 return handler ? handler.blockExit() : BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
92 buf.writestring("catch");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
93 if (type)
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
94 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
95 buf.writebyte('(');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
96 type.toCBuffer(buf, ident, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
97 buf.writebyte(')');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
98 }
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
99 buf.writenl();
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
100 buf.writebyte('{');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
101 buf.writenl();
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
102 if (handler)
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
103 handler.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
104 buf.writebyte('}');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
105 buf.writenl();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }