0
|
1 module dmd.FuncLiteralDeclaration;
|
|
2
|
|
3 import dmd.FuncDeclaration;
|
|
4 import dmd.TOK;
|
|
5 import dmd.Loc;
|
|
6 import dmd.Type;
|
|
7 import dmd.ForeachStatement;
|
|
8 import dmd.OutBuffer;
|
|
9 import dmd.HdrGenState;
|
|
10 import dmd.Dsymbol;
|
|
11 import dmd.STC;
|
|
12 import dmd.Lexer;
|
|
13
|
|
14 class FuncLiteralDeclaration : FuncDeclaration
|
|
15 {
|
|
16 TOK tok; // TOKfunction or TOKdelegate
|
|
17
|
|
18 this(Loc loc, Loc endloc, Type type, TOK tok, ForeachStatement fes)
|
|
19 {
|
|
20 super(loc, endloc, null, STC.STCundefined, type);
|
|
21
|
|
22 string id;
|
|
23
|
|
24 if (fes)
|
|
25 id = "__foreachbody";
|
|
26 else if (tok == TOK.TOKdelegate)
|
|
27 id = "__dgliteral";
|
|
28 else
|
|
29 id = "__funcliteral";
|
|
30
|
|
31 this.ident = Lexer.uniqueId(id);
|
|
32 this.tok = tok;
|
|
33 this.fes = fes;
|
|
34
|
|
35 //printf("FuncLiteralDeclaration() id = '%s', type = '%s'\n", this->ident->toChars(), type->toChars());
|
|
36 }
|
|
37
|
|
38 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
39 {
|
|
40 assert(false);
|
|
41 }
|
|
42
|
56
|
43 Dsymbol syntaxCopy(Dsymbol s)
|
0
|
44 {
|
56
|
45 FuncLiteralDeclaration f;
|
|
46
|
|
47 //printf("FuncLiteralDeclaration.syntaxCopy('%s')\n", toChars());
|
|
48 if (s)
|
|
49 f = cast(FuncLiteralDeclaration)s;
|
|
50 else
|
|
51 {
|
|
52 f = new FuncLiteralDeclaration(loc, endloc, type.syntaxCopy(), tok, fes);
|
|
53 f.ident = ident; // keep old identifier
|
|
54 }
|
|
55 FuncDeclaration.syntaxCopy(f);
|
|
56 return f;
|
0
|
57 }
|
|
58
|
|
59 bool isNested()
|
|
60 {
|
|
61 //printf("FuncLiteralDeclaration::isNested() '%s'\n", toChars());
|
|
62 return (tok == TOK.TOKdelegate);
|
|
63 }
|
|
64
|
|
65 bool isVirtual()
|
|
66 {
|
|
67 return false;
|
|
68 }
|
|
69
|
|
70 FuncLiteralDeclaration isFuncLiteralDeclaration() { return this; }
|
|
71
|
|
72 string kind()
|
|
73 {
|
|
74 return (tok == TOKdelegate) ? "delegate" : "function";
|
|
75 }
|
|
76 } |