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