annotate dmd/FuncLiteralDeclaration.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 e28b18c23469
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.FuncLiteralDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 93
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ForeachStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 class FuncLiteralDeclaration : FuncDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 TOK tok; // TOKfunction or TOKdelegate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 this(Loc loc, Loc endloc, Type type, TOK tok, ForeachStatement fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
21 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 super(loc, endloc, null, STC.STCundefined, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 string id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 if (fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 id = "__foreachbody";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 else if (tok == TOK.TOKdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 id = "__dgliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 id = "__funcliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 this.ident = Lexer.uniqueId(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.fes = fes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 //printf("FuncLiteralDeclaration() id = '%s', type = '%s'\n", this->ident->toChars(), type->toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
40 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
42 buf.writestring(kind());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
43 buf.writeByte(' ');
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
44 type.toCBuffer(buf, null, hgs);
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
45 bodyToCBuffer(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
48 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
50 FuncLiteralDeclaration f;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
51
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
52 //printf("FuncLiteralDeclaration.syntaxCopy('%s')\n", toChars());
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
53 if (s)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
54 f = cast(FuncLiteralDeclaration)s;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
55 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
56 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
57 f = new FuncLiteralDeclaration(loc, endloc, type.syntaxCopy(), tok, fes);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
58 f.ident = ident; // keep old identifier
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
59 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
60 FuncDeclaration.syntaxCopy(f);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
61 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
64 override bool isNested()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 //printf("FuncLiteralDeclaration::isNested() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 return (tok == TOK.TOKdelegate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
70 override bool isVirtual()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
75 override FuncLiteralDeclaration isFuncLiteralDeclaration() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
77 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return (tok == TOKdelegate) ? "delegate" : "function";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
81 }