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 {
|
|
36 assert(false);
|
|
37 }
|
|
38
|
|
39 void semantic(Scope sc)
|
|
40 {
|
|
41 ScopeDsymbol sym;
|
|
42
|
|
43 //printf("Catch.semantic(%s)\n", ident.toChars());
|
|
44
|
|
45 version (IN_GCC) {
|
|
46 } else {
|
|
47 if (sc.tf)
|
|
48 {
|
|
49 /* This is because the _d_local_unwind() gets the stack munged
|
|
50 * up on this. The workaround is to place any try-catches into
|
|
51 * a separate function, and call that.
|
|
52 * To fix, have the compiler automatically convert the finally
|
|
53 * body into a nested function.
|
|
54 */
|
|
55 error(loc, "cannot put catch statement inside finally block");
|
|
56 }
|
|
57 }
|
|
58
|
|
59 sym = new ScopeDsymbol();
|
|
60 sym.parent = sc.scopesym;
|
|
61 sc = sc.push(sym);
|
|
62
|
|
63 if (!type)
|
|
64 type = new TypeIdentifier(Loc(0), Id.Object_);
|
|
65 type = type.semantic(loc, sc);
|
|
66 if (!type.toBasetype().isClassHandle())
|
|
67 error("can only catch class objects, not '%s'", type.toChars());
|
|
68 else if (ident)
|
|
69 {
|
|
70 var = new VarDeclaration(loc, type, ident, null);
|
|
71 var.parent = sc.parent;
|
|
72 sc.insert(var);
|
|
73 }
|
|
74 handler = handler.semantic(sc);
|
|
75
|
|
76 sc.pop();
|
|
77 }
|
|
78
|
|
79 BE blockExit()
|
|
80 {
|
|
81 return handler ? handler.blockExit() : BE.BEfallthru;
|
|
82 }
|
|
83
|
|
84 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
85 {
|
|
86 assert(false);
|
|
87 }
|
|
88 } |