Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/SpecializationData.java @ 13528:5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 07 Jan 2014 18:52:32 +0100 |
parents | 25ecb47a6d0e |
children | 85b485b1e8e1 |
comparison
equal
deleted
inserted
replaced
13527:25ecb47a6d0e | 13528:5a0c694ef735 |
---|---|
31 import com.oracle.truffle.dsl.processor.template.*; | 31 import com.oracle.truffle.dsl.processor.template.*; |
32 import com.oracle.truffle.dsl.processor.typesystem.*; | 32 import com.oracle.truffle.dsl.processor.typesystem.*; |
33 | 33 |
34 public class SpecializationData extends TemplateMethod { | 34 public class SpecializationData extends TemplateMethod { |
35 | 35 |
36 public enum SpecializationKind { | |
37 UNINITIALIZED, SPECIALIZED, POLYMORPHIC, GENERIC | |
38 } | |
39 | |
40 private final NodeData node; | |
36 private final int order; | 41 private final int order; |
37 private final boolean generic; | 42 private final SpecializationKind kind; |
38 private final boolean polymorphic; | |
39 private final boolean uninitialized; | |
40 private final List<SpecializationThrowsData> exceptions; | 43 private final List<SpecializationThrowsData> exceptions; |
41 private List<String> guardDefinitions = Collections.emptyList(); | 44 private List<String> guardDefinitions = Collections.emptyList(); |
42 private List<GuardData> guards = Collections.emptyList(); | 45 private List<GuardData> guards = 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 NodeData node; | |
46 private boolean reachable; | 48 private boolean reachable; |
47 | 49 |
48 public SpecializationData(TemplateMethod template, int order, List<SpecializationThrowsData> exceptions) { | 50 public SpecializationData(NodeData node, TemplateMethod template, SpecializationKind kind, int order, List<SpecializationThrowsData> exceptions) { |
49 super(template); | 51 super(template); |
52 this.node = node; | |
50 this.order = order; | 53 this.order = order; |
51 this.generic = false; | 54 this.kind = kind; |
52 this.uninitialized = false; | |
53 this.polymorphic = false; | |
54 this.exceptions = exceptions; | 55 this.exceptions = exceptions; |
55 | 56 |
56 for (SpecializationThrowsData exception : exceptions) { | 57 for (SpecializationThrowsData exception : exceptions) { |
57 exception.setSpecialization(this); | 58 exception.setSpecialization(this); |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 public SpecializationData(TemplateMethod template, boolean generic, boolean uninitialized, boolean polymorphic) { | 62 public SpecializationData(NodeData node, TemplateMethod template, SpecializationKind kind) { |
62 super(template); | 63 this(node, template, kind, Specialization.DEFAULT_ORDER, new ArrayList<SpecializationThrowsData>()); |
63 this.order = Specialization.DEFAULT_ORDER; | |
64 this.generic = generic; | |
65 this.uninitialized = uninitialized; | |
66 this.polymorphic = polymorphic; | |
67 this.exceptions = Collections.emptyList(); | |
68 } | 64 } |
69 | 65 |
70 public void setReachable(boolean reachable) { | 66 public void setReachable(boolean reachable) { |
71 this.reachable = reachable; | 67 this.reachable = reachable; |
72 } | 68 } |
74 public boolean isReachable() { | 70 public boolean isReachable() { |
75 return reachable; | 71 return reachable; |
76 } | 72 } |
77 | 73 |
78 public boolean isPolymorphic() { | 74 public boolean isPolymorphic() { |
79 return polymorphic; | 75 return kind == SpecializationKind.POLYMORPHIC; |
80 } | 76 } |
81 | 77 |
82 @Override | 78 @Override |
83 protected List<MessageContainer> findChildContainers() { | 79 protected List<MessageContainer> findChildContainers() { |
84 List<MessageContainer> sinks = new ArrayList<>(); | 80 List<MessageContainer> sinks = new ArrayList<>(); |
139 return super.compareBySignature(other); | 135 return super.compareBySignature(other); |
140 } | 136 } |
141 | 137 |
142 SpecializationData m2 = (SpecializationData) other; | 138 SpecializationData m2 = (SpecializationData) other; |
143 | 139 |
140 int kindOrder = kind.compareTo(m2.kind); | |
141 if (kindOrder != 0) { | |
142 return kindOrder; | |
143 } | |
144 if (getOrder() != Specialization.DEFAULT_ORDER && m2.getOrder() != Specialization.DEFAULT_ORDER) { | 144 if (getOrder() != Specialization.DEFAULT_ORDER && m2.getOrder() != Specialization.DEFAULT_ORDER) { |
145 return getOrder() - m2.getOrder(); | 145 return getOrder() - m2.getOrder(); |
146 } else if (isUninitialized() ^ m2.isUninitialized()) { | |
147 return isUninitialized() ? -1 : 1; | |
148 } else if (isGeneric() ^ m2.isGeneric()) { | |
149 return isGeneric() ? 1 : -1; | |
150 } | 146 } |
151 | 147 |
152 if (getTemplate() != m2.getTemplate()) { | 148 if (getTemplate() != m2.getTemplate()) { |
153 throw new UnsupportedOperationException("Cannot compare two specializations with different templates."); | 149 throw new UnsupportedOperationException("Cannot compare two specializations with different templates."); |
154 } | 150 } |
158 | 154 |
159 public NodeData getNode() { | 155 public NodeData getNode() { |
160 return node; | 156 return node; |
161 } | 157 } |
162 | 158 |
163 public void setNode(NodeData node) { | |
164 this.node = node; | |
165 } | |
166 | |
167 public void setGuards(List<GuardData> guards) { | 159 public void setGuards(List<GuardData> guards) { |
168 this.guards = guards; | 160 this.guards = guards; |
169 } | 161 } |
170 | 162 |
171 public void setGuardDefinitions(List<String> guardDefinitions) { | 163 public void setGuardDefinitions(List<String> guardDefinitions) { |
175 public int getOrder() { | 167 public int getOrder() { |
176 return order; | 168 return order; |
177 } | 169 } |
178 | 170 |
179 public boolean isSpecialized() { | 171 public boolean isSpecialized() { |
180 return !isGeneric() && !isUninitialized() && !isPolymorphic(); | 172 return kind == SpecializationKind.SPECIALIZED; |
181 } | 173 } |
182 | 174 |
183 public boolean isGeneric() { | 175 public boolean isGeneric() { |
184 return generic; | 176 return kind == SpecializationKind.GENERIC; |
185 } | 177 } |
186 | 178 |
187 public boolean isUninitialized() { | 179 public boolean isUninitialized() { |
188 return uninitialized; | 180 return kind == SpecializationKind.UNINITIALIZED; |
189 } | 181 } |
190 | 182 |
191 public List<SpecializationThrowsData> getExceptions() { | 183 public List<SpecializationThrowsData> getExceptions() { |
192 return exceptions; | 184 return exceptions; |
193 } | 185 } |