annotate dmd/FuncLiteralDeclaration.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children
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
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
15 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
16
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 class FuncLiteralDeclaration : FuncDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
19 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
20
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 TOK tok; // TOKfunction or TOKdelegate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 this(Loc loc, Loc endloc, Type type, TOK tok, ForeachStatement fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
25 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 super(loc, endloc, null, STC.STCundefined, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 string id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 if (fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 id = "__foreachbody";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 else if (tok == TOK.TOKdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 id = "__dgliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 id = "__funcliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this.ident = Lexer.uniqueId(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 this.fes = fes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 //printf("FuncLiteralDeclaration() id = '%s', type = '%s'\n", this->ident->toChars(), type->toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
44 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
46 buf.writestring(kind());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
47 buf.writeByte(' ');
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
48 type.toCBuffer(buf, null, hgs);
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
49 bodyToCBuffer(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
52 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
54 FuncLiteralDeclaration f;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
55
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
56 //printf("FuncLiteralDeclaration.syntaxCopy('%s')\n", toChars());
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
57 if (s)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
58 f = cast(FuncLiteralDeclaration)s;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
59 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
60 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
61 f = new FuncLiteralDeclaration(loc, endloc, type.syntaxCopy(), tok, fes);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
62 f.ident = ident; // keep old identifier
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
63 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
64 FuncDeclaration.syntaxCopy(f);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
65 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
68 override bool isNested()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 //printf("FuncLiteralDeclaration::isNested() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 return (tok == TOK.TOKdelegate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
74 override bool isVirtual()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
79 override FuncLiteralDeclaration isFuncLiteralDeclaration() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
81 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return (tok == TOKdelegate) ? "delegate" : "function";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 56
diff changeset
85 }