Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/MethodSpecParser.java @ 20938:18c0f02fa4d2
Truffle-DSL: make type systems optional.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 15:12:48 +0200 |
parents | 62c43fcf5be2 |
children | 476374f3fe9a |
comparison
equal
deleted
inserted
replaced
20937:37ea76052733 | 20938:18c0f02fa4d2 |
---|---|
44 this.template = template; | 44 this.template = template; |
45 } | 45 } |
46 | 46 |
47 public Template getTemplate() { | 47 public Template getTemplate() { |
48 return template; | 48 return template; |
49 } | |
50 | |
51 public TypeSystemData getTypeSystem() { | |
52 return template.getTypeSystem(); | |
53 } | 49 } |
54 | 50 |
55 public boolean isEmitErrors() { | 51 public boolean isEmitErrors() { |
56 return emitErrors; | 52 return emitErrors; |
57 } | 53 } |
133 * Parameter parsing tries to parse required arguments starting from offset 0 with increasing | 129 * Parameter parsing tries to parse required arguments starting from offset 0 with increasing |
134 * offset until it finds a signature end that matches the required specification. If there is no | 130 * offset until it finds a signature end that matches the required specification. If there is no |
135 * end matching the required arguments, parsing fails. Parameters prior to the parsed required | 131 * end matching the required arguments, parsing fails. Parameters prior to the parsed required |
136 * ones are cut and used to parse the optional parameters. | 132 * ones are cut and used to parse the optional parameters. |
137 */ | 133 */ |
138 private List<Parameter> parseParameters(MethodSpec spec, List<? extends VariableElement> parameterTypes, boolean varArgs) { | 134 private static List<Parameter> parseParameters(MethodSpec spec, List<? extends VariableElement> parameterTypes, boolean varArgs) { |
139 List<Parameter> parsedRequired = null; | 135 List<Parameter> parsedRequired = null; |
140 int offset = 0; | 136 int offset = 0; |
141 for (; offset <= parameterTypes.size(); offset++) { | 137 for (; offset <= parameterTypes.size(); offset++) { |
142 List<VariableElement> parameters = new ArrayList<>(); | 138 List<VariableElement> parameters = new ArrayList<>(); |
143 parameters.addAll(parameterTypes.subList(offset, parameterTypes.size())); | 139 parameters.addAll(parameterTypes.subList(offset, parameterTypes.size())); |
164 finalParameters.addAll(parsedOptionals); | 160 finalParameters.addAll(parsedOptionals); |
165 finalParameters.addAll(parsedRequired); | 161 finalParameters.addAll(parsedRequired); |
166 return finalParameters; | 162 return finalParameters; |
167 } | 163 } |
168 | 164 |
169 private List<Parameter> parseParametersOptional(MethodSpec spec, List<? extends VariableElement> types) { | 165 private static List<Parameter> parseParametersOptional(MethodSpec spec, List<? extends VariableElement> types) { |
170 List<Parameter> parsedParams = new ArrayList<>(); | 166 List<Parameter> parsedParams = new ArrayList<>(); |
171 | 167 |
172 int typeStartIndex = 0; | 168 int typeStartIndex = 0; |
173 List<ParameterSpec> specifications = spec.getOptional(); | 169 List<ParameterSpec> specifications = spec.getOptional(); |
174 outer: for (int specIndex = 0; specIndex < specifications.size(); specIndex++) { | 170 outer: for (int specIndex = 0; specIndex < specifications.size(); specIndex++) { |
189 return null; | 185 return null; |
190 } | 186 } |
191 return parsedParams; | 187 return parsedParams; |
192 } | 188 } |
193 | 189 |
194 private List<Parameter> parseParametersRequired(MethodSpec spec, List<VariableElement> types, boolean typeVarArgs) { | 190 private static List<Parameter> parseParametersRequired(MethodSpec spec, List<VariableElement> types, boolean typeVarArgs) { |
195 List<Parameter> parsedParams = new ArrayList<>(); | 191 List<Parameter> parsedParams = new ArrayList<>(); |
196 List<ParameterSpec> specifications = spec.getRequired(); | 192 List<ParameterSpec> specifications = spec.getRequired(); |
197 boolean specVarArgs = spec.isVariableRequiredParameters(); | 193 boolean specVarArgs = spec.isVariableRequiredParameters(); |
198 int typeIndex = 0; | 194 int typeIndex = 0; |
199 int specificationIndex = 0; | 195 int specificationIndex = 0; |
246 } | 242 } |
247 | 243 |
248 return parsedParams; | 244 return parsedParams; |
249 } | 245 } |
250 | 246 |
251 private Parameter matchAnnotatedParameter(MethodSpec spec, VariableElement variable) { | 247 private static Parameter matchAnnotatedParameter(MethodSpec spec, VariableElement variable) { |
252 for (ParameterSpec parameterSpec : spec.getAnnotations()) { | 248 for (ParameterSpec parameterSpec : spec.getAnnotations()) { |
253 if (parameterSpec.matches(variable)) { | 249 if (parameterSpec.matches(variable)) { |
254 Parameter matchedParameter = matchParameter(parameterSpec, variable, -1, -1); | 250 Parameter matchedParameter = matchParameter(parameterSpec, variable, -1, -1); |
255 if (matchedParameter != null) { | 251 if (matchedParameter != null) { |
256 matchedParameter.setLocalName(variable.getSimpleName().toString()); | 252 matchedParameter.setLocalName(variable.getSimpleName().toString()); |
284 } else { | 280 } else { |
285 return null; | 281 return null; |
286 } | 282 } |
287 } | 283 } |
288 | 284 |
289 private Parameter matchParameter(ParameterSpec specification, VariableElement variable, int specificationIndex, int varArgsIndex) { | 285 private static Parameter matchParameter(ParameterSpec specification, VariableElement variable, int specificationIndex, int varArgsIndex) { |
290 TypeMirror resolvedType = variable.asType(); | 286 TypeMirror resolvedType = variable.asType(); |
291 if (hasError(resolvedType)) { | 287 if (hasError(resolvedType)) { |
292 return null; | 288 return null; |
293 } | 289 } |
294 | 290 |
295 if (!specification.matches(variable)) { | 291 if (!specification.matches(variable)) { |
296 return null; | 292 return null; |
297 } | 293 } |
298 | 294 |
299 TypeData resolvedTypeData = getTypeSystem().findTypeData(resolvedType); | 295 return new Parameter(specification, variable, specificationIndex, varArgsIndex); |
300 if (resolvedTypeData != null) { | 296 } |
301 return new Parameter(specification, resolvedTypeData, variable, specificationIndex, varArgsIndex); | |
302 } else { | |
303 return new Parameter(specification, variable, specificationIndex, varArgsIndex); | |
304 } | |
305 } | |
306 | |
307 } | 297 } |