Mercurial > projects > ddmd
annotate dmd/FuncExp.d @ 93:df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
and some additional ones I came across
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 22:50:30 +0200 |
parents | 2e2a5c3f943a |
children | e28b18c23469 |
rev | line source |
---|---|
72 | 1 module dmd.FuncExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.backend.elem; | |
5 import dmd.OutBuffer; | |
6 import dmd.Loc; | |
7 import dmd.Scope; | |
8 import dmd.InlineCostState; | |
9 import dmd.IRState; | |
10 import dmd.HdrGenState; | |
11 import dmd.FuncLiteralDeclaration; | |
0 | 12 import dmd.TOK; |
13 import dmd.TypeFunction; | |
14 import dmd.TypeDelegate; | |
15 import dmd.TY; | |
16 import dmd.Type; | |
17 import dmd.Global; | |
18 | |
19 import dmd.backend.Util; | |
20 import dmd.codegen.Util; | |
21 import dmd.backend.TYM; | |
72 | 22 import dmd.backend.Symbol; |
23 | |
0 | 24 class FuncExp : Expression |
25 { | |
26 FuncLiteralDeclaration fd; | |
27 | |
28 this(Loc loc, FuncLiteralDeclaration fd) | |
29 { | |
30 super(loc, TOK.TOKfunction, FuncExp.sizeof); | |
31 this.fd = fd; | |
32 } | |
33 | |
72 | 34 override Expression syntaxCopy() |
0 | 35 { |
56 | 36 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null)); |
0 | 37 } |
38 | |
72 | 39 override Expression semantic(Scope sc) |
0 | 40 { |
41 version (LOGSEMANTIC) { | |
42 printf("FuncExp.semantic(%s)\n", toChars()); | |
43 } | |
44 if (!type) | |
45 { | |
46 fd.semantic(sc); | |
47 | |
48 //fd.parent = sc.parent; | |
49 if (global.errors) | |
50 { | |
51 } | |
52 else | |
53 { | |
54 fd.semantic2(sc); | |
55 if (!global.errors || | |
56 // need to infer return type | |
57 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())) | |
58 { | |
59 fd.semantic3(sc); | |
60 | |
61 if (!global.errors && global.params.useInline) | |
62 fd.inlineScan(); | |
63 } | |
64 } | |
65 | |
66 // need to infer return type | |
67 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()) | |
68 (cast(TypeFunction)fd.type).next = Type.terror; | |
69 | |
70 // Type is a "delegate to" or "pointer to" the function literal | |
71 if (fd.isNested()) | |
72 { | |
73 type = new TypeDelegate(fd.type); | |
74 type = type.semantic(loc, sc); | |
75 } | |
76 else | |
77 { | |
78 type = fd.type.pointerTo(); | |
79 } | |
80 | |
81 fd.tookAddressOf++; | |
82 } | |
83 | |
84 return this; | |
85 } | |
86 | |
72 | 87 override void scanForNestedRef(Scope sc) |
0 | 88 { |
89 assert(false); | |
90 } | |
91 | |
72 | 92 override string toChars() |
0 | 93 { |
58 | 94 return fd.toChars(); |
0 | 95 } |
96 | |
72 | 97 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 98 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
72
diff
changeset
|
99 fd.toCBuffer(buf, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
72
diff
changeset
|
100 //buf.writestring(fd.toChars()); |
0 | 101 } |
102 | |
72 | 103 override elem* toElem(IRState* irs) |
0 | 104 { |
105 elem* e; | |
106 Symbol* s; | |
107 | |
108 //printf("FuncExp::toElem() %s\n", toChars()); | |
109 s = fd.toSymbol(); | |
110 e = el_ptr(s); | |
111 if (fd.isNested()) | |
112 { | |
113 elem* ethis = getEthis(loc, irs, fd); | |
114 e = el_pair(TYM.TYullong, ethis, e); | |
115 } | |
116 | |
117 irs.deferToObj.push(cast(void*)fd); | |
118 el_setLoc(e,loc); | |
119 return e; | |
120 } | |
121 | |
72 | 122 override int inlineCost(InlineCostState* ics) |
0 | 123 { |
124 assert(false); | |
125 } | |
126 } | |
127 |