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