Mercurial > hg > truffle
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java @ 19283:08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 23 Jan 2015 02:55:23 +0100 |
parents | c0fb70634640 |
children | 62c43fcf5be2 |
comparison
equal
deleted
inserted
replaced
19282:ae81dd154fb6 | 19283:08aa0372dad4 |
---|---|
22 */ | 22 */ |
23 package com.oracle.truffle.dsl.processor.model; | 23 package com.oracle.truffle.dsl.processor.model; |
24 | 24 |
25 import java.util.*; | 25 import java.util.*; |
26 | 26 |
27 import javax.lang.model.element.*; | |
28 | |
27 import com.oracle.truffle.dsl.processor.*; | 29 import com.oracle.truffle.dsl.processor.*; |
28 import com.oracle.truffle.dsl.processor.java.*; | |
29 | 30 |
30 public final class SpecializationData extends TemplateMethod { | 31 public final class SpecializationData extends TemplateMethod { |
31 | 32 |
32 public enum SpecializationKind { | 33 public enum SpecializationKind { |
33 UNINITIALIZED, | 34 UNINITIALIZED, |
38 | 39 |
39 private final NodeData node; | 40 private final NodeData node; |
40 private final SpecializationKind kind; | 41 private final SpecializationKind kind; |
41 private final List<SpecializationThrowsData> exceptions; | 42 private final List<SpecializationThrowsData> exceptions; |
42 private List<GuardExpression> guards = Collections.emptyList(); | 43 private List<GuardExpression> guards = Collections.emptyList(); |
44 private List<CacheExpression> caches = Collections.emptyList(); | |
45 private List<AssumptionExpression> assumptionExpressions = Collections.emptyList(); | |
43 private List<ShortCircuitData> shortCircuits; | 46 private List<ShortCircuitData> shortCircuits; |
44 private List<String> assumptions = Collections.emptyList(); | 47 private List<String> assumptions = Collections.emptyList(); |
45 private final Set<SpecializationData> contains = new TreeSet<>(); | 48 private final Set<SpecializationData> contains = new TreeSet<>(); |
46 private final Set<String> containsNames = new TreeSet<>(); | 49 private final Set<String> containsNames = new TreeSet<>(); |
47 private final Set<SpecializationData> excludedBy = new TreeSet<>(); | 50 private final Set<SpecializationData> excludedBy = new TreeSet<>(); |
60 for (SpecializationThrowsData exception : exceptions) { | 63 for (SpecializationThrowsData exception : exceptions) { |
61 exception.setSpecialization(this); | 64 exception.setSpecialization(this); |
62 } | 65 } |
63 } | 66 } |
64 | 67 |
68 public Parameter findByVariable(VariableElement variable) { | |
69 for (Parameter parameter : getParameters()) { | |
70 if (parameter.getVariableElement() == variable) { | |
71 return parameter; | |
72 } | |
73 } | |
74 return null; | |
75 } | |
76 | |
65 public void setInsertBefore(SpecializationData insertBefore) { | 77 public void setInsertBefore(SpecializationData insertBefore) { |
66 this.insertBefore = insertBefore; | 78 this.insertBefore = insertBefore; |
67 } | 79 } |
68 | 80 |
69 public void setInsertBeforeName(String insertBeforeName) { | 81 public void setInsertBeforeName(String insertBeforeName) { |
111 List<MessageContainer> sinks = new ArrayList<>(); | 123 List<MessageContainer> sinks = new ArrayList<>(); |
112 if (exceptions != null) { | 124 if (exceptions != null) { |
113 sinks.addAll(exceptions); | 125 sinks.addAll(exceptions); |
114 } | 126 } |
115 if (guards != null) { | 127 if (guards != null) { |
116 for (GuardExpression guard : guards) { | 128 sinks.addAll(guards); |
117 if (guard.isResolved()) { | |
118 sinks.add(guard.getResolvedGuard()); | |
119 } | |
120 } | |
121 } | 129 } |
122 return sinks; | 130 return sinks; |
123 } | 131 } |
124 | 132 |
125 public boolean hasRewrite(ProcessorContext context) { | 133 public boolean hasRewrite(ProcessorContext context) { |
282 @Override | 290 @Override |
283 public String toString() { | 291 public String toString() { |
284 return String.format("%s [id = %s, method = %s, guards = %s, signature = %s]", getClass().getSimpleName(), getId(), getMethod(), getGuards(), getTypeSignature()); | 292 return String.format("%s [id = %s, method = %s, guards = %s, signature = %s]", getClass().getSimpleName(), getId(), getMethod(), getGuards(), getTypeSignature()); |
285 } | 293 } |
286 | 294 |
287 public boolean isFrameUsedByGuard() { | 295 public boolean isFrameUsed() { |
288 for (GuardExpression guard : getGuards()) { | 296 return getFrame() != null; |
289 if (guard.getResolvedGuard() == null) { | 297 } |
290 continue; | 298 |
291 } | 299 public List<CacheExpression> getCaches() { |
292 | 300 return caches; |
293 for (Parameter param : guard.getResolvedGuard().getParameters()) { | 301 } |
294 if (ElementUtils.typeEquals(param.getType(), getNode().getFrameType())) { | 302 |
295 return true; | 303 public void setCaches(List<CacheExpression> caches) { |
296 } | 304 this.caches = caches; |
297 } | 305 } |
298 } | 306 |
299 | 307 public void setAssumptionExpressions(List<AssumptionExpression> assumptionExpressions) { |
300 return false; | 308 this.assumptionExpressions = assumptionExpressions; |
309 } | |
310 | |
311 public List<AssumptionExpression> getAssumptionExpressions() { | |
312 return assumptionExpressions; | |
301 } | 313 } |
302 | 314 |
303 public boolean isReachableAfter(SpecializationData prev) { | 315 public boolean isReachableAfter(SpecializationData prev) { |
304 if (!prev.isSpecialized()) { | 316 if (!prev.isSpecialized()) { |
305 return true; | 317 return true; |