Mercurial > projects > ddmd
comparison dmd/TemplateValueParameter.d @ 40:caa9bdb08ae6
TemplateValueParameter.matchArg implemented
author | korDen |
---|---|
date | Sat, 21 Aug 2010 07:10:53 +0400 |
parents | d4825905adc2 |
children | ea4769860460 |
comparison
equal
deleted
inserted
replaced
39:d4825905adc2 | 40:caa9bdb08ae6 |
---|---|
10 import dmd.Identifier; | 10 import dmd.Identifier; |
11 import dmd.OutBuffer; | 11 import dmd.OutBuffer; |
12 import dmd.HdrGenState; | 12 import dmd.HdrGenState; |
13 import dmd.MATCH; | 13 import dmd.MATCH; |
14 import dmd.VarDeclaration; | 14 import dmd.VarDeclaration; |
15 import dmd.Initializer; | |
16 import dmd.ExpInitializer; | |
15 import dmd.STC; | 17 import dmd.STC; |
16 import dmd.Util; | 18 import dmd.Util; |
17 import dmd.TY; | 19 import dmd.TY; |
18 import dmd.WANT; | 20 import dmd.WANT; |
19 import dmd.TOK; | 21 import dmd.TOK; |
22 | |
23 import dmd.Dsymbol : isExpression; | |
20 | 24 |
21 class TemplateValueParameter : TemplateParameter | 25 class TemplateValueParameter : TemplateParameter |
22 { | 26 { |
23 /* Syntax: | 27 /* Syntax: |
24 * valType ident : specValue = defaultValue | 28 * valType ident : specValue = defaultValue |
140 return false; | 144 return false; |
141 } | 145 } |
142 | 146 |
143 MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) | 147 MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) |
144 { | 148 { |
145 assert(false); | 149 //printf("TemplateValueParameter.matchArg()\n"); |
150 | |
151 Initializer init; | |
152 Declaration sparam; | |
153 MATCH m = MATCHexact; | |
154 Expression ei; | |
155 Object oarg; | |
156 | |
157 if (i < tiargs.dim) | |
158 oarg = cast(Object)tiargs.data[i]; | |
159 else | |
160 { | |
161 // Get default argument instead | |
162 oarg = defaultArg(loc, sc); | |
163 if (!oarg) | |
164 { | |
165 assert(i < dedtypes.dim); | |
166 // It might have already been deduced | |
167 oarg = cast(Object)dedtypes.data[i]; | |
168 if (!oarg) | |
169 goto Lnomatch; | |
170 } | |
171 } | |
172 | |
173 ei = isExpression(oarg); | |
174 Type vt; | |
175 | |
176 if (!ei && oarg) | |
177 goto Lnomatch; | |
178 | |
179 if (ei && ei.op == TOKvar) | |
180 { | |
181 // Resolve const variables that we had skipped earlier | |
182 ei = ei.optimize(WANTvalue | WANTinterpret); | |
183 } | |
184 | |
185 if (specValue) | |
186 { | |
187 if (!ei || ei == edummy) | |
188 goto Lnomatch; | |
189 | |
190 Expression e = specValue; | |
191 | |
192 e = e.semantic(sc); | |
193 e = e.implicitCastTo(sc, valType); | |
194 e = e.optimize(WANTvalue | WANTinterpret); | |
195 //e.type = e.type.toHeadMutable(); | |
196 | |
197 ei = ei.syntaxCopy(); | |
198 ei = ei.semantic(sc); | |
199 ei = ei.optimize(WANTvalue | WANTinterpret); | |
200 //ei.type = ei.type.toHeadMutable(); | |
201 //printf("\tei: %s, %s\n", ei.toChars(), ei.type.toChars()); | |
202 //printf("\te : %s, %s\n", e.toChars(), e.type.toChars()); | |
203 if (!ei.equals(e)) | |
204 goto Lnomatch; | |
205 } | |
206 else if (dedtypes.data[i]) | |
207 { // Must match already deduced value | |
208 Expression e = cast(Expression)dedtypes.data[i]; | |
209 | |
210 if (!ei || !ei.equals(e)) | |
211 goto Lnomatch; | |
212 } | |
213 Lmatch: | |
214 //printf("\tvalType: %s, ty = %d\n", valType.toChars(), valType.ty); | |
215 vt = valType.semantic(Loc(0), sc); | |
216 //printf("ei: %s, ei.type: %s\n", ei.toChars(), ei.type.toChars()); | |
217 //printf("vt = %s\n", vt.toChars()); | |
218 if (ei.type) | |
219 { | |
220 m = cast(MATCH)ei.implicitConvTo(vt); | |
221 //printf("m: %d\n", m); | |
222 if (!m) | |
223 goto Lnomatch; | |
224 } | |
225 dedtypes.data[i] = cast(void*)ei; | |
226 | |
227 init = new ExpInitializer(loc, ei); | |
228 sparam = new VarDeclaration(loc, vt, ident, init); | |
229 sparam.storage_class = STCmanifest; | |
230 *psparam = sparam; | |
231 return m; | |
232 | |
233 Lnomatch: | |
234 //printf("\tno match\n"); | |
235 *psparam = null; | |
236 return MATCHnomatch; | |
146 } | 237 } |
147 | 238 |
148 void* dummyArg() | 239 void* dummyArg() |
149 { | 240 { |
150 assert(false); | 241 assert(false); |