comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/TemplateMethod.java @ 13527:25ecb47a6d0e

Truffle-DSL: Added support for references to child arrays in @ShortCircuit; Introduced new layer NodeExecutionData to the implementation model which is in between NodeChildData and the actual parameters..
author Christian Humer <christian.humer@gmail.com>
date Tue, 07 Jan 2014 12:22:47 +0100
parents 2b9fcffd6f36
children 5a0c694ef735
comparison
equal deleted inserted replaced
13483:37ec2cabf397 13527:25ecb47a6d0e
27 import javax.lang.model.element.*; 27 import javax.lang.model.element.*;
28 import javax.lang.model.type.*; 28 import javax.lang.model.type.*;
29 29
30 import com.oracle.truffle.dsl.processor.*; 30 import com.oracle.truffle.dsl.processor.*;
31 import com.oracle.truffle.dsl.processor.typesystem.*; 31 import com.oracle.truffle.dsl.processor.typesystem.*;
32 import com.oracle.truffle.dsl.processor.util.*;
32 33
33 /** 34 /**
34 * Note: this class has a natural ordering that is inconsistent with equals. 35 * Note: this class has a natural ordering that is inconsistent with equals.
35 */ 36 */
36 public class TemplateMethod extends MessageContainer implements Comparable<TemplateMethod> { 37 public class TemplateMethod extends MessageContainer implements Comparable<TemplateMethod> {
131 } 132 }
132 } 133 }
133 return requiredParameters; 134 return requiredParameters;
134 } 135 }
135 136
137 public Iterable<ActualParameter> getSignatureParameters() {
138 return new FilteredIterable<>(getParameters(), new Predicate<ActualParameter>() {
139 public boolean evaluate(ActualParameter value) {
140 return value.getSpecification().isSignature();
141 }
142 });
143 }
144
136 public List<ActualParameter> getParameters() { 145 public List<ActualParameter> getParameters() {
137 return parameters; 146 return parameters;
138 } 147 }
139 148
140 public List<ActualParameter> findParameters(ParameterSpec spec) { 149 public List<ActualParameter> findParameters(ParameterSpec spec) {
211 signatureSize++; 220 signatureSize++;
212 } 221 }
213 return signatureSize; 222 return signatureSize;
214 } 223 }
215 224
216 public Signature getSignature() { 225 public TypeSignature getTypeSignature() {
217 Signature signature = new Signature(); 226 TypeSignature signature = new TypeSignature();
218 for (ActualParameter parameter : getReturnTypeAndParameters()) { 227 signature.types.add(getReturnType().getTypeSystemType());
219 if (!parameter.getSpecification().isSignature()) { 228 for (ActualParameter parameter : getSignatureParameters()) {
220 continue;
221 }
222 TypeData typeData = parameter.getTypeSystemType(); 229 TypeData typeData = parameter.getTypeSystemType();
223 if (typeData != null) { 230 if (typeData != null) {
224 signature.types.add(typeData); 231 signature.types.add(typeData);
225 } 232 }
226 } 233 }
239 index++; 246 index++;
240 } 247 }
241 return null; 248 return null;
242 } 249 }
243 250
244 public void updateSignature(Signature signature) { 251 public void updateSignature(TypeSignature signature) {
245 assert signature.size() >= 1; 252 assert signature.size() >= 1;
246 int signatureIndex = 0; 253 int signatureIndex = 0;
247 for (ActualParameter parameter : getReturnTypeAndParameters()) { 254 for (ActualParameter parameter : getReturnTypeAndParameters()) {
248 if (!parameter.getSpecification().isSignature()) { 255 if (!parameter.getSpecification().isSignature()) {
249 continue; 256 continue;
295 final TypeSystemData typeSystem = getTemplate().getTypeSystem(); 302 final TypeSystemData typeSystem = getTemplate().getTypeSystem();
296 if (typeSystem != compareMethod.getTemplate().getTypeSystem()) { 303 if (typeSystem != compareMethod.getTemplate().getTypeSystem()) {
297 throw new IllegalStateException("Cannot compare two methods with different type systems."); 304 throw new IllegalStateException("Cannot compare two methods with different type systems.");
298 } 305 }
299 306
300 List<TypeMirror> signature1 = getSignatureTypes(getReturnTypeAndParameters()); 307 List<TypeMirror> signature1 = getSignatureTypes(this);
301 List<TypeMirror> signature2 = getSignatureTypes(compareMethod.getReturnTypeAndParameters()); 308 List<TypeMirror> signature2 = getSignatureTypes(compareMethod);
302 if (signature1.size() != signature2.size()) { 309 if (signature1.size() != signature2.size()) {
303 return signature2.size() - signature1.size(); 310 return signature2.size() - signature1.size();
304 } 311 }
305 312
306 int result = 0; 313 int result = 0;
345 } 352 }
346 } 353 }
347 return Utils.getSimpleName(signature1).compareTo(Utils.getSimpleName(signature2)); 354 return Utils.getSimpleName(signature1).compareTo(Utils.getSimpleName(signature2));
348 } 355 }
349 356
350 public static List<TypeMirror> getSignatureTypes(List<ActualParameter> params) { 357 public static List<TypeMirror> getSignatureTypes(TemplateMethod method) {
351 List<TypeMirror> types = new ArrayList<>(); 358 List<TypeMirror> types = new ArrayList<>();
352 for (ActualParameter param : params) { 359 types.add(method.getReturnType().getType());
353 if (param.getSpecification().isSignature()) { 360 for (ActualParameter param : method.getSignatureParameters()) {
354 types.add(param.getType()); 361 types.add(param.getType());
355 }
356 } 362 }
357 return types; 363 return types;
358 } 364 }
359 365
360 public static class Signature implements Iterable<TypeData>, Comparable<Signature> { 366 public static class TypeSignature implements Iterable<TypeData>, Comparable<TypeSignature> {
361 367
362 final List<TypeData> types; 368 final List<TypeData> types;
363 369
364 public Signature() { 370 public TypeSignature() {
365 this.types = new ArrayList<>(); 371 this.types = new ArrayList<>();
366 } 372 }
367 373
368 public Signature(List<TypeData> signature) { 374 public TypeSignature(List<TypeData> signature) {
369 this.types = signature; 375 this.types = signature;
370 } 376 }
371 377
372 @Override 378 @Override
373 public int hashCode() { 379 public int hashCode() {
380 386
381 public TypeData get(int index) { 387 public TypeData get(int index) {
382 return types.get(index); 388 return types.get(index);
383 } 389 }
384 390
385 public int compareTo(Signature other) { 391 public int compareTo(TypeSignature other) {
386 if (this == other) { 392 if (this == other) {
387 return 0; 393 return 0;
388 } else if (types.size() != other.types.size()) { 394 } else if (types.size() != other.types.size()) {
389 return types.size() - other.types.size(); 395 return types.size() - other.types.size();
390 } else if (types.isEmpty()) { 396 } else if (types.isEmpty()) {
402 } 408 }
403 409
404 return 0; 410 return 0;
405 } 411 }
406 412
407 public Signature combine(Signature genericSignature, Signature other) { 413 public TypeSignature combine(TypeSignature genericSignature, TypeSignature other) {
408 assert types.size() == other.types.size(); 414 assert types.size() == other.types.size();
409 assert genericSignature.types.size() == other.types.size(); 415 assert genericSignature.types.size() == other.types.size();
410 416
411 if (this.equals(other)) { 417 if (this.equals(other)) {
412 return this; 418 return this;
413 } 419 }
414 420
415 Signature signature = new Signature(); 421 TypeSignature signature = new TypeSignature();
416 for (int i = 0; i < types.size(); i++) { 422 for (int i = 0; i < types.size(); i++) {
417 TypeData type1 = types.get(i); 423 TypeData type1 = types.get(i);
418 TypeData type2 = other.types.get(i); 424 TypeData type2 = other.types.get(i);
419 if (type1.equals(type2)) { 425 if (type1.equals(type2)) {
420 signature.types.add(type1); 426 signature.types.add(type1);
423 } 429 }
424 } 430 }
425 return signature; 431 return signature;
426 } 432 }
427 433
428 public boolean equalsParameters(Signature other) { 434 public boolean equalsParameters(TypeSignature other) {
429 if (size() != other.size()) { 435 if (size() != other.size()) {
430 return false; 436 return false;
431 } 437 }
432 return types.subList(1, types.size()).equals(other.types.subList(1, other.types.size())); 438 return types.subList(1, types.size()).equals(other.types.subList(1, other.types.size()));
433 } 439 }
434 440
435 @Override 441 @Override
436 public boolean equals(Object obj) { 442 public boolean equals(Object obj) {
437 if (obj instanceof Signature) { 443 if (obj instanceof TypeSignature) {
438 return ((Signature) obj).types.equals(types); 444 return ((TypeSignature) obj).types.equals(types);
439 } 445 }
440 return super.equals(obj); 446 return super.equals(obj);
441 } 447 }
442 448
443 public Iterator<TypeData> iterator() { 449 public Iterator<TypeData> iterator() {
447 @Override 453 @Override
448 public String toString() { 454 public String toString() {
449 return types.toString(); 455 return types.toString();
450 } 456 }
451 457
452 public boolean hasAnyParameterMatch(Signature other) { 458 public boolean hasAnyParameterMatch(TypeSignature other) {
453 for (int i = 1; i < types.size(); i++) { 459 for (int i = 1; i < types.size(); i++) {
454 TypeData type1 = types.get(i); 460 TypeData type1 = types.get(i);
455 TypeData type2 = other.types.get(i); 461 TypeData type2 = other.types.get(i);
456 if (type1.equals(type2)) { 462 if (type1.equals(type2)) {
457 return true; 463 return true;
458 } 464 }
459 } 465 }
460 return false; 466 return false;
461 } 467 }
462 468
463 public boolean isCompatibleTo(Signature signature) { 469 public boolean isCompatibleTo(TypeSignature signature) {
464 if (size() != signature.size()) { 470 if (size() != signature.size()) {
465 return false; 471 return false;
466 } 472 }
467 473
468 for (int i = 0; i < size(); i++) { 474 for (int i = 0; i < size(); i++) {