Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/SpecializationGroup.java @ 11438:b77721210bd6
Truffle-DSL: fix NPE with nodes with no frame in the execute method.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 27 Aug 2013 18:11:35 +0200 |
parents | 7fc3e1fb3965 |
children | 2868b55001d4 |
rev | line source |
---|---|
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.node; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.util.*; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.dsl.processor.template.TemplateMethod.Signature; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.dsl.processor.typesystem.*; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 /** |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 * Class creates groups of specializations to optimize the layout of generated executeAndSpecialize |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 * and generic execute methods. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 */ |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 public final class SpecializationGroup { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 private final List<String> assumptions; |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
37 private final List<TypeGuard> typeGuards; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 private final List<GuardData> guards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 private final SpecializationData specialization; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 private final List<SpecializationGroup> children = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 private SpecializationGroup parent; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 private SpecializationGroup(SpecializationData data) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 this.assumptions = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 this.typeGuards = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 this.guards = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 this.specialization = data; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 this.assumptions.addAll(data.getAssumptions()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 Signature sig = data.getSignature(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 for (int i = 1; i < sig.size(); i++) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
54 typeGuards.add(new TypeGuard(sig.get(i), i - 1)); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 this.guards.addAll(data.getGuards()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
59 public SpecializationGroup(List<SpecializationGroup> children, List<String> assumptionMatches, List<TypeGuard> typeGuardsMatches, List<GuardData> guardMatches) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 this.assumptions = assumptionMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 this.typeGuards = typeGuardsMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 this.guards = guardMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 this.specialization = null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 updateChildren(children); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
67 public TypeGuard findTypeGuard(int signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
68 for (TypeGuard guard : typeGuards) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
69 if (guard.getSignatureIndex() == signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
70 return guard; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
71 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
72 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
73 return null; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
74 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
75 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
76 public GuardData getElseConnectableGuard() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
77 if (!getTypeGuards().isEmpty() || !getAssumptions().isEmpty()) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
78 return null; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
79 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
80 SpecializationGroup previousGroup = getPreviousGroup(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
81 if (previousGroup != null && getGuards().size() >= 1 && previousGroup.getGuards().size() == 1) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
82 GuardData guard = getGuards().get(0); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
83 GuardData previousGuard = previousGroup.getGuards().get(0); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
84 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
85 if (guard.getMethod().equals(previousGuard.getMethod())) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
86 assert guard.isNegated() != previousGuard.isNegated(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
87 return guard; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
88 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
89 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
90 return null; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
91 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
92 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 private void updateChildren(List<SpecializationGroup> childs) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 if (!children.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 children.clear(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 this.children.addAll(childs); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 for (SpecializationGroup child : childs) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 child.parent = this; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 public SpecializationGroup getParent() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 return parent; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 public List<String> getAssumptions() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 return assumptions; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
111 public List<TypeGuard> getTypeGuards() { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 return typeGuards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 public List<GuardData> getGuards() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 return guards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 public List<SpecializationGroup> getChildren() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 return children; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 public SpecializationData getSpecialization() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 return specialization; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 private static SpecializationGroup combine(List<SpecializationGroup> groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 if (groups.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 throw new IllegalArgumentException("empty combinations"); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 if (groups.size() == 1) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
134 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 List<String> assumptionMatches = new ArrayList<>(); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
136 List<TypeGuard> typeGuardsMatches = new ArrayList<>(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 List<GuardData> guardMatches = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 SpecializationGroup first = groups.get(0); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 List<SpecializationGroup> others = groups.subList(1, groups.size()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 outer: for (String assumption : first.assumptions) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 for (SpecializationGroup other : others) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 if (!other.assumptions.contains(assumption)) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 // assumptions can be combined unordered |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 continue outer; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 assumptionMatches.add(assumption); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
152 outer: for (TypeGuard typeGuard : first.typeGuards) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 for (SpecializationGroup other : others) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
154 if (!other.typeGuards.contains(typeGuard)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
155 // type guards can be combined unordered |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
156 continue outer; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
159 typeGuardsMatches.add(typeGuard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
162 outer: for (GuardData guard : first.guards) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 for (SpecializationGroup other : others) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 if (!other.guards.contains(guard)) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 // we must break here. One guard may depend on the other. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 break outer; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
167 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
169 guardMatches.add(guard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
170 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
171 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
172 if (assumptionMatches.isEmpty() && typeGuardsMatches.isEmpty() && guardMatches.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
173 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
174 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
175 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
176 for (SpecializationGroup group : groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
177 group.assumptions.removeAll(assumptionMatches); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
178 group.typeGuards.removeAll(typeGuardsMatches); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
179 group.guards.removeAll(guardMatches); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
182 List<SpecializationGroup> newChildren = new ArrayList<>(groups); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
183 return new SpecializationGroup(newChildren, assumptionMatches, typeGuardsMatches, guardMatches); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
184 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
185 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
186 public static SpecializationGroup create(List<SpecializationData> specializations) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
187 List<SpecializationGroup> groups = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
188 for (SpecializationData specialization : specializations) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
189 groups.add(new SpecializationGroup(specialization)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
190 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
191 return new SpecializationGroup(createCombinationalGroups(groups), Collections.<String> emptyList(), Collections.<TypeGuard> emptyList(), Collections.<GuardData> emptyList()); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
192 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
193 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
194 @Override |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
195 public String toString() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
196 return "SpecializationGroup [assumptions=" + assumptions + ", typeGuards=" + typeGuards + ", guards=" + guards + "]"; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
197 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
198 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
199 private static List<SpecializationGroup> createCombinationalGroups(List<SpecializationGroup> groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
200 if (groups.size() <= 1) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
201 return groups; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
202 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
203 List<SpecializationGroup> newGroups = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
204 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
205 int i = 0; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
206 for (i = 0; i < groups.size();) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
207 SpecializationGroup combined = null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
208 for (int j = groups.size(); j > i + 1; j--) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
209 combined = combine(groups.subList(i, j)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
210 if (combined != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
211 break; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
213 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
214 SpecializationGroup newGroup; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
215 if (combined == null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
216 newGroup = groups.get(i); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
217 i++; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
218 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
219 newGroup = combined; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
220 List<SpecializationGroup> originalGroups = new ArrayList<>(combined.children); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
221 combined.updateChildren(createCombinationalGroups(originalGroups)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
222 i += originalGroups.size(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
223 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
224 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
225 newGroups.add(newGroup); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
226 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
227 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
228 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
229 return newGroups; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
230 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
231 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
232 public SpecializationGroup getPreviousGroup() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
233 if (parent == null || parent.children.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
234 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
235 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
236 int index = parent.children.indexOf(this); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
237 if (index <= 0) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
238 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
239 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
240 return parent.children.get(index - 1); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
241 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
242 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
243 public int getMaxSpecializationIndex() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
244 if (specialization != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
245 return specialization.getNode().getSpecializations().indexOf(specialization); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
246 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
247 int max = Integer.MIN_VALUE; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
248 for (SpecializationGroup childGroup : getChildren()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
249 max = Math.max(max, childGroup.getMaxSpecializationIndex()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
250 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
251 return max; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
252 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
253 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
254 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
255 public static final class TypeGuard { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
256 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
257 private final int signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
258 private final TypeData type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
259 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
260 public TypeGuard(TypeData type, int signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
261 this.type = type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
262 this.signatureIndex = signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
263 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
264 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
265 @Override |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
266 public int hashCode() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
267 final int prime = 31; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
268 int result = 1; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
269 result = prime * result + signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
270 result = prime * result + type.hashCode(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
271 return result; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
272 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
273 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
274 @Override |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
275 public boolean equals(Object obj) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
276 if (this == obj) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
277 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
278 } else if (obj == null) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
279 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
280 } else if (getClass() != obj.getClass()) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
281 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
282 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
283 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
284 TypeGuard other = (TypeGuard) obj; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
285 if (signatureIndex != other.signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
286 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
287 } else if (!type.equals(other.type)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
288 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
289 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
290 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
291 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
292 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
293 public int getSignatureIndex() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
294 return signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
295 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
296 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
297 public TypeData getType() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
298 return type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
299 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
300 } |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
301 } |