Mercurial > hg > truffle
annotate graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java @ 15146:65efd2eeea1b
Remove AbstractNodeIterable, move its methods to default methods on NodeIterable.
This allows to remove a number of duplicated methods in NodeList
NodeClassIterable is also interface instead of an abstract class.
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Mon, 14 Apr 2014 16:31:13 +0200 |
parents | 5e3d1a68664e |
children | 1f130000d700 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
23 package com.oracle.graal.graph.iterators; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
27 import com.oracle.graal.graph.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 |
15146
65efd2eeea1b
Remove AbstractNodeIterable, move its methods to default methods on NodeIterable.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
29 public class FilteredNodeIterable<T extends Node> implements NodeIterable<T> { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
30 |
5673
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
31 protected final NodeIterable<T> nodeIterable; |
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
32 protected NodePredicate predicate = NodePredicates.alwaysTrue(); |
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
33 protected NodePredicate until = NodePredicates.isNull(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
34 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 public FilteredNodeIterable(NodeIterable<T> nodeIterable) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 this.nodeIterable = nodeIterable; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
38 |
4328 | 39 public FilteredNodeIterable<T> and(NodePredicate nodePredicate) { |
40 this.predicate = this.predicate.and(nodePredicate); | |
41 return this; | |
42 } | |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
43 |
4328 | 44 public FilteredNodeIterable<T> or(NodePredicate nodePredicate) { |
45 this.predicate = this.predicate.or(nodePredicate); | |
46 return this; | |
47 } | |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
48 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 @Override |
4411
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
50 public NodeIterable<T> until(final T u) { |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
51 until = until.or(NodePredicates.equals(u)); |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
52 return this; |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
53 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
54 |
4411
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
55 @Override |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
56 public NodeIterable<T> until(final Class<? extends T> clazz) { |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
57 until = until.or(NodePredicates.isA(clazz)); |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
58 return this; |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
59 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
60 |
4411
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
61 @Override |
5435 | 62 public FilteredNodeIterable<T> nonNull() { |
7258
9bee93f61522
Cleanups: remove unused NodeUsagesList.replaceFirst and FrameState.block
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5673
diff
changeset
|
63 this.predicate = this.predicate.and(NodePredicates.isNotNull()); |
5435 | 64 return this; |
65 } | |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
66 |
5435 | 67 @Override |
5673
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
68 public DistinctFilteredNodeIterable<T> distinct() { |
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
69 DistinctFilteredNodeIterable<T> distinct = new DistinctFilteredNodeIterable<>(nodeIterable); |
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
70 distinct.predicate = predicate; |
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
71 distinct.until = until; |
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
72 return distinct; |
5435 | 73 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
74 |
5435 | 75 @Override |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 public Iterator<T> iterator() { |
5673
d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5608
diff
changeset
|
77 return new PredicatedProxyNodeIterator<>(until, nodeIterable.iterator(), predicate); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 } |
4411
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
79 |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
80 @SuppressWarnings("unchecked") |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
81 @Override |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
82 public <F extends T> FilteredNodeIterable<F> filter(Class<F> clazz) { |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
83 return (FilteredNodeIterable<F>) this.and(NodePredicates.isA(clazz)); |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
84 } |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
85 |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
86 @Override |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
87 public FilteredNodeIterable<T> filter(NodePredicate p) { |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
88 return this.and(p); |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
89 } |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
90 |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
91 @Override |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7258
diff
changeset
|
92 public FilteredNodeIterable<T> filterInterface(Class<?> iface) { |
4411
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
93 return this.and(NodePredicates.isAInterface(iface)); |
cd2b68ef8e23
cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4328
diff
changeset
|
94 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
95 } |