Mercurial > projects > ddmd
annotate dmd/FuncExp.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 | cd48cb899aee |
children | eb38fdcb3e62 |
rev | line source |
---|---|
72 | 1 module dmd.FuncExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.backend.elem; | |
6 import dmd.OutBuffer; | |
7 import dmd.Loc; | |
8 import dmd.Scope; | |
9 import dmd.InlineCostState; | |
179 | 10 import dmd.InterState; |
72 | 11 import dmd.IRState; |
12 import dmd.HdrGenState; | |
13 import dmd.FuncLiteralDeclaration; | |
0 | 14 import dmd.TOK; |
15 import dmd.TypeFunction; | |
16 import dmd.TypeDelegate; | |
17 import dmd.TY; | |
18 import dmd.Type; | |
19 import dmd.Global; | |
20 | |
21 import dmd.backend.Util; | |
22 import dmd.codegen.Util; | |
23 import dmd.backend.TYM; | |
72 | 24 import dmd.backend.Symbol; |
25 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
26 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
27 |
0 | 28 class FuncExp : Expression |
29 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
30 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
31 |
0 | 32 FuncLiteralDeclaration fd; |
33 | |
34 this(Loc loc, FuncLiteralDeclaration fd) | |
35 { | |
178 | 36 register(); |
0 | 37 super(loc, TOK.TOKfunction, FuncExp.sizeof); |
38 this.fd = fd; | |
39 } | |
40 | |
72 | 41 override Expression syntaxCopy() |
0 | 42 { |
56 | 43 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null)); |
0 | 44 } |
45 | |
72 | 46 override Expression semantic(Scope sc) |
0 | 47 { |
48 version (LOGSEMANTIC) { | |
49 printf("FuncExp.semantic(%s)\n", toChars()); | |
50 } | |
51 if (!type) | |
52 { | |
53 fd.semantic(sc); | |
54 | |
55 //fd.parent = sc.parent; | |
56 if (global.errors) | |
57 { | |
58 } | |
59 else | |
60 { | |
61 fd.semantic2(sc); | |
62 if (!global.errors || | |
63 // need to infer return type | |
64 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())) | |
65 { | |
66 fd.semantic3(sc); | |
67 | |
68 if (!global.errors && global.params.useInline) | |
69 fd.inlineScan(); | |
70 } | |
71 } | |
72 | |
73 // need to infer return type | |
74 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()) | |
75 (cast(TypeFunction)fd.type).next = Type.terror; | |
76 | |
77 // Type is a "delegate to" or "pointer to" the function literal | |
78 if (fd.isNested()) | |
79 { | |
80 type = new TypeDelegate(fd.type); | |
81 type = type.semantic(loc, sc); | |
82 } | |
83 else | |
84 { | |
85 type = fd.type.pointerTo(); | |
86 } | |
87 | |
88 fd.tookAddressOf++; | |
89 } | |
90 | |
91 return this; | |
92 } | |
179 | 93 |
94 Expression interpret(InterState istate) | |
95 { | |
96 version (LOG) { | |
97 writef("FuncExp::interpret() %s\n", toChars()); | |
98 } | |
99 return this; | |
100 | |
101 } | |
0 | 102 |
72 | 103 override void scanForNestedRef(Scope sc) |
0 | 104 { |
123 | 105 //printf("FuncExp.scanForNestedRef(%s)\n", toChars()); |
106 //fd.parent = sc.parent; | |
0 | 107 } |
108 | |
72 | 109 override string toChars() |
0 | 110 { |
58 | 111 return fd.toChars(); |
0 | 112 } |
113 | |
72 | 114 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 115 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
72
diff
changeset
|
116 fd.toCBuffer(buf, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
72
diff
changeset
|
117 //buf.writestring(fd.toChars()); |
0 | 118 } |
119 | |
72 | 120 override elem* toElem(IRState* irs) |
0 | 121 { |
122 elem* e; | |
123 Symbol* s; | |
124 | |
125 //printf("FuncExp::toElem() %s\n", toChars()); | |
126 s = fd.toSymbol(); | |
127 e = el_ptr(s); | |
128 if (fd.isNested()) | |
129 { | |
130 elem* ethis = getEthis(loc, irs, fd); | |
131 e = el_pair(TYM.TYullong, ethis, e); | |
132 } | |
133 | |
134 irs.deferToObj.push(cast(void*)fd); | |
135 el_setLoc(e,loc); | |
136 return e; | |
137 } | |
138 | |
72 | 139 override int inlineCost(InlineCostState* ics) |
0 | 140 { |
123 | 141 // Right now, this makes the function be output to the .obj file twice. |
142 return COST_MAX; | |
0 | 143 } |
144 } | |
145 |