Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/TemplateMethodParser.java @ 8310:89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 15 Mar 2013 21:18:33 +0100 |
parents | a219e2a5a92f |
children | 2be3865d9ea0 |
comparison
equal
deleted
inserted
replaced
8280:2ddf84436009 | 8310:89006c76f737 |
---|---|
157 return null; | 157 return null; |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 List<TypeMirror> parameterTypes = new ArrayList<>(); | 161 List<TypeMirror> parameterTypes = new ArrayList<>(); |
162 parameterTypes.addAll(methodSpecification.getImplicitTypes()); | |
163 for (VariableElement var : method.getParameters()) { | 162 for (VariableElement var : method.getParameters()) { |
164 parameterTypes.add(var.asType()); | 163 parameterTypes.add(var.asType()); |
165 } | 164 } |
166 | 165 |
167 List<ActualParameter> parameters = parseParameters(parameterTypes, parameterSpecs, methodSpecification.getImplicitTypes().size()); | 166 List<ActualParameter> parameters = parseParameters(parameterTypes, methodSpecification.getImplicitTypes(), parameterSpecs); |
168 if (parameters == null) { | 167 if (parameters == null) { |
169 if (isEmitErrors()) { | 168 if (isEmitErrors()) { |
170 E invalidMethod = create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<ActualParameter> emptyList())); | 169 E invalidMethod = create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<ActualParameter> emptyList())); |
171 String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(methodSpecification, method), | 170 String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(methodSpecification, method), |
172 createExpectedSignature(method.getSimpleName().toString(), returnTypeSpec, parameterSpecs, typeDefs)); | 171 createExpectedSignature(method.getSimpleName().toString(), returnTypeSpec, parameterSpecs, typeDefs)); |
198 } | 197 } |
199 b.append(")"); | 198 b.append(")"); |
200 return b.toString(); | 199 return b.toString(); |
201 } | 200 } |
202 | 201 |
203 private List<ActualParameter> parseParameters(List<TypeMirror> types, List<ParameterSpec> parameterSpecs, int hiddenCount) { | 202 private List<ActualParameter> parseParameters(List<TypeMirror> types, List<TypeMirror> implicitTypes, List<ParameterSpec> parameterSpecs) { |
204 Iterator<? extends TypeMirror> parameterIterator = types.iterator(); | 203 Iterator<? extends TypeMirror> parameterIterator = types.iterator(); |
204 Iterator<? extends TypeMirror> implicitParametersIterator = implicitTypes.iterator(); | |
205 Iterator<? extends ParameterSpec> specificationIterator = parameterSpecs.iterator(); | 205 Iterator<? extends ParameterSpec> specificationIterator = parameterSpecs.iterator(); |
206 | 206 |
207 TypeMirror parameter = parameterIterator.hasNext() ? parameterIterator.next() : null; | 207 TypeMirror parameter = parameterIterator.hasNext() ? parameterIterator.next() : null; |
208 TypeMirror implicitParameter = implicitParametersIterator.hasNext() ? implicitParametersIterator.next() : null; | |
208 ParameterSpec specification = specificationIterator.hasNext() ? specificationIterator.next() : null; | 209 ParameterSpec specification = specificationIterator.hasNext() ? specificationIterator.next() : null; |
209 | 210 |
210 int globalParameterIndex = 0; | |
211 int specificationParameterIndex = 0; | 211 int specificationParameterIndex = 0; |
212 List<ActualParameter> resolvedParameters = new ArrayList<>(); | 212 List<ActualParameter> resolvedParameters = new ArrayList<>(); |
213 while (parameter != null || specification != null) { | 213 while (parameter != null || specification != null) { |
214 if (parameter == null || specification == null) { | 214 if (parameter == null || specification == null) { |
215 if (specification != null && (specification.isOptional() || specification.getCardinality() == Cardinality.MULTIPLE)) { | 215 if (specification != null && (specification.isOptional() || specification.getCardinality() == Cardinality.MULTIPLE)) { |
218 continue; | 218 continue; |
219 } | 219 } |
220 return null; | 220 return null; |
221 } | 221 } |
222 | 222 |
223 boolean hidden = globalParameterIndex < hiddenCount; | 223 ActualParameter resolvedParameter = null; |
224 ActualParameter resolvedParameter = matchParameter(specification, parameter, template, specificationParameterIndex, hidden); | 224 |
225 boolean implicit = false; | |
226 if (implicitParameter != null) { | |
227 resolvedParameter = matchParameter(specification, implicitParameter, template, specificationParameterIndex, true); | |
228 if (resolvedParameter != null) { | |
229 implicit = true; | |
230 } | |
231 } | |
232 | |
233 if (resolvedParameter == null) { | |
234 resolvedParameter = matchParameter(specification, parameter, template, specificationParameterIndex, false); | |
235 } | |
236 | |
225 if (resolvedParameter == null) { | 237 if (resolvedParameter == null) { |
226 // mismatch | 238 // mismatch |
227 if (specification.isOptional()) { | 239 if (specification.isOptional()) { |
228 specification = specificationIterator.hasNext() ? specificationIterator.next() : null; | 240 specification = specificationIterator.hasNext() ? specificationIterator.next() : null; |
229 specificationParameterIndex = 0; | 241 specificationParameterIndex = 0; |
232 } | 244 } |
233 } else { | 245 } else { |
234 resolvedParameters.add(resolvedParameter); | 246 resolvedParameters.add(resolvedParameter); |
235 | 247 |
236 // match | 248 // match |
249 if (implicit) { | |
250 implicitParameter = implicitParametersIterator.hasNext() ? implicitParametersIterator.next() : null; | |
251 } else { | |
252 parameter = parameterIterator.hasNext() ? parameterIterator.next() : null; | |
253 } | |
254 | |
237 if (specification.getCardinality() == Cardinality.ONE) { | 255 if (specification.getCardinality() == Cardinality.ONE) { |
238 parameter = parameterIterator.hasNext() ? parameterIterator.next() : null; | |
239 specification = specificationIterator.hasNext() ? specificationIterator.next() : null; | 256 specification = specificationIterator.hasNext() ? specificationIterator.next() : null; |
240 globalParameterIndex++; | |
241 specificationParameterIndex = 0; | 257 specificationParameterIndex = 0; |
242 } else if (specification.getCardinality() == Cardinality.MULTIPLE) { | 258 } else if (specification.getCardinality() == Cardinality.MULTIPLE) { |
243 parameter = parameterIterator.hasNext() ? parameterIterator.next() : null; | |
244 globalParameterIndex++; | |
245 specificationParameterIndex++; | 259 specificationParameterIndex++; |
246 } | 260 } |
247 } | 261 } |
248 } | 262 } |
249 return resolvedParameters; | 263 return resolvedParameters; |
250 } | 264 } |
251 | 265 |
252 private ActualParameter matchParameter(ParameterSpec specification, TypeMirror mirror, Template typeSystem, int index, boolean hidden) { | 266 private ActualParameter matchParameter(ParameterSpec specification, TypeMirror mirror, Template typeSystem, int index, boolean implicit) { |
253 TypeMirror resolvedType = mirror; | 267 TypeMirror resolvedType = mirror; |
254 if (hasError(resolvedType)) { | 268 if (hasError(resolvedType)) { |
255 resolvedType = context.resolveNotYetCompiledType(mirror, typeSystem); | 269 resolvedType = context.resolveNotYetCompiledType(mirror, typeSystem); |
256 } | 270 } |
257 | 271 |
258 if (!specification.matches(resolvedType)) { | 272 if (!specification.matches(resolvedType)) { |
259 return null; | 273 return null; |
260 } | 274 } |
261 return new ActualParameter(specification, resolvedType, index, hidden); | 275 return new ActualParameter(specification, resolvedType, index, implicit); |
262 } | 276 } |
263 | 277 |
264 protected List<TypeDef> createTypeDefinitions(ParameterSpec returnType, List<? extends ParameterSpec> parameters) { | 278 protected List<TypeDef> createTypeDefinitions(ParameterSpec returnType, List<? extends ParameterSpec> parameters) { |
265 List<TypeDef> typeDefs = new ArrayList<>(); | 279 List<TypeDef> typeDefs = new ArrayList<>(); |
266 | 280 |