0
|
1 module dmd.Catch;
|
|
2
|
|
3 import dmd.Loc;
|
|
4 import dmd.Type;
|
|
5 import dmd.Scope;
|
|
6 import dmd.Identifier;
|
|
7 import dmd.VarDeclaration;
|
|
8 import dmd.Statement;
|
|
9 import dmd.OutBuffer;
|
|
10 import dmd.Id;
|
|
11 import dmd.TypeIdentifier;
|
|
12 import dmd.Util;
|
|
13 import dmd.ScopeDsymbol;
|
|
14 import dmd.HdrGenState;
|
|
15 import dmd.BE;
|
|
16
|
|
17 class Catch
|
|
18 {
|
|
19 Loc loc;
|
|
20 Type type;
|
|
21 Identifier ident;
|
|
22 VarDeclaration var = null;
|
|
23 Statement handler;
|
|
24
|
|
25 this(Loc loc, Type t, Identifier id, Statement handler)
|
|
26 {
|
|
27 //printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars());
|
|
28 this.loc = loc;
|
|
29 this.type = t;
|
|
30 this.ident = id;
|
|
31 this.handler = handler;
|
|
32 }
|
|
33
|
|
34 Catch syntaxCopy()
|
|
35 {
|
63
|
36 Catch c = new Catch(loc, (type ? type.syntaxCopy() : null), ident, (handler ? handler.syntaxCopy() : null));
|
|
37 return c;
|
0
|
38 }
|
|
39
|
|
40 void semantic(Scope sc)
|
|
41 {
|
|
42 ScopeDsymbol sym;
|
|
43
|
|
44 //printf("Catch.semantic(%s)\n", ident.toChars());
|
|
45
|
|
46 version (IN_GCC) {
|
|
47 } else {
|
|
48 if (sc.tf)
|
|
49 {
|
|
50 /* This is because the _d_local_unwind() gets the stack munged
|
|
51 * up on this. The workaround is to place any try-catches into
|
|
52 * a separate function, and call that.
|
|
53 * To fix, have the compiler automatically convert the finally
|
|
54 * body into a nested function.
|
|
55 */
|
|
56 error(loc, "cannot put catch statement inside finally block");
|
|
57 }
|
|
58 }
|
|
59
|
|
60 sym = new ScopeDsymbol();
|
|
61 sym.parent = sc.scopesym;
|
|
62 sc = sc.push(sym);
|
|
63
|
|
64 if (!type)
|
|
65 type = new TypeIdentifier(Loc(0), Id.Object_);
|
|
66 type = type.semantic(loc, sc);
|
|
67 if (!type.toBasetype().isClassHandle())
|
|
68 error("can only catch class objects, not '%s'", type.toChars());
|
|
69 else if (ident)
|
|
70 {
|
|
71 var = new VarDeclaration(loc, type, ident, null);
|
|
72 var.parent = sc.parent;
|
|
73 sc.insert(var);
|
|
74 }
|
|
75 handler = handler.semantic(sc);
|
|
76
|
|
77 sc.pop();
|
|
78 }
|
|
79
|
|
80 BE blockExit()
|
|
81 {
|
|
82 return handler ? handler.blockExit() : BE.BEfallthru;
|
|
83 }
|
|
84
|
|
85 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
86 {
|
|
87 assert(false);
|
|
88 }
|
|
89 } |