Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/SpecializationGroup.java @ 11758:4ac92e735a16
pylint fixes (retry)
author | Mick Jordan <mick.jordan@oracle.com> |
---|---|
date | Mon, 23 Sep 2013 21:57:44 -0700 |
parents | d6a5ab791b0d |
children | 85dcc7f59c34 |
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 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
27 import javax.lang.model.type.*; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
28 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
29 import com.oracle.truffle.dsl.processor.*; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
30 import com.oracle.truffle.dsl.processor.template.*; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 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
|
32 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
|
33 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 /** |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 * 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
|
36 * and generic execute methods. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 */ |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 public final class SpecializationGroup { |
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 List<String> assumptions; |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
41 private final List<TypeGuard> typeGuards; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 private final List<GuardData> guards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
44 private final NodeData node; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 private final SpecializationData specialization; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 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
|
47 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 private SpecializationGroup parent; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 private SpecializationGroup(SpecializationData data) { |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
51 this.node = data.getNode(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 this.assumptions = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 this.typeGuards = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 this.guards = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 this.specialization = data; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 this.assumptions.addAll(data.getAssumptions()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 Signature sig = data.getSignature(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 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
|
60 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
|
61 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 this.guards.addAll(data.getGuards()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
65 public SpecializationGroup(List<SpecializationGroup> children, List<String> assumptionMatches, List<TypeGuard> typeGuardsMatches, List<GuardData> guardMatches) { |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
66 assert !children.isEmpty() : "children must not be empty"; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 this.assumptions = assumptionMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 this.typeGuards = typeGuardsMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 this.guards = guardMatches; |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
70 this.node = children.get(0).node; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 this.specialization = null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 updateChildren(children); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
75 public List<TypeGuard> getAllGuards() { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
76 List<TypeGuard> collectedGuards = new ArrayList<>(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
77 collectedGuards.addAll(typeGuards); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
78 if (parent != null) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
79 collectedGuards.addAll(parent.getAllGuards()); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
80 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
81 return collectedGuards; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
82 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
83 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
84 public TypeGuard findTypeGuard(int signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
85 for (TypeGuard guard : typeGuards) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
86 if (guard.getSignatureIndex() == signatureIndex) { |
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 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
93 public List<GuardData> getElseConnectableGuards() { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
94 if (!getTypeGuards().isEmpty() || !getAssumptions().isEmpty()) { |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
95 return Collections.emptyList(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
96 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
97 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
98 if (getGuards().isEmpty()) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
99 return Collections.emptyList(); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
100 } |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
101 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
102 List<GuardData> elseConnectableGuards = new ArrayList<>(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
103 int guardIndex = 0; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
104 while (guardIndex < getGuards().size() && findNegatedGuardInPrevious(getGuards().get(guardIndex)) != null) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
105 elseConnectableGuards.add(getGuards().get(guardIndex)); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
106 guardIndex++; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
107 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
108 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
109 return elseConnectableGuards; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
110 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
111 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
112 private GuardData findNegatedGuardInPrevious(GuardData guard) { |
11481
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
113 SpecializationGroup previous = this.getPreviousGroup(); |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
114 if (previous == null) { |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
115 return null; |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
116 } |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
117 List<GuardData> elseConnectedGuards = previous.getElseConnectableGuards(); |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
118 |
11481
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
119 if (previous == null || previous.getGuards().size() != elseConnectedGuards.size() + 1) { |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
120 return null; |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
121 } |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
122 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
123 if (elseConnectedGuards.contains(guard)) { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
124 return guard; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
125 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
126 |
11481
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
127 GuardData previousGuard = previous.getGuards().get(elseConnectedGuards.size()); |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
128 if (guard.getMethod().equals(previousGuard.getMethod()) && guard.isNegated() != previousGuard.isNegated()) { |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
129 return guard; |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
130 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
131 return null; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
132 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
133 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
134 private void updateChildren(List<SpecializationGroup> childs) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 if (!children.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
136 children.clear(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 this.children.addAll(childs); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 for (SpecializationGroup child : childs) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 child.parent = this; |
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 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 public SpecializationGroup getParent() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 return parent; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 } |
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 public List<String> getAssumptions() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 return assumptions; |
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 public List<TypeGuard> getTypeGuards() { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 return typeGuards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
154 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
155 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
156 public List<GuardData> getGuards() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 return guards; |
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 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 public List<SpecializationGroup> getChildren() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 return children; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
162 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 public SpecializationData getSpecialization() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 return specialization; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 } |
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 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
|
169 if (groups.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
170 throw new IllegalArgumentException("empty combinations"); |
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 (groups.size() == 1) { |
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 List<String> assumptionMatches = new ArrayList<>(); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
177 List<TypeGuard> typeGuardsMatches = new ArrayList<>(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
178 List<GuardData> guardMatches = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
179 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 SpecializationGroup first = groups.get(0); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 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
|
182 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
183 outer: for (String assumption : first.assumptions) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
184 for (SpecializationGroup other : others) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
185 if (!other.assumptions.contains(assumption)) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
186 // assumptions can be combined unordered |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
187 continue outer; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
188 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
189 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
190 assumptionMatches.add(assumption); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
191 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
192 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
193 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
|
194 for (SpecializationGroup other : others) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
195 if (!other.typeGuards.contains(typeGuard)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
196 // type guards can be combined unordered |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
197 continue outer; |
11195
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 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
200 typeGuardsMatches.add(typeGuard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
201 } |
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 outer: for (GuardData guard : first.guards) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
204 for (SpecializationGroup other : others) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
205 if (!other.guards.contains(guard)) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
206 // 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
|
207 break outer; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
208 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
209 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
210 guardMatches.add(guard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
211 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
213 // check for guards for required type casts |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
214 for (Iterator<GuardData> iterator = guardMatches.iterator(); iterator.hasNext();) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
215 GuardData guardMatch = iterator.next(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
216 |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
217 int signatureIndex = 0; |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
218 for (ActualParameter parameter : guardMatch.getParameters()) { |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
219 signatureIndex++; |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
220 if (!parameter.getSpecification().isSignature()) { |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
221 continue; |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
222 } |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
223 |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
224 TypeMirror guardType = parameter.getType(); |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
225 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
226 // object guards can be safely moved up |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
227 if (Utils.isObject(guardType)) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
228 continue; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
229 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
230 |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
231 // generic guards can be safely moved up |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
232 SpecializationData generic = first.node.getGenericSpecialization(); |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
233 if (generic != null) { |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
234 ActualParameter genericParameter = generic.findParameter(parameter.getLocalName()); |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
235 if (genericParameter != null && Utils.typeEquals(genericParameter.getType(), guardType)) { |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
236 continue; |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
237 } |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
238 } |
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
239 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
240 // signature index required for moving up guards |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
241 if (containsIndex(typeGuardsMatches, signatureIndex) || (first.getParent() != null && first.getParent().containsTypeGuardIndex(signatureIndex))) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
242 continue; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
243 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
244 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
245 iterator.remove(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
246 break; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
247 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
248 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
249 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
250 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
|
251 return null; |
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 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
254 for (SpecializationGroup group : groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
255 group.assumptions.removeAll(assumptionMatches); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
256 group.typeGuards.removeAll(typeGuardsMatches); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
257 group.guards.removeAll(guardMatches); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
259 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
260 List<SpecializationGroup> newChildren = new ArrayList<>(groups); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
261 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
|
262 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
263 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
264 private boolean containsTypeGuardIndex(int index) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
265 if (containsIndex(typeGuards, index)) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
266 return true; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
267 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
268 if (parent != null) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
269 return parent.containsTypeGuardIndex(index); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
270 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
271 return false; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
272 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
273 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
274 private static boolean containsIndex(List<TypeGuard> typeGuards, int signatureIndex) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
275 for (TypeGuard guard : typeGuards) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
276 if (guard.signatureIndex == signatureIndex) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
277 return true; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
278 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
279 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
280 return false; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
281 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
282 |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
283 public static SpecializationGroup create(SpecializationData specialization) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
284 return new SpecializationGroup(specialization); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
285 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
286 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
287 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
|
288 List<SpecializationGroup> groups = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
289 for (SpecializationData specialization : specializations) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
290 groups.add(new SpecializationGroup(specialization)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
291 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
292 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
|
293 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
294 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
295 @Override |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
296 public String toString() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
297 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
|
298 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
299 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
300 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
|
301 if (groups.size() <= 1) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
302 return groups; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
303 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
304 List<SpecializationGroup> newGroups = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
305 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
306 int i = 0; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
307 for (i = 0; i < groups.size();) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
308 SpecializationGroup combined = null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
309 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
|
310 combined = combine(groups.subList(i, j)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
311 if (combined != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
312 break; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
313 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
314 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
315 SpecializationGroup newGroup; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
316 if (combined == null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
317 newGroup = groups.get(i); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
318 i++; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
319 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
320 newGroup = combined; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
321 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
|
322 combined.updateChildren(createCombinationalGroups(originalGroups)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
323 i += originalGroups.size(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
324 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
325 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
326 newGroups.add(newGroup); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
327 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
328 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
329 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
330 return newGroups; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
331 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
332 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
333 public SpecializationGroup getPreviousGroup() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
334 if (parent == null || parent.children.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
335 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
336 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
337 int index = parent.children.indexOf(this); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
338 if (index <= 0) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
339 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
340 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
341 return parent.children.get(index - 1); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
342 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
343 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
344 public int getMaxSpecializationIndex() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
345 if (specialization != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
346 return specialization.getNode().getSpecializations().indexOf(specialization); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
347 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
348 int max = Integer.MIN_VALUE; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
349 for (SpecializationGroup childGroup : getChildren()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
350 max = Math.max(max, childGroup.getMaxSpecializationIndex()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
351 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
352 return max; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
353 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
354 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
355 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
356 public static final class TypeGuard { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
357 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
358 private final int signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
359 private final TypeData type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
360 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
361 public TypeGuard(TypeData type, int signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
362 this.type = type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
363 this.signatureIndex = signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
364 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
365 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
366 @Override |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
367 public int hashCode() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
368 final int prime = 31; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
369 int result = 1; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
370 result = prime * result + signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
371 result = prime * result + type.hashCode(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
372 return result; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
373 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
374 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
375 @Override |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
376 public boolean equals(Object obj) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
377 if (this == obj) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
378 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
379 } else if (obj == null) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
380 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
381 } else if (getClass() != obj.getClass()) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
382 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
383 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
384 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
385 TypeGuard other = (TypeGuard) obj; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
386 if (signatureIndex != other.signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
387 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
388 } else if (!type.equals(other.type)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
389 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
390 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
391 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
392 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
393 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
394 public int getSignatureIndex() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
395 return signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
396 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
397 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
398 public TypeData getType() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
399 return type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
400 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
401 } |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
402 } |