Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/TemplateMethod.java @ 8592:a80bf36c6a1e
Refactor to shared template method signature comparison.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Apr 2013 11:52:38 +0200 |
parents | 89006c76f737 |
children | 8a1115c92271 |
comparison
equal
deleted
inserted
replaced
8591:5c58da5b8233 | 8592:a80bf36c6a1e |
---|---|
26 | 26 |
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.codegen.processor.*; | 30 import com.oracle.truffle.codegen.processor.*; |
31 import com.oracle.truffle.codegen.processor.typesystem.*; | |
31 | 32 |
32 public class TemplateMethod extends MessageContainer { | 33 public class TemplateMethod extends MessageContainer { |
33 | 34 |
34 private String id; | 35 private String id; |
35 private final Template template; | 36 private final Template template; |
159 } | 160 } |
160 prev = param; | 161 prev = param; |
161 } | 162 } |
162 return prev; | 163 return prev; |
163 } | 164 } |
165 | |
166 public List<TypeData> getSignature(TypeSystemData typeSystem) { | |
167 List<TypeData> types = new ArrayList<>(); | |
168 for (ActualParameter parameter : getReturnTypeAndParameters()) { | |
169 if (!parameter.getSpecification().isSignature()) { | |
170 continue; | |
171 } | |
172 TypeData typeData = parameter.getActualTypeData(typeSystem); | |
173 if (typeData != null) { | |
174 types.add(typeData); | |
175 } | |
176 } | |
177 return types; | |
178 } | |
179 | |
180 public int compareBySignature(TemplateMethod compareMethod) { | |
181 TypeSystemData typeSystem = getTemplate().getTypeSystem(); | |
182 if (typeSystem != compareMethod.getTemplate().getTypeSystem()) { | |
183 throw new IllegalStateException("Cannot compare two methods with different type systems."); | |
184 } | |
185 | |
186 List<TypeData> signature1 = getSignature(typeSystem); | |
187 List<TypeData> signature2 = compareMethod.getSignature(typeSystem); | |
188 if (signature1.size() != signature2.size()) { | |
189 return signature1.size() - signature2.size(); | |
190 } | |
191 | |
192 int result = 0; | |
193 for (int i = 0; i < signature1.size(); i++) { | |
194 int typeResult = compareActualParameter(typeSystem, signature1.get(i), signature2.get(i)); | |
195 if (result == 0) { | |
196 result = typeResult; | |
197 } else if (Math.signum(result) != Math.signum(typeResult)) { | |
198 // We cannot define an order. | |
199 return 0; | |
200 } | |
201 } | |
202 | |
203 return result; | |
204 } | |
205 | |
206 private static int compareActualParameter(TypeSystemData typeSystem, TypeData t1, TypeData t2) { | |
207 int index1 = typeSystem.findType(t1); | |
208 int index2 = typeSystem.findType(t2); | |
209 return index1 - index2; | |
210 } | |
211 | |
164 } | 212 } |