annotate graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java @ 4411:cd2b68ef8e23

cleanup around filter and predicates : remove duplicate compiler.util.NodeIterators add contains to NodeIterable support isNotA(Class).nor(Class) filtering support filtering on interfaces remove and/or(Class) from FilteredNodeIterable replace with isA(Class).or(Class) lower the cost on extending NodeIterable (remove the until field) NodeList is a NodeIterable Use NodeIterable functions where possible
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 30 Jan 2012 13:06:11 +0100
parents 60c48d99c28b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.max.graal.graph.iterators;
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
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import com.oracle.max.graal.graph.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 public class FilteredNodeIterable<T extends Node> extends NodeIterable<T> {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 private final NodeIterable<T> nodeIterable;
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
31 private NodePredicate predicate = NodePredicates.alwaysTrue();
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
32 private NodePredicate until = NodePredicates.isNull();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 public FilteredNodeIterable(NodeIterable<T> nodeIterable) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 this.nodeIterable = nodeIterable;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 }
4328
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
36 public FilteredNodeIterable<T> and(NodePredicate nodePredicate) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
37 this.predicate = this.predicate.and(nodePredicate);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
38 return this;
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
39 }
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
40 public FilteredNodeIterable<T> or(NodePredicate nodePredicate) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
41 this.predicate = this.predicate.or(nodePredicate);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
42 return this;
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4142
diff changeset
43 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 @Override
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
45 public NodeIterable<T> until(final T u) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
46 until = until.or(NodePredicates.equals(u));
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
47 return this;
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
48 }
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
49 @Override
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
50 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
51 until = until.or(NodePredicates.isA(clazz));
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 }
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
54 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 public Iterator<T> iterator() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 final Iterator<T> iterator = nodeIterable.iterator();
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
57 return new PredicatedProxyNodeIterator<>(until, iterator, predicate);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 }
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
59
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
60 @SuppressWarnings("unchecked")
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
61 @Override
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
62 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
63 return (FilteredNodeIterable<F>) this.and(NodePredicates.isA(clazz));
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
64 }
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
65
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
66 @Override
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
67 public FilteredNodeIterable<T> filter(NodePredicate p) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
68 return this.and(p);
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
69 }
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
70
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
71 @Override
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
72 public FilteredNodeIterable<T> filterInterface(Class< ? > iface) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
73 return this.and(NodePredicates.isAInterface(iface));
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4328
diff changeset
74 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 }