Mercurial > projects > ddmd
annotate dmd/TypeFunction.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | c494af1dba80 |
children | 95b3ed3cddd5 |
rev | line source |
---|---|
0 | 1 module dmd.TypeFunction; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TypeNext; |
5 import dmd.TypeSArray; | |
6 import dmd.TypeArray; | |
123 | 7 import dmd.TemplateTupleParameter; |
0 | 8 import dmd.ArrayTypes; |
9 import dmd.LINK; | |
10 import dmd.StructDeclaration; | |
11 import dmd.TypeStruct; | |
12 import dmd.Global; | |
13 import dmd.STC; | |
14 import dmd.MOD; | |
73 | 15 import dmd.PROT; |
123 | 16 import dmd.TypeIdentifier; |
17 import dmd.TemplateParameter; | |
129 | 18 import dmd.TypeInfoFunctionDeclaration; |
123 | 19 import dmd.Tuple; |
0 | 20 import dmd.Type; |
21 import dmd.Loc; | |
22 import dmd.Scope; | |
23 import dmd.Identifier; | |
24 import dmd.OutBuffer; | |
25 import dmd.HdrGenState; | |
26 import dmd.CppMangleState; | |
27 import dmd.TypeInfoDeclaration; | |
28 import dmd.MATCH; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
29 import dmd.Parameter; |
0 | 30 import dmd.Expression; |
31 import dmd.RET; | |
32 import dmd.TY; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
33 import dmd.TRUST; |
0 | 34 import dmd.Util; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
35 import dmd.FuncDeclaration; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
36 import dmd.Dsymbol; |
135 | 37 import dmd.TypeTuple; |
123 | 38 import dmd.TemplateInstance : isTuple; |
0 | 39 |
40 import dmd.backend.TYPE; | |
41 import dmd.backend.PARAM; | |
42 import dmd.backend.Util; | |
43 import dmd.backend.TYM; | |
44 import dmd.backend.TF; | |
45 import dmd.backend.mTY; | |
46 | |
47 import core.stdc.stdlib; | |
48 import core.stdc.string; | |
49 | |
129 | 50 import std.stdio; |
51 | |
0 | 52 class TypeFunction : TypeNext |
53 { | |
54 // .next is the return type | |
55 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
56 Parameters parameters; // function parameters |
0 | 57 int varargs; // 1: T t, ...) style for variable number of arguments |
58 // 2: T t ...) style for variable number of arguments | |
59 bool isnothrow; // true: nothrow | |
60 bool ispure; // true: pure | |
61 bool isproperty; // can be called without parentheses | |
62 bool isref; // true: returns a reference | |
63 LINK linkage; // calling convention | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
64 TRUST trust; // level of trust |
135 | 65 Expressions fargs; // function arguments |
0 | 66 |
67 int inuse; | |
68 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
69 this(Parameters parameters, Type treturn, int varargs, LINK linkage) |
0 | 70 { |
71 super(TY.Tfunction, treturn); | |
72 | |
73 //if (!treturn) *(char*)0=0; | |
74 // assert(treturn); | |
75 assert(0 <= varargs && varargs <= 2); | |
76 this.parameters = parameters; | |
77 this.varargs = varargs; | |
78 this.linkage = linkage; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
79 this.trust = TRUSTdefault; |
0 | 80 } |
81 | |
72 | 82 override Type syntaxCopy() |
0 | 83 { |
84 Type treturn = next ? next.syntaxCopy() : null; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
85 auto params = Parameter.arraySyntaxCopy(parameters); |
0 | 86 TypeFunction t = new TypeFunction(params, treturn, varargs, linkage); |
87 t.mod = mod; | |
88 t.isnothrow = isnothrow; | |
89 t.ispure = ispure; | |
90 t.isproperty = isproperty; | |
91 t.isref = isref; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
92 t.trust = trust; |
135 | 93 t.fargs = fargs; |
0 | 94 |
95 return t; | |
96 } | |
97 | |
98 version (DumbClone) { | |
99 } else { | |
100 final TypeFunction cloneTo(TypeFunction t) | |
101 { | |
102 super.cloneTo(t); | |
103 | |
104 // these 3 should be set by ctor | |
105 assert(t.parameters is null); | |
106 assert(t.varargs == varargs); | |
107 assert(t.linkage == linkage); | |
108 | |
109 t.isnothrow = isnothrow; | |
110 t.ispure = ispure; | |
111 t.isproperty = isproperty; | |
112 t.isref = isref; | |
113 t.inuse = inuse; | |
114 | |
115 if (parameters) | |
116 { | |
117 t.parameters = parameters.copy(); | |
129 | 118 foreach (arg; parameters) |
0 | 119 { |
120 Argument cpy = arg.clone(); | |
129 | 121 t.parameters[i] = cpy; |
0 | 122 } |
123 } | |
124 | |
125 return t; | |
126 } | |
127 | |
128 TypeFunction clone() | |
129 { | |
129 | 130 assert(this.classinfo is TypeFunction.classinfo); |
0 | 131 return cloneTo(new TypeFunction(null, next, varargs, linkage)); |
132 } | |
133 } | |
72 | 134 override Type semantic(Loc loc, Scope sc) |
0 | 135 { |
136 if (deco) // if semantic() already run | |
137 { | |
138 //printf("already done\n"); | |
139 return this; | |
140 } | |
141 //printf("TypeFunction.semantic() this = %p\n", this); | |
135 | 142 //printf("TypeFunction::semantic() %s, sc->stc = %llx, fargs = %p\n", toChars(), sc->stc, fargs); |
0 | 143 |
144 /* Copy in order to not mess up original. | |
145 * This can produce redundant copies if inferring return type, | |
146 * as semantic() will get called again on this. | |
147 */ | |
148 | |
129 | 149 TypeFunction tf = cloneThis(this); |
0 | 150 |
151 if (sc.stc & STC.STCpure) | |
152 tf.ispure = true; | |
153 if (sc.stc & STC.STCnothrow) | |
154 tf.isnothrow = true; | |
155 if (sc.stc & STC.STCref) | |
156 tf.isref = true; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
157 if (sc.stc & STCsafe) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
158 tf.trust = TRUST.TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
159 if (sc.stc & STCtrusted) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
160 tf.trust = TRUST.TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
161 if (sc.stc & STCproperty) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
162 tf.isproperty = true; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
163 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
164 tf.linkage = sc.linkage; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
165 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
166 /* If the parent is @safe, then this function defaults to safe |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
167 * too. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
168 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
169 if (tf.trust == TRUST.TRUSTdefault) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
170 for (Dsymbol p = sc.func; p; p = p.toParent2()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
171 { FuncDeclaration fd = p.isFuncDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
172 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
173 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
174 if (fd.isSafe()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
175 tf.trust = TRUST.TRUSTsafe; // default to @safe |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
176 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
177 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
178 } |
0 | 179 |
135 | 180 bool wildreturn = false; |
0 | 181 if (tf.next) |
182 { | |
183 tf.next = tf.next.semantic(loc,sc); | |
96 | 184 version(SARRAYVALUE) {} else |
185 { | |
0 | 186 if (tf.next.toBasetype().ty == TY.Tsarray) |
129 | 187 { |
188 error(loc, "functions cannot return static array %s", tf.next.toChars()); | |
0 | 189 tf.next = Type.terror; |
190 } | |
96 | 191 } |
0 | 192 if (tf.next.toBasetype().ty == TY.Tfunction) |
129 | 193 { |
194 error(loc, "functions cannot return a function"); | |
0 | 195 tf.next = Type.terror; |
196 } | |
197 if (tf.next.toBasetype().ty == TY.Ttuple) | |
129 | 198 { |
199 error(loc, "functions cannot return a tuple"); | |
0 | 200 tf.next = Type.terror; |
201 } | |
202 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) | |
129 | 203 error(loc, "functions cannot return scope %s", tf.next.toChars()); |
135 | 204 if (tf.next.toBasetype().ty == TY.Tvoid) |
205 tf.isref = false; // rewrite "ref void" as just "void" | |
206 if (tf.next.isWild()) | |
207 wildreturn = true; | |
208 } | |
0 | 209 |
135 | 210 bool wildparams = false; |
211 bool wildsubparams = false; | |
0 | 212 if (tf.parameters) |
73 | 213 { |
214 /* Create a scope for evaluating the default arguments for the parameters | |
215 */ | |
216 Scope argsc = sc.push(); | |
217 argsc.stc = STCundefined; // don't inherit storage class | |
218 argsc.protection = PROT.PROTpublic; | |
219 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
220 size_t dim = Parameter.dim(tf.parameters); |
0 | 221 |
222 for (size_t i = 0; i < dim; i++) | |
135 | 223 { auto fparam = Parameter.getNth(tf.parameters, i); |
0 | 224 |
225 tf.inuse++; | |
135 | 226 fparam.type = fparam.type.semantic(loc, argsc); |
0 | 227 if (tf.inuse == 1) tf.inuse--; |
228 | |
135 | 229 fparam.type = fparam.type.addStorageClass(fparam.storageClass); |
0 | 230 |
135 | 231 if (fparam.storageClass & (STC.STCauto | STC.STCalias | STC.STCstatic)) |
0 | 232 { |
135 | 233 if (!fparam.type) |
0 | 234 continue; |
235 } | |
236 | |
135 | 237 Type t = fparam.type.toBasetype(); |
0 | 238 |
135 | 239 if (fparam.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) |
0 | 240 { |
96 | 241 //if (t.ty == TY.Tsarray) |
242 //error(loc, "cannot have out or ref parameter of type %s", t.toChars()); | |
135 | 243 if (fparam.storageClass & STC.STCout && fparam.type.mod & (STCconst | STCimmutable)) |
96 | 244 error(loc, "cannot have const or immutabl out parameter of type %s", t.toChars()); |
0 | 245 } |
135 | 246 if (!(fparam.storageClass & STC.STClazy) && t.ty == TY.Tvoid) |
247 error(loc, "cannot have parameter of type %s", fparam.type.toChars()); | |
0 | 248 |
135 | 249 if (t.isWild()) |
250 { | |
251 wildparams = true; | |
252 if (tf.next && !wildreturn) | |
253 error(loc, "inout on parameter means inout must be on return type as well (if from D1 code, replace with 'ref')"); | |
254 } | |
255 else if (!wildsubparams && t.hasWild()) | |
256 wildsubparams = true; | |
0 | 257 |
135 | 258 if (fparam.defaultArg) |
259 { | |
260 fparam.defaultArg = fparam.defaultArg.semantic(argsc); | |
261 fparam.defaultArg = resolveProperties(argsc, fparam.defaultArg); | |
262 fparam.defaultArg = fparam.defaultArg.implicitCastTo(argsc, fparam.type); | |
263 } | |
264 | |
265 /* If fparam turns out to be a tuple, the number of parameters may | |
0 | 266 * change. |
267 */ | |
268 if (t.ty == TY.Ttuple) | |
135 | 269 { |
270 // Propagate storage class from tuple parameters to their element-parameters. | |
271 auto tt = cast(TypeTuple)t; | |
272 if (tt.arguments) | |
273 { | |
274 auto tdim = tt.arguments.dim; | |
275 foreach (narg; tt.arguments) | |
276 { | |
277 narg.storageClass = fparam.storageClass; | |
278 } | |
279 } | |
280 | |
281 /* Reset number of parameters, and back up one to do this fparam again, | |
282 * now that it is the first element of a tuple | |
283 */ | |
284 dim = Parameter.dim(tf.parameters); | |
0 | 285 i--; |
135 | 286 continue; |
0 | 287 } |
135 | 288 |
289 /* Resolve "auto ref" storage class to be either ref or value, | |
290 * based on the argument matching the parameter | |
291 */ | |
292 if (fparam.storageClass & STC.STCauto) | |
293 { | |
294 if (fargs && i < fargs.dim) | |
295 { | |
296 auto farg = fargs[i]; | |
297 if (farg.isLvalue()) | |
298 {} // ref parameter | |
299 else | |
300 fparam.storageClass &= ~STC.STCref; // value parameter | |
301 } | |
302 else | |
303 error(loc, "auto can only be used for template function parameters"); | |
304 } | |
0 | 305 } |
73 | 306 argsc.pop(); |
0 | 307 } |
135 | 308 |
309 if (wildreturn && !wildparams) | |
310 error(loc, "inout on return means inout must be on a parameter as well for %s", toChars()); | |
311 if (wildsubparams && wildparams) | |
312 error(loc, "inout must be all or none on top level for %s", toChars()); | |
313 | |
0 | 314 if (tf.next) |
315 tf.deco = tf.merge().deco; | |
316 | |
317 if (tf.inuse) | |
318 { error(loc, "recursive type"); | |
319 tf.inuse = 0; | |
320 return terror; | |
321 } | |
322 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
323 if (tf.isproperty && (tf.varargs || Parameter.dim(tf.parameters) > 1)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
324 error(loc, "properties can only have zero or one parameter"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
325 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
326 if (tf.varargs == 1 && tf.linkage != LINK.LINKd && Parameter.dim(tf.parameters) == 0) |
0 | 327 error(loc, "variadic functions with non-D linkage must have at least one parameter"); |
328 | |
329 /* Don't return merge(), because arg identifiers and default args | |
330 * can be different | |
331 * even though the types match | |
332 */ | |
333 return tf; | |
334 } | |
335 | |
72 | 336 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 337 { |
338 ubyte mc; | |
339 | |
340 //printf("TypeFunction.toDecoBuffer() this = %p %s\n", this, toChars()); | |
341 //static int nest; if (++nest == 50) *(char*)0=0; | |
342 if (inuse) | |
343 { | |
344 inuse = 2; // flag error to caller | |
345 return; | |
346 } | |
347 inuse++; | |
135 | 348 MODtoDecoBuffer(buf, mod); |
0 | 349 switch (linkage) |
350 { | |
351 case LINK.LINKd: mc = 'F'; break; | |
352 case LINK.LINKc: mc = 'U'; break; | |
353 case LINK.LINKwindows: mc = 'W'; break; | |
354 case LINK.LINKpascal: mc = 'V'; break; | |
355 case LINK.LINKcpp: mc = 'R'; break; | |
356 } | |
357 buf.writeByte(mc); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
358 if (ispure || isnothrow || isproperty || isref || trust) |
0 | 359 { |
360 if (ispure) | |
361 buf.writestring("Na"); | |
362 if (isnothrow) | |
363 buf.writestring("Nb"); | |
364 if (isref) | |
365 buf.writestring("Nc"); | |
366 if (isproperty) | |
367 buf.writestring("Nd"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
368 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
369 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
370 case TRUST.TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
371 buf.writestring("Ne"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
372 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
373 case TRUST.TRUSTsafe: |
135 | 374 buf.writestring("Nf"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
375 break; |
132
c494af1dba80
Fixes for dmd 2.037
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
131
diff
changeset
|
376 default: |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
377 } |
0 | 378 } |
379 // Write argument types | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
380 Parameter.argsToDecoBuffer(buf, parameters); |
0 | 381 //if (buf.data[buf.offset - 1] == '@') halt(); |
382 buf.writeByte('Z' - varargs); // mark end of arg list | |
79 | 383 assert(next); |
0 | 384 next.toDecoBuffer(buf); |
385 inuse--; | |
386 } | |
387 | |
72 | 388 override void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) |
0 | 389 { |
390 //printf("TypeFunction.toCBuffer() this = %p\n", this); | |
391 string p = null; | |
392 | |
393 if (inuse) | |
394 { | |
395 inuse = 2; // flag error to caller | |
396 return; | |
397 } | |
398 inuse++; | |
399 | |
400 /* Use 'storage class' style for attributes | |
401 */ | |
135 | 402 if (mod) |
403 { | |
404 MODtoBuffer(buf, mod); | |
405 buf.writeByte(' '); | |
406 } | |
0 | 407 |
408 if (ispure) | |
409 buf.writestring("pure "); | |
410 if (isnothrow) | |
411 buf.writestring("nothrow "); | |
412 if (isproperty) | |
413 buf.writestring("@property "); | |
414 if (isref) | |
415 buf.writestring("ref "); | |
416 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
417 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
418 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
419 case TRUST.TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
420 buf.writestring("@trusted "); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
421 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
422 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
423 case TRUST.TRUSTsafe: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
424 buf.writestring("@safe "); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
425 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
426 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
427 |
0 | 428 if (next && (!ident || ident.toHChars2() == ident.toChars())) |
429 next.toCBuffer2(buf, hgs, MODundefined); | |
430 if (hgs.ddoc != 1) | |
431 { | |
432 switch (linkage) | |
433 { | |
434 case LINKd: p = null; break; | |
73 | 435 case LINKc: p = " C"; break; |
436 case LINKwindows: p = " Windows"; break; | |
437 case LINKpascal: p = " Pascal"; break; | |
438 case LINKcpp: p = " C++"; break; | |
0 | 439 default: |
440 assert(0); | |
441 } | |
442 } | |
443 | |
444 if (!hgs.hdrgen && p) | |
445 buf.writestring(p); | |
446 if (ident) | |
447 { | |
448 buf.writeByte(' '); | |
449 buf.writestring(ident.toHChars2()); | |
450 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
451 Parameter.argsToCBuffer(buf, hgs, parameters, varargs); |
0 | 452 inuse--; |
453 } | |
454 | |
72 | 455 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 456 { |
457 //printf("TypeFunction::toCBuffer2() this = %p, ref = %d\n", this, isref); | |
458 string p; | |
459 | |
460 if (inuse) | |
461 { | |
462 inuse = 2; // flag error to caller | |
463 return; | |
464 } | |
465 | |
466 inuse++; | |
467 if (next) | |
468 next.toCBuffer2(buf, hgs, MODundefined); | |
469 | |
470 if (hgs.ddoc != 1) | |
471 { | |
472 switch (linkage) | |
473 { | |
474 case LINKd: p = null; break; | |
475 case LINKc: p = "C "; break; | |
476 case LINKwindows: p = "Windows "; break; | |
477 case LINKpascal: p = "Pascal "; break; | |
478 case LINKcpp: p = "C++ "; break; | |
479 default: assert(0); | |
480 } | |
481 } | |
482 | |
483 if (!hgs.hdrgen && p) | |
484 buf.writestring(p); | |
485 buf.writestring(" function"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
486 Parameter.argsToCBuffer(buf, hgs, parameters, varargs); |
0 | 487 |
488 /* Use postfix style for attributes | |
489 */ | |
490 if (mod != this.mod) | |
491 { | |
492 modToBuffer(buf); | |
493 } | |
494 | |
495 if (ispure) | |
496 buf.writestring(" pure"); | |
497 if (isnothrow) | |
498 buf.writestring(" nothrow"); | |
499 if (isproperty) | |
500 buf.writestring(" @property"); | |
501 if (isref) | |
502 buf.writestring(" ref"); | |
503 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
504 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
505 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
506 case TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
507 buf.writestring(" @trusted"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
508 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
509 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
510 case TRUSTsafe: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
511 buf.writestring(" @safe"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
512 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
513 } |
0 | 514 inuse--; |
515 } | |
516 | |
72 | 517 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 518 { |
123 | 519 //printf("TypeFunction.deduceType()\n"); |
520 //printf("\tthis = %d, ", ty); print(); | |
521 //printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
522 | |
523 // Extra check that function characteristics must match | |
524 if (tparam && tparam.ty == Tfunction) | |
525 { | |
526 TypeFunction tp = cast(TypeFunction)tparam; | |
527 if (varargs != tp.varargs || | |
528 linkage != tp.linkage) | |
529 return MATCHnomatch; | |
530 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
531 size_t nfargs = Parameter.dim(this.parameters); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
532 size_t nfparams = Parameter.dim(tp.parameters); |
123 | 533 |
534 /* See if tuple match | |
535 */ | |
536 if (nfparams > 0 && nfargs >= nfparams - 1) | |
537 { | |
538 /* See if 'A' of the template parameter matches 'A' | |
539 * of the type of the last function parameter. | |
540 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
541 auto fparam = Parameter.getNth(tp.parameters, nfparams - 1); |
123 | 542 assert(fparam); |
543 assert(fparam.type); | |
544 if (fparam.type.ty != Tident) | |
545 goto L1; | |
546 TypeIdentifier tid = cast(TypeIdentifier)fparam.type; | |
547 if (tid.idents.dim) | |
548 goto L1; | |
549 | |
550 /* Look through parameters to find tuple matching tid.ident | |
551 */ | |
552 size_t tupi = 0; | |
553 for (; 1; tupi++) | |
554 { | |
555 if (tupi == parameters.dim) | |
556 goto L1; | |
557 TemplateParameter t = parameters[tupi]; | |
558 TemplateTupleParameter tup = t.isTemplateTupleParameter(); | |
559 if (tup && tup.ident.equals(tid.ident)) | |
560 break; | |
561 } | |
562 | |
563 /* The types of the function arguments [nfparams - 1 .. nfargs] | |
564 * now form the tuple argument. | |
565 */ | |
566 int tuple_dim = nfargs - (nfparams - 1); | |
567 | |
568 /* See if existing tuple, and whether it matches or not | |
569 */ | |
570 Object o = dedtypes[tupi]; | |
571 if (o) | |
572 { | |
573 // Existing deduced argument must be a tuple, and must match | |
574 Tuple t = isTuple(o); | |
575 if (!t || t.objects.dim != tuple_dim) | |
576 return MATCHnomatch; | |
577 for (size_t i = 0; i < tuple_dim; i++) | |
578 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
579 auto arg = Parameter.getNth(this.parameters, nfparams - 1 + i); |
123 | 580 if (!arg.type.equals(t.objects[i])) |
581 return MATCHnomatch; | |
582 } | |
583 } | |
584 else | |
585 { // Create new tuple | |
586 Tuple t = new Tuple(); | |
587 t.objects.setDim(tuple_dim); | |
588 for (size_t i = 0; i < tuple_dim; i++) | |
589 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
590 auto arg = Parameter.getNth(this.parameters, nfparams - 1 + i); |
123 | 591 t.objects[i] = arg.type; |
592 } | |
593 dedtypes[tupi] = t; | |
594 } | |
595 nfparams--; // don't consider the last parameter for type deduction | |
596 goto L2; | |
597 } | |
598 | |
599 L1: | |
600 if (nfargs != nfparams) | |
601 return MATCHnomatch; | |
602 L2: | |
603 for (size_t i = 0; i < nfparams; i++) | |
604 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
605 auto a = Parameter.getNth(this.parameters, i); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
606 auto ap = Parameter.getNth(tp.parameters, i); |
123 | 607 if (a.storageClass != ap.storageClass || |
608 !a.type.deduceType(sc, ap.type, parameters, dedtypes)) | |
609 return MATCHnomatch; | |
610 } | |
611 } | |
612 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
0 | 613 } |
614 | |
72 | 615 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 616 { |
129 | 617 return new TypeInfoFunctionDeclaration(this); |
0 | 618 } |
619 | |
72 | 620 override Type reliesOnTident() |
0 | 621 { |
135 | 622 size_t dim = Parameter.dim(parameters); |
623 for (size_t i = 0; i < dim; i++) | |
624 { | |
625 auto fparam = Parameter.getNth(parameters, i); | |
626 Type t = fparam.type.reliesOnTident(); | |
627 if (t) | |
628 return t; | |
629 } | |
630 return next ? next.reliesOnTident() : null; | |
0 | 631 } |
632 | |
633 version (CPP_MANGLE) { | |
634 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
635 { | |
636 assert(false); | |
637 } | |
638 } | |
639 | |
640 /*************************** | |
641 * Examine function signature for parameter p and see if | |
642 * p can 'escape' the scope of the function. | |
643 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
644 bool parameterEscapes(Parameter p) |
0 | 645 { |
646 /* Scope parameters do not escape. | |
647 * Allow 'lazy' to imply 'scope' - | |
648 * lazy parameters can be passed along | |
649 * as lazy parameters to the next function, but that isn't | |
650 * escaping. | |
651 */ | |
652 if (p.storageClass & (STC.STCscope | STC.STClazy)) | |
653 return false; | |
654 | |
655 if (ispure) | |
656 { /* With pure functions, we need only be concerned if p escapes | |
657 * via any return statement. | |
658 */ | |
659 Type tret = nextOf().toBasetype(); | |
660 if (!isref && !tret.hasPointers()) | |
661 { /* The result has no references, so p could not be escaping | |
662 * that way. | |
663 */ | |
664 return false; | |
665 } | |
666 } | |
667 | |
668 /* Assume it escapes in the absence of better information. | |
669 */ | |
670 return true; | |
671 } | |
672 | |
673 /******************************** | |
674 * 'args' are being matched to function 'this' | |
675 * Determine match level. | |
676 * Returns: | |
677 * MATCHxxxx | |
678 */ | |
679 MATCH callMatch(Expression ethis, Expressions args) | |
680 { | |
681 //printf("TypeFunction.callMatch() %s\n", toChars()); | |
682 MATCH match = MATCH.MATCHexact; // assume exact match | |
135 | 683 bool exactwildmatch = false; |
684 bool wildmatch = false; | |
0 | 685 |
686 if (ethis) | |
687 { | |
688 Type t = ethis.type; | |
689 if (t.toBasetype().ty == TY.Tpointer) | |
690 t = t.toBasetype().nextOf(); // change struct* to struct | |
691 | |
692 if (t.mod != mod) | |
693 { | |
135 | 694 if (MODimplicitConv(t.mod, mod)) |
0 | 695 match = MATCH.MATCHconst; |
696 else | |
697 return MATCH.MATCHnomatch; | |
698 } | |
699 } | |
700 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
701 size_t nparams = Parameter.dim(parameters); |
0 | 702 size_t nargs = args ? args.dim : 0; |
703 if (nparams == nargs) { | |
704 ; | |
705 } else if (nargs > nparams) | |
706 { | |
707 if (varargs == 0) | |
708 goto Nomatch; // too many args; no match | |
709 match = MATCH.MATCHconvert; // match ... with a "conversion" match level | |
710 } | |
711 | |
712 for (size_t u = 0; u < nparams; u++) | |
713 { | |
714 MATCH m; | |
715 Expression arg; | |
716 | |
717 // BUG: what about out and ref? | |
718 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
719 auto p = Parameter.getNth(parameters, u); |
0 | 720 assert(p); |
721 if (u >= nargs) | |
722 { | |
723 if (p.defaultArg) | |
724 continue; | |
725 if (varargs == 2 && u + 1 == nparams) | |
726 goto L1; | |
727 goto Nomatch; // not enough arguments | |
728 } | |
729 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
96
diff
changeset
|
730 arg = cast(Expression)args[u]; |
0 | 731 assert(arg); |
96 | 732 // writef("arg: %s, type: %s\n", arg.toChars(), arg.type.toChars()); |
733 | |
0 | 734 |
735 // Non-lvalues do not match ref or out parameters | |
96 | 736 if (p.storageClass & (STC.STCref | STC.STCout)) |
737 { | |
738 if (!arg.isLvalue()) | |
739 goto Nomatch; | |
740 } | |
741 | |
742 if (p.storageClass & STCref) | |
743 { | |
135 | 744 /* Don't allow static arrays to be passed to mutable references |
96 | 745 * to static arrays if the argument cannot be modified. |
746 */ | |
747 Type targb = arg.type.toBasetype(); | |
748 Type tparb = p.type.toBasetype(); | |
749 //writef("%s\n", targb.toChars()); | |
750 //writef("%s\n", tparb.toChars()); | |
751 if (targb.nextOf() && tparb.ty == Tsarray && | |
135 | 752 !MODimplicitConv(targb.nextOf().mod, tparb.nextOf().mod)) |
96 | 753 goto Nomatch; |
754 } | |
0 | 755 |
756 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) | |
757 m = MATCH.MATCHconvert; | |
758 else | |
135 | 759 { |
0 | 760 m = arg.implicitConvTo(p.type); |
135 | 761 if (p.type.isWild()) |
762 { | |
763 if (m == MATCHnomatch) | |
764 { | |
765 m = arg.implicitConvTo(p.type.constOf()); | |
766 if (m == MATCHnomatch) | |
767 m = arg.implicitConvTo(p.type.sharedConstOf()); | |
768 if (m != MATCHnomatch) | |
769 wildmatch = true; // mod matched to wild | |
770 } | |
771 else | |
772 exactwildmatch = true; // wild matched to wild | |
773 | |
774 /* If both are allowed, then there could be more than one | |
775 * binding of mod to wild, leaving a gaping type hole. | |
776 */ | |
777 if (wildmatch && exactwildmatch) | |
778 m = MATCHnomatch; | |
779 } | |
780 } | |
781 | |
0 | 782 //printf("\tm = %d\n", m); |
783 if (m == MATCH.MATCHnomatch) // if no match | |
784 { | |
785 L1: | |
786 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
787 { | |
788 Type tb = p.type.toBasetype(); | |
789 TypeSArray tsa; | |
790 long sz; | |
791 | |
792 switch (tb.ty) | |
793 { | |
794 case TY.Tsarray: | |
795 tsa = cast(TypeSArray)tb; | |
796 sz = tsa.dim.toInteger(); | |
797 if (sz != nargs - u) | |
798 goto Nomatch; | |
799 case TY.Tarray: | |
800 { | |
801 TypeArray ta = cast(TypeArray)tb; | |
802 for (; u < nargs; u++) | |
803 { | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
96
diff
changeset
|
804 arg = cast(Expression)args[u]; |
0 | 805 assert(arg); |
806 static if (true) { | |
807 /* If lazy array of delegates, | |
808 * convert arg(s) to delegate(s) | |
809 */ | |
810 Type tret = p.isLazyArray(); | |
811 if (tret) | |
812 { | |
813 if (ta.next.equals(arg.type)) | |
814 { | |
815 m = MATCH.MATCHexact; | |
816 } | |
817 else | |
818 { | |
819 m = arg.implicitConvTo(tret); | |
820 if (m == MATCH.MATCHnomatch) | |
821 { | |
822 if (tret.toBasetype().ty == TY.Tvoid) | |
823 m = MATCH.MATCHconvert; | |
824 } | |
825 } | |
826 } | |
827 else | |
828 m = arg.implicitConvTo(ta.next); | |
829 } else { | |
830 m = arg.implicitConvTo(ta.next); | |
831 } | |
832 if (m == MATCH.MATCHnomatch) | |
833 goto Nomatch; | |
834 | |
835 if (m < match) | |
836 match = m; | |
837 } | |
838 goto Ldone; | |
839 } | |
840 | |
841 case TY.Tclass: | |
842 // Should see if there's a constructor match? | |
843 // Or just leave it ambiguous? | |
844 goto Ldone; | |
845 | |
846 default: | |
847 goto Nomatch; | |
848 } | |
849 } | |
850 | |
851 goto Nomatch; | |
852 } | |
853 | |
854 if (m < match) | |
855 match = m; // pick worst match | |
856 } | |
857 | |
858 Ldone: | |
859 //printf("match = %d\n", match); | |
860 return match; | |
861 | |
862 Nomatch: | |
863 //printf("no match\n"); | |
864 return MATCH.MATCHnomatch; | |
865 } | |
866 | |
96 | 867 override type* toCtype() |
0 | 868 { |
869 if (ctype) { | |
870 return ctype; | |
871 } | |
872 | |
873 type* t; | |
874 if (true) | |
875 { | |
876 param_t* paramtypes; | |
877 tym_t tyf; | |
878 type* tp; | |
879 | |
880 paramtypes = null; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
881 size_t nparams = Parameter.dim(parameters); |
0 | 882 for (size_t i = 0; i < nparams; i++) |
883 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
884 auto arg = Parameter.getNth(parameters, i); |
0 | 885 tp = arg.type.toCtype(); |
886 if (arg.storageClass & (STC.STCout | STC.STCref)) | |
887 { | |
888 // C doesn't have reference types, so it's really a pointer | |
889 // to the parameter type | |
890 tp = type_allocn(TYM.TYref, tp); | |
891 } | |
892 param_append_type(¶mtypes,tp); | |
893 } | |
894 tyf = totym(); | |
895 t = type_alloc(tyf); | |
896 t.Tflags |= TF.TFprototype; | |
897 if (varargs != 1) | |
898 t.Tflags |= TF.TFfixed; | |
899 ctype = t; | |
900 t.Tnext = next.toCtype(); | |
901 t.Tnext.Tcount++; | |
902 t.Tparamtypes = paramtypes; | |
903 } | |
904 ctype = t; | |
905 return t; | |
906 } | |
907 | |
908 /*************************** | |
909 * Determine return style of function - whether in registers or | |
910 * through a hidden pointer to the caller's stack. | |
911 */ | |
96 | 912 RET retStyle() |
0 | 913 { |
914 //printf("TypeFunction.retStyle() %s\n", toChars()); | |
95 | 915 version (DMDV2) |
916 { | |
0 | 917 if (isref) |
918 return RET.RETregs; // returns a pointer | |
919 } | |
920 | |
921 Type tn = next.toBasetype(); | |
95 | 922 Type tns = tn; |
923 ulong sz = tn.size(); | |
0 | 924 |
95 | 925 version(SARRAYVALUE) |
926 { | |
927 if (tn.ty == Tsarray) | |
928 { | |
929 do | |
930 { | |
931 tns = tns.nextOf().toBasetype(); | |
932 } while (tns.ty == Tsarray); | |
933 if (tns.ty != Tstruct) | |
934 { | |
935 if (global.params.isLinux && linkage != LINKd) | |
936 {} | |
937 else | |
938 { | |
939 switch (sz) | |
940 { case 1: | |
941 case 2: | |
942 case 4: | |
943 case 8: | |
96 | 944 return RET.RETregs; // return small structs in regs |
945 // (not 3 byte structs!) | |
95 | 946 default: |
947 break; | |
948 } | |
949 } | |
96 | 950 return RET.RETstack; |
95 | 951 } |
952 } | |
953 } | |
954 if (tns.ty == TY.Tstruct) | |
0 | 955 { |
956 StructDeclaration sd = (cast(TypeStruct)tn).sym; | |
957 if (global.params.isLinux && linkage != LINK.LINKd) { | |
958 ; | |
959 } | |
95 | 960 ///version (DMDV2) { // TODO: |
961 else if (sd.dtor || sd.cpctor) | |
962 { | |
0 | 963 } |
964 ///} | |
965 else | |
966 { | |
95 | 967 switch (sz) |
0 | 968 { |
969 case 1: | |
970 case 2: | |
971 case 4: | |
972 case 8: | |
973 return RET.RETregs; // return small structs in regs | |
974 // (not 3 byte structs!) | |
975 default: | |
976 break; | |
977 } | |
978 } | |
979 return RET.RETstack; | |
980 } | |
981 else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && | |
982 linkage == LINK.LINKc && | |
983 tn.iscomplex()) | |
984 { | |
985 if (tn.ty == TY.Tcomplex32) | |
986 return RET.RETregs; // in EDX:EAX, not ST1:ST0 | |
987 else | |
988 return RET.RETstack; | |
989 } | |
990 else | |
991 return RET.RETregs; | |
992 } | |
993 | |
72 | 994 override TYM totym() |
0 | 995 { |
996 TYM tyf; | |
997 | |
998 //printf("TypeFunction.totym(), linkage = %d\n", linkage); | |
999 switch (linkage) | |
1000 { | |
1001 case LINK.LINKwindows: | |
1002 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnsfunc; | |
1003 break; | |
1004 | |
1005 case LINK.LINKpascal: | |
1006 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnpfunc; | |
1007 break; | |
1008 | |
1009 case LINK.LINKc: | |
1010 tyf = TYM.TYnfunc; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1011 version (POSIX) {///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 1012 if (retStyle() == RET.RETstack) |
1013 tyf = TYM.TYhfunc; | |
1014 } | |
1015 break; | |
1016 | |
1017 case LINK.LINKd: | |
1018 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYjfunc; | |
1019 break; | |
1020 | |
1021 case LINK.LINKcpp: | |
1022 tyf = TYM.TYnfunc; | |
1023 break; | |
1024 | |
1025 default: | |
1026 writef("linkage = %d\n", linkage); | |
1027 assert(0); | |
1028 } | |
1029 version (DMDV2) { | |
1030 if (isnothrow) | |
1031 tyf |= mTY.mTYnothrow; | |
1032 } | |
1033 return tyf; | |
1034 } | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1035 } |