Mercurial > projects > ddmd
annotate dmd/TemplateDeclaration.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | e6e542f37b94 |
children | 206db751bd4c |
rev | line source |
---|---|
0 | 1 module dmd.TemplateDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Loc; |
5 import dmd.ScopeDsymbol; | |
6 import dmd.ArrayTypes; | |
7 import dmd.Dsymbol; | |
8 import dmd.STC; | |
9 import dmd.TemplateThisParameter; | |
10 import dmd.Global; | |
11 import dmd.Array; | |
12 import dmd.Identifier; | |
13 import dmd.TypeArray; | |
14 import dmd.Expression; | |
15 import dmd.Scope; | |
16 import dmd.TypeIdentifier; | |
17 import dmd.TypeDelegate; | |
18 import dmd.IntegerExp; | |
19 import dmd.TypeSArray; | |
20 import dmd.StringExp; | |
21 import dmd.TOK; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
22 import dmd.Parameter; |
0 | 23 import dmd.CtorDeclaration; |
24 import dmd.TypeFunction; | |
25 import dmd.TY; | |
26 import dmd.OutBuffer; | |
27 import dmd.Declaration; | |
28 import dmd.HdrGenState; | |
29 import dmd.TemplateInstance; | |
30 import dmd.WANT; | |
31 import dmd.FuncDeclaration; | |
32 import dmd.TemplateTupleParameter; | |
33 import dmd.MATCH; | |
34 import dmd.Type; | |
35 import dmd.Tuple; | |
36 import dmd.TupleDeclaration; | |
37 import dmd.Initializer; | |
79 | 38 import dmd.Json; |
0 | 39 import dmd.ExpInitializer; |
40 import dmd.TemplateValueParameter; | |
41 import dmd.AliasDeclaration; | |
42 import dmd.VarDeclaration; | |
43 import dmd.TemplateParameter; | |
44 import dmd.TemplateTypeParameter; | |
45 | |
46 import dmd.expression.Util; | |
47 | |
48 import std.stdio; | |
49 | |
50 /************************************** | |
51 * Determine if TemplateDeclaration is variadic. | |
52 */ | |
53 | |
54 TemplateTupleParameter isVariadic(TemplateParameters parameters) | |
55 { | |
56 size_t dim = parameters.dim; | |
104 | 57 TemplateTupleParameter tp = null; |
0 | 58 |
104 | 59 if (dim) |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
60 tp = parameters[dim - 1].isTemplateTupleParameter(); |
0 | 61 |
104 | 62 return tp; |
0 | 63 } |
64 | |
65 void ObjectToCBuffer(OutBuffer buf, HdrGenState* hgs, Object oarg) | |
66 { | |
104 | 67 //printf("ObjectToCBuffer()\n"); |
68 Type t = isType(oarg); | |
69 Expression e = isExpression(oarg); | |
70 Dsymbol s = isDsymbol(oarg); | |
71 Tuple v = isTuple(oarg); | |
72 if (t) | |
73 { | |
0 | 74 //printf("\tt: %s ty = %d\n", t.toChars(), t.ty); |
75 t.toCBuffer(buf, null, hgs); | |
104 | 76 } |
77 else if (e) | |
0 | 78 e.toCBuffer(buf, hgs); |
104 | 79 else if (s) |
80 { | |
0 | 81 string p = s.ident ? s.ident.toChars() : s.toChars(); |
82 buf.writestring(p); | |
104 | 83 } |
84 else if (v) | |
85 { | |
0 | 86 Objects args = v.objects; |
87 for (size_t i = 0; i < args.dim; i++) | |
88 { | |
89 if (i) | |
90 buf.writeByte(','); | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
91 Object o = args[i]; |
0 | 92 ObjectToCBuffer(buf, hgs, o); |
93 } | |
104 | 94 } |
95 else if (!oarg) | |
96 { | |
0 | 97 buf.writestring("null"); |
104 | 98 } |
99 else | |
100 { | |
0 | 101 debug writef("bad Object = %p\n", oarg); |
102 assert(0); | |
104 | 103 } |
0 | 104 } |
105 | |
106 class TemplateDeclaration : ScopeDsymbol | |
107 { | |
104 | 108 TemplateParameters parameters; // array of TemplateParameter's |
0 | 109 |
104 | 110 TemplateParameters origParameters; // originals for Ddoc |
111 Expression constraint; | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
112 Vector!TemplateInstance instances; // array of TemplateInstance's |
0 | 113 |
104 | 114 TemplateDeclaration overnext; // next overloaded TemplateDeclaration |
115 TemplateDeclaration overroot; // first in overnext list | |
0 | 116 |
104 | 117 int semanticRun; // 1 semantic() run |
0 | 118 |
104 | 119 Dsymbol onemember; // if !=NULL then one member of this template |
0 | 120 |
104 | 121 int literal; // this template declaration is a literal |
0 | 122 |
104 | 123 this(Loc loc, Identifier id, TemplateParameters parameters, Expression constraint, Dsymbols decldefs) |
0 | 124 { |
125 super(id); | |
126 | |
127 version (LOG) { | |
128 printf("TemplateDeclaration(this = %p, id = '%s')\n", this, id.toChars()); | |
129 } | |
130 static if (false) { | |
131 if (parameters) | |
132 for (int i = 0; i < parameters.dim; i++) | |
133 { | |
134 TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; | |
135 //printf("\tparameter[%d] = %p\n", i, tp); | |
136 TemplateTypeParameter ttp = tp.isTemplateTypeParameter(); | |
137 | |
138 if (ttp) | |
139 { | |
140 printf("\tparameter[%d] = %s : %s\n", i, tp.ident.toChars(), ttp.specType ? ttp.specType.toChars() : ""); | |
141 } | |
142 } | |
143 } | |
144 | |
145 this.loc = loc; | |
146 this.parameters = parameters; | |
147 this.origParameters = parameters; | |
148 this.constraint = constraint; | |
149 this.members = decldefs; | |
150 | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
151 instances = new Vector!TemplateInstance(); |
0 | 152 } |
153 | |
104 | 154 override Dsymbol syntaxCopy(Dsymbol) |
0 | 155 { |
51 | 156 //printf("TemplateDeclaration.syntaxCopy()\n"); |
157 TemplateDeclaration td; | |
158 TemplateParameters p; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
159 Dsymbols d; |
51 | 160 |
161 p = null; | |
162 if (parameters) | |
163 { | |
164 p = new TemplateParameters(); | |
165 p.setDim(parameters.dim); | |
166 for (int i = 0; i < p.dim; i++) | |
167 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
168 auto tp = parameters[i]; |
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
169 p[i] = tp.syntaxCopy(); |
51 | 170 } |
171 } | |
172 | |
173 Expression e = null; | |
174 if (constraint) | |
175 e = constraint.syntaxCopy(); | |
176 d = Dsymbol.arraySyntaxCopy(members); | |
177 td = new TemplateDeclaration(loc, ident, p, e, d); | |
178 return td; | |
0 | 179 } |
180 | |
104 | 181 override void semantic(Scope sc) |
0 | 182 { |
183 version (LOG) { | |
184 printf("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars()); | |
185 } | |
186 if (semanticRun) | |
187 return; // semantic() already run | |
188 semanticRun = 1; | |
189 | |
190 if (sc.func) | |
191 { | |
192 version (DMDV1) { | |
193 error("cannot declare template at function scope %s", sc.func.toChars()); | |
194 } | |
195 } | |
196 | |
197 if (/*global.params.useArrayBounds &&*/ sc.module_) | |
198 { | |
199 // Generate this function as it may be used | |
200 // when template is instantiated in other modules | |
201 sc.module_.toModuleArray(); | |
202 } | |
203 | |
204 if (/*global.params.useAssert &&*/ sc.module_) | |
205 { | |
206 // Generate this function as it may be used | |
207 // when template is instantiated in other modules | |
208 sc.module_.toModuleAssert(); | |
209 } | |
210 | |
211 /* Remember Scope for later instantiations, but make | |
212 * a copy since attributes can change. | |
213 */ | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
214 this.scope_ = sc.clone(); |
0 | 215 this.scope_.setNoFree(); |
216 | |
217 // Set up scope for parameters | |
218 ScopeDsymbol paramsym = new ScopeDsymbol(); | |
219 paramsym.parent = sc.parent; | |
220 Scope paramscope = sc.push(paramsym); | |
221 paramscope.parameterSpecialization = 1; | |
222 paramscope.stc = STCundefined; | |
223 | |
224 if (!parent) | |
225 parent = sc.parent; | |
226 | |
227 if (global.params.doDocComments) | |
228 { | |
229 origParameters = new TemplateParameters(); | |
230 origParameters.setDim(parameters.dim); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
231 foreach (size_t i, TemplateParameter tp; parameters) |
0 | 232 { |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
233 origParameters[i] = tp.syntaxCopy(); |
0 | 234 } |
235 } | |
236 | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
237 foreach (tp; parameters) |
0 | 238 { |
239 tp.declareParameter(paramscope); | |
240 } | |
241 | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
242 foreach (size_t i, TemplateParameter tp; parameters) |
0 | 243 { |
244 tp.semantic(paramscope); | |
245 if (i + 1 != parameters.dim && tp.isTemplateTupleParameter()) | |
246 error("template tuple parameter must be last one"); | |
247 } | |
248 | |
249 paramscope.pop(); | |
250 | |
251 if (members) | |
252 { | |
253 Dsymbol s; | |
254 if (Dsymbol.oneMembers(members, &s)) | |
255 { | |
256 if (s && s.ident && s.ident.equals(ident)) | |
257 { | |
258 onemember = s; | |
259 s.parent = this; | |
260 } | |
261 } | |
262 } | |
263 | |
264 /* BUG: should check: | |
265 * o no virtual functions or non-static data members of classes | |
266 */ | |
267 } | |
268 | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
269 /********************************** |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
270 * Overload existing TemplateDeclaration 'this' with the new one 's'. |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
271 * Return !=0 if successful; i.e. no conflict. |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
272 */ |
104 | 273 override bool overloadInsert(Dsymbol s) |
0 | 274 { |
50 | 275 TemplateDeclaration *pf; |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
276 TemplateDeclaration f; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
277 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
278 version (LOG) { |
50 | 279 printf("TemplateDeclaration.overloadInsert('%.*s')\n", s.toChars()); |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
280 } |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
281 f = s.isTemplateDeclaration(); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
282 if (!f) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
283 return false; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
284 |
50 | 285 TemplateDeclaration pthis = this; |
286 for (pf = &pthis; *pf; pf = &(*pf).overnext) | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
287 { |
50 | 288 static if (false) { |
289 // Conflict if TemplateParameter's match | |
290 // Will get caught anyway later with TemplateInstance, but | |
291 // should check it now. | |
292 if (f.parameters.dim != f2.parameters.dim) | |
293 goto Lcontinue; | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
294 |
50 | 295 for (int i = 0; i < f.parameters.dim; i++) |
296 { | |
297 TemplateParameter p1 = cast(TemplateParameter)f.parameters.data[i]; | |
298 TemplateParameter p2 = cast(TemplateParameter)f2.parameters.data[i]; | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
299 |
50 | 300 if (!p1.overloadMatch(p2)) |
301 goto Lcontinue; | |
302 } | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
303 |
50 | 304 version (LOG) { |
305 printf("\tfalse: conflict\n"); | |
306 } | |
307 return false; | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
308 |
50 | 309 Lcontinue: |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
310 ; |
50 | 311 } |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
312 } |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
313 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
314 f.overroot = this; |
50 | 315 *pf = f; |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
316 version (LOG) { |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
317 printf("\ttrue: no conflict\n"); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
318 } |
50 | 319 |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
320 return true; |
0 | 321 } |
322 | |
104 | 323 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 324 { |
104 | 325 static if (false) // Should handle template functions |
326 { | |
327 if (onemember && onemember.isFuncDeclaration()) | |
328 buf.writestring("foo "); | |
329 } | |
330 buf.writestring(kind()); | |
331 buf.writeByte(' '); | |
332 buf.writestring(ident.toChars()); | |
333 buf.writeByte('('); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
334 foreach (size_t i, TemplateParameter tp; parameters) |
104 | 335 { |
336 if (hgs.ddoc) | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
337 tp = origParameters[i]; |
104 | 338 if (i) |
339 buf.writeByte(','); | |
340 tp.toCBuffer(buf, hgs); | |
341 } | |
342 buf.writeByte(')'); | |
343 version(DMDV2) | |
344 { | |
345 if (constraint) | |
346 { buf.writestring(" if ("); | |
347 constraint.toCBuffer(buf, hgs); | |
348 buf.writeByte(')'); | |
349 } | |
350 } | |
351 | |
352 if (hgs.hdrgen) | |
353 { | |
354 hgs.tpltMember++; | |
355 buf.writenl(); | |
356 buf.writebyte('{'); | |
357 buf.writenl(); | |
358 foreach (Dsymbol s; members) | |
359 s.toCBuffer(buf, hgs); | |
360 | |
361 buf.writebyte('}'); | |
362 buf.writenl(); | |
363 hgs.tpltMember--; | |
364 } | |
0 | 365 } |
366 | |
79 | 367 override void toJsonBuffer(OutBuffer buf) |
368 { | |
369 //writef("TemplateDeclaration.toJsonBuffer()\n"); | |
370 | |
371 buf.writestring("{\n"); | |
372 | |
373 JsonProperty(buf, Pname, toChars()); | |
374 JsonProperty(buf, Pkind, kind()); | |
375 if (comment) | |
376 JsonProperty(buf, Pcomment, comment); | |
377 | |
378 if (loc.linnum) | |
379 JsonProperty(buf, Pline, loc.linnum); | |
380 | |
381 JsonString(buf, Pmembers); | |
382 buf.writestring(" : [\n"); | |
383 size_t offset = buf.offset; | |
384 foreach (Dsymbol s; members) | |
385 { | |
386 if (offset != buf.offset) | |
96 | 387 { buf.writestring(",\n"); |
79 | 388 offset = buf.offset; |
389 } | |
390 s.toJsonBuffer(buf); | |
391 } | |
96 | 392 JsonRemoveComma(buf); |
79 | 393 buf.writestring("]\n"); |
394 | |
395 buf.writestring("}\n"); | |
396 } | |
397 | |
104 | 398 override string kind() |
0 | 399 { |
50 | 400 return (onemember && onemember.isAggregateDeclaration()) |
401 ? onemember.kind() | |
402 : "template"; | |
0 | 403 } |
404 | |
104 | 405 override string toChars() |
0 | 406 { |
49 | 407 OutBuffer buf = new OutBuffer(); |
408 HdrGenState hgs; | |
409 | |
410 /// memset(&hgs, 0, hgs.sizeof); | |
411 buf.writestring(ident.toChars()); | |
412 buf.writeByte('('); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
413 foreach (size_t i, TemplateParameter tp; parameters) |
49 | 414 { |
415 if (i) | |
416 buf.writeByte(','); | |
417 tp.toCBuffer(buf, &hgs); | |
418 } | |
419 buf.writeByte(')'); | |
420 version (DMDV2) { | |
421 if (constraint) | |
422 { | |
423 buf.writestring(" if ("); | |
424 constraint.toCBuffer(buf, &hgs); | |
425 buf.writeByte(')'); | |
426 } | |
427 } | |
428 buf.writeByte(0); | |
429 return buf.extractString(); | |
0 | 430 } |
431 | |
104 | 432 override void emitComment(Scope sc) |
0 | 433 { |
434 assert(false); | |
435 } | |
50 | 436 |
104 | 437 // void toDocBuffer(OutBuffer *buf); |
0 | 438 |
439 /*************************************** | |
440 * Given that ti is an instance of this TemplateDeclaration, | |
441 * deduce the types of the parameters to this, and store | |
442 * those deduced types in dedtypes[]. | |
443 * Input: | |
444 * flag 1: don't do semantic() because of dummy types | |
445 * 2: don't change types in matchArg() | |
446 * Output: | |
447 * dedtypes deduced arguments | |
448 * Return match level. | |
449 */ | |
104 | 450 MATCH matchWithInstance(TemplateInstance ti, Objects dedtypes, int flag) |
0 | 451 { |
452 MATCH m; | |
453 int dedtypes_dim = dedtypes.dim; | |
454 | |
455 version (LOGM) { | |
50 | 456 printf("\n+TemplateDeclaration.matchWithInstance(this = %.*s, ti = %.*s, flag = %d)\n", toChars(), ti.toChars(), flag); |
0 | 457 } |
458 | |
459 static if (false) { | |
460 printf("dedtypes.dim = %d, parameters.dim = %d\n", dedtypes_dim, parameters.dim); | |
461 if (ti.tiargs.dim) | |
462 printf("ti.tiargs.dim = %d, [0] = %p\n", ti.tiargs.dim, ti.tiargs.data[0]); | |
463 } | |
464 dedtypes.zero(); | |
465 | |
466 int parameters_dim = parameters.dim; | |
467 int variadic = isVariadic() !is null; | |
468 | |
469 // If more arguments than parameters, no match | |
470 if (ti.tiargs.dim > parameters_dim && !variadic) | |
471 { | |
472 version (LOGM) { | |
50 | 473 printf(" no match: more arguments than parameters\n"); |
0 | 474 } |
50 | 475 return MATCHnomatch; |
0 | 476 } |
477 | |
478 assert(dedtypes_dim == parameters_dim); | |
479 assert(dedtypes_dim >= ti.tiargs.dim || variadic); | |
480 | |
481 // Set up scope for parameters | |
482 assert(cast(size_t)cast(void*)scope_ > 0x10000); | |
483 ScopeDsymbol paramsym = new ScopeDsymbol(); | |
484 paramsym.parent = scope_.parent; | |
485 Scope paramscope = scope_.push(paramsym); | |
486 paramscope.stc = STCundefined; | |
487 | |
488 // Attempt type deduction | |
489 m = MATCHexact; | |
490 for (int i = 0; i < dedtypes_dim; i++) | |
491 { | |
492 MATCH m2; | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
493 auto tp = parameters[i]; |
0 | 494 Declaration sparam; |
495 | |
496 //printf("\targument [%d]\n", i); | |
497 version (LOGM) { | |
498 //printf("\targument [%d] is %s\n", i, oarg ? oarg.toChars() : "null"); | |
499 TemplateTypeParameter *ttp = tp.isTemplateTypeParameter(); | |
500 if (ttp) | |
501 printf("\tparameter[%d] is %s : %s\n", i, tp.ident.toChars(), ttp.specType ? ttp.specType.toChars() : ""); | |
502 } | |
503 | |
504 version (DMDV1) { | |
505 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, &sparam); | |
506 } else { | |
507 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, &sparam, (flag & 2) ? 1 : 0); | |
508 } | |
509 //printf("\tm2 = %d\n", m2); | |
510 | |
511 if (m2 == MATCHnomatch) | |
512 { | |
513 static if (false) { | |
514 printf("\tmatchArg() for parameter %i failed\n", i); | |
515 } | |
516 goto Lnomatch; | |
517 } | |
518 | |
519 if (m2 < m) | |
520 m = m2; | |
521 | |
522 if (!flag) | |
523 sparam.semantic(paramscope); | |
524 if (!paramscope.insert(sparam)) | |
525 goto Lnomatch; | |
526 } | |
527 | |
528 if (!flag) | |
529 { | |
530 /* Any parameter left without a type gets the type of | |
531 * its corresponding arg | |
532 */ | |
533 for (int i = 0; i < dedtypes_dim; i++) | |
534 { | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
535 if (!dedtypes[i]) |
0 | 536 { |
537 assert(i < ti.tiargs.dim); | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
538 dedtypes[i] = ti.tiargs[i]; |
0 | 539 } |
540 } | |
541 } | |
542 | |
543 version (DMDV2) { | |
544 if (m && constraint && !(flag & 1)) | |
545 { /* Check to see if constraint is satisfied. | |
546 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
547 makeParamNamesVisibleInConstraint(paramscope); |
0 | 548 Expression e = constraint.syntaxCopy(); |
549 paramscope.flags |= SCOPE.SCOPEstaticif; | |
550 e = e.semantic(paramscope); | |
551 e = e.optimize(WANTvalue | WANTinterpret); | |
552 if (e.isBool(true)) { | |
553 ; | |
554 } else if (e.isBool(false)) | |
555 goto Lnomatch; | |
556 else | |
557 { | |
558 e.error("constraint %s is not constant or does not evaluate to a bool", e.toChars()); | |
559 } | |
560 } | |
561 } | |
562 | |
563 version (LOGM) { | |
564 // Print out the results | |
565 printf("--------------------------\n"); | |
566 printf("template %s\n", toChars()); | |
567 printf("instance %s\n", ti.toChars()); | |
568 if (m) | |
569 { | |
570 for (int i = 0; i < dedtypes_dim; i++) | |
571 { | |
572 TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; | |
573 Object oarg; | |
574 | |
575 printf(" [%d]", i); | |
576 | |
577 if (i < ti.tiargs.dim) | |
578 oarg = cast(Object)ti.tiargs.data[i]; | |
579 else | |
580 oarg = null; | |
581 tp.print(oarg, cast(Object)dedtypes.data[i]); | |
582 } | |
583 } | |
584 else | |
585 goto Lnomatch; | |
586 } | |
587 | |
588 version (LOGM) { | |
589 printf(" match = %d\n", m); | |
590 } | |
591 goto Lret; | |
592 | |
593 Lnomatch: | |
594 version (LOGM) { | |
595 printf(" no match\n"); | |
596 } | |
597 m = MATCHnomatch; | |
598 | |
599 Lret: | |
600 paramscope.pop(); | |
601 version (LOGM) { | |
602 printf("-TemplateDeclaration.matchWithInstance(this = %p, ti = %p) = %d\n", this, ti, m); | |
603 } | |
604 return m; | |
605 } | |
606 | |
51 | 607 /******************************************** |
608 * Determine partial specialization order of 'this' vs td2. | |
609 * Returns: | |
610 * match this is at least as specialized as td2 | |
611 * 0 td2 is more specialized than this | |
612 */ | |
104 | 613 MATCH leastAsSpecialized(TemplateDeclaration td2) |
0 | 614 { |
104 | 615 /* This works by taking the template parameters to this template |
51 | 616 * declaration and feeding them to td2 as if it were a template |
617 * instance. | |
618 * If it works, then this template is at least as specialized | |
619 * as td2. | |
620 */ | |
621 | |
622 scope TemplateInstance ti = new TemplateInstance(Loc(0), ident); // create dummy template instance | |
623 scope Objects dedtypes = new Objects(); | |
624 | |
625 version (LOG_LEASTAS) { | |
626 printf("%s.leastAsSpecialized(%s)\n", toChars(), td2.toChars()); | |
627 } | |
628 | |
629 // Set type arguments to dummy template instance to be types | |
630 // generated from the parameters to this template declaration | |
631 ti.tiargs = new Objects(); | |
632 ti.tiargs.setDim(parameters.dim); | |
633 for (int i = 0; i < ti.tiargs.dim; i++) | |
634 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
635 auto tp = parameters[i]; |
51 | 636 |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
637 auto p = tp.dummyArg(); |
51 | 638 if (p) |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
639 ti.tiargs[i] = p; |
51 | 640 else |
641 ti.tiargs.setDim(i); | |
642 } | |
643 | |
644 // Temporary Array to hold deduced types | |
645 //dedtypes.setDim(parameters.dim); | |
646 dedtypes.setDim(td2.parameters.dim); | |
647 | |
648 // Attempt a type deduction | |
649 MATCH m = td2.matchWithInstance(ti, dedtypes, 1); | |
650 if (m) | |
651 { | |
652 /* A non-variadic template is more specialized than a | |
653 * variadic one. | |
654 */ | |
655 if (isVariadic() && !td2.isVariadic()) | |
656 goto L1; | |
657 | |
658 version (LOG_LEASTAS) { | |
659 printf(" matches %d, so is least as specialized\n", m); | |
660 } | |
661 return m; | |
662 } | |
663 L1: | |
664 version (LOG_LEASTAS) { | |
665 printf(" doesn't match, so is not as specialized\n"); | |
666 } | |
667 return MATCHnomatch; | |
0 | 668 } |
669 | |
670 /************************************************* | |
671 * Match function arguments against a specific template function. | |
672 * Input: | |
673 * loc instantiation location | |
674 * targsi Expression/Type initial list of template arguments | |
675 * ethis 'this' argument if !null | |
676 * fargs arguments to function | |
677 * Output: | |
678 * dedargs Expression/Type deduced template arguments | |
679 * Returns: | |
680 * match level | |
681 */ | |
104 | 682 MATCH deduceFunctionTemplateMatch(Loc loc, Objects targsi, Expression ethis, Expressions fargs, Objects dedargs) |
0 | 683 { |
684 size_t nfparams; | |
685 size_t nfargs; | |
686 size_t nargsi; // array size of targsi | |
687 int fptupindex = -1; | |
688 int tuple_dim = 0; | |
689 MATCH match = MATCHexact; | |
690 FuncDeclaration fd = onemember.toAlias().isFuncDeclaration(); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
691 Parameters fparameters; // function parameter list |
0 | 692 int fvarargs; // function varargs |
693 scope Objects dedtypes = new Objects(); // for T:T*, the dedargs is the T*, dedtypes is the T | |
694 | |
79 | 695 static if (false) |
696 { | |
0 | 697 printf("\nTemplateDeclaration.deduceFunctionTemplateMatch() %s\n", toChars()); |
698 for (i = 0; i < fargs.dim; i++) | |
699 { | |
700 Expression e = cast(Expression)fargs.data[i]; | |
701 printf("\tfarg[%d] is %s, type is %s\n", i, e.toChars(), e.type.toChars()); | |
702 } | |
703 printf("fd = %s\n", fd.toChars()); | |
704 printf("fd.type = %p\n", fd.type); | |
705 } | |
706 | |
707 assert(cast(size_t)cast(void*)scope_ > 0x10000); | |
708 | |
709 dedargs.setDim(parameters.dim); | |
710 dedargs.zero(); | |
711 | |
712 dedtypes.setDim(parameters.dim); | |
713 dedtypes.zero(); | |
714 | |
715 // Set up scope for parameters | |
716 ScopeDsymbol paramsym = new ScopeDsymbol(); | |
717 paramsym.parent = scope_.parent; | |
718 Scope paramscope = scope_.push(paramsym); | |
719 | |
720 TemplateTupleParameter tp = isVariadic(); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
721 int tp_is_declared = 0; |
0 | 722 |
79 | 723 static if (false) |
724 { | |
0 | 725 for (i = 0; i < dedargs.dim; i++) |
726 { | |
727 printf("\tdedarg[%d] = ", i); | |
728 Object oarg = cast(Object)dedargs.data[i]; | |
729 if (oarg) printf("%s", oarg.toChars()); | |
730 printf("\n"); | |
731 } | |
732 } | |
733 | |
734 | |
735 nargsi = 0; | |
736 if (targsi) | |
79 | 737 { |
738 // Set initial template arguments | |
0 | 739 nargsi = targsi.dim; |
79 | 740 size_t n = parameters.dim; |
0 | 741 if (tp) |
742 n--; | |
743 if (nargsi > n) | |
744 { | |
745 if (!tp) | |
746 goto Lnomatch; | |
747 | |
748 /* The extra initial template arguments | |
749 * now form the tuple argument. | |
750 */ | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
751 auto t = new Tuple(); |
0 | 752 assert(parameters.dim); |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
753 dedargs[parameters.dim - 1] = t; |
0 | 754 |
755 tuple_dim = nargsi - n; | |
756 t.objects.setDim(tuple_dim); | |
757 for (size_t i = 0; i < tuple_dim; i++) | |
758 { | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
759 t.objects[i] = targsi[n + i]; |
0 | 760 } |
761 declareParameter(paramscope, tp, t); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
762 tp_is_declared = 1; |
0 | 763 } |
764 else | |
765 n = nargsi; | |
766 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
767 memcpy(dedargs.ptr, targsi.ptr, n * (*dedargs.ptr).sizeof); |
0 | 768 |
769 for (size_t i = 0; i < n; i++) | |
770 { | |
771 assert(i < parameters.dim); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
772 auto tp2 = parameters[i]; |
0 | 773 MATCH m; |
774 Declaration sparam = null; | |
775 | |
776 m = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam); | |
777 //printf("\tdeduceType m = %d\n", m); | |
778 if (m == MATCHnomatch) | |
779 goto Lnomatch; | |
780 if (m < match) | |
781 match = m; | |
782 | |
783 sparam.semantic(paramscope); | |
784 if (!paramscope.insert(sparam)) | |
785 goto Lnomatch; | |
786 } | |
787 } | |
79 | 788 static if (false) |
789 { | |
0 | 790 for (i = 0; i < dedargs.dim; i++) |
791 { | |
792 printf("\tdedarg[%d] = ", i); | |
793 Object oarg = cast(Object)dedargs.data[i]; | |
794 if (oarg) printf("%s", oarg.toChars()); | |
795 printf("\n"); | |
796 } | |
797 } | |
798 | |
799 if (fd.type) | |
800 { | |
801 assert(fd.type.ty == Tfunction); | |
802 TypeFunction fdtype = cast(TypeFunction)fd.type; | |
803 fparameters = fdtype.parameters; | |
804 fvarargs = fdtype.varargs; | |
805 } | |
806 else | |
807 { | |
808 CtorDeclaration fctor = fd.isCtorDeclaration(); | |
809 assert(fctor); | |
810 fparameters = fctor.arguments; | |
811 fvarargs = fctor.varargs; | |
812 } | |
813 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
814 nfparams = Parameter.dim(fparameters); // number of function parameters |
0 | 815 nfargs = fargs ? fargs.dim : 0; // number of function arguments |
816 | |
817 /* Check for match of function arguments with variadic template | |
818 * parameter, such as: | |
819 * | |
820 * template Foo(T, A...) { void Foo(T t, A a); } | |
821 * void main() { Foo(1,2,3); } | |
822 */ | |
823 if (tp) // if variadic | |
824 { | |
79 | 825 if (nfparams == 0 && nfargs != 0) // if no function parameters |
0 | 826 { |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
827 if (tp_is_declared) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
828 goto L2; |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
829 auto t = new Tuple(); |
0 | 830 //printf("t = %p\n", t); |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
831 dedargs[parameters.dim - 1] = t; |
0 | 832 declareParameter(paramscope, tp, t); |
833 goto L2; | |
834 } | |
835 else if (nfargs < nfparams - 1) | |
836 goto L1; | |
837 else | |
838 { | |
839 /* Figure out which of the function parameters matches | |
840 * the tuple template parameter. Do this by matching | |
841 * type identifiers. | |
842 * Set the index of this function parameter to fptupindex. | |
843 */ | |
844 for (fptupindex = 0; fptupindex < nfparams; fptupindex++) | |
845 { | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
846 auto fparam = fparameters[fptupindex]; |
0 | 847 if (fparam.type.ty != Tident) |
848 continue; | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
849 auto tid = cast(TypeIdentifier)fparam.type; |
0 | 850 if (!tp.ident.equals(tid.ident) || tid.idents.dim) |
851 continue; | |
852 | |
853 if (fvarargs) // variadic function doesn't | |
854 goto Lnomatch; // go with variadic template | |
855 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
856 if (tp_is_declared) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
857 goto L2; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
858 |
0 | 859 /* The types of the function arguments |
860 * now form the tuple argument. | |
861 */ | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
862 auto t = new Tuple(); |
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
863 dedargs[parameters.dim - 1] = t; |
0 | 864 |
865 tuple_dim = nfargs - (nfparams - 1); | |
866 t.objects.setDim(tuple_dim); | |
867 for (size_t i = 0; i < tuple_dim; i++) | |
868 { | |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
87
diff
changeset
|
869 auto farg = fargs[fptupindex + i]; |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
870 t.objects[i] = farg.type; |
0 | 871 } |
872 declareParameter(paramscope, tp, t); | |
873 goto L2; | |
874 } | |
875 fptupindex = -1; | |
876 } | |
877 } | |
878 | |
879 L1: | |
880 if (nfparams == nfargs) { | |
881 ; | |
882 } else if (nfargs > nfparams) { | |
883 if (fvarargs == 0) | |
884 goto Lnomatch; // too many args, no match | |
885 match = MATCHconvert; // match ... with a conversion | |
886 } | |
887 | |
888 L2: | |
889 version (DMDV2) { | |
890 // Match 'ethis' to any TemplateThisParameter's | |
891 if (ethis) | |
892 { | |
893 for (size_t i = 0; i < parameters.dim; i++) | |
894 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
895 auto tp2 = parameters[i]; |
0 | 896 TemplateThisParameter ttp = tp2.isTemplateThisParameter(); |
897 if (ttp) | |
898 { | |
899 MATCH m; | |
900 | |
901 Type t = new TypeIdentifier(Loc(0), ttp.ident); | |
902 m = ethis.type.deduceType(paramscope, t, parameters, dedtypes); | |
903 if (!m) | |
904 goto Lnomatch; | |
905 if (m < match) | |
906 match = m; // pick worst match | |
907 } | |
908 } | |
909 } | |
910 } | |
911 | |
912 // Loop through the function parameters | |
913 for (size_t i = 0; i < nfparams; i++) | |
914 { | |
915 /* Skip over function parameters which wound up | |
916 * as part of a template tuple parameter. | |
917 */ | |
918 if (i == fptupindex) | |
919 { | |
920 if (fptupindex == nfparams - 1) | |
921 break; | |
922 i += tuple_dim - 1; | |
923 continue; | |
924 } | |
925 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
926 auto fparam = Parameter.getNth(fparameters, i); |
0 | 927 |
928 if (i >= nfargs) // if not enough arguments | |
929 { | |
930 if (fparam.defaultArg) | |
931 { | |
932 /* Default arguments do not participate in template argument | |
933 * deduction. | |
934 */ | |
935 goto Lmatch; | |
936 } | |
937 } | |
938 else | |
939 { | |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
87
diff
changeset
|
940 auto farg = fargs[i]; |
0 | 941 static if (false) { |
942 printf("\tfarg.type = %s\n", farg.type.toChars()); | |
943 printf("\tfparam.type = %s\n", fparam.type.toChars()); | |
944 } | |
945 Type argtype = farg.type; | |
946 | |
947 version (DMDV2) { | |
948 /* Allow string literals which are type [] to match with [dim] | |
949 */ | |
950 if (farg.op == TOKstring) | |
951 { | |
952 StringExp se = cast(StringExp)farg; | |
953 if (!se.committed && argtype.ty == Tarray && | |
954 fparam.type.toBasetype().ty == Tsarray) | |
955 { | |
956 argtype = new TypeSArray(argtype.nextOf(), new IntegerExp(se.loc, se.len, Type.tindex)); | |
957 argtype = argtype.semantic(se.loc, null); | |
958 argtype = argtype.invariantOf(); | |
959 } | |
960 } | |
961 } | |
962 | |
963 MATCH m; | |
964 m = argtype.deduceType(paramscope, fparam.type, parameters, dedtypes); | |
965 //printf("\tdeduceType m = %d\n", m); | |
966 | |
967 /* If no match, see if there's a conversion to a delegate | |
968 */ | |
969 if (!m && fparam.type.toBasetype().ty == Tdelegate) | |
970 { | |
971 TypeDelegate td = cast(TypeDelegate)fparam.type.toBasetype(); | |
972 TypeFunction tf = cast(TypeFunction)td.next; | |
973 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
974 if (!tf.varargs && Parameter.dim(tf.parameters) == 0) |
0 | 975 { |
976 m = farg.type.deduceType(paramscope, tf.next, parameters, dedtypes); | |
977 if (!m && tf.next.toBasetype().ty == Tvoid) | |
978 m = MATCHconvert; | |
979 } | |
980 //printf("\tm2 = %d\n", m); | |
981 } | |
982 | |
983 if (m) | |
984 { | |
985 if (m < match) | |
986 match = m; // pick worst match | |
987 continue; | |
988 } | |
989 } | |
990 | |
991 /* The following code for variadic arguments closely | |
992 * matches TypeFunction.callMatch() | |
993 */ | |
994 if (!(fvarargs == 2 && i + 1 == nfparams)) | |
995 goto Lnomatch; | |
996 | |
997 /* Check for match with function parameter T... | |
998 */ | |
999 Type tb = fparam.type.toBasetype(); | |
1000 switch (tb.ty) | |
1001 { | |
1002 // Perhaps we can do better with this, see TypeFunction.callMatch() | |
1003 case Tsarray: | |
1004 { | |
1005 TypeSArray tsa = cast(TypeSArray)tb; | |
1006 ulong sz = tsa.dim.toInteger(); | |
1007 if (sz != nfargs - i) | |
1008 goto Lnomatch; | |
1009 } | |
1010 case Tarray: | |
1011 { | |
1012 TypeArray ta = cast(TypeArray)tb; | |
1013 for (; i < nfargs; i++) | |
1014 { | |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
87
diff
changeset
|
1015 auto arg = fargs[i]; |
0 | 1016 assert(arg); |
1017 MATCH m; | |
1018 /* If lazy array of delegates, | |
1019 * convert arg(s) to delegate(s) | |
1020 */ | |
1021 Type tret = fparam.isLazyArray(); | |
1022 if (tret) | |
1023 { | |
1024 if (ta.next.equals(arg.type)) | |
1025 { | |
1026 m = MATCHexact; | |
1027 } | |
1028 else | |
1029 { | |
1030 m = arg.implicitConvTo(tret); | |
1031 if (m == MATCHnomatch) | |
1032 { | |
1033 if (tret.toBasetype().ty == Tvoid) | |
1034 m = MATCHconvert; | |
1035 } | |
1036 } | |
1037 } | |
1038 else | |
1039 { | |
1040 m = arg.type.deduceType(paramscope, ta.next, parameters, dedtypes); | |
1041 //m = arg.implicitConvTo(ta.next); | |
1042 } | |
1043 if (m == MATCHnomatch) | |
1044 goto Lnomatch; | |
1045 if (m < match) | |
1046 match = m; | |
1047 } | |
1048 goto Lmatch; | |
1049 } | |
1050 case Tclass: | |
1051 case Tident: | |
1052 goto Lmatch; | |
1053 | |
1054 default: | |
1055 goto Lnomatch; | |
1056 } | |
1057 } | |
1058 | |
1059 Lmatch: | |
1060 | |
1061 /* Fill in any missing arguments with their defaults. | |
1062 */ | |
1063 for (size_t i = nargsi; i < dedargs.dim; i++) | |
1064 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1065 auto tp2 = parameters[i]; |
0 | 1066 //printf("tp2[%d] = %s\n", i, tp2.ident.toChars()); |
1067 /* For T:T*, the dedargs is the T*, dedtypes is the T | |
1068 * But for function templates, we really need them to match | |
1069 */ | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
1070 Object oarg = dedargs[i]; |
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
1071 Object oded = dedtypes[i]; |
0 | 1072 //printf("1dedargs[%d] = %p, dedtypes[%d] = %p\n", i, oarg, i, oded); |
1073 //if (oarg) printf("oarg: %s\n", oarg.toChars()); | |
1074 //if (oded) printf("oded: %s\n", oded.toChars()); | |
1075 if (!oarg) | |
1076 { | |
1077 if (oded) | |
1078 { | |
1079 if (tp2.specialization()) | |
1080 { | |
1081 /* The specialization can work as long as afterwards | |
1082 * the oded == oarg | |
1083 */ | |
1084 Declaration sparam; | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
1085 dedargs[i] = oded; |
0 | 1086 MATCH m2 = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0); |
1087 //printf("m2 = %d\n", m2); | |
1088 if (!m2) | |
1089 goto Lnomatch; | |
1090 if (m2 < match) | |
1091 match = m2; // pick worst match | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
1092 if (dedtypes[i] !is oded) |
0 | 1093 error("specialization not allowed for deduced parameter %s", tp2.ident.toChars()); |
1094 } | |
1095 } | |
1096 else | |
1097 { | |
1098 oded = tp2.defaultArg(loc, paramscope); | |
1099 if (!oded) | |
1100 goto Lnomatch; | |
1101 } | |
1102 declareParameter(paramscope, tp2, oded); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
90
diff
changeset
|
1103 dedargs[i] = oded; |
0 | 1104 } |
1105 } | |
1106 | |
1107 version (DMDV2) { | |
1108 if (constraint) | |
1109 { /* Check to see if constraint is satisfied. | |
1110 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1111 makeParamNamesVisibleInConstraint(paramscope); |
0 | 1112 Expression e = constraint.syntaxCopy(); |
1113 paramscope.flags |= SCOPE.SCOPEstaticif; | |
1114 e = e.semantic(paramscope); | |
1115 e = e.optimize(WANTvalue | WANTinterpret); | |
1116 if (e.isBool(true)) { | |
1117 ; | |
1118 } else if (e.isBool(false)) | |
1119 goto Lnomatch; | |
1120 else | |
1121 { | |
1122 e.error("constraint %s is not constant or does not evaluate to a bool", e.toChars()); | |
1123 } | |
1124 } | |
1125 } | |
1126 | |
1127 static if (false) { | |
1128 for (i = 0; i < dedargs.dim; i++) | |
1129 { | |
1130 Type t = cast(Type)dedargs.data[i]; | |
1131 printf("\tdedargs[%d] = %d, %s\n", i, t.dyncast(), t.toChars()); | |
1132 } | |
1133 } | |
1134 | |
1135 paramscope.pop(); | |
1136 //printf("\tmatch %d\n", match); | |
1137 return match; | |
1138 | |
1139 Lnomatch: | |
1140 paramscope.pop(); | |
1141 //printf("\tnomatch\n"); | |
1142 return MATCHnomatch; | |
1143 } | |
104 | 1144 |
0 | 1145 /************************************************* |
1146 * Given function arguments, figure out which template function | |
1147 * to expand, and return that function. | |
1148 * If no match, give error message and return null. | |
1149 * Input: | |
1150 * sc instantiation scope | |
1151 * loc instantiation location | |
1152 * targsi initial list of template arguments | |
1153 * ethis if !null, the 'this' pointer argument | |
1154 * fargs arguments to function | |
1155 * flags 1: do not issue error message on no match, just return null | |
1156 */ | |
1157 FuncDeclaration deduceFunctionTemplate(Scope sc, Loc loc, Objects targsi, Expression ethis, Expressions fargs, int flags = 0) | |
1158 { | |
1159 MATCH m_best = MATCHnomatch; | |
1160 TemplateDeclaration td_ambig = null; | |
1161 TemplateDeclaration td_best = null; | |
1162 Objects tdargs = new Objects(); | |
1163 TemplateInstance ti; | |
1164 FuncDeclaration fd; | |
1165 | |
1166 static if (false) { | |
1167 printf("TemplateDeclaration.deduceFunctionTemplate() %s\n", toChars()); | |
104 | 1168 printf(" targsi:\n"); |
0 | 1169 if (targsi) |
1170 { | |
1171 for (int i = 0; i < targsi.dim; i++) | |
1172 { | |
1173 Object arg = cast(Object)targsi.data[i]; | |
1174 printf("\t%s\n", arg.toChars()); | |
1175 } | |
1176 } | |
104 | 1177 printf(" fargs:\n"); |
0 | 1178 for (int i = 0; i < fargs.dim; i++) |
1179 { | |
1180 Expression arg = cast(Expression)fargs.data[i]; | |
1181 printf("\t%s %s\n", arg.type.toChars(), arg.toChars()); | |
1182 //printf("\tty = %d\n", arg.type.ty); | |
1183 } | |
1184 } | |
1185 | |
1186 for (TemplateDeclaration td = this; td; td = td.overnext) | |
1187 { | |
1188 if (!td.semanticRun) | |
1189 { | |
1190 error("forward reference to template %s", td.toChars()); | |
1191 goto Lerror; | |
1192 } | |
1193 if (!td.onemember || !td.onemember.toAlias().isFuncDeclaration()) | |
1194 { | |
1195 error("is not a function template"); | |
1196 goto Lerror; | |
1197 } | |
1198 | |
1199 MATCH m; | |
1200 scope Objects dedargs = new Objects(); | |
1201 | |
1202 m = td.deduceFunctionTemplateMatch(loc, targsi, ethis, fargs, dedargs); | |
1203 //printf("deduceFunctionTemplateMatch = %d\n", m); | |
1204 if (!m) // if no match | |
1205 continue; | |
1206 | |
1207 if (m < m_best) | |
1208 goto Ltd_best; | |
1209 if (m > m_best) | |
1210 goto Ltd; | |
1211 | |
1212 { | |
1213 // Disambiguate by picking the most specialized TemplateDeclaration | |
1214 MATCH c1 = td.leastAsSpecialized(td_best); | |
1215 MATCH c2 = td_best.leastAsSpecialized(td); | |
1216 //printf("c1 = %d, c2 = %d\n", c1, c2); | |
1217 | |
1218 if (c1 > c2) | |
1219 goto Ltd; | |
1220 else if (c1 < c2) | |
1221 goto Ltd_best; | |
1222 else | |
1223 goto Lambig; | |
1224 } | |
1225 | |
1226 Lambig: // td_best and td are ambiguous | |
1227 td_ambig = td; | |
1228 continue; | |
1229 | |
1230 Ltd_best: // td_best is the best match so far | |
1231 td_ambig = null; | |
1232 continue; | |
1233 | |
1234 Ltd: // td is the new best match | |
1235 td_ambig = null; | |
1236 assert(cast(size_t)cast(void*)td.scope_ > 0x10000); | |
1237 td_best = td; | |
1238 m_best = m; | |
1239 tdargs.setDim(dedargs.dim); | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
1240 memcpy(tdargs.ptr, dedargs.ptr, tdargs.dim * (void*).sizeof); |
0 | 1241 continue; |
1242 } | |
1243 if (!td_best) | |
1244 { | |
1245 if (!(flags & 1)) | |
1246 error(loc, "does not match any function template declaration"); | |
1247 goto Lerror; | |
1248 } | |
1249 if (td_ambig) | |
1250 { | |
1251 error(loc, "matches more than one function template declaration:\n %s\nand:\n %s", | |
1252 td_best.toChars(), td_ambig.toChars()); | |
1253 } | |
1254 | |
1255 /* The best match is td_best with arguments tdargs. | |
1256 * Now instantiate the template. | |
1257 */ | |
1258 assert(cast(size_t)cast(void*)td_best.scope_ > 0x10000); | |
1259 ti = new TemplateInstance(loc, td_best, tdargs); | |
1260 ti.semantic(sc); | |
1261 fd = ti.toAlias().isFuncDeclaration(); | |
1262 if (!fd) | |
1263 goto Lerror; | |
1264 return fd; | |
1265 | |
1266 Lerror: | |
1267 /// version (DMDV2) { | |
1268 if (!(flags & 1)) | |
1269 /// } | |
1270 { | |
1271 HdrGenState hgs; | |
1272 | |
1273 scope OutBuffer bufa = new OutBuffer(); | |
1274 Objects args = targsi; | |
1275 if (args) | |
1276 { | |
1277 for (int i = 0; i < args.dim; i++) | |
1278 { | |
1279 if (i) | |
1280 bufa.writeByte(','); | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
1281 Object oarg = args[i]; |
0 | 1282 ObjectToCBuffer(bufa, &hgs, oarg); |
1283 } | |
1284 } | |
1285 | |
1286 scope OutBuffer buf = new OutBuffer(); | |
1287 argExpTypesToCBuffer(buf, fargs, &hgs); | |
1288 error(loc, "cannot deduce template function from argument types !(%s)(%s)", bufa.toChars(), buf.toChars()); | |
1289 } | |
1290 return null; | |
1291 } | |
1292 | |
1293 /************************************************** | |
1294 * Declare template parameter tp with value o, and install it in the scope sc. | |
1295 */ | |
104 | 1296 void declareParameter(Scope sc, TemplateParameter tp, Object o) |
0 | 1297 { |
1298 //printf("TemplateDeclaration.declareParameter('%s', o = %p)\n", tp.ident.toChars(), o); | |
1299 | |
1300 Type targ = isType(o); | |
1301 Expression ea = isExpression(o); | |
1302 Dsymbol sa = isDsymbol(o); | |
1303 Tuple va = isTuple(o); | |
1304 | |
1305 Dsymbol s; | |
1306 | |
1307 // See if tp.ident already exists with a matching definition | |
1308 Dsymbol scopesym; | |
1309 s = sc.search(loc, tp.ident, &scopesym); | |
1310 if (s && scopesym == sc.scopesym) | |
1311 { | |
1312 TupleDeclaration td = s.isTupleDeclaration(); | |
1313 if (va && td) | |
1314 { | |
1315 Tuple tup = new Tuple(); | |
1316 assert(false); // < not implemented | |
1317 ///tup.objects = *td.objects; | |
1318 if (match(va, tup, this, sc)) | |
1319 { | |
1320 return; | |
1321 } | |
1322 } | |
1323 } | |
1324 | |
1325 if (targ) | |
1326 { | |
1327 //printf("type %s\n", targ.toChars()); | |
1328 s = new AliasDeclaration(Loc(0), tp.ident, targ); | |
1329 } | |
1330 else if (sa) | |
1331 { | |
1332 //printf("Alias %s %s;\n", sa.ident.toChars(), tp.ident.toChars()); | |
1333 s = new AliasDeclaration(Loc(0), tp.ident, sa); | |
1334 } | |
1335 else if (ea) | |
1336 { | |
1337 // tdtypes.data[i] always matches ea here | |
1338 Initializer init = new ExpInitializer(loc, ea); | |
1339 TemplateValueParameter tvp = tp.isTemplateValueParameter(); | |
1340 | |
1341 Type t = tvp ? tvp.valType : null; | |
1342 | |
1343 VarDeclaration v = new VarDeclaration(loc, t, tp.ident, init); | |
1344 v.storage_class = STCmanifest; | |
1345 s = v; | |
1346 } | |
1347 else if (va) | |
1348 { | |
1349 //printf("\ttuple\n"); | |
1350 s = new TupleDeclaration(loc, tp.ident, va.objects); | |
1351 } | |
1352 else | |
1353 { | |
1354 debug writefln(o.toString()); | |
1355 assert(0); | |
1356 } | |
1357 | |
1358 if (!sc.insert(s)) | |
1359 error("declaration %s is already defined", tp.ident.toChars()); | |
1360 | |
1361 s.semantic(sc); | |
1362 } | |
1363 | |
104 | 1364 override TemplateDeclaration isTemplateDeclaration() { return this; } |
0 | 1365 |
104 | 1366 TemplateTupleParameter isVariadic() |
0 | 1367 { |
1368 return .isVariadic(parameters); | |
1369 } | |
1370 | |
63 | 1371 /*********************************** |
1372 * We can overload templates. | |
1373 */ | |
104 | 1374 override bool isOverloadable() |
0 | 1375 { |
104 | 1376 return true; |
0 | 1377 } |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1378 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1379 /**************************** |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1380 * Declare all the function parameters as variables |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1381 * and add them to the scope |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1382 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1383 void makeParamNamesVisibleInConstraint(Scope paramscope) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1384 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1385 /* We do this ONLY if there is only one function in the template. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1386 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1387 FuncDeclaration fd = onemember && onemember.toAlias() ? |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1388 onemember.toAlias().isFuncDeclaration() : NULL; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1389 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1390 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1391 paramscope.parent = fd; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1392 Parameters fparameters; // function parameter list |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1393 int fvarargs; // function varargs |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1394 if (fd.type) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1395 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1396 assert(fd.type.ty == Tfunction); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1397 TypeFunction fdtype = cast(TypeFunction )fd.type; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1398 fparameters = fdtype.parameters; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1399 fvarargs = fdtype.varargs; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1400 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1401 else // Constructors don't have type's |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1402 { CtorDeclaration fctor = fd.isCtorDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1403 assert(fctor); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1404 fparameters = fctor.arguments; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1405 fvarargs = fctor.varargs; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1406 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1407 size_t nfparams = Parameter.dim(fparameters); // Num function parameters |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1408 for (int i = 0; i < nfparams; i++) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1409 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1410 Parameter fparam = Parameter.getNth(fparameters, i).syntaxCopy(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1411 if (!fparam.ident) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1412 continue; // don't add it, if it has no name |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1413 Type vtype = fparam.type.syntaxCopy(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1414 // isPure will segfault if called on a ctor, because fd->type is null. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1415 if (fd.type && fd.isPure()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1416 vtype = vtype.addMod(MODconst); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1417 VarDeclaration v = new VarDeclaration(loc, vtype, fparam.ident, null); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1418 v.storage_class |= STCparameter; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1419 // Not sure if this condition is correct/necessary. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1420 // It's from func.c |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1421 if (//fd->type && fd->type->ty == Tfunction && |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1422 fvarargs == 2 && i + 1 == nfparams) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1423 v.storage_class |= STCvariadic; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1424 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1425 v.storage_class |= fparam.storageClass & (STCin | STCout | STCref | STClazy | STCfinal | STC_TYPECTOR | STCnodtor); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1426 v.semantic(paramscope); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1427 if (!paramscope.insert(v)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1428 error("parameter %s.%s is already defined", toChars(), v.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1429 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1430 v.parent = this; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1431 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1432 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1433 } |
72 | 1434 } |