annotate dmd/TemplateDeclaration.d @ 49:0aa7d1437ada

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