annotate dmd/Catch.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents cab4c37afb89
children af724d3510d7
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 class Catch
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 Type type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 VarDeclaration var = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 Statement handler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this(Loc loc, Type t, Identifier id, Statement handler)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 //printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this.ident = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this.handler = handler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 Catch syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
37 Catch c = new Catch(loc, (type ? type.syntaxCopy() : null), ident, (handler ? handler.syntaxCopy() : null));
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
38 return c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 void semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 ScopeDsymbol sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 //printf("Catch.semantic(%s)\n", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 if (sc.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 /* This is because the _d_local_unwind() gets the stack munged
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 * up on this. The workaround is to place any try-catches into
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 * a separate function, and call that.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 * To fix, have the compiler automatically convert the finally
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 * body into a nested function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 error(loc, "cannot put catch statement inside finally block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 sym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 sym.parent = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 sc = sc.push(sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 type = new TypeIdentifier(Loc(0), Id.Object_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (!type.toBasetype().isClassHandle())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 error("can only catch class objects, not '%s'", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 else if (ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 var = new VarDeclaration(loc, type, ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 var.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 sc.insert(var);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 handler = handler.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 BE blockExit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return handler ? handler.blockExit() : BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }